Skip to content

Commit

Permalink
push queue breaking change (#530)
Browse files Browse the repository at this point in the history
don't run test against server version after v2.3.4
building version comparisons into ServerInfo
added notes about version change
  • Loading branch information
scottf authored Aug 25, 2021
1 parent e24a3c2 commit f5963c6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 174 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ Version 2.5.0 adds some back pressure to publish calls to alleviate issues when

Previous versions are still available in the repo.

### Versions 2.11.6 and server versions

Version 2.11.6 is the last java-nats version which is supported to work with server v2.3.4 and earlier.
It will not be officially supported to work with servers after v2.3.4, but _should be fine_ if you don't use
the queue behavior advertised in example code `NatsJsPushSubQueueDurable.java` and provided with java-nats 2.11.5.
The example does not work correctly against server versions after server v2.3.4
due to a significant change made to correct _queue_ behavior that was considered wrong.

If you want to take advantage of the fixes and features provided in the server after v2.3.4,
you __must__ upgrade to the upcoming client release, version 2.12.0

### SSL/TLS Performance

After recent tests we realized that TLS performance is lower than we would like. After researching the problem and possible solutions we came to a few conclusions:
Expand Down

This file was deleted.

24 changes: 24 additions & 0 deletions src/main/java/io/nats/client/api/ServerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,30 @@ public String getCluster() {
return cluster;
}

private String getComparableVersion(String vString) {
try {
String[] v = vString.replaceAll("v", "").replaceAll("-", ".").split("\\Q.\\E");
int at = vString.indexOf("-");
return "" + (Integer.parseInt(v[0]) * 10000) + (Integer.parseInt(v[1]) * 100) + Integer.parseInt(v[2])
+ (at == -1 ? "" : vString.substring(at));
}
catch (NumberFormatException nfe) {
return "";
}
}

public boolean isNewerVersionThan(String vTarget) {
return getComparableVersion(version).compareTo(getComparableVersion(vTarget)) > 0;
}

public boolean isSameVersion(String vTarget) {
return getComparableVersion(version).compareTo(getComparableVersion(vTarget)) == 0;
}

public boolean isOlderThanVersion(String vTarget) {
return getComparableVersion(version).compareTo(getComparableVersion(vTarget)) < 0;
}

@Override
public String toString() {
return "ServerInfo{" +
Expand Down
18 changes: 17 additions & 1 deletion src/test/java/io/nats/client/api/ServerInfoTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testValidInfoString() {
ServerInfo info = new ServerInfo(json);
assertEquals("serverId", info.getServerId());
assertEquals("serverName", info.getServerName());
assertEquals("0.0.0", info.getVersion());
assertEquals("1.2.3", info.getVersion());
assertEquals("go0.0.0", info.getGoVersion());
assertEquals("host", info.getHost());
assertEquals(7777, info.getPort());
Expand All @@ -53,6 +53,22 @@ public void testValidInfoString() {
assertArrayEquals(ascii, info.getNonce());

assertNotNull(info.toString()); // COVERAGE

ServerInfo info234 = new ServerInfo(json.replace("1.2.3", "2.3.4"));
ServerInfo info235 = new ServerInfo(json.replace("1.2.3", "2.3.5"));
ServerInfo info235Beta2 = new ServerInfo(json.replace("1.2.3", "2.3.5-beta.2"));
assertTrue(info.isOlderThanVersion("2.3.4"));
assertTrue(info234.isOlderThanVersion("2.3.5"));
assertTrue(info235.isOlderThanVersion("2.3.5-beta.2"));
assertTrue(info.isSameVersion("1.2.3"));
assertTrue(info234.isSameVersion("2.3.4"));
assertTrue(info235.isSameVersion("2.3.5"));
assertTrue(info235Beta2.isSameVersion("2.3.5-beta.2"));
assertFalse(info235.isSameVersion("2.3.4"));
assertFalse(info235Beta2.isSameVersion("2.3.5"));
assertTrue(info234.isNewerVersionThan("1.2.3"));
assertTrue(info235.isNewerVersionThan("2.3.4"));
assertTrue(info235Beta2.isNewerVersionThan("2.3.5"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class JetStreamPushQueueTests extends JetStreamTestBase {
@Test
public void testQueueSub() throws Exception {
runInJsServer(nc -> {
if (nc.getServerInfo().isNewerVersionThan("2.3.4")) {
System.out.println("This test will not work after server version v2.3.4");
return;
}

// Create our JetStream context to receive JetStream messages.
JetStream js = nc.jetStream();

Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/data/ServerInfoJson.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
INFO {"server_id": "serverId","server_name": "serverName","version": "0.0.0","go": "go0.0.0","host": "host","port": 7777,"headersSupported": true,"auth_required": true,"tls_required": true,"max_payload": 100000000000,"proto": 1,"ldm": true,"jetstream": true,"client_id": 42,"client_ip": "127.0.0.1","cluster": "cluster","connect_urls":["url0", "url1"],"nonce":"<encoded>","headers": true,}
INFO {"server_id": "serverId","server_name": "serverName","version": "1.2.3","go": "go0.0.0","host": "host","port": 7777,"headersSupported": true,"auth_required": true,"tls_required": true,"max_payload": 100000000000,"proto": 1,"ldm": true,"jetstream": true,"client_id": 42,"client_ip": "127.0.0.1","cluster": "cluster","connect_urls":["url0", "url1"],"nonce":"<encoded>","headers": true,}

0 comments on commit f5963c6

Please sign in to comment.