Search in sources :

Example 16 with DOMEntity

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

the class DistributedEntityOwnershipServiceTest method testRegisterCandidate.

@Test
public void testRegisterCandidate() throws Exception {
    DistributedEntityOwnershipService service = spy(DistributedEntityOwnershipService.start(dataStore.getActorContext(), EntityOwnerSelectionStrategyConfig.newBuilder().build()));
    YangInstanceIdentifier entityId = YangInstanceIdentifier.of(QNAME);
    DOMEntity entity = new DOMEntity(ENTITY_TYPE, entityId);
    DOMEntityOwnershipCandidateRegistration reg = service.registerCandidate(entity);
    verifyRegisterCandidateLocal(service, entity);
    verifyEntityOwnershipCandidateRegistration(entity, reg);
    verifyEntityCandidate(service.getLocalEntityOwnershipShard(), ENTITY_TYPE, entityId, dataStore.getActorContext().getCurrentMemberName().getName());
    try {
        service.registerCandidate(entity);
        fail("Expected CandidateAlreadyRegisteredException");
    } catch (CandidateAlreadyRegisteredException e) {
        // expected
        assertEquals("getEntity", entity, e.getEntity());
    }
    // Register a different entity - should succeed
    reset(service);
    DOMEntity entity2 = new DOMEntity(ENTITY_TYPE2, entityId);
    DOMEntityOwnershipCandidateRegistration reg2 = service.registerCandidate(entity2);
    verifyEntityOwnershipCandidateRegistration(entity2, reg2);
    verifyEntityCandidate(service.getLocalEntityOwnershipShard(), ENTITY_TYPE2, entityId, dataStore.getActorContext().getCurrentMemberName().getName());
    service.close();
}
Also used : CandidateAlreadyRegisteredException(org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException) DOMEntityOwnershipCandidateRegistration(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 17 with DOMEntity

use of org.opendaylight.mdsal.eos.dom.api.DOMEntity 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)

Example 18 with DOMEntity

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

the class DistributedEntityOwnershipServiceTest method testIsCandidateRegistered.

@Test
public void testIsCandidateRegistered() throws CandidateAlreadyRegisteredException {
    DistributedEntityOwnershipService service = DistributedEntityOwnershipService.start(dataStore.getActorContext(), EntityOwnerSelectionStrategyConfig.newBuilder().build());
    final DOMEntity test = new DOMEntity("test-type", "test");
    assertFalse(service.isCandidateRegistered(test));
    service.registerCandidate(test);
    assertTrue(service.isCandidateRegistered(test));
    service.close();
}
Also used : DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) Test(org.junit.Test)

Example 19 with DOMEntity

use of org.opendaylight.mdsal.eos.dom.api.DOMEntity 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));
}
Also used : DOMEntityOwnershipListener(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener) DOMEntityOwnershipChange(org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) Test(org.junit.Test)

Example 20 with DOMEntity

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

the class EntityOwnershipShardTest method testDelayedEntityOwnerSelection.

@Test
public void testDelayedEntityOwnerSelection() throws Exception {
    testLog.info("testDelayedEntityOwnerSelection starting");
    final ShardTestKit kit = new ShardTestKit(getSystem());
    EntityOwnerSelectionStrategyConfig.Builder builder = EntityOwnerSelectionStrategyConfig.newBuilder().addStrategy(ENTITY_TYPE, LastCandidateSelectionStrategy.class, 500);
    dataStoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(2);
    ShardIdentifier leaderId = newShardId(LOCAL_MEMBER_NAME);
    ShardIdentifier peerId1 = newShardId(PEER_MEMBER_1_NAME);
    ShardIdentifier peerId2 = newShardId(PEER_MEMBER_2_NAME);
    TestActorRef<TestEntityOwnershipShard> peer1 = actorFactory.createTestActor(TestEntityOwnershipShard.props(newShardBuilder(peerId1, peerMap(leaderId.toString(), peerId2.toString()), PEER_MEMBER_1_NAME)), peerId1.toString());
    peer1.underlyingActor().startDroppingMessagesOfType(ElectionTimeout.class);
    TestActorRef<TestEntityOwnershipShard> peer2 = actorFactory.createTestActor(TestEntityOwnershipShard.props(newShardBuilder(peerId2, peerMap(leaderId.toString(), peerId1.toString()), PEER_MEMBER_2_NAME)), peerId2.toString());
    peer2.underlyingActor().startDroppingMessagesOfType(ElectionTimeout.class);
    TestActorRef<EntityOwnershipShard> leader = actorFactory.createTestActor(newShardProps(leaderId, peerMap(peerId1.toString(), peerId2.toString()), LOCAL_MEMBER_NAME, builder.build()), leaderId.toString());
    ShardTestKit.waitUntilLeader(leader);
    DOMEntity entity = new DOMEntity(ENTITY_TYPE, ENTITY_ID1);
    // Add a remote candidate
    peer1.tell(new RegisterCandidateLocal(entity), kit.getRef());
    kit.expectMsgClass(SuccessReply.class);
    // Register local
    leader.tell(new RegisterCandidateLocal(entity), kit.getRef());
    kit.expectMsgClass(SuccessReply.class);
    // Verify the local candidate becomes owner
    verifyCommittedEntityCandidate(leader, entity.getType(), entity.getIdentifier(), PEER_MEMBER_1_NAME);
    verifyCommittedEntityCandidate(leader, entity.getType(), entity.getIdentifier(), LOCAL_MEMBER_NAME);
    verifyOwner(leader, entity.getType(), entity.getIdentifier(), LOCAL_MEMBER_NAME);
    testLog.info("testDelayedEntityOwnerSelection ending");
}
Also used : RegisterCandidateLocal(org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal) ShardTestKit(org.opendaylight.controller.cluster.datastore.ShardTestKit) EntityOwnerSelectionStrategyConfig(org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfig) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) Test(org.junit.Test)

Aggregations

DOMEntity (org.opendaylight.mdsal.eos.dom.api.DOMEntity)26 Test (org.junit.Test)21 ShardTestKit (org.opendaylight.controller.cluster.datastore.ShardTestKit)13 RegisterCandidateLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal)13 ShardIdentifier (org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier)11 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)9 DOMEntityOwnershipListener (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener)7 RegisterListenerLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterListenerLocal)4 UnregisterCandidateLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterCandidateLocal)4 DOMEntityOwnershipChange (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange)4 PeerDown (org.opendaylight.controller.cluster.datastore.messages.PeerDown)3 ArrayList (java.util.ArrayList)2 UnregisterListenerLocal (org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterListenerLocal)2 EntityOwnerSelectionStrategyConfig (org.opendaylight.controller.cluster.datastore.entityownership.selectionstrategy.EntityOwnerSelectionStrategyConfig)2 PeerUp (org.opendaylight.controller.cluster.datastore.messages.PeerUp)2 DOMEntityOwnershipCandidateRegistration (org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipCandidateRegistration)2 DataContainerChild (org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild)2 ActorRef (akka.actor.ActorRef)1 TestActorRef (akka.testkit.TestActorRef)1 TestKit (akka.testkit.javadsl.TestKit)1