Search in sources :

Example 1 with DataTree

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

the class ShardRecoveryCoordinatorTest method createSnapshot.

private static ShardSnapshotState createSnapshot() {
    final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, SchemaContextHelper.PEOPLE_YANG));
    DataTreeSnapshot snapshot = dataTree.takeSnapshot();
    DataTreeModification modification = snapshot.newModification();
    modification.merge(CarsModel.BASE_PATH, CarsModel.create());
    modification.merge(PeopleModel.BASE_PATH, PeopleModel.create());
    modification.ready();
    dataTree.commit(dataTree.prepare(modification));
    return new ShardSnapshotState(new MetadataShardDataTreeSnapshot(dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get()));
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) ShardSnapshotState(org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot) MetadataShardDataTreeSnapshot(org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)

Example 2 with DataTree

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

the class ShardRecoveryCoordinatorTest method readPeople.

private Optional<NormalizedNode<?, ?>> readPeople(final ShardDataTree shardDataTree) {
    final DataTree dataTree = shardDataTree.getDataTree();
    // FIXME: this should not be called here
    dataTree.setSchemaContext(peopleSchemaContext);
    return shardDataTree.readNode(PeopleModel.BASE_PATH);
}
Also used : DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)

Example 3 with DataTree

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

the class ShardRecoveryCoordinatorTest method readCars.

private Optional<NormalizedNode<?, ?>> readCars(final ShardDataTree shardDataTree) {
    final DataTree dataTree = shardDataTree.getDataTree();
    // FIXME: this should not be called here
    dataTree.setSchemaContext(peopleSchemaContext);
    return shardDataTree.readNode(CarsModel.BASE_PATH);
}
Also used : DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)

Example 4 with DataTree

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

the class ShardTest method testApplyState.

@Test
public void testApplyState() throws Exception {
    final TestActorRef<Shard> shard = actorFactory.createTestActor(newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), "testApplyState");
    ShardTestKit.waitUntilLeader(shard);
    final DataTree store = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
    final DataTreeModification writeMod = store.takeSnapshot().newModification();
    final ContainerNode node = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
    writeMod.write(TestModel.TEST_PATH, node);
    writeMod.ready();
    final TransactionIdentifier tx = nextTransactionId();
    shard.underlyingActor().applyState(null, null, payloadForModification(store, writeMod, tx));
    final Stopwatch sw = Stopwatch.createStarted();
    while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
        Uninterruptibles.sleepUninterruptibly(75, TimeUnit.MILLISECONDS);
        final NormalizedNode<?, ?> actual = readStore(shard, TestModel.TEST_PATH);
        if (actual != null) {
            assertEquals("Applied state", node, actual);
            return;
        }
    }
    fail("State was not applied");
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) Stopwatch(com.google.common.base.Stopwatch) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) Test(org.junit.Test)

Example 5 with DataTree

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

the class ShardTest method testInMemoryDataTreeRestore.

/**
 * This test simply verifies that the applySnapShot logic will work.
 */
@Test
public void testInMemoryDataTreeRestore() throws ReadFailedException, DataValidationFailedException {
    final DataTree store = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
    final DataTreeModification putTransaction = store.takeSnapshot().newModification();
    putTransaction.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    commitTransaction(store, putTransaction);
    final NormalizedNode<?, ?> expected = readStore(store, YangInstanceIdentifier.EMPTY);
    final DataTreeModification writeTransaction = store.takeSnapshot().newModification();
    writeTransaction.delete(YangInstanceIdentifier.EMPTY);
    writeTransaction.write(YangInstanceIdentifier.EMPTY, expected);
    commitTransaction(store, writeTransaction);
    final NormalizedNode<?, ?> actual = readStore(store, YangInstanceIdentifier.EMPTY);
    assertEquals(expected, actual);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) Test(org.junit.Test)

Aggregations

DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)33 Test (org.junit.Test)21 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)19 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)14 ActorRef (akka.actor.ActorRef)7 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)7 MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)7 ShardSnapshotState (org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState)6 AddressFromURIString (akka.actor.AddressFromURIString)5 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)5 FiniteDuration (scala.concurrent.duration.FiniteDuration)5 TestActorRef (akka.testkit.TestActorRef)4 CanCommitTransaction (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction)4 CanCommitTransactionReply (org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply)4 GetShardDataTree (org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree)4 LocalPrimaryShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalPrimaryShardFound)4 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 TestKit (akka.testkit.javadsl.TestKit)3 Timeout (akka.util.Timeout)3 InOrder (org.mockito.InOrder)3