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=acac104c7972bdad01efab6d5fff4a7f6b85c8d9;hb=refs%2Fchanges%2F97%2F42497%2F27;hp=a3c9a6cca4bd569c501797e492c09a21bcc4db83;hpb=94603c85193862f85bf9d9aa51d5062d9f84e979;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 a3c9a6cca4..acac104c79 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 @@ -10,17 +10,13 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; - 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; -import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationByteStringPayload; -import org.opendaylight.controller.cluster.raft.protobuff.client.messages.CompositeModificationPayload; +import org.mockito.Mockito; +import org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload; +import org.opendaylight.controller.cluster.datastore.persisted.PreBoronShardDataTreeSnapshot; import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel; import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; @@ -30,12 +26,13 @@ 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; import org.slf4j.LoggerFactory; -public class ShardRecoveryCoordinatorTest { +public class ShardRecoveryCoordinatorTest extends AbstractTest { private ShardDataTree peopleDataTree; private SchemaContext peopleSchemaContext; @@ -46,12 +43,16 @@ public class ShardRecoveryCoordinatorTest { peopleSchemaContext = SchemaContextHelper.select(SchemaContextHelper.PEOPLE_YANG); carsSchemaContext = SchemaContextHelper.select(SchemaContextHelper.CARS_YANG); - peopleDataTree = new ShardDataTree(peopleSchemaContext); + final Shard mockShard = Mockito.mock(Shard.class); + + peopleDataTree = new ShardDataTree(mockShard, peopleSchemaContext, TreeType.OPERATIONAL); } + @Deprecated @Test public void testAppendRecoveredLogEntryDataTreeCandidatePayload(){ - final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); + final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, + null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); try { coordinator.appendRecoveredLogEntry(DataTreeCandidatePayload.create(createCar())); @@ -63,49 +64,23 @@ public class ShardRecoveryCoordinatorTest { } @Test - public void testAppendRecoveredLogEntryModificationPayload() throws IOException { - final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); - coordinator.startLogRecoveryBatch(10); - try { - final MutableCompositeModification modification = new MutableCompositeModification((short) 1); - modification.addModification(new WriteModification(CarsModel.BASE_PATH, CarsModel.create())); - coordinator.appendRecoveredLogEntry(new ModificationPayload(modification)); - } catch(final SchemaValidationFailedException e){ - fail("SchemaValidationFailedException should not happen if pruning is done"); - } - } - - @Test - public void testAppendRecoveredLogEntryCompositeModificationPayload() throws IOException { - final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); + public void testAppendRecoveredLogEntryCommitTransactionPayload() throws IOException { + final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, + null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); try { - final MutableCompositeModification modification = new MutableCompositeModification((short) 1); - modification.addModification(new WriteModification(CarsModel.BASE_PATH, CarsModel.create())); - coordinator.appendRecoveredLogEntry(new CompositeModificationPayload(modification.toSerializable())); + coordinator.appendRecoveredLogEntry(CommitTransactionPayload.create(nextTransactionId(), createCar())); } catch(final SchemaValidationFailedException e){ fail("SchemaValidationFailedException should not happen if pruning is done"); } - } - @Test - public void testAppendRecoveredLogEntryCompositeModificationByteStringPayload() throws IOException { - final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); - coordinator.startLogRecoveryBatch(10); - try { - final MutableCompositeModification modification = new MutableCompositeModification((short) 1); - modification.addModification(new WriteModification(CarsModel.BASE_PATH, CarsModel.create())); - coordinator.appendRecoveredLogEntry(new CompositeModificationByteStringPayload(modification.toSerializable())); - } catch(final SchemaValidationFailedException e){ - fail("SchemaValidationFailedException should not happen if pruning is done"); - } - - assertEquals(false, readCars(peopleDataTree).isPresent()); + coordinator.applyCurrentLogRecoveryBatch(); } @Test public void testApplyRecoverySnapshot(){ - final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree , peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); + final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, + null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); coordinator.applyRecoverySnapshot(createSnapshot()); @@ -117,7 +92,8 @@ public class ShardRecoveryCoordinatorTest { @Test public void testApplyCurrentLogRecoveryBatch(){ - final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, peopleSchemaContext, "foobar", LoggerFactory.getLogger("foo")); + final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, + null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); try { @@ -128,7 +104,7 @@ public class ShardRecoveryCoordinatorTest { } private DataTreeCandidateTip createCar(){ - final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(); + final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); dataTree.setSchemaContext(carsSchemaContext); final DataTreeSnapshot snapshot = dataTree.takeSnapshot(); @@ -157,7 +133,7 @@ public class ShardRecoveryCoordinatorTest { } private static byte[] createSnapshot(){ - final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(); + final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); dataTree.setSchemaContext(SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, SchemaContextHelper.PEOPLE_YANG)); DataTreeSnapshot snapshot = dataTree.takeSnapshot(); @@ -167,20 +143,9 @@ public class ShardRecoveryCoordinatorTest { modification.merge(CarsModel.BASE_PATH, CarsModel.create()); modification.merge(PeopleModel.BASE_PATH, PeopleModel.create()); modification.ready(); - final DataTreeCandidateTip prepare = dataTree.prepare(modification); - - dataTree.commit(prepare); - - snapshot = dataTree.takeSnapshot(); - - modification = snapshot.newModification(); - - final Optional> optional = modification.readNode(YangInstanceIdentifier.EMPTY); - - final byte[] bytes = SerializationUtils.serializeNormalizedNode(optional.get()); - - return bytes; - + dataTree.commit(dataTree.prepare(modification)); + return new PreBoronShardDataTreeSnapshot(dataTree.takeSnapshot().readNode(YangInstanceIdentifier.EMPTY).get()) + .serialize(); } } \ No newline at end of file