use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestRoutingTableSnapshot method testRoutingTableSnapshot.
@Test
public void testRoutingTableSnapshot() throws InterruptedException {
RoutingTableProvider routingTableProvider = new RoutingTableProvider(_manager, PropertyType.EXTERNALVIEW);
String db1 = "TestDB-1";
_setupTool.addResourceToCluster(CLUSTER_NAME, db1, NUM_PARTITIONS, "MasterSlave", IdealState.RebalanceMode.FULL_AUTO.name());
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, db1, NUM_REPLICAS);
Thread.sleep(200);
HelixClusterVerifier clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkAddr(ZK_ADDR).build();
Assert.assertTrue(clusterVerifier.verify());
IdealState idealState1 = _setupTool.getClusterManagementTool().getResourceIdealState(CLUSTER_NAME, db1);
RoutingTableSnapshot routingTableSnapshot = routingTableProvider.getRoutingTableSnapshot();
validateMapping(idealState1, routingTableSnapshot);
Assert.assertEquals(routingTableSnapshot.getInstanceConfigs().size(), NUM_NODES);
Assert.assertEquals(routingTableSnapshot.getResources().size(), 1);
Assert.assertEquals(routingTableSnapshot.getLiveInstances().size(), NUM_NODES);
// add new DB and shutdown an instance
String db2 = "TestDB-2";
_setupTool.addResourceToCluster(CLUSTER_NAME, db2, NUM_PARTITIONS, "MasterSlave", IdealState.RebalanceMode.FULL_AUTO.name());
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, db2, NUM_REPLICAS);
// shutdown an instance
_participants[0].syncStop();
Thread.sleep(200);
Assert.assertTrue(clusterVerifier.verify());
// the original snapshot should not change
Assert.assertEquals(routingTableSnapshot.getInstanceConfigs().size(), NUM_NODES);
Assert.assertEquals(routingTableSnapshot.getResources().size(), 1);
Assert.assertEquals(routingTableSnapshot.getLiveInstances().size(), NUM_NODES);
RoutingTableSnapshot newRoutingTableSnapshot = routingTableProvider.getRoutingTableSnapshot();
Assert.assertEquals(newRoutingTableSnapshot.getInstanceConfigs().size(), NUM_NODES);
Assert.assertEquals(newRoutingTableSnapshot.getResources().size(), 2);
Assert.assertEquals(newRoutingTableSnapshot.getLiveInstances().size(), NUM_NODES - 1);
}
use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestRoutingTable method testMultiThread.
@Test()
public void testMultiThread() throws Exception {
final RoutingTableProvider routingTable = new RoutingTableProvider();
List<ExternalView> externalViewList = new ArrayList<>();
ZNRecord record = new ZNRecord("TESTDB");
for (int i = 0; i < 1000; i++) {
add(record, "TESTDB_" + i, "localhost_8900", "MASTER");
}
externalViewList.add(new ExternalView(record));
routingTable.onExternalViewChange(externalViewList, changeContext);
Callable<Boolean> runnable = new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try {
int count = 0;
while (count < 100) {
List<InstanceConfig> instancesList = routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
AssertJUnit.assertEquals(instancesList.size(), 1);
// System.out.println(System.currentTimeMillis() + "-->"
// + instancesList.size());
Thread.sleep(5);
count++;
}
} catch (InterruptedException e) {
// e.printStackTrace();
}
return true;
}
};
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
Future<Boolean> submit = executor.submit(runnable);
int count = 0;
while (count < 10) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
routingTable.onExternalViewChange(externalViewList, changeContext);
count++;
}
Boolean result = submit.get(60, TimeUnit.SECONDS);
AssertJUnit.assertEquals(result, Boolean.TRUE);
}
use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestRoutingTable method testSimple.
@Test()
public void testSimple() {
List<InstanceConfig> instances;
RoutingTableProvider routingTable = new RoutingTableProvider();
ZNRecord record = new ZNRecord("TESTDB");
// one master
add(record, "TESTDB_0", "localhost_8900", "MASTER");
List<ExternalView> externalViewList = new ArrayList<>();
externalViewList.add(new ExternalView(record));
routingTable.onExternalViewChange(externalViewList, changeContext);
instances = routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 1);
// additions
add(record, "TESTDB_0", "localhost_8901", "MASTER");
add(record, "TESTDB_1", "localhost_8900", "SLAVE");
externalViewList = new ArrayList<ExternalView>();
externalViewList.add(new ExternalView(record));
routingTable.onExternalViewChange(externalViewList, changeContext);
instances = routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 2);
instances = routingTable.getInstances("TESTDB", "TESTDB_1", "SLAVE");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 1);
// updates
add(record, "TESTDB_0", "localhost_8901", "SLAVE");
externalViewList = new ArrayList<>();
externalViewList.add(new ExternalView(record));
routingTable.onExternalViewChange(externalViewList, changeContext);
instances = routingTable.getInstances("TESTDB", "TESTDB_0", "SLAVE");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 1);
}
Aggregations