eolivelli commented on code in PR #17856:
URL: https://github.com/apache/pulsar/pull/17856#discussion_r994245060
##########
pulsar-client/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java:
##########
@@ -80,6 +82,73 @@ public void testClientCnxTimeout() throws Exception {
eventLoop.shutdownGracefully();
}
+ @Test
+ public void testPendingLookupRequestSemaphore() throws Exception {
+ EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(1, false,
new DefaultThreadFactory("testClientCnxTimeout"));
+ ClientConfigurationData conf = new ClientConfigurationData();
+ conf.setOperationTimeoutMs(10_000);
+ conf.setKeepAliveIntervalSeconds(0);
+ ClientCnx cnx = new ClientCnx(conf, eventLoop);
+
+ ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
+ Channel channel = mock(Channel.class);
+ when(ctx.channel()).thenReturn(channel);
+ ChannelFuture listenerFuture = mock(ChannelFuture.class);
+ when(listenerFuture.addListener(any())).thenReturn(listenerFuture);
+ when(ctx.writeAndFlush(any())).thenReturn(listenerFuture);
+ cnx.channelActive(ctx);
+ CountDownLatch countDownLatch1 = new CountDownLatch(1);
+ CountDownLatch countDownLatch2 = new CountDownLatch(1);
+ new Thread(() -> {
+ try {
+ Thread.sleep(1_000);
+ CompletableFuture<BinaryProtoLookupService.LookupDataResult>
future =
+ cnx.newLookup(null, 123);
+ countDownLatch1.countDown();
+ future.get();
+ } catch (Exception e) {
+ // ignore exception
+ assertTrue(e instanceof
PulsarClientException.ConnectException);
Review Comment:
I am not sure that TestNG will catch this assertion error out of the main
thread.
I think that we should use a CompletableFuture<Throwable> and grab this
exception.
you won't need the `countDownLatch2` any more
```
} catch (Exception e) {
errorCatcher.complete(t);
}
....
assertThat(errorCatcher.get(),
instanceOf(PulsarClientException.ConnectException))
or something like that
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]