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%2Futils%2FActorContextTest.java;h=14536ba7a0429fe53c43228d54a1fd8247a6e107;hp=1cc89f18af960557ba510814e6fe7c5326fa34ea;hb=28b2fd303b8e8bc757de6ead454ae06469113b34;hpb=6823ef1fd8f0a2f7ea39a2e85276a73e5de0bf72 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java index 1cc89f18af..14536ba7a0 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java @@ -1,3 +1,11 @@ +/* + * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.controller.cluster.datastore.utils; import static org.junit.Assert.assertEquals; @@ -23,7 +31,6 @@ import akka.util.Timeout; import com.google.common.base.Optional; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import com.google.common.util.concurrent.Uninterruptibles; import com.typesafe.config.ConfigFactory; import java.util.Arrays; import java.util.Map; @@ -33,8 +40,10 @@ import org.junit.Test; import org.mockito.Mockito; import org.opendaylight.controller.cluster.datastore.AbstractActorTest; import org.opendaylight.controller.cluster.datastore.ClusterWrapper; -import org.opendaylight.controller.cluster.datastore.Configuration; +import org.opendaylight.controller.cluster.datastore.DataStoreVersions; import org.opendaylight.controller.cluster.datastore.DatastoreContext; +import org.opendaylight.controller.cluster.datastore.DatastoreContextFactory; +import org.opendaylight.controller.cluster.datastore.config.Configuration; import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException; import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException; import org.opendaylight.controller.cluster.datastore.exceptions.PrimaryNotFoundException; @@ -45,6 +54,9 @@ import org.opendaylight.controller.cluster.datastore.messages.LocalShardFound; import org.opendaylight.controller.cluster.datastore.messages.LocalShardNotFound; import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo; import org.opendaylight.controller.cluster.datastore.messages.RemotePrimaryShardFound; +import org.opendaylight.controller.cluster.raft.utils.EchoActor; +import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -280,53 +292,6 @@ public class ActorContextTest extends AbstractActorTest{ assertEquals(false, actorContext.isPathLocal("akka.tcp://system@127.0.0.1:2551/")); } - @Test - public void testResolvePathForRemoteActor() { - ActorContext actorContext = - new ActorContext(getSystem(), mock(ActorRef.class), mock( - ClusterWrapper.class), - mock(Configuration.class)); - - String actual = actorContext.resolvePath( - "akka.tcp://system@127.0.0.1:2550/user/shardmanager/shard", - "akka://system/user/shardmanager/shard/transaction"); - - String expected = "akka.tcp://system@127.0.0.1:2550/user/shardmanager/shard/transaction"; - - assertEquals(expected, actual); - } - - @Test - public void testResolvePathForLocalActor() { - ActorContext actorContext = - new ActorContext(getSystem(), mock(ActorRef.class), mock(ClusterWrapper.class), - mock(Configuration.class)); - - String actual = actorContext.resolvePath( - "akka://system/user/shardmanager/shard", - "akka://system/user/shardmanager/shard/transaction"); - - String expected = "akka://system/user/shardmanager/shard/transaction"; - - assertEquals(expected, actual); - } - - @Test - public void testResolvePathForRemoteActorWithProperRemoteAddress() { - ActorContext actorContext = - new ActorContext(getSystem(), mock(ActorRef.class), mock(ClusterWrapper.class), - mock(Configuration.class)); - - String actual = actorContext.resolvePath( - "akka.tcp://system@7.0.0.1:2550/user/shardmanager/shard", - "akka.tcp://system@7.0.0.1:2550/user/shardmanager/shard/transaction"); - - String expected = "akka.tcp://system@7.0.0.1:2550/user/shardmanager/shard/transaction"; - - assertEquals(expected, actual); - } - - @Test public void testClientDispatcherIsGlobalDispatcher(){ ActorContext actorContext = @@ -365,9 +330,12 @@ public class ActorContextTest extends AbstractActorTest{ DatastoreContext newContext = DatastoreContext.newBuilder().operationTimeoutInSeconds(6). shardTransactionCommitTimeoutInSeconds(8).build(); - actorContext.setDatastoreContext(newContext); + DatastoreContextFactory mockContextFactory = mock(DatastoreContextFactory.class); + Mockito.doReturn(newContext).when(mockContextFactory).getBaseDatastoreContext(); + + actorContext.setDatastoreContext(mockContextFactory); - expectMsgClass(duration("5 seconds"), DatastoreContext.class); + expectMsgClass(duration("5 seconds"), DatastoreContextFactory.class); Assert.assertSame("getDatastoreContext", newContext, actorContext.getDatastoreContext()); @@ -383,16 +351,18 @@ public class ActorContextTest extends AbstractActorTest{ TestActorRef shardManager = TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); - DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config"). + DatastoreContext dataStoreContext = DatastoreContext.newBuilder(). + logicalStoreType(LogicalDatastoreType.CONFIGURATION). shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build(); final String expPrimaryPath = "akka://test-system/find-primary-shard"; + final short expPrimaryVersion = DataStoreVersions.CURRENT_VERSION; ActorContext actorContext = new ActorContext(getSystem(), shardManager, mock(ClusterWrapper.class), mock(Configuration.class), dataStoreContext, new PrimaryShardInfoFutureCache()) { @Override protected Future doAsk(ActorRef actorRef, Object message, Timeout timeout) { - return Futures.successful((Object) new RemotePrimaryShardFound(expPrimaryPath)); + return Futures.successful((Object) new RemotePrimaryShardFound(expPrimaryPath, expPrimaryVersion)); } }; @@ -403,6 +373,7 @@ public class ActorContextTest extends AbstractActorTest{ assertEquals("LocalShardDataTree present", false, actual.getLocalShardDataTree().isPresent()); assertTrue("Unexpected PrimaryShardActor path " + actual.getPrimaryShardActor().path(), expPrimaryPath.endsWith(actual.getPrimaryShardActor().pathString())); + assertEquals("getPrimaryShardVersion", expPrimaryVersion, actual.getPrimaryShardVersion()); Future cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar"); @@ -423,7 +394,8 @@ public class ActorContextTest extends AbstractActorTest{ TestActorRef shardManager = TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); - DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config"). + DatastoreContext dataStoreContext = DatastoreContext.newBuilder(). + logicalStoreType(LogicalDatastoreType.CONFIGURATION). shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build(); final DataTree mockDataTree = Mockito.mock(DataTree.class); @@ -445,6 +417,7 @@ public class ActorContextTest extends AbstractActorTest{ assertSame("LocalShardDataTree", mockDataTree, actual.getLocalShardDataTree().get()); assertTrue("Unexpected PrimaryShardActor path " + actual.getPrimaryShardActor().path(), expPrimaryPath.endsWith(actual.getPrimaryShardActor().pathString())); + assertEquals("getPrimaryShardVersion", DataStoreVersions.CURRENT_VERSION, actual.getPrimaryShardVersion()); Future cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar"); @@ -473,7 +446,8 @@ public class ActorContextTest extends AbstractActorTest{ TestActorRef shardManager = TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class)); - DatastoreContext dataStoreContext = DatastoreContext.newBuilder().dataStoreType("config"). + DatastoreContext dataStoreContext = DatastoreContext.newBuilder(). + logicalStoreType(LogicalDatastoreType.CONFIGURATION). shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build(); ActorContext actorContext = @@ -509,8 +483,10 @@ public class ActorContextTest extends AbstractActorTest{ TestActorRef shardManagerActorRef = TestActorRef.create(getSystem(), MockShardManager.props()); MockShardManager shardManagerActor = shardManagerActorRef.underlyingActor(); - shardManagerActor.addFindPrimaryResp("shard1", new RemotePrimaryShardFound(shardActorRef1.path().toString())); - shardManagerActor.addFindPrimaryResp("shard2", new RemotePrimaryShardFound(shardActorRef2.path().toString())); + shardManagerActor.addFindPrimaryResp("shard1", new RemotePrimaryShardFound(shardActorRef1.path().toString(), + DataStoreVersions.CURRENT_VERSION)); + shardManagerActor.addFindPrimaryResp("shard2", new RemotePrimaryShardFound(shardActorRef2.path().toString(), + DataStoreVersions.CURRENT_VERSION)); shardManagerActor.addFindPrimaryResp("shard3", new NoShardLeaderException("not found")); Configuration mockConfig = mock(Configuration.class); @@ -523,25 +499,9 @@ public class ActorContextTest extends AbstractActorTest{ actorContext.broadcast(new TestMessage()); - expectFirstMatching(shardActorRef1, TestMessage.class); - expectFirstMatching(shardActorRef2, TestMessage.class); + MessageCollectorActor.expectFirstMatching(shardActorRef1, TestMessage.class); + MessageCollectorActor.expectFirstMatching(shardActorRef2, TestMessage.class); }}; } - private T expectFirstMatching(ActorRef actor, Class clazz) { - int count = 5000 / 50; - for(int i = 0; i < count; i++) { - try { - T message = (T) MessageCollectorActor.getFirstMatching(actor, clazz); - if(message != null) { - return message; - } - } catch (Exception e) {} - - Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS); - } - - Assert.fail("Did not receive message of type " + clazz); - return null; - } }