Skip to content

Commit

Permalink
Fix use of JsOptions timeout (#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf authored Aug 16, 2023
1 parent 04ac649 commit 154bcff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
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

0 comments on commit 154bcff

Please sign in to comment.