use of org.apache.atlas.listener.ActiveStateChangeHandler in project incubator-atlas by apache.
the class ActiveInstanceElectorServiceTest method testPassiveStateSetIfActivationFails.
@Test
public void testPassiveStateSetIfActivationFails() 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);
doThrow(new AtlasBaseException()).when(activeInstanceState).update("id1");
ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory, activeInstanceState, serviceState);
activeInstanceElectorService.start();
activeInstanceElectorService.isLeader();
InOrder inOrder = inOrder(serviceState);
inOrder.verify(serviceState).becomingActive();
inOrder.verify(serviceState).becomingPassive();
inOrder.verify(serviceState).setPassive();
}
use of org.apache.atlas.listener.ActiveStateChangeHandler in project incubator-atlas by apache.
the class ActiveInstanceElectorServiceTest method testRegisteredHandlersAreNotifiedWhenInstanceIsActive.
@Test
public void testRegisteredHandlersAreNotifiedWhenInstanceIsActive() 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.isLeader();
verify(handler1).instanceIsActive();
verify(handler2).instanceIsActive();
}
use of org.apache.atlas.listener.ActiveStateChangeHandler in project incubator-atlas by apache.
the class ActiveInstanceElectorServiceTest method testActiveStateSetOnBecomingLeader.
@Test
public void testActiveStateSetOnBecomingLeader() {
ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory, activeInstanceState, serviceState);
activeInstanceElectorService.isLeader();
InOrder inOrder = inOrder(serviceState);
inOrder.verify(serviceState).becomingActive();
inOrder.verify(serviceState).setActive();
}
use of org.apache.atlas.listener.ActiveStateChangeHandler in project incubator-atlas by apache.
the class ActiveInstanceElectorServiceTest method testRegisteredHandlersAreNotifiedOfPassiveWhenStateUpdateFails.
@Test
public void testRegisteredHandlersAreNotifiedOfPassiveWhenStateUpdateFails() 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);
Set<ActiveStateChangeHandler> changeHandlers = new HashSet<>();
final ActiveStateChangeHandler handler1 = mock(ActiveStateChangeHandler.class);
final ActiveStateChangeHandler handler2 = mock(ActiveStateChangeHandler.class);
changeHandlers.add(handler1);
changeHandlers.add(handler2);
doThrow(new AtlasBaseException()).when(activeInstanceState).update("id1");
ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, changeHandlers, curatorFactory, activeInstanceState, serviceState);
activeInstanceElectorService.start();
activeInstanceElectorService.isLeader();
verify(handler1).instanceIsPassive();
verify(handler2).instanceIsPassive();
}
use of org.apache.atlas.listener.ActiveStateChangeHandler in project incubator-atlas by apache.
the class ActiveInstanceElectorServiceTest method testCuratorFactoryIsClosedOnStop.
@Test
public void testCuratorFactoryIsClosedOnStop() 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);
ActiveInstanceElectorService activeInstanceElectorService = new ActiveInstanceElectorService(configuration, new HashSet<ActiveStateChangeHandler>(), curatorFactory, activeInstanceState, serviceState);
activeInstanceElectorService.start();
activeInstanceElectorService.stop();
verify(curatorFactory).close();
}
Aggregations