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()));
}
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);
}
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);
}
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");
}
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);
}
Aggregations