From: Tom Pantelis Date: Thu, 27 Apr 2017 10:45:11 +0000 (-0400) Subject: Bug 8301: Fix some issues with testProducerRegistrations X-Git-Tag: release/nitrogen~308 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=64b9093c2c9ce670b92f2d0ea44c76dc9a385b5a Bug 8301: Fix some issues with testProducerRegistrations The LogicalDatastoreType.CONFIGURATION type was being used for both data stores - modified the IntegrationTestKit to set the logicalStoreType appropriately. Fixed a synchronization issue in DistributedShardedDOMDataTree#lookupShardFrontend where it accessed shards unprotected. Change-Id: I628add86667e4a812f8e7516bac59f9b66fe4033 Signed-off-by: Tom Pantelis --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java index 424439f6e5..54b33a4ccd 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTree.java @@ -464,8 +464,9 @@ public class DistributedShardedDOMDataTree implements DOMDataTreeService, DOMDat DOMDataTreePrefixTableEntry> lookupShardFrontend( final DOMDataTreeIdentifier prefix) { - return shards.lookup(prefix); - + synchronized (shards) { + return shards.lookup(prefix); + } } DOMDataTreeProducer localCreateProducer(final Collection prefix) { @@ -675,7 +676,7 @@ public class DistributedShardedDOMDataTree implements DOMDataTreeService, DOMDat final Object o = actorContext.executeOperation(shardDataTreeActor, new ProducerRemoved(subtrees)); if (o instanceof DOMDataTreeProducerException) { - throw ((DOMDataTreeProducerException) o); + throw (DOMDataTreeProducerException) o; } else if (o instanceof Throwable) { throw new DOMDataTreeProducerException("Unable to close producer", (Throwable) o); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java index 01678ad74e..1c4bfcfbb2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java @@ -128,7 +128,7 @@ public class IntegrationTestKit extends ShardTestKit { final ClusterWrapper cluster = new ClusterWrapperImpl(getSystem()); final Configuration config = new ConfigurationImpl(moduleShardsConfig, modulesConfig); - datastoreContextBuilder.dataStoreName(typeName); + setDataStoreName(typeName); final DatastoreContext datastoreContext = datastoreContextBuilder.build(); final DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class); @@ -152,12 +152,22 @@ public class IntegrationTestKit extends ShardTestKit { return dataStore; } + private void setDataStoreName(String typeName) { + if ("config".equals(typeName)) { + datastoreContextBuilder.logicalStoreType(LogicalDatastoreType.CONFIGURATION); + } else if ("operational".equals(typeName)) { + datastoreContextBuilder.logicalStoreType(LogicalDatastoreType.OPERATIONAL); + } else { + datastoreContextBuilder.dataStoreName(typeName); + } + } + public DistributedDataStore setupDistributedDataStoreWithoutConfig(final String typeName, final SchemaContext schemaContext) { final ClusterWrapper cluster = new ClusterWrapperImpl(getSystem()); final ConfigurationImpl configuration = new ConfigurationImpl(new EmptyModuleShardConfigProvider()); - getDatastoreContextBuilder().dataStoreName(typeName); + setDataStoreName(typeName); final DatastoreContext datastoreContext = getDatastoreContextBuilder().build(); @@ -180,7 +190,7 @@ public class IntegrationTestKit extends ShardTestKit { final ClusterWrapper cluster = new ClusterWrapperImpl(getSystem()); final ConfigurationImpl configuration = new ConfigurationImpl(new EmptyModuleShardConfigProvider()); - getDatastoreContextBuilder().dataStoreName(typeName); + setDataStoreName(typeName); final DatastoreContext datastoreContext = getDatastoreContextBuilder().logicalStoreType(storeType).build(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeRemotingTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeRemotingTest.java index 63a3852f6d..36a533e67b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeRemotingTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardedDOMDataTreeRemotingTest.java @@ -27,7 +27,6 @@ import java.util.Collections; import org.junit.After; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; import org.opendaylight.controller.cluster.ActorSystemProvider; @@ -54,7 +53,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLe import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Ignore("https://bugs.opendaylight.org/show_bug.cgi?id=8301") public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { private static final Logger LOG = LoggerFactory.getLogger(DistributedShardedDOMDataTreeRemotingTest.class); @@ -72,14 +70,10 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { private final Builder leaderDatastoreContextBuilder = - DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5) - .logicalStoreType( - org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION); + DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5); private final DatastoreContext.Builder followerDatastoreContextBuilder = - DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5) - .logicalStoreType( - org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION); + DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5); private DistributedDataStore leaderConfigDatastore; private DistributedDataStore leaderOperDatastore; @@ -164,6 +158,8 @@ public class DistributedShardedDOMDataTreeRemotingTest extends AbstractTest { followerOperDatastore, followerConfigDatastore); + followerTestKit.waitForMembersUp("member-1"); + leaderShardFactory.init(); followerShardFactory.init();