@Override public void commandRun() { if (!isZKServerRunning()) { pw.println(ZK_NOT_SERVING); } else { for (ServerCnxn c : factory.getConnections()) { c.dumpConnectionInfo(pw, false); pw.println(); } pw.println(); } } }
LOG.info("Stat command output"); pw.println("Clients:"); for(ServerCnxn c : factory.getConnections()){ c.dumpConnectionInfo(pw, true); pw.println();
@Before public void setUp() { outputWriter = new StringWriter(); ServerCnxn serverCnxnMock = mock(ServerCnxn.class); LeaderZooKeeperServer zks = mock(LeaderZooKeeperServer.class); when(zks.isRunning()).thenReturn(true); providerMock = mock(ServerStats.Provider.class); when(zks.serverStats()).thenReturn(new ServerStats(providerMock)); ZKDatabase zkDatabaseMock = mock(ZKDatabase.class); when(zks.getZKDatabase()).thenReturn(zkDatabaseMock); Leader leaderMock = mock(Leader.class); when(leaderMock.getProposalStats()).thenReturn(new BufferStats()); when(zks.getLeader()).thenReturn(leaderMock); ServerCnxnFactory serverCnxnFactory = mock(ServerCnxnFactory.class); ServerCnxn serverCnxn = mock(ServerCnxn.class); List<ServerCnxn> connections = new ArrayList<>(); connections.add(serverCnxn); when(serverCnxnFactory.getConnections()).thenReturn(connections); statCommand = new StatCommand(new PrintWriter(outputWriter), serverCnxnMock, FourLetterCommands.statCmd); statCommand.setZkServer(zks); statCommand.setFactory(serverCnxnFactory); }
"Didn't instantiate ServerCnxnFactory with NIOServerCnxnFactory!", serverFactory instanceof NIOServerCnxnFactory); Iterable<ServerCnxn> connections = serverFactory.getConnections(); for (ServerCnxn serverCnxn : connections) { serverCnxn.close();
/** * Checks if a session is registered with the server as a watcher. * * @param long sessionId the session ID to check * @param path the path to check for watchers * @param type the type of watcher * @return true if the client session is a watcher on path for the type */ private boolean isServerSessionWatcher(long sessionId, String path, WatcherType type) { Set<ServerCnxn> cnxns = new HashSet<>(); CollectionUtils.addAll(cnxns, serverFactory.getConnections().iterator()); for (ServerCnxn cnxn : cnxns) { if (cnxn.getSessionId() == sessionId) { return getServer(serverFactory).getZKDatabase().getDataTree() .containsWatcher(path, type, cnxn); } } return false; } }
zk.exists(path, true)); Assert.assertEquals(1, zkServer.getZKDatabase().getDataTree().getWatchCount()); Iterable<ServerCnxn> connections = serverFactory.getConnections(); Assert.assertEquals("Mismatch in number of live connections!", 1, serverFactory.getNumAliveConnections());