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%2FDistributedDataStoreRemotingIntegrationTest.java;h=8100bdc6a2ec7331baa31f26a02682674a60e3ad;hp=c29cc4eea14888a05bca5e51121e0286f31723ce;hb=fd38fb36d0992a3a2391837f6e12615ed98a8bb5;hpb=7fd01f9dc19ef8f02c1b70973fcb091dc0ad8b1e diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java index c29cc4eea1..8100bdc6a2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java @@ -34,6 +34,9 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder; import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException; import org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException; import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply; @@ -64,6 +67,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; 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.ImmutableNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; @@ -133,7 +137,7 @@ public class DistributedDataStoreRemotingIntegrationTest { leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), SHARD_NAMES); } - private void verifyCars(DOMStoreReadTransaction readTx, MapEntryNode... entries) throws Exception { + private static void verifyCars(DOMStoreReadTransaction readTx, MapEntryNode... entries) throws Exception { Optional> optional = readTx.read(CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS); assertEquals("isPresent", true, optional.isPresent()); @@ -145,14 +149,14 @@ public class DistributedDataStoreRemotingIntegrationTest { assertEquals("Car list node", listBuilder.build(), optional.get()); } - private void verifyNode(DOMStoreReadTransaction readTx, YangInstanceIdentifier path, NormalizedNode expNode) + private static void verifyNode(DOMStoreReadTransaction readTx, YangInstanceIdentifier path, NormalizedNode expNode) throws Exception { Optional> optional = readTx.read(path).get(5, TimeUnit.SECONDS); assertEquals("isPresent", true, optional.isPresent()); assertEquals("Data node", expNode, optional.get()); } - private void verifyExists(DOMStoreReadTransaction readTx, YangInstanceIdentifier path) throws Exception { + private static void verifyExists(DOMStoreReadTransaction readTx, YangInstanceIdentifier path) throws Exception { Boolean exists = readTx.exists(path).get(5, TimeUnit.SECONDS); assertEquals("exists", true, exists); } @@ -482,7 +486,7 @@ public class DistributedDataStoreRemotingIntegrationTest { // Switch the leader to the follower followerDatastoreContextBuilder.shardElectionTimeoutFactor(1); - followerDistributedDataStore.onDatastoreContextUpdated(followerDatastoreContextBuilder.build()); + sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder); JavaTestKit.shutdownActorSystem(leaderSystem, null, true); @@ -519,7 +523,7 @@ public class DistributedDataStoreRemotingIntegrationTest { Optional carsFollowerShard = followerDistributedDataStore.getActorContext().findLocalShard("cars"); assertEquals("Cars follower shard found", true, carsFollowerShard.isPresent()); - TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(); + TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL); dataTree.setSchemaContext(SchemaContextHelper.full()); DataTreeModification modification = dataTree.takeSnapshot().newModification(); @@ -580,7 +584,7 @@ public class DistributedDataStoreRemotingIntegrationTest { JavaTestKit.shutdownActorSystem(leaderSystem, null, true); followerDatastoreContextBuilder.operationTimeoutInMillis(50).shardElectionTimeoutFactor(1); - followerDistributedDataStore.onDatastoreContextUpdated(followerDatastoreContextBuilder.build()); + sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder); DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction(); @@ -612,7 +616,7 @@ public class DistributedDataStoreRemotingIntegrationTest { Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); followerDatastoreContextBuilder.operationTimeoutInMillis(10).shardElectionTimeoutFactor(1); - followerDistributedDataStore.onDatastoreContextUpdated(followerDatastoreContextBuilder.build()); + sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder); DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction(); @@ -646,7 +650,7 @@ public class DistributedDataStoreRemotingIntegrationTest { JavaTestKit.shutdownActorSystem(leaderSystem, null, true); followerDatastoreContextBuilder.operationTimeoutInMillis(500); - followerDistributedDataStore.onDatastoreContextUpdated(followerDatastoreContextBuilder.build()); + sendDatastoreContextUpdate(followerDistributedDataStore, followerDatastoreContextBuilder); DOMStoreReadWriteTransaction rwTx = followerDistributedDataStore.newReadWriteTransaction(); @@ -654,4 +658,17 @@ public class DistributedDataStoreRemotingIntegrationTest { followerTestKit.doCommit(rwTx.ready()); } + + private static void sendDatastoreContextUpdate(DistributedDataStore dataStore, final Builder builder) { + DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class); + Answer answer = new Answer() { + @Override + public DatastoreContext answer(InvocationOnMock invocation) { + return builder.build(); + } + }; + Mockito.doAnswer(answer).when(mockContextFactory).getBaseDatastoreContext(); + Mockito.doAnswer(answer).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString()); + dataStore.onDatastoreContextUpdated(mockContextFactory); + } }