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