Search in sources :

Example 96 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class ShardTransactionTest method testOnReceiveBatchedModificationsFailure.

@Test(expected = TestException.class)
public void testOnReceiveBatchedModificationsFailure() throws Exception {
    new TestKit(getSystem()) {

        {
            ShardDataTreeTransactionParent parent = Mockito.mock(ShardDataTreeTransactionParent.class);
            DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
            ReadWriteShardDataTreeTransaction mockWriteTx = new ReadWriteShardDataTreeTransaction(parent, nextTransactionId(), mockModification);
            final ActorRef transaction = newTransactionActor(RW, mockWriteTx, "testOnReceiveBatchedModificationsFailure");
            TestKit watcher = new TestKit(getSystem());
            watcher.watch(transaction);
            YangInstanceIdentifier path = TestModel.TEST_PATH;
            ContainerNode node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
            doThrow(new TestException()).when(mockModification).write(path, node);
            final TransactionIdentifier tx1 = nextTransactionId();
            BatchedModifications batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
            batched.addModification(new WriteModification(path, node));
            transaction.tell(batched, getRef());
            expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
            batched.setReady(true);
            batched.setTotalMessagesSent(2);
            transaction.tell(batched, getRef());
            Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
            if (failure != null) {
                Throwables.propagateIfPossible(failure.cause(), Exception.class);
                throw new RuntimeException(failure.cause());
            }
        }
    };
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TestKit(akka.testkit.javadsl.TestKit) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Example 97 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class ShardTransactionTest method testReadWriteTxOnReceiveCloseTransaction.

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

        {
            final ActorRef transaction = newTransactionActor(RW, readWriteTransaction(), "testReadWriteTxOnReceiveCloseTransaction");
            watch(transaction);
            transaction.tell(new CloseTransaction().toSerializable(), getRef());
            expectMsgClass(duration("3 seconds"), CloseTransactionReply.class);
            expectTerminated(duration("3 seconds"), transaction);
        }
    };
}
Also used : CloseTransaction(org.opendaylight.controller.cluster.datastore.messages.CloseTransaction) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Example 98 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class ShardTransactionTest method testWriteOnlyTxOnReceiveCloseTransaction.

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

        {
            final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testWriteTxOnReceiveCloseTransaction");
            watch(transaction);
            transaction.tell(new CloseTransaction().toSerializable(), getRef());
            expectMsgClass(duration("3 seconds"), CloseTransactionReply.class);
            expectTerminated(duration("3 seconds"), transaction);
        }
    };
}
Also used : CloseTransaction(org.opendaylight.controller.cluster.datastore.messages.CloseTransaction) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Example 99 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class ShardTransactionTest method testOnReceiveBatchedModificationsReadyWithoutImmediateCommit.

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

        {
            final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithoutImmediateCommit");
            TestKit watcher = new TestKit(getSystem());
            watcher.watch(transaction);
            YangInstanceIdentifier writePath = TestModel.TEST_PATH;
            NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
            final TransactionIdentifier tx1 = nextTransactionId();
            BatchedModifications batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
            batched.addModification(new WriteModification(writePath, writeData));
            transaction.tell(batched, getRef());
            BatchedModificationsReply reply = expectMsgClass(duration("5 seconds"), BatchedModificationsReply.class);
            assertEquals("getNumBatched", 1, reply.getNumBatched());
            batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
            batched.setReady(true);
            batched.setTotalMessagesSent(2);
            transaction.tell(batched, getRef());
            expectMsgClass(duration("5 seconds"), ReadyTransactionReply.class);
            watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
        }
    };
}
Also used : WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) BatchedModificationsReply(org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply) ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) TestKit(akka.testkit.javadsl.TestKit) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

Example 100 with TestKit

use of akka.testkit.javadsl.TestKit in project controller by opendaylight.

the class ShardTransactionTest method testOnReceiveDataExistsNegative.

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

        {
            testOnReceiveDataExistsNegative(newTransactionActor(RO, readOnlyTransaction(), "testDataExistsNegativeRO"));
            testOnReceiveDataExistsNegative(newTransactionActor(RW, readWriteTransaction(), "testDataExistsNegativeRW"));
        }

        private void testOnReceiveDataExistsNegative(final ActorRef transaction) {
            transaction.tell(new DataExists(TestModel.TEST_PATH, DataStoreVersions.CURRENT_VERSION), getRef());
            DataExistsReply reply = expectMsgClass(duration("5 seconds"), DataExistsReply.class);
            assertFalse(reply.exists());
        }
    };
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) DataExists(org.opendaylight.controller.cluster.datastore.messages.DataExists) DataExistsReply(org.opendaylight.controller.cluster.datastore.messages.DataExistsReply) TestKit(akka.testkit.javadsl.TestKit) Test(org.junit.Test)

Aggregations

TestKit (akka.testkit.javadsl.TestKit)124 Test (org.junit.Test)115 ActorRef (akka.actor.ActorRef)84 TestActorRef (akka.testkit.TestActorRef)63 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)44 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)37 AddressFromURIString (akka.actor.AddressFromURIString)28 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)26 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)22 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)22 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)17 ShardLeaderStateChanged (org.opendaylight.controller.cluster.datastore.messages.ShardLeaderStateChanged)17 FindPrimary (org.opendaylight.controller.cluster.datastore.messages.FindPrimary)16 MockConfiguration (org.opendaylight.controller.cluster.datastore.utils.MockConfiguration)16 Props (akka.actor.Props)15 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)15 Failure (akka.actor.Status.Failure)14 AbstractActorTest (org.opendaylight.controller.cluster.datastore.AbstractActorTest)14 FiniteDuration (scala.concurrent.duration.FiniteDuration)14 ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)13