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%2FIntegrationTestKit.java;h=356026019f7a19ca54a1cd956231b01f9fe6e947;hp=f09441e07ea98f93a3f3e2ff4fc158b66ada48c4;hb=2f77e92af7a68b4a97dbfb709c6cc9b11a49878a;hpb=5370e8be094b802caa732efb4da5a035c53dc9c6 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 f09441e07e..356026019f 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 @@ -29,8 +29,9 @@ import org.mockito.Mockito; import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder; import org.opendaylight.controller.cluster.datastore.config.Configuration; import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl; +import org.opendaylight.controller.cluster.datastore.config.EmptyModuleShardConfigProvider; import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats; -import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot; +import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; @@ -49,7 +50,7 @@ public class IntegrationTestKit extends ShardTestKit { protected DatastoreContext.Builder datastoreContextBuilder; protected DatastoreSnapshot restoreFromSnapshot; - public IntegrationTestKit(ActorSystem actorSystem, Builder datastoreContextBuilder) { + public IntegrationTestKit(final ActorSystem actorSystem, final Builder datastoreContextBuilder) { super(actorSystem); this.datastoreContextBuilder = datastoreContextBuilder; } @@ -58,23 +59,23 @@ public class IntegrationTestKit extends ShardTestKit { return datastoreContextBuilder; } - public DistributedDataStore setupDistributedDataStore(String typeName, String... shardNames) { + public AbstractDataStore setupDistributedDataStore(final String typeName, final String... shardNames) { return setupDistributedDataStore(typeName, "module-shards.conf", true, SchemaContextHelper.full(), shardNames); } - public DistributedDataStore setupDistributedDataStore(String typeName, boolean waitUntilLeader, - String... shardNames) { + public AbstractDataStore setupDistributedDataStore(final String typeName, final boolean waitUntilLeader, + final String... shardNames) { return setupDistributedDataStore(typeName, "module-shards.conf", waitUntilLeader, SchemaContextHelper.full(), shardNames); } - public DistributedDataStore setupDistributedDataStore(final String typeName, final String moduleShardsConfig, + public AbstractDataStore setupDistributedDataStore(final String typeName, final String moduleShardsConfig, final boolean waitUntilLeader, final String... shardNames) { return setupDistributedDataStore(typeName, moduleShardsConfig, waitUntilLeader, SchemaContextHelper.full(), shardNames); } - public DistributedDataStore setupDistributedDataStore(final String typeName, final String moduleShardsConfig, + public AbstractDataStore setupDistributedDataStore(final String typeName, final String moduleShardsConfig, final boolean waitUntilLeader, final SchemaContext schemaContext, final String... shardNames) { final ClusterWrapper cluster = new ClusterWrapperImpl(getSystem()); final Configuration config = new ConfigurationImpl(moduleShardsConfig, "modules.conf"); @@ -86,7 +87,7 @@ public class IntegrationTestKit extends ShardTestKit { Mockito.doReturn(datastoreContext).when(mockContextFactory).getBaseDatastoreContext(); Mockito.doReturn(datastoreContext).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString()); - DistributedDataStore dataStore = new DistributedDataStore(getSystem(), cluster, config, mockContextFactory, + AbstractDataStore dataStore = new DistributedDataStore(getSystem(), cluster, config, mockContextFactory, restoreFromSnapshot); dataStore.onGlobalContextUpdated(schemaContext); @@ -99,7 +100,29 @@ public class IntegrationTestKit extends ShardTestKit { return dataStore; } - public void waitUntilLeader(ActorContext actorContext, String... shardNames) { + 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); + + final DatastoreContext datastoreContext = getDatastoreContextBuilder().build(); + + final DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class); + Mockito.doReturn(datastoreContext).when(mockContextFactory).getBaseDatastoreContext(); + Mockito.doReturn(datastoreContext).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString()); + + final DistributedDataStore dataStore = new DistributedDataStore(getSystem(), cluster, + configuration, mockContextFactory, restoreFromSnapshot); + + dataStore.onGlobalContextUpdated(schemaContext); + + datastoreContextBuilder = DatastoreContext.newBuilderFrom(datastoreContext); + return dataStore; + } + + public void waitUntilLeader(final ActorContext actorContext, final String... shardNames) { for (String shardName: shardNames) { ActorRef shard = findLocalShard(actorContext, shardName); @@ -109,7 +132,7 @@ public class IntegrationTestKit extends ShardTestKit { } } - public void waitUntilNoLeader(ActorContext actorContext, String... shardNames) { + public void waitUntilNoLeader(final ActorContext actorContext, final String... shardNames) { for (String shardName: shardNames) { ActorRef shard = findLocalShard(actorContext, shardName); assertNotNull("No local shard found for " + shardName, shard); @@ -118,7 +141,7 @@ public class IntegrationTestKit extends ShardTestKit { } } - public void waitForMembersUp(String... otherMembers) { + public void waitForMembersUp(final String... otherMembers) { Set otherMembersSet = Sets.newHashSet(otherMembers); Stopwatch sw = Stopwatch.createStarted(); while (sw.elapsed(TimeUnit.SECONDS) <= 10) { @@ -136,7 +159,7 @@ public class IntegrationTestKit extends ShardTestKit { fail("Member(s) " + otherMembersSet + " are not Up"); } - public static ActorRef findLocalShard(ActorContext actorContext, String shardName) { + public static ActorRef findLocalShard(final ActorContext actorContext, final String shardName) { ActorRef shard = null; for (int i = 0; i < 20 * 5 && shard == null; i++) { Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS); @@ -148,8 +171,8 @@ public class IntegrationTestKit extends ShardTestKit { return shard; } - public static void verifyShardStats(DistributedDataStore datastore, String shardName, ShardStatsVerifier verifier) - throws Exception { + public static void verifyShardStats(final AbstractDataStore datastore, final String shardName, + final ShardStatsVerifier verifier) throws Exception { ActorContext actorContext = datastore.getActorContext(); Future future = actorContext.findLocalShardAsync(shardName); @@ -173,8 +196,8 @@ public class IntegrationTestKit extends ShardTestKit { throw lastError; } - void testWriteTransaction(DistributedDataStore dataStore, YangInstanceIdentifier nodePath, - NormalizedNode nodeToWrite) throws Exception { + void testWriteTransaction(final AbstractDataStore dataStore, final YangInstanceIdentifier nodePath, + final NormalizedNode nodeToWrite) throws Exception { // 1. Create a write-only Tx @@ -218,7 +241,7 @@ public class IntegrationTestKit extends ShardTestKit { } @SuppressWarnings("checkstyle:IllegalCatch") - void assertExceptionOnCall(Callable callable, Class expType) + void assertExceptionOnCall(final Callable callable, final Class expType) throws Exception { try { callable.call(); @@ -229,13 +252,10 @@ public class IntegrationTestKit extends ShardTestKit { } void assertExceptionOnTxChainCreates(final DOMStoreTransactionChain txChain, - Class expType) throws Exception { - assertExceptionOnCall(new Callable() { - @Override - public Void call() throws Exception { - txChain.newWriteOnlyTransaction(); - return null; - } + final Class expType) throws Exception { + assertExceptionOnCall(() -> { + txChain.newWriteOnlyTransaction(); + return null; }, expType); assertExceptionOnCall(() -> {