X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardRecoveryCoordinatorTest.java;h=f4468b0e59d025a87f44365fc37e5797668e33a4;hb=dc6370feeb5fc47be3e267bf85d6354013d0409b;hp=f14bb3de765e73afb771755542031b3120190a71;hpb=2b0ddf57e4d3d2e78637a6762ae6b5a05128a3a1;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinatorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinatorTest.java index f14bb3de76..f4468b0e59 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinatorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinatorTest.java @@ -14,7 +14,6 @@ import com.google.common.base.Optional; import java.io.IOException; import org.junit.Before; import org.junit.Test; -import org.opendaylight.controller.cluster.datastore.modification.ModificationPayload; import org.opendaylight.controller.cluster.datastore.modification.MutableCompositeModification; import org.opendaylight.controller.cluster.datastore.modification.WriteModification; import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils; @@ -29,6 +28,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot; import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree; +import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType; import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory; import org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFailedException; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -45,57 +45,47 @@ public class ShardRecoveryCoordinatorTest { peopleSchemaContext = SchemaContextHelper.select(SchemaContextHelper.PEOPLE_YANG); carsSchemaContext = SchemaContextHelper.select(SchemaContextHelper.CARS_YANG); - peopleDataTree = new ShardDataTree(peopleSchemaContext); + peopleDataTree = new ShardDataTree(peopleSchemaContext, TreeType.OPERATIONAL); } @Test public void testAppendRecoveredLogEntryDataTreeCandidatePayload(){ - ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); + final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, + peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); try { coordinator.appendRecoveredLogEntry(DataTreeCandidatePayload.create(createCar())); - } catch(SchemaValidationFailedException e){ + } catch(final SchemaValidationFailedException e){ fail("SchemaValidationFailedException should not happen if pruning is done"); } coordinator.applyCurrentLogRecoveryBatch(); } - @Test - public void testAppendRecoveredLogEntryModificationPayload() throws IOException { - ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); - coordinator.startLogRecoveryBatch(10); - try { - MutableCompositeModification modification = new MutableCompositeModification((short) 1); - modification.addModification(new WriteModification(CarsModel.BASE_PATH, CarsModel.create())); - coordinator.appendRecoveredLogEntry(new ModificationPayload(modification)); - } catch(SchemaValidationFailedException e){ - fail("SchemaValidationFailedException should not happen if pruning is done"); - } - } - @Test public void testAppendRecoveredLogEntryCompositeModificationPayload() throws IOException { - ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); + final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, + peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); try { - MutableCompositeModification modification = new MutableCompositeModification((short) 1); + final MutableCompositeModification modification = new MutableCompositeModification((short) 1); modification.addModification(new WriteModification(CarsModel.BASE_PATH, CarsModel.create())); coordinator.appendRecoveredLogEntry(new CompositeModificationPayload(modification.toSerializable())); - } catch(SchemaValidationFailedException e){ + } catch(final SchemaValidationFailedException e){ fail("SchemaValidationFailedException should not happen if pruning is done"); } } @Test public void testAppendRecoveredLogEntryCompositeModificationByteStringPayload() throws IOException { - ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); + final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, + peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); try { - MutableCompositeModification modification = new MutableCompositeModification((short) 1); + final MutableCompositeModification modification = new MutableCompositeModification((short) 1); modification.addModification(new WriteModification(CarsModel.BASE_PATH, CarsModel.create())); coordinator.appendRecoveredLogEntry(new CompositeModificationByteStringPayload(modification.toSerializable())); - } catch(SchemaValidationFailedException e){ + } catch(final SchemaValidationFailedException e){ fail("SchemaValidationFailedException should not happen if pruning is done"); } @@ -104,7 +94,8 @@ public class ShardRecoveryCoordinatorTest { @Test public void testApplyRecoverySnapshot(){ - ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree , peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); + final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, + peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); coordinator.applyRecoverySnapshot(createSnapshot()); @@ -116,55 +107,48 @@ public class ShardRecoveryCoordinatorTest { @Test public void testApplyCurrentLogRecoveryBatch(){ - ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); + final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, + peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); try { coordinator.applyCurrentLogRecoveryBatch(); - } catch(IllegalArgumentException e){ + } catch(final IllegalArgumentException e){ fail("IllegalArgumentException should not happen - if the pruning modification delegate is passed"); } } private DataTreeCandidateTip createCar(){ - TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(); + final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); dataTree.setSchemaContext(carsSchemaContext); - DataTreeSnapshot snapshot = dataTree.takeSnapshot(); + final DataTreeSnapshot snapshot = dataTree.takeSnapshot(); - DataTreeModification modification = snapshot.newModification(); + final DataTreeModification modification = snapshot.newModification(); modification.merge(CarsModel.BASE_PATH, CarsModel.create()); - + modification.ready(); return dataTree.prepare(modification); } - private Optional> readCars(ShardDataTree shardDataTree){ - TipProducingDataTree dataTree = shardDataTree.getDataTree(); + private Optional> readCars(final ShardDataTree shardDataTree){ + final TipProducingDataTree dataTree = shardDataTree.getDataTree(); + // FIXME: this should not be called here dataTree.setSchemaContext(peopleSchemaContext); - DataTreeSnapshot snapshot = dataTree.takeSnapshot(); - - DataTreeModification modification = snapshot.newModification(); - - return modification.readNode(CarsModel.BASE_PATH); + return shardDataTree.readNode(CarsModel.BASE_PATH); } - private Optional> readPeople(ShardDataTree shardDataTree){ - TipProducingDataTree dataTree = shardDataTree.getDataTree(); + private Optional> readPeople(final ShardDataTree shardDataTree){ + final TipProducingDataTree dataTree = shardDataTree.getDataTree(); + // FIXME: this should not be called here dataTree.setSchemaContext(peopleSchemaContext); - DataTreeSnapshot snapshot = dataTree.takeSnapshot(); - - DataTreeModification modification = snapshot.newModification(); - - return modification.readNode(PeopleModel.BASE_PATH); + return shardDataTree.readNode(PeopleModel.BASE_PATH); } - - - private byte[] createSnapshot(){ - TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(); + private static byte[] createSnapshot(){ + final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); dataTree.setSchemaContext(SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, SchemaContextHelper.PEOPLE_YANG)); DataTreeSnapshot snapshot = dataTree.takeSnapshot(); @@ -173,8 +157,8 @@ public class ShardRecoveryCoordinatorTest { modification.merge(CarsModel.BASE_PATH, CarsModel.create()); modification.merge(PeopleModel.BASE_PATH, PeopleModel.create()); - - DataTreeCandidateTip prepare = dataTree.prepare(modification); + modification.ready(); + final DataTreeCandidateTip prepare = dataTree.prepare(modification); dataTree.commit(prepare); @@ -182,9 +166,9 @@ public class ShardRecoveryCoordinatorTest { modification = snapshot.newModification(); - Optional> optional = modification.readNode(YangInstanceIdentifier.EMPTY); + final Optional> optional = modification.readNode(YangInstanceIdentifier.EMPTY); - byte[] bytes = SerializationUtils.serializeNormalizedNode(optional.get()); + final byte[] bytes = SerializationUtils.serializeNormalizedNode(optional.get()); return bytes;