use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree in project controller by opendaylight.
the class DistributedDataStoreRemotingIntegrationTest method testInstallSnapshot.
@Test
public void testInstallSnapshot() throws Exception {
final String testName = "testInstallSnapshot";
final String leaderCarShardName = "member-1-shard-cars-" + testName;
final String followerCarShardName = "member-2-shard-cars-" + testName;
// Setup a saved snapshot on the leader. The follower will startup with no data and the leader should
// install a snapshot to sync the follower.
DataTree tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SchemaContextHelper.full());
final ContainerNode carsNode = CarsModel.newCarsNode(CarsModel.newCarsMapNode(CarsModel.newCarEntry("optima", BigInteger.valueOf(20000))));
AbstractShardTest.writeToStore(tree, CarsModel.BASE_PATH, carsNode);
final NormalizedNode<?, ?> snapshotRoot = AbstractShardTest.readStore(tree, YangInstanceIdentifier.EMPTY);
final Snapshot initialSnapshot = Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(snapshotRoot)), Collections.emptyList(), 5, 1, 5, 1, 1, null, null);
InMemorySnapshotStore.addSnapshot(leaderCarShardName, initialSnapshot);
InMemorySnapshotStore.addSnapshotSavedLatch(leaderCarShardName);
InMemorySnapshotStore.addSnapshotSavedLatch(followerCarShardName);
initDatastoresWithCars(testName);
final Optional<NormalizedNode<?, ?>> readOptional = leaderDistributedDataStore.newReadOnlyTransaction().read(CarsModel.BASE_PATH).checkedGet(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, readOptional.isPresent());
assertEquals("Node", carsNode, readOptional.get());
verifySnapshot(InMemorySnapshotStore.waitForSavedSnapshot(leaderCarShardName, Snapshot.class), initialSnapshot, snapshotRoot);
verifySnapshot(InMemorySnapshotStore.waitForSavedSnapshot(followerCarShardName, Snapshot.class), initialSnapshot, snapshotRoot);
}
use of org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree in project controller by opendaylight.
the class TransactionProxyTest method testReadyWithLocalTransactionWithFailure.
@Test
public void testReadyWithLocalTransactionWithFailure() throws Exception {
ActorRef shardActorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
doReturn(getSystem().actorSelection(shardActorRef.path())).when(mockActorContext).actorSelection(shardActorRef.path().toString());
DataTree mockDataTree = createDataTree();
DataTreeModification mockModification = mockDataTree.takeSnapshot().newModification();
doThrow(new RuntimeException("mock")).when(mockModification).ready();
doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef, mockDataTree))).when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, WRITE_ONLY);
expectReadyLocalTransaction(shardActorRef, true);
NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
transactionProxy.write(TestModel.TEST_PATH, nodeToWrite);
DOMStoreThreePhaseCommitCohort ready = transactionProxy.ready();
assertTrue(ready instanceof SingleCommitCohortProxy);
verifyCohortFutures((SingleCommitCohortProxy) ready, RuntimeException.class);
}
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() {
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();
return dataTree;
}
Aggregations