use of org.opendaylight.controller.cluster.raft.persisted.Snapshot in project controller by opendaylight.
the class DistributedDataStoreIntegrationTest method testRestoreFromDatastoreSnapshot.
@Test
public void testRestoreFromDatastoreSnapshot() throws Exception {
new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
{
final String name = "transactionIntegrationTest";
final ContainerNode carsNode = CarsModel.newCarsNode(CarsModel.newCarsMapNode(CarsModel.newCarEntry("optima", BigInteger.valueOf(20000L)), CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000L))));
DataTree dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.full());
AbstractShardTest.writeToStore(dataTree, CarsModel.BASE_PATH, carsNode);
NormalizedNode<?, ?> root = AbstractShardTest.readStore(dataTree, YangInstanceIdentifier.EMPTY);
final Snapshot carsSnapshot = Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)), Collections.emptyList(), 2, 1, 2, 1, 1, "member-1", null);
dataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.full());
final NormalizedNode<?, ?> peopleNode = PeopleModel.create();
AbstractShardTest.writeToStore(dataTree, PeopleModel.BASE_PATH, peopleNode);
root = AbstractShardTest.readStore(dataTree, YangInstanceIdentifier.EMPTY);
final Snapshot peopleSnapshot = Snapshot.create(new ShardSnapshotState(new MetadataShardDataTreeSnapshot(root)), Collections.emptyList(), 2, 1, 2, 1, 1, "member-1", null);
restoreFromSnapshot = new DatastoreSnapshot(name, null, Arrays.asList(new DatastoreSnapshot.ShardSnapshot("cars", carsSnapshot), new DatastoreSnapshot.ShardSnapshot("people", peopleSnapshot)));
try (AbstractDataStore dataStore = setupAbstractDataStore(testParameter, name, "module-shards-member1.conf", true, "cars", "people")) {
final DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
// two reads
Optional<NormalizedNode<?, ?>> optional = readTx.read(CarsModel.BASE_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", carsNode, optional.get());
optional = readTx.read(PeopleModel.BASE_PATH).get(5, TimeUnit.SECONDS);
assertEquals("isPresent", true, optional.isPresent());
assertEquals("Data node", peopleNode, optional.get());
}
}
};
}
use of org.opendaylight.controller.cluster.raft.persisted.Snapshot 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);
}
Aggregations