1 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
3 import static org.junit.Assert.assertFalse;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
6 import static org.junit.Assert.fail;
7 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapEntryBuilder;
8 import static org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes.mapNodeBuilder;
9 import com.google.common.base.Optional;
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
20 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
21 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
22 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class ConcurrentTreeModificationTest {
27 private static final Logger LOG = LoggerFactory.getLogger(ConcurrentTreeModificationTest.class);
29 private static final Short ONE_ID = 1;
30 private static final Short TWO_ID = 2;
32 private static final YangInstanceIdentifier OUTER_LIST_1_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
33 .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) //
36 private static final YangInstanceIdentifier OUTER_LIST_2_PATH = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
37 .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
40 private static final MapEntryNode FOO_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, ONE_ID) //
41 .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) //
45 private static final MapEntryNode BAR_NODE = mapEntryBuilder(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, TWO_ID) //
46 .withChild(mapNodeBuilder(TestModel.INNER_LIST_QNAME) //
50 private SchemaContext schemaContext;
51 private RootModificationApplyOperation rootOper;
52 private InMemoryDataTree inMemoryDataTree;
55 public void prepare() {
56 schemaContext = TestModel.createTestContext();
57 assertNotNull("Schema context must not be null.", schemaContext);
58 rootOper = RootModificationApplyOperation.from(SchemaAwareApplyOperation.from(schemaContext));
59 inMemoryDataTree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create();
60 inMemoryDataTree.setSchemaContext(schemaContext);
63 private static ContainerNode createFooTestContainerNode() {
64 return ImmutableContainerNodeBuilder
66 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
68 mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
69 .withChild(FOO_NODE).build()).build();
72 private static ContainerNode createBarTestContainerNode() {
73 return ImmutableContainerNodeBuilder
75 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
77 mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
78 .withChild(BAR_NODE).build()).build();
81 private static <T> T assertPresentAndType(final Optional<?> potential, final Class<T> type) {
82 assertNotNull(potential);
83 assertTrue(potential.isPresent());
84 assertTrue(type.isInstance(potential.get()));
85 return type.cast(potential.get());
89 public void writeWrite1stLevelEmptyTreeTest() throws DataValidationFailedException {
90 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
92 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
94 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
97 modificationTree1.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
98 modificationTree2.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
100 inMemoryDataTree.validate(modificationTree1);
101 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
102 inMemoryDataTree.commit(prepare1);
105 inMemoryDataTree.validate(modificationTree2);
106 fail("Exception should have been thrown.");
107 } catch (ConflictingModificationAppliedException ex) {
108 LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected.");
110 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
111 inMemoryDataTree.commit(prepare2);
113 Optional<NormalizedNode<?, ?>> testNodeAfterCommits = modificationTree1.readNode(TestModel.TEST_PATH);
114 assertPresentAndType(testNodeAfterCommits, ContainerNode.class);
118 public void writeMerge1stLevelEmptyTreeTest() throws DataValidationFailedException {
119 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
121 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
123 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
126 modificationTree1.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
127 modificationTree2.merge(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
129 inMemoryDataTree.validate(modificationTree1);
130 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
131 inMemoryDataTree.commit(prepare1);
133 inMemoryDataTree.validate(modificationTree2);
134 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
135 inMemoryDataTree.commit(prepare2);
137 Optional<NormalizedNode<?, ?>> testNodeAfterCommits = modificationTree1.readNode(TestModel.TEST_PATH);
138 assertPresentAndType(testNodeAfterCommits, ContainerNode.class);
142 public void writeWriteFooBar1stLevelEmptyTreeTest() throws DataValidationFailedException {
143 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
145 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
147 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
150 modificationTree1.write(TestModel.TEST_PATH, createFooTestContainerNode());
151 modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode());
153 inMemoryDataTree.validate(modificationTree1);
154 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
155 inMemoryDataTree.commit(prepare1);
158 inMemoryDataTree.validate(modificationTree2);
159 fail("Exception should have been thrown.");
160 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
161 inMemoryDataTree.commit(prepare2);
162 } catch (ConflictingModificationAppliedException ex) {
163 LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected.");
166 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
167 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
168 assertFalse(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH).isPresent());
172 public void writeMergeFooBar1stLevelEmptyTreeTest() throws DataValidationFailedException {
173 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
175 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
177 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
180 modificationTree1.write(TestModel.TEST_PATH, createFooTestContainerNode());
181 modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode());
183 inMemoryDataTree.validate(modificationTree1);
184 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
185 inMemoryDataTree.commit(prepare1);
187 inMemoryDataTree.validate(modificationTree2);
188 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
189 inMemoryDataTree.commit(prepare2);
191 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
192 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
193 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class);
197 public void mergeWriteFooBar1stLevelEmptyTreeTest() throws DataValidationFailedException {
198 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
200 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
202 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
205 modificationTree1.merge(TestModel.TEST_PATH, createFooTestContainerNode());
206 modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode());
208 inMemoryDataTree.validate(modificationTree1);
209 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
210 inMemoryDataTree.commit(prepare1);
213 inMemoryDataTree.validate(modificationTree2);
214 fail("Exception should have been thrown.");
215 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
216 inMemoryDataTree.commit(prepare2);
217 } catch (ConflictingModificationAppliedException ex) {
218 LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected.");
221 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
222 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
223 assertFalse(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH).isPresent());
227 public void mergeMergeFooBar1stLevelEmptyTreeTest() throws DataValidationFailedException {
228 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
230 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
232 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
235 modificationTree1.merge(TestModel.TEST_PATH, createFooTestContainerNode());
236 modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode());
238 inMemoryDataTree.validate(modificationTree1);
239 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
240 inMemoryDataTree.commit(prepare1);
242 inMemoryDataTree.validate(modificationTree2);
243 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
244 inMemoryDataTree.commit(prepare2);
246 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
247 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
248 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class);
252 public void writeWriteFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException {
253 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
254 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
255 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
256 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
258 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
260 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
263 modificationTree1.write(TestModel.TEST_PATH, createFooTestContainerNode());
264 modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode());
266 inMemoryDataTree.validate(modificationTree1);
267 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
268 inMemoryDataTree.commit(prepare1);
271 inMemoryDataTree.validate(modificationTree2);
272 fail("Exception should have been thrown.");
273 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
274 inMemoryDataTree.commit(prepare2);
275 } catch (ConflictingModificationAppliedException ex) {
276 LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected.");
279 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
280 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
281 assertFalse(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH).isPresent());
285 public void writeMergeFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException {
286 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
287 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
288 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
289 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
291 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
293 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
296 modificationTree1.write(TestModel.TEST_PATH, createFooTestContainerNode());
297 modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode());
299 inMemoryDataTree.validate(modificationTree1);
300 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
301 inMemoryDataTree.commit(prepare1);
303 inMemoryDataTree.validate(modificationTree2);
304 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
305 inMemoryDataTree.commit(prepare2);
307 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
308 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
309 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class);
314 public void mergeWriteFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException {
315 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
316 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
317 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
318 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
320 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
322 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
325 modificationTree1.merge(TestModel.TEST_PATH, createFooTestContainerNode());
326 modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode());
328 inMemoryDataTree.validate(modificationTree1);
329 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
330 inMemoryDataTree.commit(prepare1);
333 inMemoryDataTree.validate(modificationTree2);
334 fail("Exception should have been thrown.");
335 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
336 inMemoryDataTree.commit(prepare2);
337 } catch (ConflictingModificationAppliedException ex) {
338 LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected.");
342 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
343 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
344 assertFalse(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH).isPresent());
348 public void mergeMergeFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException {
349 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
350 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
351 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
352 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
354 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
356 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
359 modificationTree1.merge(TestModel.TEST_PATH, createFooTestContainerNode());
360 modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode());
362 inMemoryDataTree.validate(modificationTree1);
363 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
364 inMemoryDataTree.commit(prepare1);
366 inMemoryDataTree.validate(modificationTree2);
367 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
368 inMemoryDataTree.commit(prepare2);
370 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
371 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
372 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class);
376 public void deleteWriteFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException {
377 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
378 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
379 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
380 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
382 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
384 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
387 modificationTree1.delete(TestModel.TEST_PATH);
388 modificationTree2.write(TestModel.TEST_PATH, createBarTestContainerNode());
390 inMemoryDataTree.validate(modificationTree1);
391 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
392 inMemoryDataTree.commit(prepare1);
395 inMemoryDataTree.validate(modificationTree2);
396 fail("Exception should have been thrown.");
397 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
398 inMemoryDataTree.commit(prepare2);
399 } catch (ConflictingModificationAppliedException ex) {
400 LOG.debug("ConflictingModificationAppliedException - '{}' was thrown as expected.");
404 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
405 assertFalse(snapshotAfterCommits.readNode(TestModel.TEST_PATH).isPresent());
409 public void deleteMergeFooBar1stLevelEmptyContainerTest() throws DataValidationFailedException {
410 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
411 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
412 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
413 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
415 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
417 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
420 modificationTree1.delete(TestModel.TEST_PATH);
421 modificationTree2.merge(TestModel.TEST_PATH, createBarTestContainerNode());
423 inMemoryDataTree.validate(modificationTree1);
424 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
425 inMemoryDataTree.commit(prepare1);
427 inMemoryDataTree.validate(modificationTree2);
428 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
429 inMemoryDataTree.commit(prepare2);
431 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
432 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class);
436 public void writeWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
437 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
438 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
439 initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
440 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
441 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
443 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
445 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
448 modificationTree1.write(OUTER_LIST_1_PATH, FOO_NODE);
449 modificationTree2.write(OUTER_LIST_2_PATH, BAR_NODE);
451 inMemoryDataTree.validate(modificationTree1);
452 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
453 inMemoryDataTree.commit(prepare1);
455 inMemoryDataTree.validate(modificationTree2);
456 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
457 inMemoryDataTree.commit(prepare2);
459 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
460 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
461 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class);
465 public void writeMergeFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
466 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
467 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
468 initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
469 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
470 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
472 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
474 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
477 modificationTree1.write(OUTER_LIST_1_PATH, FOO_NODE);
478 modificationTree2.merge(OUTER_LIST_2_PATH, BAR_NODE);
480 inMemoryDataTree.validate(modificationTree1);
481 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
482 inMemoryDataTree.commit(prepare1);
484 inMemoryDataTree.validate(modificationTree2);
485 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
486 inMemoryDataTree.commit(prepare2);
488 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
489 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
490 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class);
494 public void mergeWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
495 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
496 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
497 initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
498 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
499 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
501 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
503 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
506 modificationTree1.merge(OUTER_LIST_1_PATH, FOO_NODE);
507 modificationTree2.write(OUTER_LIST_2_PATH, BAR_NODE);
509 inMemoryDataTree.validate(modificationTree1);
510 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
511 inMemoryDataTree.commit(prepare1);
513 inMemoryDataTree.validate(modificationTree2);
514 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
515 inMemoryDataTree.commit(prepare2);
517 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
518 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
519 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class);
523 public void mergeMergeFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
524 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
525 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
526 initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
527 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
528 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
530 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
532 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
535 modificationTree1.merge(OUTER_LIST_1_PATH, FOO_NODE);
536 modificationTree2.merge(OUTER_LIST_2_PATH, BAR_NODE);
538 inMemoryDataTree.validate(modificationTree1);
539 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
540 inMemoryDataTree.commit(prepare1);
542 inMemoryDataTree.validate(modificationTree2);
543 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
544 inMemoryDataTree.commit(prepare2);
546 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
547 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_1_PATH), MapEntryNode.class);
548 assertPresentAndType(snapshotAfterCommits.readNode(OUTER_LIST_2_PATH), MapEntryNode.class);
552 public void deleteWriteFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
553 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
554 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
555 initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
556 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
557 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
559 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
561 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
564 modificationTree1.delete(TestModel.TEST_PATH);
565 modificationTree2.merge(OUTER_LIST_2_PATH, BAR_NODE);
567 inMemoryDataTree.validate(modificationTree1);
568 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
569 inMemoryDataTree.commit(prepare1);
572 inMemoryDataTree.validate(modificationTree2);
573 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
574 inMemoryDataTree.commit(prepare2);
575 fail("Exception should have been thrown");
576 } catch (Exception e) {
577 LOG.debug("Exception was thrown because path no longer exist in tree");
580 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
581 assertFalse(snapshotAfterCommits.readNode(TestModel.TEST_PATH).isPresent());
585 public void deleteMergeFooBar2ndLevelEmptyContainerTest() throws DataValidationFailedException {
586 DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
587 initialDataTreeModification.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
588 initialDataTreeModification.write(TestModel.OUTER_LIST_PATH, mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
589 inMemoryDataTree.commit(inMemoryDataTree.prepare(initialDataTreeModification));
590 InMemoryDataTreeSnapshot initialDataTreeSnapshot = inMemoryDataTree.takeSnapshot();
592 DataTreeModification modificationTree1 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
594 DataTreeModification modificationTree2 = new InMemoryDataTreeModification(initialDataTreeSnapshot,
597 modificationTree1.delete(TestModel.TEST_PATH);
598 modificationTree2.merge(OUTER_LIST_2_PATH, BAR_NODE);
600 inMemoryDataTree.validate(modificationTree1);
601 DataTreeCandidate prepare1 = inMemoryDataTree.prepare(modificationTree1);
602 inMemoryDataTree.commit(prepare1);
605 inMemoryDataTree.validate(modificationTree2);
606 DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
607 inMemoryDataTree.commit(prepare2);
608 fail("Exception should have been thrown");
609 } catch (Exception e) {
610 LOG.debug("Exception was thrown because path no longer exist in tree");
613 InMemoryDataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
614 assertFalse(snapshotAfterCommits.readNode(TestModel.TEST_PATH).isPresent());