@Test public void testList() throws Exception { PrintStream originalOut = System.out; ByteArrayOutputStream outContent = new ByteArrayOutputStream(); System.setOut(new PrintStream(outContent, false, "UTF-8")); ZooKeeperServerRunner zooKeeperServerRunner = new ZooKeeperServerRunner(0); String connectString = zooKeeperServerRunner.start(); String configFilePath = IntegrationTestHelper.createYamlConfigFile(DIR_NAME, CONFIG_FILE_NAME, createProperties(connectString, CLUSTER_ROOT)); try { ZNode clusterRootZNode = new ZNode(CLUSTER_ROOT); ZNode storeRoot = new ZNode(clusterRootZNode, StoreMetadata.STORE_ZNODE_NAME); ZooKeeperClient zkClient = new ZooKeeperClientImpl(connectString, ZK_SESSION_TIMEOUT, ZK_CONNECT_TIMEOUT); ZooKeeperCli.Create.createCluster(zkClient, clusterRootZNode, CLUSTER_NAME, NUM_PARTITIONS); ZooKeeperCli.Create.createStores(zkClient, clusterRootZNode, NUM_PARTITIONS, STORAGE_GROUP_MAP, STORAGE_CONNECTION_MAP); int partitionId = 0, generation = 5, sessionId = 10, numReplicas = 2; String connectStringTemplate = "fakehost%d:600%d"; HashMap<ReplicaId, ReplicaState> replicaStates = new HashMap<>(); ZNode partitionRoot = new ZNode(storeRoot, StoreMetadata.PARTITION_ZNODE_NAME); ZNode znode = new ZNode(partitionRoot, Integer.toString(partitionId)); for (int i = 0; i < numReplicas; i++) { ReplicaId replicaId = new ReplicaId(partitionId, String.format(connectStringTemplate, i, i)); replicaStates.put(replicaId, new ReplicaState(replicaId, -1L, ReplicaState.UNRESOLVED)); } zkClient.create( znode, new PartitionMetadata(generation, sessionId, replicaStates), PartitionMetadataSerializer.INSTANCE, CreateMode.PERSISTENT ); String[] showCommandArgs = { "list", "--cli-config-path", configFilePath }; ZooKeeperCli.testMain(showCommandArgs); String expectedCmdOutput = "store [/test/root/store] replica and group assignments:\n" + " fakehost0:6000 = [0, 1, 2], GroupId: 1\n" + " fakehost1:6001 = [0, 1, 2], GroupId: 1\n" + "store [/test/root/store] connections:\n" + " fakehost1:6001 has admin port: 6101\n" + " fakehost0:6000 has admin port: 6100\n" + "store [/test/root/store/partition/0] replica states:\n" + " ReplicaId(0,fakehost0:6000), SessionId: -1, closingHighWaterMark: UNRESOLVED\n" + " ReplicaId(0,fakehost1:6001), SessionId: -1, closingHighWaterMark: UNRESOLVED\n" + "store [/test/root/store/partition/1] replica states:\n" + "No node found\n" + "store [/test/root/store/partition/2] replica states:\n" + "No node found\n"; assertTrue(outContent.toString("UTF-8").contains(expectedCmdOutput)); } finally { System.setOut(originalOut); outContent.close(); zooKeeperServerRunner.stop(); zooKeeperServerRunner.clear(); } }
public static void testMain(String[] args) { new ZooKeeperCli(args, true).processCmd(); }
ZooKeeperCli extends SubcommandCli { public static void testMain(String[] args) { new ZooKeeperCli(args, true).processCmd(); } }
ZooKeeperCli extends SubcommandCli { public static void testMain(String[] args) { new ZooKeeperCli(args, true).processCmd(); } private  ZooKeeperCli(String[] args, boolean useByTest); }
ZooKeeperCli extends SubcommandCli { public static void testMain(String[] args) { new ZooKeeperCli(args, true).processCmd(); } private  ZooKeeperCli(String[] args, boolean useByTest); static void testMain(String[] args); static void main(String[] args); }
ZooKeeperCli extends SubcommandCli { public static void testMain(String[] args) { new ZooKeeperCli(args, true).processCmd(); } private  ZooKeeperCli(String[] args, boolean useByTest); static void testMain(String[] args); static void main(String[] args);  }