Skip to content

Commit 9e78a19

Browse files
committed
Flip ByteBuffer after read retry
References #307
1 parent ff8ef23 commit 9e78a19

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/main/java/com/rabbitmq/client/impl/nio/SslEngineByteBufferInputStream.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public int read() throws IOException {
7373
if(bytesRead <= 0) {
7474
throw new IllegalStateException("Should be reading something from the network");
7575
}
76+
// see https://github.com/rabbitmq/rabbitmq-java-client/issues/307
77+
cipherIn.flip();
7678
}
7779
plainIn.clear();
7880
result = sslEngine.unwrap(cipherIn, plainIn);

src/test/java/com/rabbitmq/client/test/ssl/NioTlsUnverifiedConnection.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public void openConnection()
4040
throws IOException, TimeoutException {
4141
try {
4242
connectionFactory.useSslProtocol();
43+
connectionFactory.useNio();
4344
} catch (Exception ex) {
4445
throw new IOException(ex.toString());
4546
}
@@ -55,15 +56,15 @@ public void openConnection()
5556
}
5657
}
5758
if(connection == null) {
58-
fail("Couldn't open TLS connection after 3 attemps");
59+
fail("Couldn't open TLS connection after 3 attempts");
5960
}
6061

6162
}
6263

6364
@Test
6465
public void connectionGetConsume() throws Exception {
6566
CountDownLatch latch = new CountDownLatch(1);
66-
connection = basicGetBasicConsume(connection, "tls.nio.queue", latch);
67+
connection = basicGetBasicConsume(connection, "tls.nio.queue", latch, 100 * 1000);
6768
boolean messagesReceived = latch.await(5, TimeUnit.SECONDS);
6869
assertTrue("Message has not been received", messagesReceived);
6970
}
@@ -94,13 +95,20 @@ public void configure(SSLEngine sslEngine) throws IOException {
9495
}
9596
}
9697

97-
private Connection basicGetBasicConsume(Connection connection, String queue, final CountDownLatch latch)
98+
@Test public void largeMessage() throws Exception {
99+
CountDownLatch latch = new CountDownLatch(1);
100+
connection = basicGetBasicConsume(connection, "tls.nio.queue", latch, 1 * 1000 * 1000);
101+
boolean messagesReceived = latch.await(5, TimeUnit.SECONDS);
102+
assertTrue("Message has not been received", messagesReceived);
103+
}
104+
105+
private Connection basicGetBasicConsume(Connection connection, String queue, final CountDownLatch latch, int msgSize)
98106
throws IOException, TimeoutException {
99107
Channel channel = connection.createChannel();
100108
channel.queueDeclare(queue, false, false, false, null);
101109
channel.queuePurge(queue);
102110

103-
channel.basicPublish("", queue, null, new byte[100 * 1000]);
111+
channel.basicPublish("", queue, null, new byte[msgSize]);
104112

105113
channel.basicConsume(queue, false, new DefaultConsumer(channel) {
106114

0 commit comments

Comments
 (0)