Search in sources :

Example 1 with InMemoryDataTreeFactory

use of org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory 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 InMemoryDataTreeFactory

use of org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory 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 3 with InMemoryDataTreeFactory

use of org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory 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)

Example 4 with InMemoryDataTreeFactory

use of org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory in project controller by opendaylight.

the class AbstractShardTest method setupInMemorySnapshotStore.

DataTree setupInMemorySnapshotStore() throws DataValidationFailedException {
    final DataTree testStore = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
    writeToStore(testStore, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
    final NormalizedNode<?, ?> root = readStore(testStore, YangInstanceIdentifier.EMPTY);
    InMemorySnapshotStore.addSnapshot(shardID.toString(), Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)), Collections.<ReplicatedLogEntry>emptyList(), 0, 1, -1, -1, 1, null, null));
    return testStore;
}
Also used : ReplicatedLogEntry(org.opendaylight.controller.cluster.raft.ReplicatedLogEntry) 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) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)

Example 5 with InMemoryDataTreeFactory

use of org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory in project controller by opendaylight.

the class AbstractShardTest method createDelegatingMockDataTree.

protected DataTree createDelegatingMockDataTree() throws Exception {
    final DataTree actual = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION);
    final DataTree mock = mock(DataTree.class);
    doAnswer(invocation -> {
        actual.validate(invocation.getArgumentAt(0, DataTreeModification.class));
        return null;
    }).when(mock).validate(any(DataTreeModification.class));
    doAnswer(invocation -> actual.prepare(invocation.getArgumentAt(0, DataTreeModification.class))).when(mock).prepare(any(DataTreeModification.class));
    doAnswer(invocation -> {
        actual.commit(invocation.getArgumentAt(0, DataTreeCandidate.class));
        return null;
    }).when(mock).commit(any(DataTreeCandidate.class));
    doAnswer(invocation -> {
        actual.setSchemaContext(invocation.getArgumentAt(0, SchemaContext.class));
        return null;
    }).when(mock).setSchemaContext(any(SchemaContext.class));
    doAnswer(invocation -> actual.takeSnapshot()).when(mock).takeSnapshot();
    doAnswer(invocation -> actual.getRootPath()).when(mock).getRootPath();
    return mock;
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)

Aggregations

DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)14 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)14 Test (org.junit.Test)9 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)9 MetadataShardDataTreeSnapshot (org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot)7 ShardSnapshotState (org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState)6 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)5 Snapshot (org.opendaylight.controller.cluster.raft.persisted.Snapshot)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 AddressFromURIString (akka.actor.AddressFromURIString)2 Stopwatch (com.google.common.base.Stopwatch)2 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)2 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)2 GetShardDataTree (org.opendaylight.controller.cluster.datastore.messages.GetShardDataTree)2 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)2 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)2 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot)2 ActorRef (akka.actor.ActorRef)1 ActorSelection (akka.actor.ActorSelection)1 ExtendedActorSystem (akka.actor.ExtendedActorSystem)1