Search in sources :

Example 1 with RoutingTableProvider

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));
}
Also used : ExternalView(org.apache.helix.model.ExternalView) ArrayList(java.util.ArrayList) RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with RoutingTableProvider

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);
}
Also used : ExternalView(org.apache.helix.model.ExternalView) InstanceConfig(org.apache.helix.model.InstanceConfig) ArrayList(java.util.ArrayList) RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) Test(org.testng.annotations.Test)

Example 3 with RoutingTableProvider

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);
}
Also used : ExternalView(org.apache.helix.model.ExternalView) RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) Test(org.testng.annotations.Test)

Example 4 with RoutingTableProvider

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");
}
Also used : ExternalView(org.apache.helix.model.ExternalView) InstanceConfig(org.apache.helix.model.InstanceConfig) ArrayList(java.util.ArrayList) RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) Test(org.testng.annotations.Test)

Example 5 with RoutingTableProvider

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);
}
Also used : HelixManager(org.apache.helix.HelixManager) RoutingTableProvider(org.apache.helix.spectator.RoutingTableProvider) Test(org.testng.annotations.Test)

Aggregations

RoutingTableProvider (org.apache.helix.spectator.RoutingTableProvider)14 Test (org.testng.annotations.Test)11 ArrayList (java.util.ArrayList)6 ExternalView (org.apache.helix.model.ExternalView)6 InstanceConfig (org.apache.helix.model.InstanceConfig)5 IdealState (org.apache.helix.model.IdealState)3 HashSet (java.util.HashSet)2 HelixManager (org.apache.helix.HelixManager)2 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)2 HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)2 BeforeClass (org.testng.annotations.BeforeClass)2 Date (java.util.Date)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)1 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)1 ClusterConfig (org.apache.helix.model.ClusterConfig)1 RoutingTableSnapshot (org.apache.helix.spectator.RoutingTableSnapshot)1 ClusterStateVerifier (org.apache.helix.tools.ClusterStateVerifier)1