Bug 4564: Implement clustering backup-datastore RPC
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / IntegrationTestKit.java
index 0eedc78bb41b248d67c9a9a69fb0efc550433238..67a6479e0847c160871913782266808fcf8251a1 100644 (file)
@@ -18,6 +18,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.Uninterruptibles;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
+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;
@@ -64,8 +65,11 @@ public class IntegrationTestKit extends ShardTestKit {
         datastoreContextBuilder.dataStoreType(typeName);
 
         DatastoreContext datastoreContext = datastoreContextBuilder.build();
+        DatastoreContextFactory mockContextFactory = Mockito.mock(DatastoreContextFactory.class);
+        Mockito.doReturn(datastoreContext).when(mockContextFactory).getBaseDatastoreContext();
+        Mockito.doReturn(datastoreContext).when(mockContextFactory).getShardDatastoreContext(Mockito.anyString());
 
-        DistributedDataStore dataStore = new DistributedDataStore(getSystem(), cluster, config, datastoreContext);
+        DistributedDataStore dataStore = new DistributedDataStore(getSystem(), cluster, config, mockContextFactory);
 
         dataStore.onGlobalContextUpdated(schemaContext);
 
@@ -95,7 +99,7 @@ public class IntegrationTestKit extends ShardTestKit {
         }
     }
 
-    private ActorRef findLocalShard(ActorContext actorContext, String shardName) {
+    private static ActorRef findLocalShard(ActorContext actorContext, String shardName) {
         ActorRef shard = null;
         for(int i = 0; i < 20 * 5 && shard == null; i++) {
             Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
@@ -150,7 +154,7 @@ public class IntegrationTestKit extends ShardTestKit {
         cohort.commit().get(5, TimeUnit.SECONDS);
     }
 
-    void cleanup(DistributedDataStore dataStore) {
+    public void cleanup(DistributedDataStore dataStore) {
         if(dataStore != null) {
             dataStore.getActorContext().getShardManager().tell(PoisonPill.getInstance(), null);
         }
@@ -192,4 +196,4 @@ public class IntegrationTestKit extends ShardTestKit {
             }
         }, expType);
     }
-}
\ No newline at end of file
+}