Search in sources :

Example 46 with ContainerNode

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

the class ShardTest method testBatchedModificationsWithOperationFailure.

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

        {
            final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testBatchedModificationsWithOperationFailure");
            waitUntilLeader(shard);
            // Test merge with invalid data. An exception should occur when
            // the merge is applied. Note that
            // write will not validate the children for performance reasons.
            final TransactionIdentifier transactionID = nextTransactionId();
            final ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
            BatchedModifications batched = new BatchedModifications(transactionID, CURRENT_VERSION);
            batched.addModification(new MergeModification(TestModel.TEST_PATH, invalidData));
            shard.tell(batched, getRef());
            Failure failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            final Throwable cause = failure.cause();
            batched = new BatchedModifications(transactionID, DataStoreVersions.CURRENT_VERSION);
            batched.setReady(true);
            batched.setTotalMessagesSent(2);
            shard.tell(batched, getRef());
            failure = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
            assertEquals("Failure cause", cause, failure.cause());
        }
    };
}
Also used : FollowerInitialSyncUpStatus(org.opendaylight.controller.cluster.raft.base.messages.FollowerInitialSyncUpStatus) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) BatchedModifications(org.opendaylight.controller.cluster.datastore.messages.BatchedModifications) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) 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 47 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode 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 48 with ContainerNode

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

the class ShardTest method testApplySnapshot.

@Test
public void testApplySnapshot() throws Exception {
    final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testApplySnapshot");
    ShardTestKit.waitUntilLeader(shard);
    final DataTree store = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
    final ContainerNode container = ImmutableContainerNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)).build()).build();
    writeToStore(store, TestModel.TEST_PATH, container);
    final YangInstanceIdentifier root = YangInstanceIdentifier.EMPTY;
    final NormalizedNode<?, ?> expected = readStore(store, root);
    final Snapshot snapshot = Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(expected)), Collections.<ReplicatedLogEntry>emptyList(), 1, 2, 3, 4, -1, null, null);
    shard.tell(new ApplySnapshot(snapshot), ActorRef.noSender());
    final Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
        Uninterruptibles.sleepUninterruptibly(75, TimeUnit.MILLISECONDS);
        try {
            assertEquals("Root node", expected, readStore(shard, root));
            return;
        } catch (final AssertionError e) {
        // try again
        }
    }
    fail("Snapshot was not applied");
}
Also used : ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) ApplySnapshot(org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) Stopwatch(com.google.common.base.Stopwatch) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) ApplySnapshot(org.opendaylight.controller.cluster.raft.base.messages.ApplySnapshot) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Test(org.junit.Test)

Example 49 with ContainerNode

use of org.opendaylight.yangtools.yang.data.api.schema.ContainerNode 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 50 with ContainerNode

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

the class DistributedDataStoreIntegrationTest method testRestoreFromDatastoreSnapshot.

@Test
public void testRestoreFromDatastoreSnapshot() throws Exception {
    new IntegrationTestKit(getSystem(), datastoreContextBuilder) {

        {
            final String name = "transactionIntegrationTest";
            final ContainerNode carsNode = CarsModel.newCarsNode(CarsModel.newCarsMapNode(CarsModel.newCarEntry("optima", BigInteger.valueOf(20000L)), CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000L))));
            DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.full());
            AbstractShardTest.writeToStore(dataTree, CarsModel.BASE_PATH, carsNode);
            NormalizedNode<?, ?> root = AbstractShardTest.readStore(dataTree, YangInstanceIdentifier.EMPTY);
            final Snapshot carsSnapshot = Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)), Collections.emptyList(), 2, 1, 2, 1, 1, "member-1", null);
            dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.full());
            final NormalizedNode<?, ?> peopleNode = PeopleModel.create();
            AbstractShardTest.writeToStore(dataTree, PeopleModel.BASE_PATH, peopleNode);
            root = AbstractShardTest.readStore(dataTree, YangInstanceIdentifier.EMPTY);
            final Snapshot peopleSnapshot = Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)), Collections.emptyList(), 2, 1, 2, 1, 1, "member-1", null);
            restoreFromSnapshot = new DatastoreSnapshot(name, null, Arrays.asList(new DatastoreSnapshot.ShardSnapshot("cars", carsSnapshot), new DatastoreSnapshot.ShardSnapshot("people", peopleSnapshot)));
            try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, name, "module-shards-member1.conf", true, "cars", "people")) {
                final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
                // two reads
                Optional<NormalizedNode<?, ?>> optional = readTx.read(CarsModel.BASE_PATH).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("Data node", carsNode, optional.get());
                optional = readTx.read(PeopleModel.BASE_PATH).get(5, TimeUnit.SECONDS);
                assertEquals("isPresent", true, optional.isPresent());
                assertEquals("Data node", peopleNode, optional.get());
            }
        }
    };
}
Also used : ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) DOMStoreReadTransaction(org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) AddressFromURIString(akka.actor.AddressFromURIString) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) Snapshot(org.opendaylight.controller.cluster.raft.persisted.Snapshot) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) Test(org.junit.Test)

Aggregations

ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)81 Test (org.junit.Test)46 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)32 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)28 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)18 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)12 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)12 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)9 DefaultDOMRpcResult (org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult)8 ByteBuf (io.netty.buffer.ByteBuf)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 Map (java.util.Map)6 DOMRpcResult (org.opendaylight.controller.md.sal.dom.api.DOMRpcResult)6 Collection (java.util.Collection)4 ExecutionException (java.util.concurrent.ExecutionException)4 ConcurrentDOMDataBroker (org.opendaylight.controller.cluster.databroker.ConcurrentDOMDataBroker)4 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)4 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)4 DOMDataWriteTransaction (org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction)4 DOMRpcException (org.opendaylight.controller.md.sal.dom.api.DOMRpcException)4