Search in sources :

Example 1 with ActiveStateChangeHandler

use of org.apache.atlas.listener.ActiveStateChangeHandler in project incubator-atlas by apache.

the class ActiveInstanceElectorServiceTest method testRegisteredHandlersAreNotifiedOfPassiveWhenInstanceIsPassive.

@Test
public void testRegisteredHandlersAreNotifiedOfPassiveWhenInstanceIsPassive() throws AtlasException {
    when(configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
    when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
    when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(new String[] { "id1" });
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX + "id1")).thenReturn("127.0.0.1:21000");
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
    LeaderLatch leaderLatch = mock(LeaderLatch.class);
    when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
    Set<ActiveStateChangeHandler> changeHandlers = new HashSet<>();
    final ActiveStateChangeHandler handler1 = mock(ActiveStateChangeHandler.class);
    final ActiveStateChangeHandler handler2 = mock(ActiveStateChangeHandler.class);
    changeHandlers.add(handler1);
    changeHandlers.add(handler2);
    ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, changeHandlers, curatorFactory, activeInstanceState, serviceState);
    activeInstanceElectorService.start();
    activeInstanceElectorService.notLeader();
    verify(handler1).instanceIsPassive();
    verify(handler2).instanceIsPassive();
}
Also used : LeaderLatch(org.apache.curator.framework.recipes.leader.LeaderLatch) HashSet(java.util.HashSet) ActiveStateChangeHandler(org.apache.atlas.listener.ActiveStateChangeHandler) Test(org.testng.annotations.Test)

Example 2 with ActiveStateChangeHandler

use of org.apache.atlas.listener.ActiveStateChangeHandler in project incubator-atlas by apache.

the class ActiveInstanceElectorServiceTest method testPassiveStateSetOnLoosingLeadership.

@Test
public void testPassiveStateSetOnLoosingLeadership() {
    ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory, activeInstanceState, serviceState);
    activeInstanceElectorService.notLeader();
    InOrder inOrder = inOrder(serviceState);
    inOrder.verify(serviceState).becomingPassive();
    inOrder.verify(serviceState).setPassive();
}
Also used : InOrder(org.mockito.InOrder) ActiveStateChangeHandler(org.apache.atlas.listener.ActiveStateChangeHandler) Test(org.testng.annotations.Test)

Example 3 with ActiveStateChangeHandler

use of org.apache.atlas.listener.ActiveStateChangeHandler in project incubator-atlas by apache.

the class ActiveInstanceElectorServiceTest method testLeaderElectionIsLeftOnStop.

@Test
public void testLeaderElectionIsLeftOnStop() throws IOException, AtlasException {
    when(configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
    when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
    when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(new String[] { "id1" });
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX + "id1")).thenReturn("127.0.0.1:21000");
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
    LeaderLatch leaderLatch = mock(LeaderLatch.class);
    when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
    ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory, activeInstanceState, serviceState);
    activeInstanceElectorService.start();
    activeInstanceElectorService.stop();
    verify(leaderLatch).close();
}
Also used : LeaderLatch(org.apache.curator.framework.recipes.leader.LeaderLatch) ActiveStateChangeHandler(org.apache.atlas.listener.ActiveStateChangeHandler) Test(org.testng.annotations.Test)

Example 4 with ActiveStateChangeHandler

use of org.apache.atlas.listener.ActiveStateChangeHandler in project incubator-atlas by apache.

the class ActiveInstanceElectorServiceTest method testSharedStateIsUpdatedWhenInstanceIsActive.

@Test
public void testSharedStateIsUpdatedWhenInstanceIsActive() throws Exception {
    when(configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
    when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
    when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(new String[] { "id1" });
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX + "id1")).thenReturn("127.0.0.1:21000");
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
    LeaderLatch leaderLatch = mock(LeaderLatch.class);
    when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
    ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory, activeInstanceState, serviceState);
    activeInstanceElectorService.start();
    activeInstanceElectorService.isLeader();
    verify(activeInstanceState).update("id1");
}
Also used : LeaderLatch(org.apache.curator.framework.recipes.leader.LeaderLatch) ActiveStateChangeHandler(org.apache.atlas.listener.ActiveStateChangeHandler) Test(org.testng.annotations.Test)

Example 5 with ActiveStateChangeHandler

use of org.apache.atlas.listener.ActiveStateChangeHandler in project incubator-atlas by apache.

the class ActiveInstanceElectorServiceTest method testListenerIsAddedForActiveInstanceCallbacks.

@Test
public void testListenerIsAddedForActiveInstanceCallbacks() throws Exception {
    when(configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
    when(configuration.getBoolean(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)).thenReturn(true);
    when(configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS)).thenReturn(new String[] { "id1" });
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX + "id1")).thenReturn("127.0.0.1:21000");
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
    LeaderLatch leaderLatch = mock(LeaderLatch.class);
    when(curatorFactory.leaderLatchInstance("id1", HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(leaderLatch);
    ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory, activeInstanceState, serviceState);
    activeInstanceElectorService.start();
    verify(leaderLatch).addListener(activeInstanceElectorService);
}
Also used : LeaderLatch(org.apache.curator.framework.recipes.leader.LeaderLatch) ActiveStateChangeHandler(org.apache.atlas.listener.ActiveStateChangeHandler) Test(org.testng.annotations.Test)

Aggregations

ActiveStateChangeHandler (org.apache.atlas.listener.ActiveStateChangeHandler)14 Test (org.testng.annotations.Test)12 LeaderLatch (org.apache.curator.framework.recipes.leader.LeaderLatch)10 InOrder (org.mockito.InOrder)4 HashSet (java.util.HashSet)3 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)3 AtlasException (org.apache.atlas.AtlasException)2 IOException (java.io.IOException)1