codelipenghui commented on a change in pull request #5913: Fixes #5814: add
SentConnectFrame state check when running `handleError`
URL: https://github.com/apache/pulsar/pull/5913#discussion_r361029167
##########
File path:
pulsar-client/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java
##########
@@ -60,4 +64,35 @@ public void testClientCnxTimeout() throws Exception {
}
}
+ @Test
+ public void testReceiveErrorAtSendConnectFrameState() throws Exception {
+ ThreadFactory threadFactory = new
DefaultThreadFactory("testReceiveErrorAtSendConnectFrameState");
+ EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(1,
threadFactory);
+ ClientConfigurationData conf = new ClientConfigurationData();
+ conf.setOperationTimeoutMs(10);
+ ClientCnx cnx = new ClientCnx(conf, eventLoop);
+
+ ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
+ Channel channel = mock(Channel.class);
+ when(ctx.channel()).thenReturn(channel);
+
+ Field ctxField = PulsarHandler.class.getDeclaredField("ctx");
+ ctxField.setAccessible(true);
+ ctxField.set(cnx, ctx);
+
+ // set connection as SentConnectFrame
+ Field cnxField = ClientCnx.class.getDeclaredField("state");
+ cnxField.setAccessible(true);
+ cnxField.set(cnx, ClientCnx.State.SentConnectFrame);
+
+ // receive error
+ PulsarApi.CommandError commandError =
PulsarApi.CommandError.newBuilder()
+
.setRequestId(-1).setError(PulsarApi.ServerError.AuthenticationError).setMessage("authentication
was failed").build();
+ try {
+ cnx.handleError(commandError);
+ } catch (Exception e) {
+ fail("should not throw any error");
Review comment:
Shall we need to catch exceptions here, looks you can throw it directly.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services