From fd54e703a044fdb2a0334e9815b6ce668b8acda0 Mon Sep 17 00:00:00 2001 From: Scott Fauerbach Date: Tue, 7 Sep 2021 21:27:54 -0400 Subject: [PATCH] updated readme gradle and maven for snapshots (#539) --- README.md | 40 ++++++- .../NatsJsPullSubExpireUseCases.java | 107 ++++++++++++------ .../nats/client/impl/JetStreamPullTests.java | 28 ++++- 3 files changed, 133 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index a2153d1b3..f089e1735 100644 --- a/README.md +++ b/README.md @@ -101,10 +101,22 @@ repositories { maven { url "https://oss.sonatype.org/content/repositories/releases" } +} +``` + +If you need a snapshot version, you must add the url for the snapshots and change your dependency. + +```groovy +repositories { + ... maven { url "https://oss.sonatype.org/content/repositories/snapshots" } } + +dependencies { + implementation 'io.nats:jnats:2.12.0-SNAPSHOT' +} ``` ### Using Maven @@ -126,10 +138,34 @@ If you need the absolute latest, before it propagates to maven central, you can latest-repo https://oss.sonatype.org/content/repositories/releases - true - false + + true + + + +``` + +If you need a snapshot version, you must enable snapshots and change your dependency. + +```xml + + + latest-repo + https://oss.sonatype.org/content/repositories/releases + + true + + + true + + + + io.nats + jnats + 2.12.0-SNAPSHOT + ``` If you are using the 1.x version of java-nats and don't want to upgrade to 2.0.0 please use ranges in your POM file, java-nats-streaming 1.x is using [1.1, 1.9.9) for this. diff --git a/src/examples/java/io/nats/examples/jetstream/NatsJsPullSubExpireUseCases.java b/src/examples/java/io/nats/examples/jetstream/NatsJsPullSubExpireUseCases.java index 9bd086427..09bc499c0 100644 --- a/src/examples/java/io/nats/examples/jetstream/NatsJsPullSubExpireUseCases.java +++ b/src/examples/java/io/nats/examples/jetstream/NatsJsPullSubExpireUseCases.java @@ -50,6 +50,10 @@ public static void main(String[] args) { try (Connection nc = Nats.connect(ExampleUtils.createExampleOptions(exArgs.server))) { NatsJsUtils.createOrUpdateStream(nc, exArgs.stream, exArgs.subject); + // after version 2.4.0 the server behavior changed regarding returning 408's + // and that it no longer returns any 408s + boolean no408sAreComing = nc.getServerInfo().isNewerVersionThan("2.4.0"); + // Create our JetStream context to receive JetStream messages. JetStream js = nc.jetStream(); @@ -66,71 +70,106 @@ public static void main(String[] args) { JetStreamSubscription sub = js.subscribe(exArgs.subject, pullOptions); nc.flush(Duration.ofSeconds(1)); - sub.pullExpiresIn(10, Duration.ofSeconds(2)); - // 1. Publish some that is less than the batch size. System.out.println("\n----------\n1. Publish some amount of messages, but not entire batch size."); publish(js, exArgs.subject, "A", 6); + sub.pullExpiresIn(10, Duration.ofMillis(1200)); List messages = readMessagesAck(sub, Duration.ofSeconds(2)); - System.out.println("We should have received 6 total messages, we received: " + messages.size()); - System.out.println("We should have received 6 regular messages, we received: " + countJs(messages)); - System.out.println("We should have received 0 408 markers of last batch, we received: " + count408s(messages)); + if (no408sAreComing) { + System.out.println("We should have received 6 total messages, we received: " + messages.size()); + } + else { + System.out.println("We should have received 6 total messages, we received: " + messages.size()); + System.out.println("We should have received 6 regular messages, we received: " + countJs(messages)); + System.out.println("We should have received 0 408 markers of last batch, we received: " + count408s(messages)); + } // 2. Publish some more covering our pull size... System.out.println("----------\n2. Publish more than the batch size."); - sub.pullExpiresIn(10, Duration.ofSeconds(2)); + sub.pullExpiresIn(10, Duration.ofMillis(1200)); publish(js, exArgs.subject, "B", 14); messages = readMessagesAck(sub, Duration.ofSeconds(2)); - System.out.println("We should have received 14 total messages, we received: " + messages.size()); - System.out.println("We should have received 10 regular messages, we received: " + countJs(messages)); - System.out.println("We should have received 4 408 markers of last batch, we received: " + count408s(messages)); + if (no408sAreComing) { + System.out.println("We should have received 10 total messages, we received: " + messages.size()); + } + else { + System.out.println("We should have received 14 total messages, we received: " + messages.size()); + System.out.println("We should have received 10 regular messages, we received: " + countJs(messages)); + System.out.println("We should have received 4 408 markers of last batch, we received: " + count408s(messages)); + } // 3. There are still 4 messages from B, but the batch was finished // - won't get any messages until a pull is issued. - System.out.println("----------\n3. Read without re-issue."); + System.out.println("----------\n3. Read without issuing a pull."); messages = readMessagesAck(sub, Duration.ofSeconds(2)); System.out.println("We should have received 0 total messages, we received: " + messages.size()); // 4. re-issue the pull to get the last 4 - System.out.println("----------\n4. Re-issue to get the last 4."); - sub.pullExpiresIn(10, Duration.ofSeconds(2)); + System.out.println("----------\n4. Issue the pull to get the last 4."); + sub.pullExpiresIn(10, Duration.ofMillis(1200)); messages = readMessagesAck(sub, Duration.ofSeconds(2)); - System.out.println("We should have received 4 total messages, we received: " + messages.size()); - System.out.println("We should have received 4 regular messages, we received: " + countJs(messages)); - System.out.println("We should have received 0 408 markers of last batch, we received: " + count408s(messages)); + if (no408sAreComing) { + System.out.println("We should have received 4 total messages, we received: " + messages.size()); + } + else { + System.out.println("We should have received 4 total messages, we received: " + messages.size()); + System.out.println("We should have received 4 regular messages, we received: " + countJs(messages)); + System.out.println("We should have received 0 408 markers of last batch, we received: " + count408s(messages)); + } // 5. publish a lot of messages System.out.println("----------\n5. Publish a lot of messages. The last pull was under the batch size."); + System.out.println( " Issue another pull with batch size less than number of messages."); publish(js, exArgs.subject, "C", 25); - sub.pullExpiresIn(10, Duration.ofSeconds(2)); + sub.pullExpiresIn(10, Duration.ofMillis(1200)); messages = readMessagesAck(sub, Duration.ofSeconds(2)); - System.out.println("We should have received 16 total messages, we received: " + messages.size()); - System.out.println("We should have received 10 regular messages, we received: " + countJs(messages)); - System.out.println("We should have received 6 408 markers of last batch, we received: " + count408s(messages)); + if (no408sAreComing) { + System.out.println("We should have received 10 total messages, we received: " + messages.size()); + } + else { + System.out.println("We should have received 16 total messages, we received: " + messages.size()); + System.out.println("We should have received 10 regular messages, we received: " + countJs(messages)); + System.out.println("We should have received 6 408 markers of last batch, we received: " + count408s(messages)); + } // 6. there are still more messages - System.out.println("----------\n6. Still more messages."); - sub.pullExpiresIn(10, Duration.ofSeconds(2)); + System.out.println("----------\n6. Still more messages. Issue another pull with batch size less than number of messages."); + sub.pullExpiresIn(10, Duration.ofMillis(1200)); messages = readMessagesAck(sub, Duration.ofSeconds(2)); - System.out.println("We should have received 1 total messages, we received: " + messages.size()); - System.out.println("We should have received 10 regular messages, we received: " + countJs(messages)); - System.out.println("We should have received 0 408 markers of last batch, we received: " + count408s(messages)); + if (no408sAreComing) { + System.out.println("We should have received 10 total messages, we received: " + messages.size()); + } + else { + System.out.println("We should have received 10 total messages, we received: " + messages.size()); + System.out.println("We should have received 10 regular messages, we received: " + countJs(messages)); + System.out.println("We should have received 0 408 markers of last batch, we received: " + count408s(messages)); + } // 7. there are still more messages - System.out.println("----------\n7. Still more messages."); - sub.pullExpiresIn(10, Duration.ofSeconds(2)); + System.out.println("----------\n7. Still more messages. Issue another pull with batch size more than number of messages."); + sub.pullExpiresIn(10, Duration.ofMillis(1200)); messages = readMessagesAck(sub, Duration.ofSeconds(2)); - System.out.println("We should have received 5 total messages, we received: " + messages.size()); - System.out.println("We should have received 5 regular messages, we received: " + countJs(messages)); - System.out.println("We should have received 0 408 markers of last batch, we received: " + count408s(messages)); + if (no408sAreComing) { + System.out.println("We should have received 5 total messages, we received: " + messages.size()); + } + else { + System.out.println("We should have received 5 total messages, we received: " + messages.size()); + System.out.println("We should have received 5 regular messages, we received: " + countJs(messages)); + System.out.println("We should have received 0 408 markers of last batch, we received: " + count408s(messages)); + } // 8. we got them all - System.out.println("----------\n7. No messages left."); - sub.pullExpiresIn(10, Duration.ofSeconds(2)); + System.out.println("----------\n8. No messages left."); + sub.pullExpiresIn(10, Duration.ofMillis(1200)); messages = readMessagesAck(sub, Duration.ofSeconds(2)); - System.out.println("We should have received 5 total messages, we received: " + messages.size()); - System.out.println("We should have received 0 regular messages, we received: " + countJs(messages)); - System.out.println("We should have received 5 408 markers of last batch, we received: " + count408s(messages)); + if (no408sAreComing) { + System.out.println("We should have received 0 total messages, we received: " + messages.size()); + } + else { + System.out.println("We should have received 5 total messages, we received: " + messages.size()); + System.out.println("We should have received 0 regular messages, we received: " + countJs(messages)); + System.out.println("We should have received 5 408 markers of last batch, we received: " + count408s(messages)); + } System.out.println("----------\n"); } diff --git a/src/test/java/io/nats/client/impl/JetStreamPullTests.java b/src/test/java/io/nats/client/impl/JetStreamPullTests.java index 377c6341d..1822935b0 100644 --- a/src/test/java/io/nats/client/impl/JetStreamPullTests.java +++ b/src/test/java/io/nats/client/impl/JetStreamPullTests.java @@ -318,6 +318,7 @@ public void testAfterIncompleteExpiresPulls() throws Exception { runInJsServer(nc -> { // Create our JetStream context to receive JetStream messages. JetStream js = nc.jetStream(); + boolean serverHasExpireChange = nc.getServerInfo().isNewerVersionThan("2.4.0"); // create the stream. createMemoryStream(nc, STREAM, SUBJECT); @@ -343,8 +344,13 @@ public void testAfterIncompleteExpiresPulls() throws Exception { jsPublish(js, SUBJECT, "B", 10); sub.pullExpiresIn(10, Duration.ofMillis(expires)); // using Duration version here messages = readMessagesAck(sub); - assertEquals(15, messages.size()); - assertStarts408(messages, 5, 10); + if (serverHasExpireChange) { + assertEquals(10, messages.size()); + } + else { + assertEquals(15, messages.size()); + assertStarts408(messages, 5, 10); + } sleep(expires); // make sure the pull actually expires jsPublish(js, SUBJECT, "C", 5); @@ -357,8 +363,13 @@ public void testAfterIncompleteExpiresPulls() throws Exception { jsPublish(js, SUBJECT, "D", 10); sub.pull(10); messages = readMessagesAck(sub); - assertEquals(15, messages.size()); - assertStarts408(messages, 5, 10); + if (serverHasExpireChange) { + assertEquals(10, messages.size()); + } + else { + assertEquals(15, messages.size()); + assertStarts408(messages, 5, 10); + } jsPublish(js, SUBJECT, "E", 5); sub.pullExpiresIn(10, expires); // using millis version here @@ -370,8 +381,13 @@ public void testAfterIncompleteExpiresPulls() throws Exception { jsPublish(js, SUBJECT, "F", 10); sub.pullNoWait(10); messages = readMessagesAck(sub); - assertEquals(15, messages.size()); - assertStarts408(messages, 5, 10); + if (serverHasExpireChange) { + assertEquals(10, messages.size()); + } + else { + assertEquals(15, messages.size()); + assertStarts408(messages, 5, 10); + } jsPublish(js, SUBJECT, "G", 5); sub.pullExpiresIn(10, expires); // using millis version here