X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardRecoveryCoordinatorTest.java;h=fc257b8cbbdf3fa8fd67295b4924dfa7b5c11ac9;hb=e78622411319748472b5d9edab14eb6dc92cf6b1;hp=79ea5d4cd6e27cbb3338cd2ec797a043509a26e1;hpb=744080c6e16bd2ba675b7b526b900aa6ee68bb90;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 79ea5d4cd6..fc257b8cbb 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,12 +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.mockito.Mockito; import org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload; -import org.opendaylight.controller.cluster.datastore.utils.SerializationUtils; +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; @@ -38,26 +41,13 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { 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); - } - - @Deprecated - @Test - public void testAppendRecoveredLogEntryDataTreeCandidatePayload(){ - final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, - null, "foobar", LoggerFactory.getLogger("foo")); - coordinator.startLogRecoveryBatch(10); - try { - coordinator.appendRecoveredLogEntry(DataTreeCandidatePayload.create(createCar())); - } catch(final SchemaValidationFailedException e){ - fail("SchemaValidationFailedException should not happen if pruning is done"); - } + final Shard mockShard = Mockito.mock(Shard.class); - coordinator.applyCurrentLogRecoveryBatch(); + peopleDataTree = new ShardDataTree(mockShard, peopleSchemaContext, TreeType.OPERATIONAL); } @Test @@ -67,7 +57,7 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { coordinator.startLogRecoveryBatch(10); try { coordinator.appendRecoveredLogEntry(CommitTransactionPayload.create(nextTransactionId(), createCar())); - } catch(final SchemaValidationFailedException e){ + } catch (final SchemaValidationFailedException e) { fail("SchemaValidationFailedException should not happen if pruning is done"); } @@ -75,7 +65,7 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { } @Test - public void testApplyRecoverySnapshot(){ + public void testApplyRecoverySnapshot() { final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, null, "foobar", LoggerFactory.getLogger("foo")); coordinator.startLogRecoveryBatch(10); @@ -88,19 +78,19 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { @Test - public void testApplyCurrentLogRecoveryBatch(){ + public void testApplyCurrentLogRecoveryBatch() { final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, 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); @@ -113,7 +103,7 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { 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); @@ -121,7 +111,7 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { 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); @@ -129,9 +119,10 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { 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(); @@ -140,18 +131,9 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { 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()); + dataTree.commit(dataTree.prepare(modification)); - return bytes; + return new ShardSnapshotState(new MetadataShardDataTreeSnapshot(dataTree.takeSnapshot().readNode( + YangInstanceIdentifier.EMPTY).get())); } -} \ No newline at end of file +}