use of org.opendaylight.controller.cluster.dom.api.LeaderLocationListener in project controller by opendaylight.
the class CDSShardAccessImplTest method testRegisterLeaderLocationListener.
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testRegisterLeaderLocationListener() {
final LeaderLocationListener listener1 = mock(LeaderLocationListener.class);
// first registration should be OK
shardAccess.registerLeaderLocationListener(listener1);
// second registration should fail with IllegalArgumentEx
try {
shardAccess.registerLeaderLocationListener(listener1);
fail("Should throw exception");
} catch (final Exception e) {
assertTrue(e instanceof IllegalArgumentException);
}
// null listener registration should fail with NPE
try {
shardAccess.registerLeaderLocationListener(null);
fail("Should throw exception");
} catch (final Exception e) {
assertTrue(e instanceof NullPointerException);
}
// registering listener on closed shard access should fail with IllegalStateEx
final LeaderLocationListener listener2 = mock(LeaderLocationListener.class);
shardAccess.close();
try {
shardAccess.registerLeaderLocationListener(listener2);
fail("Should throw exception");
} catch (final Exception ex) {
assertTrue(ex instanceof IllegalStateException);
}
}
use of org.opendaylight.controller.cluster.dom.api.LeaderLocationListener in project controller by opendaylight.
the class RoleChangeListenerActorTest method testOnDataTreeChanged.
@Test
public void testOnDataTreeChanged() {
final LeaderLocationListener listener = mock(LeaderLocationListener.class);
doNothing().when(listener).onLeaderLocationChanged(any());
final Props props = RoleChangeListenerActor.props(getSystem().deadLetters(), listener);
final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedChanged");
subject.tell(new LeaderStateChanged("member-1", null, (short) 0), noSender());
verify(listener, timeout(5000)).onLeaderLocationChanged(eq(LeaderLocation.UNKNOWN));
subject.tell(new LeaderStateChanged("member-1", "member-1", (short) 0), noSender());
verify(listener, timeout(5000)).onLeaderLocationChanged(eq(LeaderLocation.LOCAL));
subject.tell(new LeaderStateChanged("member-1", "member-2", (short) 0), noSender());
verify(listener, timeout(5000)).onLeaderLocationChanged(eq(LeaderLocation.REMOTE));
}
use of org.opendaylight.controller.cluster.dom.api.LeaderLocationListener in project controller by opendaylight.
the class CDSShardAccessImplTest method testOnLeaderLocationChanged.
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testOnLeaderLocationChanged() {
final LeaderLocationListener listener1 = mock(LeaderLocationListener.class);
doThrow(new RuntimeException("Failed")).when(listener1).onLeaderLocationChanged(any());
final LeaderLocationListener listener2 = mock(LeaderLocationListener.class);
doNothing().when(listener2).onLeaderLocationChanged(any());
final LeaderLocationListener listener3 = mock(LeaderLocationListener.class);
doNothing().when(listener3).onLeaderLocationChanged(any());
final LeaderLocationListenerRegistration<?> reg1 = shardAccess.registerLeaderLocationListener(listener1);
final LeaderLocationListenerRegistration<?> reg2 = shardAccess.registerLeaderLocationListener(listener2);
final LeaderLocationListenerRegistration<?> reg3 = shardAccess.registerLeaderLocationListener(listener3);
// Error in listener1 should not affect dispatching change to other listeners
shardAccess.onLeaderLocationChanged(LeaderLocation.LOCAL);
verify(listener1).onLeaderLocationChanged(eq(LeaderLocation.LOCAL));
verify(listener2).onLeaderLocationChanged(eq(LeaderLocation.LOCAL));
verify(listener3).onLeaderLocationChanged(eq(LeaderLocation.LOCAL));
// Closed listeners shouldn't see new leader location changes
reg1.close();
reg2.close();
shardAccess.onLeaderLocationChanged(LeaderLocation.REMOTE);
verify(listener3).onLeaderLocationChanged(eq(LeaderLocation.REMOTE));
verifyNoMoreInteractions(listener1);
verifyNoMoreInteractions(listener2);
// Closed shard access should not dispatch any new events
shardAccess.close();
shardAccess.onLeaderLocationChanged(LeaderLocation.UNKNOWN);
verifyNoMoreInteractions(listener1);
verifyNoMoreInteractions(listener2);
verifyNoMoreInteractions(listener3);
reg3.close();
}
use of org.opendaylight.controller.cluster.dom.api.LeaderLocationListener in project controller by opendaylight.
the class RoleChangeListenerActorTest method testRegisterRoleChangeListenerOnStart.
@Test
public void testRegisterRoleChangeListenerOnStart() {
new TestKit(getSystem()) {
{
final LeaderLocationListener listener = mock(LeaderLocationListener.class);
final Props props = RoleChangeListenerActor.props(getRef(), listener);
getSystem().actorOf(props, "testRegisterRoleChangeListenerOnStart");
expectMsgClass(RegisterRoleChangeListener.class);
}
};
}
Aggregations