use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestRoutingTable method testGetResources.
@Test()
public void testGetResources() {
RoutingTableProvider routingTable = new RoutingTableProvider();
List<ExternalView> externalViewList = new ArrayList<>();
Set<String> databases = new HashSet<>();
for (int i = 0; i < 5; i++) {
String db = "TESTDB" + i;
ZNRecord record = new ZNRecord(db);
// one master
add(record, db + "_0", "localhost_8900", "MASTER");
add(record, db + "_1", "localhost_8901", "SLAVE");
externalViewList.add(new ExternalView(record));
databases.add(db);
}
routingTable.onExternalViewChange(externalViewList, changeContext);
Collection<String> resources = routingTable.getResources();
Assert.assertEquals(databases.size(), externalViewList.size());
Assert.assertEquals(databases, new HashSet<>(resources));
}
use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestRoutingTable method testStateUnitGroupDeletion.
@Test()
public void testStateUnitGroupDeletion() throws InterruptedException {
List<InstanceConfig> instances;
RoutingTableProvider routingTable = new RoutingTableProvider();
List<ExternalView> externalViewList = new ArrayList<ExternalView>();
ZNRecord record = new ZNRecord("TESTDB");
// one master
add(record, "TESTDB_0", "localhost_8900", "MASTER");
externalViewList.add(new ExternalView(record));
routingTable.onExternalViewChange(externalViewList, changeContext);
instances = routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 1);
externalViewList.clear();
routingTable.onExternalViewChange(externalViewList, changeContext);
Thread.sleep(100);
instances = routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
AssertJUnit.assertNotNull(instances);
AssertJUnit.assertEquals(instances.size(), 0);
}
use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestRoutingTable method testNullAndEmpty.
@Test()
public void testNullAndEmpty() {
RoutingTableProvider routingTable = new RoutingTableProvider();
routingTable.onExternalViewChange(null, changeContext);
List<ExternalView> list = Collections.emptyList();
routingTable.onExternalViewChange(list, changeContext);
}
use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestRoutingTable method testGetInstanceForAllStateUnits.
@Test()
public void testGetInstanceForAllStateUnits() {
List<InstanceConfig> instancesList;
Set<InstanceConfig> instancesSet;
InstanceConfig[] instancesArray;
RoutingTableProvider routingTable = new RoutingTableProvider();
List<ExternalView> externalViewList = new ArrayList<ExternalView>();
ZNRecord record = new ZNRecord("TESTDB");
// one master
add(record, "TESTDB_0", "localhost_8900", "MASTER");
add(record, "TESTDB_1", "localhost_8900", "MASTER");
add(record, "TESTDB_2", "localhost_8900", "MASTER");
add(record, "TESTDB_3", "localhost_8900", "SLAVE");
add(record, "TESTDB_4", "localhost_8900", "SLAVE");
add(record, "TESTDB_5", "localhost_8900", "SLAVE");
add(record, "TESTDB_0", "localhost_8901", "SLAVE");
add(record, "TESTDB_1", "localhost_8901", "SLAVE");
add(record, "TESTDB_2", "localhost_8901", "SLAVE");
add(record, "TESTDB_3", "localhost_8901", "MASTER");
add(record, "TESTDB_4", "localhost_8901", "MASTER");
add(record, "TESTDB_5", "localhost_8901", "MASTER");
externalViewList.add(new ExternalView(record));
routingTable.onExternalViewChange(externalViewList, changeContext);
instancesList = routingTable.getInstances("TESTDB", "TESTDB_0", "MASTER");
AssertJUnit.assertNotNull(instancesList);
AssertJUnit.assertEquals(instancesList.size(), 1);
instancesSet = routingTable.getInstances("TESTDB", "MASTER");
AssertJUnit.assertNotNull(instancesSet);
AssertJUnit.assertEquals(instancesSet.size(), 2);
instancesSet = routingTable.getInstances("TESTDB", "SLAVE");
AssertJUnit.assertNotNull(instancesSet);
AssertJUnit.assertEquals(instancesSet.size(), 2);
instancesArray = new InstanceConfig[instancesSet.size()];
instancesSet.toArray(instancesArray);
AssertJUnit.assertEquals(instancesArray[0].getHostName(), "localhost");
AssertJUnit.assertEquals(instancesArray[0].getPort(), "8900");
AssertJUnit.assertEquals(instancesArray[1].getHostName(), "localhost");
AssertJUnit.assertEquals(instancesArray[1].getPort(), "8901");
}
use of org.apache.helix.spectator.RoutingTableProvider in project helix by apache.
the class TestCorrectnessOnConnectivityLoss method testSpectator.
@SuppressWarnings("deprecation")
@Test
public void testSpectator() throws Exception {
Map<String, Integer> stateReachedCounts = Maps.newHashMap();
HelixManager participant = HelixManagerFactory.getZKHelixManager(_clusterName, "localhost_12918", InstanceType.PARTICIPANT, ZK_ADDR);
participant.getStateMachineEngine().registerStateModelFactory("OnlineOffline", new MyStateModelFactory(stateReachedCounts));
participant.connect();
RoutingTableProvider routingTableProvider = new RoutingTableProvider();
HelixManager spectator = HelixManagerFactory.getZKHelixManager(_clusterName, "spectator", InstanceType.SPECTATOR, ZK_ADDR);
spectator.connect();
spectator.addConfigChangeListener(routingTableProvider);
spectator.addExternalViewChangeListener(routingTableProvider);
Thread.sleep(1000);
// Now let's stop the ZK server; this should do nothing
TestHelper.stopZkServer(_zkServer);
Thread.sleep(1000);
// Verify routing table still works
Assert.assertEquals(routingTableProvider.getInstances("resource0", "ONLINE").size(), 1);
Assert.assertEquals(routingTableProvider.getInstances("resource0", "OFFLINE").size(), 0);
}
Aggregations