Search in sources :

Example 1 with ReadData

use of org.opendaylight.controller.cluster.datastore.messages.ReadData in project controller by opendaylight.

the class ShardTransactionTest method testOnReceiveReadData.

@Test
public void testOnReceiveReadData() throws Exception {
    new TestKit(getSystem()) {

        {
            testOnReceiveReadData(newTransactionActor(RO, readOnlyTransaction(), "testReadDataRO"));
            testOnReceiveReadData(newTransactionActor(RW, readWriteTransaction(), "testReadDataRW"));
        }

        private void testOnReceiveReadData(final ActorRef transaction) {
            transaction.tell(new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), getRef());
            ReadDataReply reply = expectMsgClass(duration("5 seconds"), ReadDataReply.class);
            assertNotNull(reply.getNormalizedNode());
        }
    };
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TestKit(akka.testkit.javadsl.TestKit) ReadDataReply(org.opendaylight.controller.cluster.datastore.messages.ReadDataReply) ReadData(org.opendaylight.controller.cluster.datastore.messages.ReadData) Test(org.junit.Test)

Example 2 with ReadData

use of org.opendaylight.controller.cluster.datastore.messages.ReadData 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 3 with ReadData

use of org.opendaylight.controller.cluster.datastore.messages.ReadData in project controller by opendaylight.

the class ShardTest method testBatchedModificationsOnTransactionChain.

@Test
public void testBatchedModificationsOnTransactionChain() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testBatchedModificationsOnTransactionChain");
            waitUntilLeader(shard);
            final LocalHistoryIdentifier historyId = nextHistoryId();
            final TransactionIdentifier transactionID1 = new TransactionIdentifier(historyId, 0);
            final TransactionIdentifier transactionID2 = new TransactionIdentifier(historyId, 1);
            final FiniteDuration duration = duration("5 seconds");
            // Send a BatchedModifications to start a chained write
            // transaction and ready it.
            final ContainerNode containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
            final YangInstanceIdentifier path = TestModel.TEST_PATH;
            shard.tell(newBatchedModifications(transactionID1, path, containerNode, true, false, 1), getRef());
            expectMsgClass(duration, ReadyTransactionReply.class);
            // Create a read Tx on the same chain.
            shard.tell(new CreateTransaction(transactionID2, TransactionType.READ_ONLY.ordinal(), DataStoreVersions.CURRENT_VERSION).toSerializable(), getRef());
            final CreateTransactionReply createReply = expectMsgClass(duration("3 seconds"), CreateTransactionReply.class);
            getSystem().actorSelection(createReply.getTransactionPath()).tell(new ReadData(path, DataStoreVersions.CURRENT_VERSION), getRef());
            final ReadDataReply readReply = expectMsgClass(duration("3 seconds"), ReadDataReply.class);
            assertEquals("Read node", containerNode, readReply.getNormalizedNode());
            // Commit the write transaction.
            shard.tell(new CanCommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            final CanCommitTransactionReply canCommitReply = CanCommitTransactionReply.fromSerializable(expectMsgClass(duration, CanCommitTransactionReply.class));
            assertEquals("Can commit", true, canCommitReply.getCanCommit());
            shard.tell(new CommitTransaction(transactionID1, CURRENT_VERSION).toSerializable(), getRef());
            expectMsgClass(duration, CommitTransactionReply.class);
            // Verify data in the data store.
            final NormalizedNode<?, ?> actualNode = readStore(shard, path);
            assertEquals("Stored node", containerNode, actualNode);
        }
    };
}
Also used : CreateTransaction(org.opendaylight.controller.cluster.datastore.messages.CreateTransaction) FiniteDuration(scala.concurrent.duration.FiniteDuration) CreateTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply) LocalHistoryIdentifier(org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) CanCommitTransactionReply(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) CommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CommitTransaction) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) CanCommitTransaction(org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) ReadDataReply(org.opendaylight.controller.cluster.datastore.messages.ReadDataReply) ReadData(org.opendaylight.controller.cluster.datastore.messages.ReadData) Test(org.junit.Test)

Example 4 with ReadData

use of org.opendaylight.controller.cluster.datastore.messages.ReadData in project controller by opendaylight.

the class ShardTransactionFailureTest method testNegativeReadWithReadOnlyTransactionClosed.

@Test(expected = ReadFailedException.class)
public void testNegativeReadWithReadOnlyTransactionClosed() throws Exception {
    final ActorRef shard = createShard();
    final Props props = ShardTransaction.props(RO, STORE.newReadOnlyTransaction(nextTransactionId()), shard, datastoreContext, shardStats);
    final TestActorRef<ShardTransaction> subject = TestActorRef.create(getSystem(), props, "testNegativeReadWithReadOnlyTransactionClosed");
    Future<Object> future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
    Await.result(future, Duration.create(3, TimeUnit.SECONDS));
    subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor();
    future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
    Await.result(future, Duration.create(3, TimeUnit.SECONDS));
}
Also used : TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) Props(akka.actor.Props) ReadData(org.opendaylight.controller.cluster.datastore.messages.ReadData) Test(org.junit.Test)

Example 5 with ReadData

use of org.opendaylight.controller.cluster.datastore.messages.ReadData in project controller by opendaylight.

the class ShardTransactionFailureTest method testNegativeReadWithReadWriteTransactionClosed.

@Test(expected = ReadFailedException.class)
public void testNegativeReadWithReadWriteTransactionClosed() throws Exception {
    final ActorRef shard = createShard();
    final Props props = ShardTransaction.props(RW, STORE.newReadWriteTransaction(nextTransactionId()), shard, datastoreContext, shardStats);
    final TestActorRef<ShardTransaction> subject = TestActorRef.create(getSystem(), props, "testNegativeReadWithReadWriteTransactionClosed");
    Future<Object> future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
    Await.result(future, Duration.create(3, TimeUnit.SECONDS));
    subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor();
    future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
    Await.result(future, Duration.create(3, TimeUnit.SECONDS));
}
Also used : TestActorRef(akka.testkit.TestActorRef) ActorRef(akka.actor.ActorRef) Props(akka.actor.Props) ReadData(org.opendaylight.controller.cluster.datastore.messages.ReadData) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ReadData (org.opendaylight.controller.cluster.datastore.messages.ReadData)6 ActorRef (akka.actor.ActorRef)4 TestActorRef (akka.testkit.TestActorRef)4 ReadDataReply (org.opendaylight.controller.cluster.datastore.messages.ReadDataReply)3 Props (akka.actor.Props)2 TestKit (akka.testkit.javadsl.TestKit)2 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)2 LocalHistoryIdentifier (org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier)1 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)1 CanCommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction)1 CanCommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply)1 CommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CommitTransaction)1 CreateTransaction (org.opendaylight.controller.cluster.datastore.messages.CreateTransaction)1 CreateTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)1 FiniteDuration (scala.concurrent.duration.FiniteDuration)1