- @Test
- public void testModicationRecovery() throws Exception {
-
- // Set up the InMemorySnapshotStore.
- setupInMemorySnapshotStore();
-
- // Set up the InMemoryJournal.
-
- InMemoryJournal.addEntry(shardID.toString(), 0, DUMMY_DATA);
-
- ShardDataTree shardDataTree = new ShardDataTree(SCHEMA_CONTEXT, TreeType.CONFIGURATION);
-
- InMemoryJournal.addEntry(shardID.toString(), 1, new ReplicatedLogImplEntry(0, 1, newDataTreeCandidatePayload(
- shardDataTree,
- new WriteModification(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)),
- new WriteModification(TestModel.OUTER_LIST_PATH,
- ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()))));
-
- final int nListEntries = 16;
- final Set<Integer> listEntryKeys = new HashSet<>();
-
- // Add some ModificationPayload entries
- for(int i = 1; i <= nListEntries; i++) {
- listEntryKeys.add(Integer.valueOf(i));
- final YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
- .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, i).build();
- final Modification mod = new MergeModification(path,
- ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, i));
- InMemoryJournal.addEntry(shardID.toString(), i + 1, new ReplicatedLogImplEntry(i, 1,
- newDataTreeCandidatePayload(shardDataTree, mod)));
- }
-
- InMemoryJournal.addEntry(shardID.toString(), nListEntries + 2,
- new ApplyJournalEntries(nListEntries));
-
- testRecovery(listEntryKeys);
- }
-
- private static DataTreeCandidatePayload newDataTreeCandidatePayload(final Modification... mods) throws Exception {
- return newDataTreeCandidatePayload(new ShardDataTree(SCHEMA_CONTEXT, TreeType.CONFIGURATION), mods);
- }
-
- private static DataTreeCandidatePayload newDataTreeCandidatePayload(ShardDataTree shardDataTree,
- final Modification... mods) throws Exception {
- DataTreeModification dataTreeModification = shardDataTree.newModification();
- for(final Modification mod: mods) {
- mod.apply(dataTreeModification);
- }
-
- return DataTreeCandidatePayload.create(shardDataTree.commit(dataTreeModification));
- }
-