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=39285f9d67f90bfe6c51ec981debf5ff1b305833;hp=fc257b8cbbdf3fa8fd67295b4924dfa7b5c11ac9;hb=20a32e6459fd1e27e7669bf1ebc7742b96787b94;hpb=5c08efbf3a3d046a7650f1b32a6cacfb1e4a6d0d 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 fc257b8cbb..39285f9d67 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 @@ -8,7 +8,8 @@ package org.opendaylight.controller.cluster.datastore; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import com.google.common.base.Optional; @@ -24,21 +25,25 @@ import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel; import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration; 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.Logger; import org.slf4j.LoggerFactory; public class ShardRecoveryCoordinatorTest extends AbstractTest { + private static final Logger FOO_LOGGER = LoggerFactory.getLogger("foo"); private ShardDataTree peopleDataTree; private SchemaContext peopleSchemaContext; private SchemaContext carsSchemaContext; + private ShardRecoveryCoordinator coordinator; @Before public void setUp() { @@ -48,13 +53,12 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { final Shard mockShard = Mockito.mock(Shard.class); peopleDataTree = new ShardDataTree(mockShard, peopleSchemaContext, TreeType.OPERATIONAL); + coordinator = ShardRecoveryCoordinator.create(peopleDataTree, "foobar", FOO_LOGGER); + coordinator.startLogRecoveryBatch(10); } @Test public void testAppendRecoveredLogEntryCommitTransactionPayload() throws IOException { - final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, - null, "foobar", LoggerFactory.getLogger("foo")); - coordinator.startLogRecoveryBatch(10); try { coordinator.appendRecoveredLogEntry(CommitTransactionPayload.create(nextTransactionId(), createCar())); } catch (final SchemaValidationFailedException e) { @@ -66,23 +70,15 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { @Test public void testApplyRecoverySnapshot() { - final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, - null, "foobar", LoggerFactory.getLogger("foo")); - coordinator.startLogRecoveryBatch(10); - coordinator.applyRecoverySnapshot(createSnapshot()); - assertEquals(false, readCars(peopleDataTree).isPresent()); - assertEquals(true, readPeople(peopleDataTree).isPresent()); + assertFalse(readCars(peopleDataTree).isPresent()); + assertTrue(readPeople(peopleDataTree).isPresent()); } @Test public void testApplyCurrentLogRecoveryBatch() { - final ShardRecoveryCoordinator coordinator = new ShardRecoveryCoordinator(peopleDataTree, - null, "foobar", LoggerFactory.getLogger("foo")); - coordinator.startLogRecoveryBatch(10); - try { coordinator.applyCurrentLogRecoveryBatch(); } catch (final IllegalArgumentException e) { @@ -90,9 +86,9 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { } } - private DataTreeCandidateTip createCar() { - final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - dataTree.setSchemaContext(carsSchemaContext); + private DataTreeCandidate createCar() { + final DataTree dataTree = new InMemoryDataTreeFactory().create( + DataTreeConfiguration.DEFAULT_OPERATIONAL, carsSchemaContext); final DataTreeSnapshot snapshot = dataTree.takeSnapshot(); @@ -104,7 +100,7 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { } private Optional> readCars(final ShardDataTree shardDataTree) { - final TipProducingDataTree dataTree = shardDataTree.getDataTree(); + final DataTree dataTree = shardDataTree.getDataTree(); // FIXME: this should not be called here dataTree.setSchemaContext(peopleSchemaContext); @@ -112,7 +108,7 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { } private Optional> readPeople(final ShardDataTree shardDataTree) { - final TipProducingDataTree dataTree = shardDataTree.getDataTree(); + final DataTree dataTree = shardDataTree.getDataTree(); // FIXME: this should not be called here dataTree.setSchemaContext(peopleSchemaContext); @@ -120,8 +116,8 @@ public class ShardRecoveryCoordinatorTest extends AbstractTest { } private static ShardSnapshotState createSnapshot() { - final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); - dataTree.setSchemaContext(SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, + final DataTree dataTree = new InMemoryDataTreeFactory().create( + DataTreeConfiguration.DEFAULT_OPERATIONAL, SchemaContextHelper.select(SchemaContextHelper.CARS_YANG, SchemaContextHelper.PEOPLE_YANG)); DataTreeSnapshot snapshot = dataTree.takeSnapshot();