use of org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory in project controller by opendaylight.
the class PruningDataTreeModificationTest method testWriteRootNode.
@Test
public void testWriteRootNode() throws Exception {
final DataTree localDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
DataTreeModification mod = localDataTree.takeSnapshot().newModification();
mod.write(CarsModel.BASE_PATH, CarsModel.create());
mod.ready();
localDataTree.validate(mod);
localDataTree.commit(localDataTree.prepare(mod));
NormalizedNode<?, ?> normalizedNode = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get();
pruningDataTreeModification.write(YangInstanceIdentifier.EMPTY, normalizedNode);
dataTree.commit(getCandidate());
Optional<NormalizedNode<?, ?>> actual = dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY);
assertTrue("Root present", actual.isPresent());
assertEquals("Root node", normalizedNode, actual.get());
}
use of org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory in project controller by opendaylight.
the class CommitTransactionPayloadTest method testUnmodifiedRootCandidate.
@Test
public void testUnmodifiedRootCandidate() throws Exception {
final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SchemaContextHelper.select(SchemaContextHelper.CARS_YANG));
DataTreeModification modification = dataTree.takeSnapshot().newModification();
modification.ready();
candidate = dataTree.prepare(modification);
CommitTransactionPayload payload = CommitTransactionPayload.create(nextTransactionId(), candidate);
assertCandidateEquals(candidate, payload.getCandidate().getValue());
}
use of org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory in project controller by opendaylight.
the class ReadyLocalTransactionSerializerTest method testToAndFromBinary.
@Test
public void testToAndFromBinary() throws NotSerializableException {
DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, TestModel.createTestContext());
DataTreeModification modification = dataTree.takeSnapshot().newModification();
ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
TransactionIdentifier txId = nextTransactionId();
ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
final ExtendedActorSystem system = (ExtendedActorSystem) ExtendedActorSystem.create("test");
final Object deserialized;
try {
final ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer(system);
final byte[] bytes = serializer.toBinary(readyMessage);
deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
} finally {
JavaTestKit.shutdownActorSystem(system);
}
assertNotNull("fromBinary returned null", deserialized);
assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
BatchedModifications batched = (BatchedModifications) deserialized;
assertEquals("getTransactionID", txId, batched.getTransactionId());
assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());
List<Modification> batchedMods = batched.getModifications();
assertEquals("getModifications size", 2, batchedMods.size());
Modification mod = batchedMods.get(0);
assertEquals("Modification type", WriteModification.class, mod.getClass());
assertEquals("Modification getPath", TestModel.TEST_PATH, ((WriteModification) mod).getPath());
assertEquals("Modification getData", writeData, ((WriteModification) mod).getData());
mod = batchedMods.get(1);
assertEquals("Modification type", MergeModification.class, mod.getClass());
assertEquals("Modification getPath", TestModel.OUTER_LIST_PATH, ((MergeModification) mod).getPath());
assertEquals("Modification getData", mergeData, ((MergeModification) mod).getData());
}
use of org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory in project controller by opendaylight.
the class ShardRecoveryCoordinatorTest method createCar.
private DataTreeCandidate createCar() {
final DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, carsSchemaContext);
final DataTreeSnapshot snapshot = dataTree.takeSnapshot();
final DataTreeModification modification = snapshot.newModification();
modification.merge(CarsModel.BASE_PATH, CarsModel.create());
modification.ready();
return dataTree.prepare(modification);
}
use of org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory 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");
}
Aggregations