@Test public void testAddAndRemovePreferredPartition() throws Exception { int numPartitions = 4; int numServers = 2; Properties properties = new Properties(); properties.setProperty(IntegrationTestHelper.Config.ZNODE_PATH, "/server/cli/test"); properties.setProperty(IntegrationTestHelper.Config.NUM_PARTITIONS, String.valueOf(numPartitions)); properties.setProperty(IntegrationTestHelper.Config.NUM_SERVERS, String.valueOf(numServers)); properties.setProperty(IntegrationTestHelper.Config.ZK_SESSION_TIMEOUT, "30000"); IntegrationTestHelper helper = new IntegrationTestHelper(properties); Properties cfgProperties = createProperties(helper.getZkConnectString(), helper.getZnodePath(), helper.getSslSetup()); String configFilePath = IntegrationTestHelper.createYamlConfigFile(DIR_NAME, CONFIG_FILE_NAME, cfgProperties); int partitionId = 3; Set<ServerDescriptor> serverDescriptors = null; PartitionAssignment partitionAssignment = null; try { helper.startZooKeeperServer(); WaltzServerRunner serverRunner1 = helper.getWaltzServerRunner(0); serverRunner1.startAsync(); serverRunner1.awaitStart(); int serverPort1 = helper.getServerPort(0); String serverEndpoint1 = helper.getHost() + ":" + serverPort1; String[] args1 = { "add-preferred-partition", "--server", serverEndpoint1, "--partition", String.valueOf(partitionId), "--cli-config-path", configFilePath }; ServerCli.testMain(args1); serverDescriptors = helper.getWaltzServerRunner().getServerDescriptors(); for (ServerDescriptor serverDescriptor : serverDescriptors) { if (serverDescriptor.endpoint.toString().equals(serverEndpoint1)) { assertTrue(serverDescriptor.partitions.contains(partitionId)); Boolean partitionMatch = false; partitionAssignment = helper.getWaltzServerRunner().getPartitionAssignment(); List<PartitionInfo> partitionInfoList = partitionAssignment.partitionsFor(serverDescriptor.serverId); for (PartitionInfo partitionInfo : partitionInfoList) { if (partitionInfo.partitionId == partitionId) { partitionMatch = true; } } assertTrue(partitionMatch); } } WaltzServerRunner serverRunner2 = helper.getWaltzServerRunner(1); serverRunner2.startAsync(); serverRunner2.awaitStart(); int serverPort2 = helper.getServerPort(1); String serverEndpoint2 = helper.getHost() + ":" + serverPort2; String[] args2 = { "add-preferred-partition", "--server", serverEndpoint2, "--partition", String.valueOf(partitionId), "--cli-config-path", configFilePath }; ServerCli.testMain(args2); serverDescriptors = helper.getWaltzServerRunner(1).getServerDescriptors(); for (ServerDescriptor serverDescriptor : serverDescriptors) { if (serverDescriptor.endpoint.toString().equals(serverEndpoint2)) { assertTrue(serverDescriptor.partitions.contains(partitionId)); Boolean partitionMatch = false; partitionAssignment = helper.getWaltzServerRunner(1).getPartitionAssignment(); List<PartitionInfo> partitionInfoList = partitionAssignment.partitionsFor(serverDescriptor.serverId); for (PartitionInfo partitionInfo : partitionInfoList) { if (partitionInfo.partitionId == partitionId) { partitionMatch = true; } } assertFalse(partitionMatch); } } String[] args3 = { "remove-preferred-partition", "--server", serverEndpoint1, "--partition", String.valueOf(partitionId), "--cli-config-path", configFilePath }; ServerCli.testMain(args3); serverDescriptors = helper.getWaltzServerRunner().getServerDescriptors(); for (ServerDescriptor serverDescriptor : serverDescriptors) { if (serverDescriptor.endpoint.toString().equals(serverEndpoint1)) { assertFalse(serverDescriptor.partitions.contains(partitionId)); } if (serverDescriptor.endpoint.toString().equals(serverEndpoint2)) { assertTrue(serverDescriptor.partitions.contains(partitionId)); Boolean partitionMatch = false; partitionAssignment = helper.getWaltzServerRunner().getPartitionAssignment(); List<PartitionInfo> partitionInfoList = partitionAssignment.partitionsFor(serverDescriptor.serverId); for (PartitionInfo partitionInfo : partitionInfoList) { if (partitionInfo.partitionId == partitionId) { partitionMatch = true; } } assertTrue(partitionMatch); } } } finally { helper.closeAll(); } }
public static void testMain(String[] args) { new ServerCli(args, true).processCmd(); }
ServerCli extends SubcommandCli { public static void testMain(String[] args) { new ServerCli(args, true).processCmd(); } }
ServerCli extends SubcommandCli { public static void testMain(String[] args) { new ServerCli(args, true).processCmd(); } private  ServerCli(String[] args, boolean useByTest); }
ServerCli extends SubcommandCli { public static void testMain(String[] args) { new ServerCli(args, true).processCmd(); } private  ServerCli(String[] args, boolean useByTest); static void testMain(String[] args); static void main(String[] args); }
ServerCli extends SubcommandCli { public static void testMain(String[] args) { new ServerCli(args, true).processCmd(); } private  ServerCli(String[] args, boolean useByTest); static void testMain(String[] args); static void main(String[] args);  }