1 package org.opendaylight.controller.cluster.datastore;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import com.google.common.base.Optional;
6 import java.util.concurrent.ExecutionException;
7 import org.junit.Before;
9 import org.opendaylight.controller.md.cluster.datastore.model.CarsModel;
10 import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel;
11 import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper;
12 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
13 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 public class ShardDataTreeTest {
19 SchemaContext fullSchema;
23 fullSchema = SchemaContextHelper.full();
27 public void testWrite() throws ExecutionException, InterruptedException {
28 modify(new ShardDataTree(fullSchema), false, true, true);
32 public void testMerge() throws ExecutionException, InterruptedException {
33 modify(new ShardDataTree(fullSchema), true, true, true);
37 private void modify(ShardDataTree shardDataTree, boolean merge, boolean expectedCarsPresent, boolean expectedPeoplePresent) throws ExecutionException, InterruptedException {
39 assertEquals(fullSchema, shardDataTree.getSchemaContext());
41 ReadWriteShardDataTreeTransaction transaction = shardDataTree.newReadWriteTransaction("txn-1", null);
43 DataTreeModification snapshot = transaction.getSnapshot();
45 assertNotNull(snapshot);
48 snapshot.merge(CarsModel.BASE_PATH, CarsModel.create());
49 snapshot.merge(PeopleModel.BASE_PATH, PeopleModel.create());
51 snapshot.write(CarsModel.BASE_PATH, CarsModel.create());
52 snapshot.write(PeopleModel.BASE_PATH, PeopleModel.create());
55 ShardDataTreeCohort cohort = shardDataTree.finishTransaction(transaction);
57 cohort.preCommit().get();
58 cohort.commit().get();
61 ReadOnlyShardDataTreeTransaction readOnlyShardDataTreeTransaction = shardDataTree.newReadOnlyTransaction("txn-2", null);
63 DataTreeSnapshot snapshot1 = readOnlyShardDataTreeTransaction.getSnapshot();
65 Optional<NormalizedNode<?, ?>> optional = snapshot1.readNode(CarsModel.BASE_PATH);
67 assertEquals(expectedCarsPresent, optional.isPresent());
69 Optional<NormalizedNode<?, ?>> optional1 = snapshot1.readNode(PeopleModel.BASE_PATH);
71 assertEquals(expectedPeoplePresent, optional1.isPresent());