Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of JsOptions timeout #953

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/io/nats/client/JetStreamOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
*/
public class JetStreamOptions {

@Deprecated
public static final Duration DEFAULT_TIMEOUT = Options.DEFAULT_CONNECTION_TIMEOUT;

public static final JetStreamOptions DEFAULT_JS_OPTIONS = new Builder().build();

private final String jsPrefix;
Expand Down Expand Up @@ -75,7 +77,7 @@ public boolean isDefaultPrefix() {
}

/**
* Gets the whether the publish no ack flag was set
* Gets whether the publish no ack flag was set
* @return the flag
*/
public boolean isPublishNoAck() {
Expand Down Expand Up @@ -203,7 +205,6 @@ public Builder optOut290ConsumerCreate(boolean optOut) {
* @return JetStream options
*/
public JetStreamOptions build() {
this.requestTimeout = requestTimeout == null ? DEFAULT_TIMEOUT : requestTimeout;
return new JetStreamOptions(this);
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/io/nats/client/impl/NatsJetStreamImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ public CachedStreamInfo(StreamInfo si) {
// ----------------------------------------------------------------------------------------------------
NatsJetStreamImpl(NatsConnection connection, JetStreamOptions jsOptions) throws IOException {
conn = connection;
jso = JetStreamOptions.builder(jsOptions).build(); // builder handles null

// Get a working version of JetStream Options...
// Clone the input jsOptions (JetStreamOptions.builder(...) handles null.
// If jsOptions is not supplied or the jsOptions request timeout
// was not set, use the connection options connect timeout.
Duration rt = jsOptions == null || jsOptions.getRequestTimeout() == null ? conn.getOptions().getConnectionTimeout() : jsOptions.getRequestTimeout();
jso = JetStreamOptions.builder(jsOptions).requestTimeout(rt).build();

consumerCreate290Available = conn.getInfo().isSameOrNewerThanVersion("2.9.0") && !jso.isOptOut290ConsumerCreate();
}

Expand Down Expand Up @@ -93,7 +100,7 @@ else if (durable == null) {
}

ConsumerCreateRequest ccr = new ConsumerCreateRequest(streamName, config);
Message resp = makeRequestResponseRequired(subj, ccr.serialize(), conn.getOptions().getConnectionTimeout());
Message resp = makeRequestResponseRequired(subj, ccr.serialize(), jso.getRequestTimeout());
return new ConsumerInfo(resp).throwOnHasError();
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/nats/client/JetStreamOptionsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public class JetStreamOptionsTests extends TestBase {
public void testBuilder() {
// default
JetStreamOptions jso = JetStreamOptions.defaultOptions();
assertEquals(Options.DEFAULT_CONNECTION_TIMEOUT, jso.getRequestTimeout());
assertNull(jso.getRequestTimeout());
assertEquals(DEFAULT_API_PREFIX, jso.getPrefix());
assertTrue(jso.isDefaultPrefix());
assertFalse(jso.isPublishNoAck());
assertFalse(jso.isOptOut290ConsumerCreate());

// default copy
jso = JetStreamOptions.builder(jso).build();
assertEquals(Options.DEFAULT_CONNECTION_TIMEOUT, jso.getRequestTimeout());
assertNull(jso.getRequestTimeout());
assertEquals(DEFAULT_API_PREFIX, jso.getPrefix());
assertTrue(jso.isDefaultPrefix());
assertFalse(jso.isPublishNoAck());
Expand Down Expand Up @@ -69,15 +69,15 @@ public void testBuilder() {
.publishNoAck(false)
.optOut290ConsumerCreate(false)
.build();
assertEquals(Options.DEFAULT_CONNECTION_TIMEOUT, jso.getRequestTimeout());
assertNull(jso.getRequestTimeout());
assertEquals("pre.", jso.getPrefix());
assertFalse(jso.isDefaultPrefix());
assertFalse(jso.isPublishNoAck());
assertFalse(jso.isOptOut290ConsumerCreate());

// variations / coverage copy
jso = JetStreamOptions.builder(jso).build();
assertEquals(Options.DEFAULT_CONNECTION_TIMEOUT, jso.getRequestTimeout());
assertNull(jso.getRequestTimeout());
assertEquals("pre.", jso.getPrefix());
assertFalse(jso.isDefaultPrefix());
assertFalse(jso.isPublishNoAck());
Expand Down