You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by GitBox <gi...@apache.org> on 2020/11/17 18:03:05 UTC

[GitHub] [zookeeper] ztzg commented on a change in pull request #1513: ZOOKEEPER-3978 : Adding additional security metrics to zookeeper

ztzg commented on a change in pull request #1513:
URL: https://github.com/apache/zookeeper/pull/1513#discussion_r525373640



##########
File path: zookeeper-server/src/test/java/org/apache/zookeeper/server/NettyServerCnxnTest.java
##########
@@ -143,6 +155,51 @@ public void testClientResponseStatsUpdate() throws IOException, InterruptedExcep
         }
     }
 
+    @Test
+    public void testNonMTLSLocalConn() throws IOException, InterruptedException, KeeperException {
+        try (ZooKeeper zk = createClient()) {
+            ServerStats serverStats = serverFactory.getZooKeeperServer().serverStats();
+            //2 for local stat connection and this client
+            assertEquals(2, serverStats.getNonMTLSLocalConnCount());
+            assertEquals(0, serverStats.getNonMTLSRemoteConnCount());
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testNonMTLSRemoteConn() throws Exception {
+        Channel channel = mock(Channel.class);
+        ChannelId id = mock(ChannelId.class);
+        ChannelFuture success = mock(ChannelFuture.class);
+        ChannelHandlerContext context = mock(ChannelHandlerContext.class);
+        ChannelPipeline channelPipeline = mock(ChannelPipeline.class);
+
+        when(context.channel()).thenReturn(channel);
+        when(channel.pipeline()).thenReturn(channelPipeline);
+        when(success.channel()).thenReturn(channel);
+        when(channel.closeFuture()).thenReturn(success);
+
+        InetSocketAddress address = new InetSocketAddress(0);
+        when(channel.remoteAddress()).thenReturn(address);
+        when(channel.id()).thenReturn(id);
+        NettyServerCnxnFactory factory = new NettyServerCnxnFactory();
+        LeaderZooKeeperServer zks = mock(LeaderZooKeeperServer.class);
+        factory.setZooKeeperServer(zks);
+        Attribute atr = mock(Attribute.class);
+        Mockito.doReturn(atr).when(channel).attr(
+                Mockito.any()
+        );
+        doNothing().when(atr).set(Mockito.any());
+
+        ServerStats.Provider providerMock = mock(ServerStats.Provider.class);

Review comment:
       The version committed to `master` has an additional
   
   ```java
   when(zks.isRunning()).thenReturn(true);
   ```
   
   between the two lines above:
   
   https://github.com/p-malik/zookeeper/blob/b842cd4b463a7c3674963f6f66fc392293c1334c/zookeeper-server/src/test/java/org/apache/zookeeper/server/NettyServerCnxnTest.java#L201-L205
   
   Should the same treatment be applied to this branch?




----------------------------------------------------------------
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:
users@infra.apache.org