Search in sources :

Example 1 with BatchedModifications

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

the class EntityOwnershipShardCommitCoordinator method newBatchedModifications.

private BatchedModifications newBatchedModifications() {
    BatchedModifications modifications = new BatchedModifications(new TransactionIdentifier(historyId, ++transactionIDCounter), DataStoreVersions.CURRENT_VERSION);
    modifications.setDoCommitOnReady(true);
    modifications.setReady(true);
    modifications.setTotalMessagesSent(1);
    return modifications;
}
Also used : TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)

Example 2 with BatchedModifications

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

the class ShardTest method testOnBatchedModificationsWhenNotLeader.

@Test
public void testOnBatchedModificationsWhenNotLeader() {
    final AtomicBoolean overrideLeaderCalls = new AtomicBoolean();
    new ShardTestKit(getSystem()) {

        {
            final Creator<Shard> creator = new Creator<Shard>() {

                private static final long serialVersionUID = 1L;

                @Override
                public Shard create() throws Exception {
                    return new Shard(newShardBuilder()) {

                        @Override
                        protected boolean isLeader() {
                            return overrideLeaderCalls.get() ? false : super.isLeader();
                        }

                        @Override
                        public ActorSelection getLeader() {
                            return overrideLeaderCalls.get() ? getSystem().actorSelection(getRef().path()) : super.getLeader();
                        }
                    };
                }
            };
            final TestActorRef<Shard> shard = actorFactory.createTestActor(Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), "testOnBatchedModificationsWhenNotLeader");
            waitUntilLeader(shard);
            overrideLeaderCalls.set(true);
            final BatchedModifications batched = new BatchedModifications(nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
            shard.tell(batched, ActorRef.noSender());
            expectMsgEquals(batched);
        }
    };
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Creator(akka.japi.Creator) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

Example 3 with BatchedModifications

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

the class ShardTest method testBatchedModificationsReadyWithIncorrectTotalMessageCount.

@Test(expected = IllegalStateException.class)
public void testBatchedModificationsReadyWithIncorrectTotalMessageCount() throws Exception {
    new ShardTestKit(getSystem()) {

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testBatchedModificationsReadyWithIncorrectTotalMessageCount");
            waitUntilLeader(shard);
            final TransactionIdentifier transactionID = nextTransactionId();
            final BatchedModifications batched = new BatchedModifications(transactionID, DataStoreVersions.CURRENT_VERSION);
            batched.setReady(true);
            batched.setTotalMessagesSent(2);
            shard.tell(batched, getRef());
            final Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            if (failure != null) {
                Throwables.propagateIfPossible(failure.cause(), Exception.class);
                throw new RuntimeException(failure.cause());
            }
        }
    };
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Failure(akka.actor.Status.Failure) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

Example 4 with BatchedModifications

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

the class ShardTransactionTest method testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount.

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

        {
            final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount");
            TestKit watcher = new TestKit(getSystem());
            watcher.watch(transaction);
            BatchedModifications batched = new BatchedModifications(nextTransactionId(), 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.throwIfInstanceOf(failure.cause(), Exception.class);
                Throwables.throwIfUnchecked(failure.cause());
                throw new RuntimeException(failure.cause());
            }
        }
    };
}
Also used : ActorRef(akka.actor.ActorRef) TestActorRef(akka.testkit.TestActorRef) TestKit(akka.testkit.javadsl.TestKit) Failure(akka.actor.Status.Failure) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) Test(org.junit.Test)

Example 5 with BatchedModifications

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

the class ShardTransactionTest method testOnReceiveBatchedModificationsReadyWithImmediateCommit.

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

        {
            final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithImmediateCommit");
            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();
            BatchedModifications batched = new BatchedModifications(nextTransactionId(), DataStoreVersions.CURRENT_VERSION);
            batched.addModification(new WriteModification(writePath, writeData));
            batched.setReady(true);
            batched.setDoCommitOnReady(true);
            batched.setTotalMessagesSent(1);
            transaction.tell(batched, getRef());
            expectMsgClass(duration("5 seconds"), CommitTransactionReply.class);
            watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
        }
    };
}
Also used : 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) Test(org.junit.Test)

Aggregations

BatchedModifications (org.opendaylight.controller.cluster.datastore.messages.BatchedModifications)31 Test (org.junit.Test)17 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)13 ActorRef (akka.actor.ActorRef)12 Failure (akka.actor.Status.Failure)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)7 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)6 TestActorRef (akka.testkit.TestActorRef)5 TestKit (akka.testkit.javadsl.TestKit)5 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)5 Timeout (akka.util.Timeout)4 CommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply)4 DOMStoreThreePhaseCommitCohort (org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort)4 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)4 DeleteModification (org.opendaylight.controller.cluster.datastore.modification.DeleteModification)3 FollowerInitialSyncUpStatus (org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus)3 InOrder (org.mockito.InOrder)2 BatchedModificationsReply (org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply)2 ReadyLocalTransaction (org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction)2