use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange in project controller by opendaylight.
the class DistributedEntityOwnershipIntegrationTest method testCloseCandidateRegistrationInQuickSuccession.
/**
* Reproduces bug <a href="https://bugs.opendaylight.org/show_bug.cgi?id=4554">4554</a>.
*/
@Test
public void testCloseCandidateRegistrationInQuickSuccession() throws Exception {
String name = "testCloseCandidateRegistrationInQuickSuccession";
MemberNode leaderNode = MemberNode.builder(memberNodes).akkaConfig("Member1").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(leaderDatastoreContextBuilder).build();
MemberNode follower1Node = MemberNode.builder(memberNodes).akkaConfig("Member2").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
MemberNode follower2Node = MemberNode.builder(memberNodes).akkaConfig("Member3").testName(name).moduleShardsConfig(MODULE_SHARDS_CONFIG).schemaContext(SCHEMA_CONTEXT).createOperDatastore(false).datastoreContextBuilder(followerDatastoreContextBuilder).build();
AbstractDataStore leaderDistributedDataStore = leaderNode.configDataStore();
leaderDistributedDataStore.waitTillReady();
follower1Node.configDataStore().waitTillReady();
follower2Node.configDataStore().waitTillReady();
final DOMEntityOwnershipService leaderEntityOwnershipService = newOwnershipService(leaderDistributedDataStore);
final DOMEntityOwnershipService follower1EntityOwnershipService = newOwnershipService(follower1Node.configDataStore());
final DOMEntityOwnershipService follower2EntityOwnershipService = newOwnershipService(follower2Node.configDataStore());
leaderNode.kit().waitUntilLeader(leaderNode.configDataStore().getActorContext(), ENTITY_OWNERSHIP_SHARD_NAME);
leaderEntityOwnershipService.registerListener(ENTITY_TYPE1, leaderMockListener);
follower1EntityOwnershipService.registerListener(ENTITY_TYPE1, follower1MockListener);
follower2EntityOwnershipService.registerListener(ENTITY_TYPE1, follower2MockListener);
final DOMEntityOwnershipCandidateRegistration candidate1 = leaderEntityOwnershipService.registerCandidate(ENTITY1);
verify(leaderMockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, true, true));
final DOMEntityOwnershipCandidateRegistration candidate2 = follower1EntityOwnershipService.registerCandidate(ENTITY1);
verify(follower1MockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
final DOMEntityOwnershipCandidateRegistration candidate3 = follower2EntityOwnershipService.registerCandidate(ENTITY1);
verify(follower2MockListener, timeout(5000)).ownershipChanged(ownershipChange(ENTITY1, false, false, true));
Mockito.reset(leaderMockListener, follower1MockListener, follower2MockListener);
ArgumentCaptor<DOMEntityOwnershipChange> leaderChangeCaptor = ArgumentCaptor.forClass(DOMEntityOwnershipChange.class);
ArgumentCaptor<DOMEntityOwnershipChange> follower1ChangeCaptor = ArgumentCaptor.forClass(DOMEntityOwnershipChange.class);
ArgumentCaptor<DOMEntityOwnershipChange> follower2ChangeCaptor = ArgumentCaptor.forClass(DOMEntityOwnershipChange.class);
doNothing().when(leaderMockListener).ownershipChanged(leaderChangeCaptor.capture());
doNothing().when(follower1MockListener).ownershipChanged(follower1ChangeCaptor.capture());
doNothing().when(follower2MockListener).ownershipChanged(follower2ChangeCaptor.capture());
candidate1.close();
candidate2.close();
candidate3.close();
boolean passed = false;
for (int i = 0; i < 100; i++) {
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
final Optional<EntityOwnershipState> leaderState = leaderEntityOwnershipService.getOwnershipState(ENTITY1);
final Optional<EntityOwnershipState> follower1State = follower1EntityOwnershipService.getOwnershipState(ENTITY1);
final Optional<EntityOwnershipState> follower2State = follower2EntityOwnershipService.getOwnershipState(ENTITY1);
final Optional<DOMEntityOwnershipChange> leaderChange = getValueSafely(leaderChangeCaptor);
final Optional<DOMEntityOwnershipChange> follower1Change = getValueSafely(follower1ChangeCaptor);
final Optional<DOMEntityOwnershipChange> follower2Change = getValueSafely(follower2ChangeCaptor);
if (!leaderState.isPresent() || leaderState.get() == EntityOwnershipState.NO_OWNER && follower1State.isPresent() && follower1State.get() == EntityOwnershipState.NO_OWNER && follower2State.isPresent() && follower2State.get() == EntityOwnershipState.NO_OWNER && leaderChange.isPresent() && !leaderChange.get().getState().hasOwner() && follower1Change.isPresent() && !follower1Change.get().getState().hasOwner() && follower2Change.isPresent() && !follower2Change.get().getState().hasOwner()) {
passed = true;
break;
}
}
assertTrue("No ownership change message was sent with hasOwner=false", passed);
}
use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange in project controller by opendaylight.
the class EntityOwnershipListenerActorTest method testOnEntityOwnershipChangedWithListenerEx.
@Test
public void testOnEntityOwnershipChangedWithListenerEx() {
DOMEntityOwnershipListener mockListener = mock(DOMEntityOwnershipListener.class);
DOMEntity entity1 = new DOMEntity("test", YangInstanceIdentifier.of(QName.create("test", "id1")));
doThrow(new RuntimeException("mock")).when(mockListener).ownershipChanged(ownershipChange(entity1, false, true, true));
DOMEntity entity2 = new DOMEntity("test", YangInstanceIdentifier.of(QName.create("test", "id2")));
doNothing().when(mockListener).ownershipChanged(ownershipChange(entity2, true, false, false));
TestActorRef<EntityOwnershipListenerActor> listenerActor = actorFactory.createTestActor(EntityOwnershipListenerActor.props(mockListener), actorFactory.generateActorId("listener"));
listenerActor.tell(new DOMEntityOwnershipChange(entity1, EntityOwnershipChangeState.from(false, true, true)), ActorRef.noSender());
listenerActor.tell(new DOMEntityOwnershipChange(entity2, EntityOwnershipChangeState.from(true, false, false)), ActorRef.noSender());
verify(mockListener, timeout(5000)).ownershipChanged(ownershipChange(entity2, true, false, false));
}
use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange in project controller by opendaylight.
the class LegacyEntityOwnershipServiceAdapterTest method testRegisterListener.
@Test
public void testRegisterListener() {
DOMEntityOwnershipListenerRegistration mockDOMReg = mock(DOMEntityOwnershipListenerRegistration.class);
doNothing().when(mockDOMReg).close();
doReturn(mockDOMReg).when(mockDOMService).registerListener(eq(DOM_ENTITY.getType()), any(DOMEntityOwnershipListener.class));
EntityOwnershipListener mockListener = mock(EntityOwnershipListener.class);
doNothing().when(mockListener).ownershipChanged(any(EntityOwnershipChange.class));
EntityOwnershipListenerRegistration reg = adapter.registerListener(LEGACY_ENTITY.getType(), mockListener);
assertNotNull("registerListener returned null", reg);
assertEquals("getInstance", mockListener, reg.getInstance());
assertEquals("getEntityType", LEGACY_ENTITY.getType(), reg.getEntityType());
ArgumentCaptor<DOMEntityOwnershipListener> domListenerCaptor = ArgumentCaptor.forClass(DOMEntityOwnershipListener.class);
verify(mockDOMService).registerListener(eq(DOM_ENTITY.getType()), domListenerCaptor.capture());
DOMEntityOwnershipChange domOwnershipChange = new DOMEntityOwnershipChange(DOM_ENTITY, EntityOwnershipChangeState.LOCAL_OWNERSHIP_GRANTED);
domListenerCaptor.getValue().ownershipChanged(domOwnershipChange);
ArgumentCaptor<EntityOwnershipChange> ownershipChangeCaptor = ArgumentCaptor.forClass(EntityOwnershipChange.class);
verify(mockListener).ownershipChanged(ownershipChangeCaptor.capture());
EntityOwnershipChange change = ownershipChangeCaptor.getValue();
assertEquals("getEntity", LEGACY_ENTITY, change.getEntity());
assertEquals("wasOwner", false, change.wasOwner());
assertEquals("isOwner", true, change.isOwner());
assertEquals("hasOwner", true, change.hasOwner());
reg.close();
verify(mockDOMReg).close();
}
use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange in project controller by opendaylight.
the class EntityOwnershipListenerSupport method notifyListeners.
@GuardedBy("listenerLock")
private void notifyListeners(final DOMEntity entity, final boolean wasOwner, final boolean isOwner, final boolean hasOwner, final Collection<ListenerActorRefEntry> listenerEntries) {
DOMEntityOwnershipChange changed = new DOMEntityOwnershipChange(entity, EntityOwnershipChangeState.from(wasOwner, isOwner, hasOwner), inJeopardy);
for (ListenerActorRefEntry entry : listenerEntries) {
ActorRef listenerActor = entry.actorFor();
LOG.debug("{}: Notifying EntityOwnershipListenerActor {} with {}", logId, listenerActor, changed);
listenerActor.tell(changed, ActorRef.noSender());
}
}
use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange in project controller by opendaylight.
the class EntityOwnershipListenerActorTest method testOnEntityOwnershipChanged.
@Test
public void testOnEntityOwnershipChanged() {
DOMEntityOwnershipListener mockListener = mock(DOMEntityOwnershipListener.class);
TestActorRef<EntityOwnershipListenerActor> listenerActor = actorFactory.createTestActor(EntityOwnershipListenerActor.props(mockListener), actorFactory.generateActorId("listener"));
DOMEntity entity = new DOMEntity("test", YangInstanceIdentifier.of(QName.create("test", "id1")));
boolean wasOwner = false;
boolean isOwner = true;
boolean hasOwner = true;
listenerActor.tell(new DOMEntityOwnershipChange(entity, EntityOwnershipChangeState.from(wasOwner, isOwner, hasOwner)), ActorRef.noSender());
verify(mockListener, timeout(5000)).ownershipChanged(ownershipChange(entity, wasOwner, isOwner, hasOwner));
}
Aggregations