X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardRecoveryCoordinatorTest.java;h=736e29170364bf0af6a6f3ecdffcdcd69125311d;hp=b730150668fa3796eee6ed55c97553a27df74614;hb=7204c455a1636a7fc89bcd28fe9e9000eaa81b3b;hpb=43aab07cdbc80eda69e84a26085afe1b37f4002e 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 b730150668..736e291703 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,16 +10,15 @@ 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.MetadataShardDataTreeSnapshot; +import org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState; 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; @@ -35,28 +34,31 @@ import org.opendaylight.yangtools.yang.data.impl.schema.tree.SchemaValidationFai 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; private SchemaContext carsSchemaContext; @Before - public void setUp(){ + public void setUp() { peopleSchemaContext = SchemaContextHelper.select(SchemaContextHelper.PEOPLE_YANG); carsSchemaContext = SchemaContextHelper.select(SchemaContextHelper.CARS_YANG); - peopleDataTree = new ShardDataTree(peopleSchemaContext, TreeType.OPERATIONAL); + final Shard mockShard = Mockito.mock(Shard.class); + + peopleDataTree = new ShardDataTree(mockShard, peopleSchemaContext, TreeType.OPERATIONAL); } + @Deprecated @Test - public void testAppendRecoveredLogEntryDataTreeCandidatePayload(){ + public void testAppendRecoveredLogEntryDataTreeCandidatePayload() { final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, - peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo")); + null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); try { coordinator.appendRecoveredLogEntry(DataTreeCandidatePayload.create(createCar())); - } catch(final SchemaValidationFailedException e){ + } catch (final SchemaValidationFailedException e) { fail("SchemaValidationFailedException should not happen if pruning is done"); } @@ -64,53 +66,23 @@ public class ShardRecoveryCoordinatorTest { } @Test - public void testAppendRecoveredLogEntryModificationPayload() throws IOException { - final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, - peopleSchemaContext, 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 ModificationPayload(modification)); - } catch(final SchemaValidationFailedException e){ - fail("SchemaValidationFailedException should not happen if pruning is done"); - } - } - - @Test - public void testAppendRecoveredLogEntryCompositeModificationPayload() throws IOException { + public void testAppendRecoveredLogEntryCommitTransactionPayload() throws IOException { final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, - peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo")); + 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())); - } catch(final SchemaValidationFailedException e){ + 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, 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 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(){ + public void testApplyRecoverySnapshot() { final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, - peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo")); + null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); coordinator.applyRecoverySnapshot(createSnapshot()); @@ -121,19 +93,19 @@ public class ShardRecoveryCoordinatorTest { @Test - public void testApplyCurrentLogRecoveryBatch(){ + public void testApplyCurrentLogRecoveryBatch() { final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, - peopleSchemaContext, null, "foobar", LoggerFactory.getLogger("foo")); + null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); try { coordinator.applyCurrentLogRecoveryBatch(); - } catch(final IllegalArgumentException e){ + } catch (final IllegalArgumentException e) { fail("IllegalArgumentException should not happen - if the pruning modification delegate is passed"); } } - private DataTreeCandidateTip createCar(){ + private DataTreeCandidateTip createCar() { final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); dataTree.setSchemaContext(carsSchemaContext); @@ -146,7 +118,7 @@ public class ShardRecoveryCoordinatorTest { return dataTree.prepare(modification); } - private Optional> readCars(final ShardDataTree shardDataTree){ + private Optional> readCars(final ShardDataTree shardDataTree) { final TipProducingDataTree dataTree = shardDataTree.getDataTree(); // FIXME: this should not be called here dataTree.setSchemaContext(peopleSchemaContext); @@ -154,7 +126,7 @@ public class ShardRecoveryCoordinatorTest { return shardDataTree.readNode(CarsModel.BASE_PATH); } - private Optional> readPeople(final ShardDataTree shardDataTree){ + private Optional> readPeople(final ShardDataTree shardDataTree) { final TipProducingDataTree dataTree = shardDataTree.getDataTree(); // FIXME: this should not be called here dataTree.setSchemaContext(peopleSchemaContext); @@ -162,9 +134,10 @@ public class ShardRecoveryCoordinatorTest { return shardDataTree.readNode(PeopleModel.BASE_PATH); } - private static byte[] createSnapshot(){ + private static ShardSnapshotState createSnapshot() { final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - dataTree.setSchemaContext(SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, SchemaContextHelper.PEOPLE_YANG)); + dataTree.setSchemaContext(SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, + SchemaContextHelper.PEOPLE_YANG)); DataTreeSnapshot snapshot = dataTree.takeSnapshot(); @@ -173,20 +146,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 ShardSnapshotState(new MetadataShardDataTreeSnapshot(dataTree.takeSnapshot().readNode( + YangInstanceIdentifier.EMPTY).get())); } -} \ No newline at end of file +}