Search in sources :

Example 1 with StaticConfig

use of com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig in project databus by linkedin.

the class TestDatabusV2ClusterRegistrationImpl method testRegistrationStartFromInvalidState.

@Test
public void testRegistrationStartFromInvalidState() throws Exception {
    DatabusHttpClientImpl client = null;
    try {
        DatabusHttpClientImpl.Config clientConfig = new DatabusHttpClientImpl.Config();
        clientConfig.getContainer().getJmx().setRmiEnabled(false);
        clientConfig.getContainer().setHttpPort(12003);
        client = new DatabusHttpClientImpl(clientConfig);
        registerRelay(1, "relay1", new InetSocketAddress("localhost", 8888), "S1,S2", client);
        registerRelay(2, "relay2", new InetSocketAddress("localhost", 7777), "S1,S3", client);
        registerRelay(3, "relay1.1", new InetSocketAddress("localhost", 8887), "S1,S2", client);
        registerRelay(4, "relay3", new InetSocketAddress("localhost", 6666), "S3,S4,S5", client);
        TestDbusPartitionListener listener = new TestDbusPartitionListener();
        StaticConfig ckptConfig = new StaticConfig("localhost:1356", "dummy", 1, 1);
        DbusClusterInfo clusterInfo = new DbusClusterInfo("dummy", 10, 1);
        DatabusV2ClusterRegistrationImpl reg = new TestableDatabusV2ClusterRegistrationImpl(null, client, ckptConfig, clusterInfo, new TestDbusClusterConsumerFactory(), new TestDbusServerSideFilterFactory(), listener, "S1", "S3");
        try {
            // Invoking start from INIT state in illegal
            reg.start();
            Assert.fail();
        } catch (IllegalStateException e) {
        }
        try {
            // Invoking start from DEREGISTERED state in illegal
            reg.onRegister();
            reg.start();
            reg.shutdown();
            reg.deregister();
            reg.start();
            Assert.fail();
        } catch (IllegalStateException e) {
        }
    } finally {
        if (null != client) {
            client.shutdown();
        }
    }
}
Also used : DbusClusterInfo(com.linkedin.databus.client.pub.DbusClusterInfo) DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) StaticConfig(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig) InetSocketAddress(java.net.InetSocketAddress) StaticConfig(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) Test(org.testng.annotations.Test)

Example 2 with StaticConfig

use of com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig in project databus by linkedin.

the class TestDatabusV2ClusterRegistrationImpl method testRegistration.

@Test
public void testRegistration() throws Exception {
    DatabusHttpClientImpl client = null;
    try {
        DatabusHttpClientImpl.Config clientConfig = new DatabusHttpClientImpl.Config();
        clientConfig.getContainer().getJmx().setRmiEnabled(false);
        clientConfig.getContainer().setHttpPort(12003);
        client = new DatabusHttpClientImpl(clientConfig);
        registerRelay(1, "relay1", new InetSocketAddress("localhost", 8888), "S1,S2", client);
        registerRelay(2, "relay2", new InetSocketAddress("localhost", 7777), "S1,S3", client);
        registerRelay(3, "relay1.1", new InetSocketAddress("localhost", 8887), "S1,S2", client);
        registerRelay(4, "relay3", new InetSocketAddress("localhost", 6666), "S3,S4,S5", client);
        TestDbusPartitionListener listener = new TestDbusPartitionListener();
        StaticConfig ckptConfig = new StaticConfig("localhost:1356", "dummy", 1, 1);
        DbusClusterInfo clusterInfo = new DbusClusterInfo("dummy", 10, 1);
        DatabusV2ClusterRegistrationImpl reg = new TestableDatabusV2ClusterRegistrationImpl(null, client, ckptConfig, clusterInfo, new TestDbusClusterConsumerFactory(), new TestDbusServerSideFilterFactory(), listener, "S1", "S3");
        reg.onRegister();
        // Start
        reg.start();
        assertEquals("State CHeck", reg.getState(), RegistrationState.STARTED);
        // Add Partition(s)
        reg.onGainedPartitionOwnership(1);
        assertEquals("Listener called ", listener.isAddPartitionCalled(1), true);
        reg.onGainedPartitionOwnership(2);
        assertEquals("Listener called ", listener.isAddPartitionCalled(2), true);
        assertEquals("Partition Regs size ", 2, reg.getPartitionRegs().size());
        reg.onGainedPartitionOwnership(3);
        assertEquals("Listener called ", listener.isAddPartitionCalled(3), true);
        assertEquals("Partition Regs size ", 3, reg.getPartitionRegs().size());
        reg.onGainedPartitionOwnership(4);
        assertEquals("Listener called ", listener.isAddPartitionCalled(4), true);
        //duplicate call
        listener.clearCallbacks();
        reg.onGainedPartitionOwnership(4);
        assertEquals("Listener called ", listener.isAddPartitionCalled(4), false);
        assertEquals("Partition Regs size ", 4, reg.getPartitionRegs().size());
        List<String> gotPartitionList = new ArrayList<String>();
        for (DbusPartitionInfo p : reg.getPartitions()) gotPartitionList.add(p.toString());
        Collections.sort(gotPartitionList);
        assertEquals("Partitions Check", gotPartitionList.toString(), "[1, 2, 3, 4]");
        // Drop Partitions
        reg.onLostPartitionOwnership(1);
        gotPartitionList.clear();
        for (DbusPartitionInfo p : reg.getPartitions()) gotPartitionList.add(p.toString());
        Collections.sort(gotPartitionList);
        assertEquals("Partitions Check", "[2, 3, 4]", gotPartitionList.toString());
        assertEquals("Listener called ", true, listener.isDropPartitionCalled(1));
        reg.onLostPartitionOwnership(2);
        assertEquals("Listener called ", true, listener.isDropPartitionCalled(2));
        //duplicate call
        listener.clearCallbacks();
        reg.onLostPartitionOwnership(2);
        assertEquals("Listener called ", false, listener.isDropPartitionCalled(2));
        assertEquals("Partitions Check", "[3, 4]", reg.getPartitions().toString());
        assertEquals("Partition Regs size ", 2, reg.getPartitionRegs().size());
        reg.onReset(3);
        assertEquals("Listener called ", true, listener.isDropPartitionCalled(3));
        //duplicate call
        listener.clearCallbacks();
        reg.onReset(3);
        assertEquals("Listener called ", false, listener.isDropPartitionCalled(3));
        assertEquals("Partitions Check", "[4]", reg.getPartitions().toString());
        assertEquals("Partition Regs size ", 1, reg.getPartitionRegs().size());
        reg.onError(4);
        assertEquals("Listener called ", true, listener.isDropPartitionCalled(4));
        //duplicate call
        listener.clearCallbacks();
        reg.onError(4);
        assertEquals("Listener called ", false, listener.isDropPartitionCalled(4));
        assertEquals("Partitions Check", "[]", reg.getPartitions().toString());
        assertEquals("Partition Regs size ", 0, reg.getPartitionRegs().size());
        // Add Partiton 1 again
        listener.clearCallbacks();
        reg.onGainedPartitionOwnership(1);
        assertEquals("Listener called ", listener.isAddPartitionCalled(1), true);
        assertEquals("Partition Regs size ", 1, reg.getPartitionRegs().size());
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.STARTED);
        // Pausing
        reg.pause();
        assertEquals("State CHeck", reg.getState(), RegistrationState.PAUSED);
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.PAUSED);
        // Resume
        reg.resume();
        assertEquals("State CHeck", reg.getState(), RegistrationState.RESUMED);
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.RESUMED);
        // Suspended
        reg.suspendOnError(null);
        assertEquals("State CHeck", reg.getState(), RegistrationState.SUSPENDED_ON_ERROR);
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.SUSPENDED_ON_ERROR);
        // resume
        reg.resume();
        assertEquals("State CHeck", reg.getState(), RegistrationState.RESUMED);
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.RESUMED);
        // Active node change notification
        List<String> newActiveNodes = new ArrayList<String>();
        newActiveNodes.add("localhost:7070");
        newActiveNodes.add("localhost:8080");
        newActiveNodes.add("localhost:9090");
        reg.onInstanceChange(newActiveNodes);
        assertEquals("Active Nodes", newActiveNodes, reg.getCurrentActiveNodes());
        newActiveNodes.remove(2);
        reg.onInstanceChange(newActiveNodes);
        assertEquals("Active Nodes", newActiveNodes, reg.getCurrentActiveNodes());
        newActiveNodes.add("localhost:1010");
        reg.onInstanceChange(newActiveNodes);
        assertEquals("Active Nodes", newActiveNodes, reg.getCurrentActiveNodes());
        // Partition Mapping change notification
        Map<Integer, String> activePartitionMap = new HashMap<Integer, String>();
        for (int i = 0; i < 10; i++) {
            String node = null;
            if (i % 2 == 0)
                node = "localhost:8080";
            else
                node = "localhost:7070";
            activePartitionMap.put(i, node);
        }
        reg.onPartitionMappingChange(activePartitionMap);
        assertEquals("Partition Mapping Check", activePartitionMap, reg.getActivePartitionMap());
        activePartitionMap.remove(9);
        reg.onPartitionMappingChange(activePartitionMap);
        assertEquals("Partition Mapping Check", activePartitionMap, reg.getActivePartitionMap());
        activePartitionMap.put(9, "localhost:8708");
        reg.onPartitionMappingChange(activePartitionMap);
        assertEquals("Partition Mapping Check", activePartitionMap, reg.getActivePartitionMap());
        // shutdown
        reg.shutdown();
        assertEquals("State Check", reg.getState(), RegistrationState.SHUTDOWN);
        assertEquals("Child State CHeck", reg.getPartitionRegs().values().iterator().next().getState(), RegistrationState.SHUTDOWN);
        // Operations during shutdown state
        boolean gotException = false;
        try {
            reg.onGainedPartitionOwnership(1);
        } catch (IllegalStateException ex) {
            gotException = true;
        }
        assertEquals("Exception", true, gotException);
        gotException = false;
        try {
            reg.onLostPartitionOwnership(1);
        } catch (IllegalStateException ex) {
            gotException = true;
        }
        assertEquals("Exception", true, gotException);
        gotException = false;
        try {
            reg.pause();
        } catch (IllegalStateException ex) {
            gotException = true;
        }
        assertEquals("Exception", true, gotException);
        gotException = false;
        try {
            reg.suspendOnError(null);
        } catch (IllegalStateException ex) {
            gotException = true;
        }
        assertEquals("Exception", true, gotException);
        gotException = false;
        try {
            reg.resume();
        } catch (IllegalStateException ex) {
            gotException = true;
        }
        assertEquals("Exception", true, gotException);
        // deregister
        reg.deregister();
        assertEquals("State Check", reg.getState(), RegistrationState.DEREGISTERED);
        assertEquals("Child State CHeck", 0, reg.getPartitionRegs().size());
    } finally {
        if (null != client)
            client.shutdown();
    }
}
Also used : HashMap(java.util.HashMap) DbusKeyCompositeFilterConfig(com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig) StaticConfig(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig) InetSocketAddress(java.net.InetSocketAddress) StaticConfig(com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig) ArrayList(java.util.ArrayList) DatabusHttpClientImpl(com.linkedin.databus.client.DatabusHttpClientImpl) DbusClusterInfo(com.linkedin.databus.client.pub.DbusClusterInfo) DbusPartitionInfo(com.linkedin.databus.client.pub.DbusPartitionInfo) Test(org.testng.annotations.Test)

Aggregations

DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)2 StaticConfig (com.linkedin.databus.client.pub.ClusterCheckpointPersistenceProvider.StaticConfig)2 DbusClusterInfo (com.linkedin.databus.client.pub.DbusClusterInfo)2 DbusKeyCompositeFilterConfig (com.linkedin.databus2.core.filter.DbusKeyCompositeFilterConfig)2 InetSocketAddress (java.net.InetSocketAddress)2 Test (org.testng.annotations.Test)2 DbusPartitionInfo (com.linkedin.databus.client.pub.DbusPartitionInfo)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1