Search in sources :

Example 1 with DOMEntityOwnershipListenerRegistration

use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration 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();
}
Also used : DOMEntityOwnershipListener(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener) DOMEntityOwnershipListenerRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration) DOMEntityOwnershipChange(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange) EntityOwnershipChange(org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipChange) EntityOwnershipListener(org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener) DOMEntityOwnershipListener(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener) DOMEntityOwnershipChange(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange) EntityOwnershipListenerRegistration(org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration) DOMEntityOwnershipListenerRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration) Test(org.junit.Test)

Example 2 with DOMEntityOwnershipListenerRegistration

use of org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration in project controller by opendaylight.

the class DistributedEntityOwnershipServiceTest method testListenerRegistration.

@Test
public void testListenerRegistration() {
    DistributedEntityOwnershipService service = spy(DistributedEntityOwnershipService.start(dataStore.getActorContext(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
    YangInstanceIdentifier entityId = YangInstanceIdentifier.of(QNAME);
    DOMEntity entity = new DOMEntity(ENTITY_TYPE, entityId);
    DOMEntityOwnershipListener listener = mock(DOMEntityOwnershipListener.class);
    DOMEntityOwnershipListenerRegistration reg = service.registerListener(entity.getType(), listener);
    assertNotNull("EntityOwnershipListenerRegistration null", reg);
    assertEquals("getEntityType", entity.getType(), reg.getEntityType());
    assertEquals("getInstance", listener, reg.getInstance());
    RegisterListenerLocal regListener = verifyMessage(service, RegisterListenerLocal.class);
    assertSame("getListener", listener, regListener.getListener());
    assertEquals("getEntityType", entity.getType(), regListener.getEntityType());
    reset(service);
    reg.close();
    UnregisterListenerLocal unregListener = verifyMessage(service, UnregisterListenerLocal.class);
    assertEquals("getEntityType", entity.getType(), unregListener.getEntityType());
    assertSame("getListener", listener, unregListener.getListener());
    service.close();
}
Also used : DOMEntityOwnershipListener(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener) DOMEntityOwnershipListenerRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration) UnregisterListenerLocal(org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterListenerLocal) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) RegisterListenerLocal(org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterListenerLocal) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 DOMEntityOwnershipListener (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener)2 DOMEntityOwnershipListenerRegistration (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration)2 RegisterListenerLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterListenerLocal)1 UnregisterListenerLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterListenerLocal)1 EntityOwnershipChange (org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipChange)1 EntityOwnershipListener (org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener)1 EntityOwnershipListenerRegistration (org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration)1 DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)1 DOMEntityOwnershipChange (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange)1 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)1