Skip to content

Commit

Permalink
reader hmsg protocol line length size was wrong (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf authored Oct 19, 2022
1 parent 148ceed commit fac8c01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/nats/client/impl/NatsConnectionReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,10 @@ void parseProtocolMessage() throws IOException {
break;
case OP_HMSG:
int hProtocolLength = this.msgLinePosition; //This is just after the last character
int hProtocolLineLength = hProtocolLength + 4; // 5 for the "HMSG "
int hProtocolLineLength = hProtocolLength + 5; // 5 for the "HMSG "

if (this.utf8Mode) {
hProtocolLineLength = protocolBuffer.remaining() + 4;
hProtocolLineLength = protocolBuffer.remaining() + 5;

CharBuffer buff = StandardCharsets.UTF_8.decode(protocolBuffer);
hProtocolLength = buff.remaining();
Expand Down
18 changes: 14 additions & 4 deletions src/test/java/io/nats/client/impl/NatsStatisticsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,27 @@ public void testInOutOKRequestStats() throws Exception {
assertSame(Connection.Status.CONNECTED, nc.getStatus(), "Connected Status");

Dispatcher d = nc.createDispatcher((msg) -> {
nc.publish(msg.getReplyTo(), new byte[16]);
Message m = NatsMessage.builder()
.subject(msg.getReplyTo())
.data(new byte[16])
.headers(new Headers().put("header", "reply"))
.build();
nc.publish(m);
});
d.subscribe("subject");

Future<Message> incoming = nc.request("subject", new byte[8]);
Message m = NatsMessage.builder()
.subject("subject")
.data(new byte[8])
.headers(new Headers().put("header", "request"))
.build();
Future<Message> incoming = nc.request(m);
Message msg = incoming.get(500, TimeUnit.MILLISECONDS);

assertNotNull(msg);
assertEquals(0, stats.getOutstandingRequests(), "outstanding");
assertTrue(stats.getInBytes() > 100, "bytes in");
assertTrue(stats.getInBytes() > 100, "bytes out");
assertTrue(stats.getInBytes() > 200, "bytes in");
assertTrue(stats.getOutBytes() > 400, "bytes out");
assertEquals(2, stats.getInMsgs(), "messages in"); // reply & request
assertEquals(6, stats.getOutMsgs(), "messages out"); // ping, sub, pub, msg, pub, msg
assertEquals(5, stats.getOKs(), "oks"); //sub, pub, msg, pub, msg
Expand Down

0 comments on commit fac8c01

Please sign in to comment.