use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree 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.api.schema.tree.DataTree 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;
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree in project controller by opendaylight.
the class TransactionProxyTest method createDataTree.
private static DataTree createDataTree(final NormalizedNode<?, ?> readResponse) {
DataTree dataTree = mock(DataTree.class);
DataTreeSnapshot dataTreeSnapshot = mock(DataTreeSnapshot.class);
DataTreeModification dataTreeModification = mock(DataTreeModification.class);
doReturn(dataTreeSnapshot).when(dataTree).takeSnapshot();
doReturn(dataTreeModification).when(dataTreeSnapshot).newModification();
doReturn(java.util.Optional.of(readResponse)).when(dataTreeModification).readNode(any(YangInstanceIdentifier.class));
return dataTree;
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree in project controller by opendaylight.
the class ShardManagerTest method testOnReceiveFindPrimaryWaitForShardLeader.
@Test
public void testOnReceiveFindPrimaryWaitForShardLeader() throws Exception {
LOG.info("testOnReceiveFindPrimaryWaitForShardLeader starting");
datastoreContextBuilder.shardInitializationTimeout(10, TimeUnit.SECONDS);
new TestKit(getSystem()) {
{
final ActorRef shardManager = actorFactory.createActor(newPropsShardMgrWithMockShardActor());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
// We're passing waitUntilInitialized = true to FindPrimary so
// the response should be
// delayed until we send ActorInitialized and
// RoleChangeNotification.
shardManager.tell(new FindPrimary(Shard.DEFAULT_NAME, true), getRef());
expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
shardManager.tell(new ActorInitialized(), mockShardActor);
expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
shardManager.tell(new RoleChangeNotification(memberId, RaftState.Candidate.name(), RaftState.Leader.name()), mockShardActor);
expectNoMsg(FiniteDuration.create(150, TimeUnit.MILLISECONDS));
DataTree mockDataTree = mock(DataTree.class);
shardManager.tell(new ShardLeaderStateChanged(memberId, memberId, mockDataTree, DataStoreVersions.CURRENT_VERSION), mockShardActor);
LocalPrimaryShardFound primaryFound = expectMsgClass(duration("5 seconds"), LocalPrimaryShardFound.class);
assertTrue("Unexpected primary path " + primaryFound.getPrimaryPath(), primaryFound.getPrimaryPath().contains("member-1-shard-default"));
assertSame("getLocalShardDataTree", mockDataTree, primaryFound.getLocalShardDataTree());
expectNoMsg(FiniteDuration.create(200, TimeUnit.MILLISECONDS));
}
};
LOG.info("testOnReceiveFindPrimaryWaitForShardLeader ending");
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree 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());
}
Aggregations