Search in sources :

Example 46 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class LocalTransactionContextTest method testWrite.

@Test
public void testWrite() {
    YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
    NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
    localTransactionContext.executeModification(new WriteModification(yangInstanceIdentifier, normalizedNode));
    verify(readWriteTransaction).write(yangInstanceIdentifier, normalizedNode);
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 47 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class LocalTransactionContextTest method testReadyWithDeleteError.

@Test
public void testReadyWithDeleteError() {
    YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
    RuntimeException error = new RuntimeException("mock");
    doThrow(error).when(readWriteTransaction).delete(yangInstanceIdentifier);
    localTransactionContext.executeModification(new DeleteModification(yangInstanceIdentifier));
    localTransactionContext.executeModification(new DeleteModification(yangInstanceIdentifier));
    verify(readWriteTransaction).delete(yangInstanceIdentifier);
    doReadyWithExpectedError(error);
}
Also used : DeleteModification(org.opendaylight.controller.cluster.datastore.modification.DeleteModification) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 48 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class LocalTransactionContextTest method testRead.

@Test
public void testRead() {
    YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
    NormalizedNode<?, ?> normalizedNode = mock(NormalizedNode.class);
    doReturn(Futures.immediateCheckedFuture(Optional.of(normalizedNode))).when(readWriteTransaction).read(yangInstanceIdentifier);
    localTransactionContext.executeRead(new ReadData(yangInstanceIdentifier, DataStoreVersions.CURRENT_VERSION), SettableFuture.<Optional<NormalizedNode<?, ?>>>create());
    verify(readWriteTransaction).read(yangInstanceIdentifier);
}
Also used : NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ReadData(org.opendaylight.controller.cluster.datastore.messages.ReadData) Test(org.junit.Test)

Example 49 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class LocalTransactionContextTest method testExists.

@Test
public void testExists() {
    YangInstanceIdentifier yangInstanceIdentifier = YangInstanceIdentifier.EMPTY;
    doReturn(Futures.immediateCheckedFuture(true)).when(readWriteTransaction).exists(yangInstanceIdentifier);
    localTransactionContext.executeRead(new DataExists(yangInstanceIdentifier, DataStoreVersions.CURRENT_VERSION), SettableFuture.<Boolean>create());
    verify(readWriteTransaction).exists(yangInstanceIdentifier);
}
Also used : DataExists(org.opendaylight.controller.cluster.datastore.messages.DataExists) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 50 with YangInstanceIdentifier

use of org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier in project controller by opendaylight.

the class EntityOwnershipShardTest method testOnRegisterCandidateLocalWithNoInitialConsensus.

@Test
public void testOnRegisterCandidateLocalWithNoInitialConsensus() throws Exception {
    testLog.info("testOnRegisterCandidateLocalWithNoInitialConsensus starting");
    final ShardTestKit kit = new ShardTestKit(getSystem());
    dataStoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(2).shardTransactionCommitTimeoutInSeconds(1);
    ShardIdentifier leaderId = newShardId(LOCAL_MEMBER_NAME);
    ShardIdentifier peerId = newShardId(PEER_MEMBER_1_NAME);
    TestActorRef<TestEntityOwnershipShard> peer = actorFactory.createTestActor(TestEntityOwnershipShard.props(newShardBuilder(peerId, peerMap(leaderId.toString()), PEER_MEMBER_1_NAME)), peerId.toString());
    TestEntityOwnershipShard peerShard = peer.underlyingActor();
    peerShard.startDroppingMessagesOfType(ElectionTimeout.class);
    // Drop AppendEntries so consensus isn't reached.
    peerShard.startDroppingMessagesOfType(AppendEntries.class);
    TestActorRef<EntityOwnershipShard> leader = actorFactory.createTestActor(newShardProps(leaderId, peerMap(peerId.toString()), LOCAL_MEMBER_NAME), leaderId.toString());
    ShardTestKit.waitUntilLeader(leader);
    YangInstanceIdentifier entityId = ENTITY_ID1;
    DOMEntity entity = new DOMEntity(ENTITY_TYPE, entityId);
    leader.tell(new RegisterCandidateLocal(entity), kit.getRef());
    kit.expectMsgClass(SuccessReply.class);
    // Wait enough time for the commit to timeout.
    Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
    // Resume AppendEntries - the follower should ack the commit which should then result in the candidate
    // write being applied to the state.
    peerShard.stopDroppingMessagesOfType(AppendEntries.class);
    verifyCommittedEntityCandidate(leader, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
    verifyOwner(leader, ENTITY_TYPE, entityId, LOCAL_MEMBER_NAME);
    testLog.info("testOnRegisterCandidateLocalWithNoInitialConsensus ending");
}
Also used : RegisterCandidateLocal(org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal) ShardTestKit(org.opendaylight.controller.cluster.datastore.ShardTestKit) ShardIdentifier(org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier) DOMEntity(org.opendaylight.mdsal.eos.dom.api.DOMEntity) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Aggregations

YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)187 Test (org.junit.Test)111 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)34 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)21 ActorRef (akka.actor.ActorRef)19 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)19 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)15 TestActorRef (akka.testkit.TestActorRef)14 TestKit (akka.testkit.javadsl.TestKit)13 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)12 ArrayList (java.util.ArrayList)11 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)10 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)10 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)10 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)10 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)9 RegisterChangeListener (org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener)9 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)9 DOMStoreWriteTransaction (org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction)9 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)9