From: Moiz Raja Date: Thu, 16 Oct 2014 17:03:23 +0000 (+0000) Subject: Merge "Bug-1607: Clustering : Remove actorFor (deprecated) call from TransactionProx... X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=3c2de556e2b813b8da925199cb2dc4389c76ef39;hp=1b8f7c7beaed83797320686bebddd536637aed9a;p=controller.git Merge "Bug-1607: Clustering : Remove actorFor (deprecated) call from TransactionProxy.java" --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java index f5ca6e3c5a..b16ec0ac9f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransaction.java @@ -13,12 +13,10 @@ import akka.actor.PoisonPill; import akka.actor.Props; import akka.actor.ReceiveTimeout; import akka.japi.Creator; - +import akka.serialization.Serialization; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor; - - import org.opendaylight.controller.cluster.datastore.exceptions.UnknownMessageException; import org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard.ShardStats; import org.opendaylight.controller.cluster.datastore.messages.CloseTransaction; @@ -207,8 +205,8 @@ public abstract class ShardTransaction extends AbstractUntypedActor { DOMStoreThreePhaseCommitCohort cohort = transaction.ready(); ActorRef cohortActor = getContext().actorOf( ThreePhaseCommitCohort.props(cohort, shardActor, modification, shardStats), "cohort"); - getSender() - .tell(new ReadyTransactionReply(cohortActor.path()).toSerializable(), getSelf()); + getSender().tell(new ReadyTransactionReply( + Serialization.serializedActorPath(cohortActor)).toSerializable(), getSelf()); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java index 515be372e8..6e7669695e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java @@ -8,16 +8,13 @@ package org.opendaylight.controller.cluster.datastore; -import akka.actor.ActorPath; import akka.actor.ActorSelection; import akka.dispatch.Futures; import akka.dispatch.OnComplete; - import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; - import org.opendaylight.controller.cluster.datastore.messages.AbortTransaction; import org.opendaylight.controller.cluster.datastore.messages.AbortTransactionReply; import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransaction; @@ -30,7 +27,6 @@ import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import scala.concurrent.Future; import scala.runtime.AbstractFunction1; @@ -45,29 +41,29 @@ public class ThreePhaseCommitCohortProxy implements DOMStoreThreePhaseCommitCoho private static final Logger LOG = LoggerFactory.getLogger(ThreePhaseCommitCohortProxy.class); private final ActorContext actorContext; - private final List> cohortPathFutures; - private volatile List cohortPaths; + private final List> cohortFutures; + private volatile List cohorts; private final String transactionId; public ThreePhaseCommitCohortProxy(ActorContext actorContext, - List> cohortPathFutures, String transactionId) { + List> cohortFutures, String transactionId) { this.actorContext = actorContext; - this.cohortPathFutures = cohortPathFutures; + this.cohortFutures = cohortFutures; this.transactionId = transactionId; } - private Future buildCohortPathsList() { + private Future buildCohortList() { - Future> combinedFutures = Futures.sequence(cohortPathFutures, + Future> combinedFutures = Futures.sequence(cohortFutures, actorContext.getActorSystem().dispatcher()); - return combinedFutures.transform(new AbstractFunction1, Void>() { + return combinedFutures.transform(new AbstractFunction1, Void>() { @Override - public Void apply(Iterable paths) { - cohortPaths = Lists.newArrayList(paths); + public Void apply(Iterable actorSelections) { + cohorts = Lists.newArrayList(actorSelections); if(LOG.isDebugEnabled()) { LOG.debug("Tx {} successfully built cohort path list: {}", - transactionId, cohortPaths); + transactionId, cohorts); } return null; } @@ -87,12 +83,12 @@ public class ThreePhaseCommitCohortProxy implements DOMStoreThreePhaseCommitCoho // extracted from ReadyTransactionReply messages by the Futures that were obtained earlier // and passed to us from upstream processing. If any one fails then we'll fail canCommit. - buildCohortPathsList().onComplete(new OnComplete() { + buildCohortList().onComplete(new OnComplete() { @Override public void onComplete(Throwable failure, Void notUsed) throws Throwable { if(failure != null) { if(LOG.isDebugEnabled()) { - LOG.debug("Tx {}: a cohort path Future failed: {}", transactionId, failure); + LOG.debug("Tx {}: a cohort Future failed: {}", transactionId, failure); } returnFuture.setException(failure); } else { @@ -150,12 +146,11 @@ public class ThreePhaseCommitCohortProxy implements DOMStoreThreePhaseCommitCoho } private Future> invokeCohorts(Object message) { - List> futureList = Lists.newArrayListWithCapacity(cohortPaths.size()); - for(ActorPath actorPath : cohortPaths) { + List> futureList = Lists.newArrayListWithCapacity(cohorts.size()); + for(ActorSelection cohort : cohorts) { if(LOG.isDebugEnabled()) { - LOG.debug("Tx {}: Sending {} to cohort {}", transactionId, message, actorPath); + LOG.debug("Tx {}: Sending {} to cohort {}", transactionId, message, cohort); } - ActorSelection cohort = actorContext.actorSelection(actorPath); futureList.add(actorContext.executeOperationAsync(cohort, message)); } @@ -198,11 +193,11 @@ public class ThreePhaseCommitCohortProxy implements DOMStoreThreePhaseCommitCoho // The cohort actor list should already be built at this point by the canCommit phase but, // if not for some reason, we'll try to build it here. - if(cohortPaths != null) { + if(cohorts != null) { finishVoidOperation(operationName, message, expectedResponseClass, propagateException, returnFuture); } else { - buildCohortPathsList().onComplete(new OnComplete() { + buildCohortList().onComplete(new OnComplete() { @Override public void onComplete(Throwable failure, Void notUsed) throws Throwable { if(failure != null) { @@ -280,7 +275,7 @@ public class ThreePhaseCommitCohortProxy implements DOMStoreThreePhaseCommitCoho } @VisibleForTesting - List> getCohortPathFutures() { - return Collections.unmodifiableList(cohortPathFutures); + List> getCohortFutures() { + return Collections.unmodifiableList(cohortFutures); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java index b74c89d727..b467ee4ddb 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.cluster.datastore; -import akka.actor.ActorPath; +import akka.actor.ActorSelection; import akka.dispatch.Futures; import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; @@ -28,7 +28,7 @@ import java.util.List; public class TransactionChainProxy implements DOMStoreTransactionChain{ private final ActorContext actorContext; private final String transactionChainId; - private volatile List> cohortPathFutures = Collections.emptyList(); + private volatile List> cohortFutures = Collections.emptyList(); public TransactionChainProxy(ActorContext actorContext) { this.actorContext = actorContext; @@ -63,14 +63,14 @@ public class TransactionChainProxy implements DOMStoreTransactionChain{ return transactionChainId; } - public void onTransactionReady(List> cohortPathFutures){ - this.cohortPathFutures = cohortPathFutures; + public void onTransactionReady(List> cohortFutures){ + this.cohortFutures = cohortFutures; } public void waitTillCurrentTransactionReady(){ try { Await.result(Futures - .sequence(this.cohortPathFutures, actorContext.getActorSystem().dispatcher()), + .sequence(this.cohortFutures, actorContext.getActorSystem().dispatcher()), actorContext.getOperationDuration()); } catch (Exception e) { throw new IllegalStateException("Failed when waiting for transaction on a chain to become ready", e); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java index 19d9a66a52..ec198510d3 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.cluster.datastore; -import akka.actor.ActorPath; import akka.actor.ActorSelection; import akka.dispatch.OnComplete; @@ -315,7 +314,7 @@ public class TransactionProxy implements DOMStoreReadWriteTransaction { LOG.debug("Tx {} Trying to get {} transactions ready for commit", identifier, remoteTransactionPaths.size()); } - List> cohortPathFutures = Lists.newArrayList(); + List> cohortFutures = Lists.newArrayList(); for(TransactionContext transactionContext : remoteTransactionPaths.values()) { @@ -323,14 +322,14 @@ public class TransactionProxy implements DOMStoreReadWriteTransaction { LOG.debug("Tx {} Readying transaction for shard {}", identifier, transactionContext.getShardName()); } - cohortPathFutures.add(transactionContext.readyTransaction()); + cohortFutures.add(transactionContext.readyTransaction()); } if(transactionChainProxy != null){ - transactionChainProxy.onTransactionReady(cohortPathFutures); + transactionChainProxy.onTransactionReady(cohortFutures); } - return new ThreePhaseCommitCohortProxy(actorContext, cohortPathFutures, + return new ThreePhaseCommitCohortProxy(actorContext, cohortFutures, identifier.toString()); } @@ -439,7 +438,7 @@ public class TransactionProxy implements DOMStoreReadWriteTransaction { void closeTransaction(); - Future readyTransaction(); + Future readyTransaction(); void writeData(YangInstanceIdentifier path, NormalizedNode data); @@ -499,10 +498,6 @@ public class TransactionProxy implements DOMStoreReadWriteTransaction { return actor; } - private String getResolvedCohortPath(String cohortPath) { - return actorContext.resolvePath(actorPath, cohortPath); - } - @Override public void closeTransaction() { if(LOG.isDebugEnabled()) { @@ -512,7 +507,7 @@ public class TransactionProxy implements DOMStoreReadWriteTransaction { } @Override - public Future readyTransaction() { + public Future readyTransaction() { if(LOG.isDebugEnabled()) { LOG.debug("Tx {} readyTransaction called with {} previous recorded operations pending", identifier, recordedOperationFutures.size()); @@ -538,9 +533,9 @@ public class TransactionProxy implements DOMStoreReadWriteTransaction { // Transform the combined Future into a Future that returns the cohort actor path from // the ReadyTransactionReply. That's the end result of the ready operation. - return combinedFutures.transform(new AbstractFunction1, ActorPath>() { + return combinedFutures.transform(new AbstractFunction1, ActorSelection>() { @Override - public ActorPath apply(Iterable notUsed) { + public ActorSelection apply(Iterable notUsed) { if(LOG.isDebugEnabled()) { LOG.debug("Tx {} readyTransaction: pending recorded operations succeeded", identifier); @@ -557,16 +552,9 @@ public class TransactionProxy implements DOMStoreReadWriteTransaction { if(serializedReadyReply.getClass().equals( ReadyTransactionReply.SERIALIZABLE_CLASS)) { ReadyTransactionReply reply = ReadyTransactionReply.fromSerializable( - actorContext.getActorSystem(), serializedReadyReply); - - String resolvedCohortPath = getResolvedCohortPath( - reply.getCohortPath().toString()); + serializedReadyReply); - if(LOG.isDebugEnabled()) { - LOG.debug("Tx {} readyTransaction: resolved cohort path {}", - identifier, resolvedCohortPath); - } - return actorContext.actorFor(resolvedCohortPath); + return actorContext.actorSelection(reply.getCohortPath()); } else { // Throwing an exception here will fail the Future. @@ -805,7 +793,7 @@ public class TransactionProxy implements DOMStoreReadWriteTransaction { } @Override - public Future readyTransaction() { + public Future readyTransaction() { if(LOG.isDebugEnabled()) { LOG.debug("Tx {} readyTransaction called", identifier); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ReadyTransactionReply.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ReadyTransactionReply.java index 5273dc2479..59dd6db06e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ReadyTransactionReply.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/ReadyTransactionReply.java @@ -8,32 +8,32 @@ package org.opendaylight.controller.cluster.datastore.messages; -import akka.actor.ActorPath; -import akka.actor.ActorSystem; import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages; public class ReadyTransactionReply implements SerializableMessage { public static final Class SERIALIZABLE_CLASS = ShardTransactionMessages.ReadyTransactionReply.class; - private final ActorPath cohortPath; + private final String cohortPath; - public ReadyTransactionReply(ActorPath cohortPath) { + public ReadyTransactionReply(String cohortPath) { this.cohortPath = cohortPath; } - public ActorPath getCohortPath() { + public String getCohortPath() { return cohortPath; } @Override public ShardTransactionMessages.ReadyTransactionReply toSerializable() { return ShardTransactionMessages.ReadyTransactionReply.newBuilder() - .setActorPath(cohortPath.toString()).build(); + .setActorPath(cohortPath).build(); } - public static ReadyTransactionReply fromSerializable(ActorSystem actorSystem,Object serializable){ - ShardTransactionMessages.ReadyTransactionReply o = (ShardTransactionMessages.ReadyTransactionReply) serializable; - return new ReadyTransactionReply( - actorSystem.actorFor(o.getActorPath()).path()); + public static ReadyTransactionReply fromSerializable(Object serializable) { + ShardTransactionMessages.ReadyTransactionReply o = + (ShardTransactionMessages.ReadyTransactionReply) serializable; + + return new ReadyTransactionReply(o.getActorPath()); + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java index 44f4ef77d7..d8af09c86b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/ActorContext.java @@ -237,34 +237,6 @@ public class ActorContext { actorSystem.shutdown(); } - /** - * @deprecated Need to stop using this method. There are ways to send a - * remote ActorRef as a string which should be used instead of this hack - * - * @param primaryPath - * @param localPathOfRemoteActor - * @return - */ - @Deprecated - public String resolvePath(final String primaryPath, - final String localPathOfRemoteActor) { - StringBuilder builder = new StringBuilder(); - String[] primaryPathElements = primaryPath.split("/"); - builder.append(primaryPathElements[0]).append("//") - .append(primaryPathElements[1]).append(primaryPathElements[2]); - String[] remotePathElements = localPathOfRemoteActor.split("/"); - for (int i = 3; i < remotePathElements.length; i++) { - builder.append("/").append(remotePathElements[i]); - } - - return builder.toString(); - - } - - public ActorPath actorFor(String path){ - return actorSystem.actorFor(path).path(); - } - public String getCurrentMemberName(){ return clusterWrapper.getCurrentMemberName(); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/BasicIntegrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/BasicIntegrationTest.java index 7b826302f5..a718ca7e4c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/BasicIntegrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/BasicIntegrationTest.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.cluster.datastore; -import akka.actor.ActorPath; import akka.actor.ActorRef; import akka.actor.ActorSelection; import akka.actor.Props; @@ -134,11 +133,10 @@ public class BasicIntegrationTest extends AbstractActorTest { @Override protected ActorSelection match(Object in) { if (in.getClass().equals(ReadyTransactionReply.SERIALIZABLE_CLASS)) { - ActorPath cohortPath = - ReadyTransactionReply.fromSerializable(getSystem(),in) + String cohortPath = + ReadyTransactionReply.fromSerializable(in) .getCohortPath(); - return getSystem() - .actorSelection(cohortPath); + return getSystem().actorSelection(cohortPath); } else { throw noMatch(); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java index 3c9d857fe8..b7ac371812 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java @@ -4,19 +4,8 @@ import akka.actor.ActorPath; import akka.actor.ActorSelection; import akka.actor.Props; import akka.dispatch.Futures; - import com.google.common.collect.Lists; import com.google.common.util.concurrent.ListenableFuture; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.times; - import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -33,13 +22,20 @@ import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransacti import org.opendaylight.controller.cluster.datastore.messages.SerializableMessage; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor; - import scala.concurrent.Future; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.isA; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { @SuppressWarnings("serial") @@ -56,28 +52,28 @@ public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest { doReturn(getSystem()).when(actorContext).getActorSystem(); } - private Future newCohortPath() { + private Future newCohort() { ActorPath path = getSystem().actorOf(Props.create(DoNothingActor.class)).path(); - doReturn(mock(ActorSelection.class)).when(actorContext).actorSelection(path); - return Futures.successful(path); + ActorSelection actorSelection = getSystem().actorSelection(path); + return Futures.successful(actorSelection); } private final ThreePhaseCommitCohortProxy setupProxy(int nCohorts) throws Exception { - List> cohortPathFutures = Lists.newArrayList(); + List> cohortFutures = Lists.newArrayList(); for(int i = 1; i <= nCohorts; i++) { - cohortPathFutures.add(newCohortPath()); + cohortFutures.add(newCohort()); } - return new ThreePhaseCommitCohortProxy(actorContext, cohortPathFutures, "txn-1"); + return new ThreePhaseCommitCohortProxy(actorContext, cohortFutures, "txn-1"); } private ThreePhaseCommitCohortProxy setupProxyWithFailedCohortPath() throws Exception { - List> cohortPathFutures = Lists.newArrayList(); - cohortPathFutures.add(newCohortPath()); - cohortPathFutures.add(Futures.failed(new TestException())); + List> cohortFutures = Lists.newArrayList(); + cohortFutures.add(newCohort()); + cohortFutures.add(Futures.failed(new TestException())); - return new ThreePhaseCommitCohortProxy(actorContext, cohortPathFutures, "txn-1"); + return new ThreePhaseCommitCohortProxy(actorContext, cohortFutures, "txn-1"); } private void setupMockActorContext(Class requestType, Object... responses) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java index bdcca42d15..592337f93f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java @@ -1,12 +1,12 @@ package org.opendaylight.controller.cluster.datastore; -import akka.actor.ActorPath; +import com.google.common.util.concurrent.CheckedFuture; + import akka.actor.ActorRef; import akka.actor.ActorSelection; import akka.actor.Props; import akka.dispatch.Futures; import com.google.common.base.Optional; -import com.google.common.util.concurrent.CheckedFuture; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatcher; @@ -182,7 +182,7 @@ public class TransactionProxyTest extends AbstractActorTest { return argThat(matcher); } - private Future readyTxReply(ActorPath path) { + private Future readyTxReply(String path) { return Futures.successful((Object)new ReadyTransactionReply(path).toSerializable()); } @@ -227,12 +227,6 @@ public class TransactionProxyTest extends AbstractActorTest { doReturn(createTransactionReply(actorRef)).when(mockActorContext). executeOperation(eq(getSystem().actorSelection(actorRef.path())), eqCreateTransaction(memberName, type)); - - doReturn(actorRef.path().toString()).when(mockActorContext).resolvePath( - anyString(), eq(actorRef.path().toString())); - - doReturn(actorRef.path()).when(mockActorContext).actorFor(actorRef.path().toString()); - return actorRef; } @@ -631,19 +625,19 @@ public class TransactionProxyTest extends AbstractActorTest { DeleteDataReply.SERIALIZABLE_CLASS); } - private void verifyCohortPathFutures(ThreePhaseCommitCohortProxy proxy, - Object... expReplies) throws Exception { + private void verifyCohortFutures(ThreePhaseCommitCohortProxy proxy, + Object... expReplies) throws Exception { assertEquals("getReadyOperationFutures size", expReplies.length, - proxy.getCohortPathFutures().size()); + proxy.getCohortFutures().size()); int i = 0; - for( Future future: proxy.getCohortPathFutures()) { + for( Future future: proxy.getCohortFutures()) { assertNotNull("Ready operation Future is null", future); Object expReply = expReplies[i++]; - if(expReply instanceof ActorPath) { - ActorPath actual = Await.result(future, Duration.create(5, TimeUnit.SECONDS)); - assertEquals("Cohort actor path", expReply, actual); + if(expReply instanceof ActorSelection) { + ActorSelection actual = Await.result(future, Duration.create(5, TimeUnit.SECONDS)); + assertEquals("Cohort actor path", (ActorSelection) expReply, actual); } else { // Expecting exception. try { @@ -669,7 +663,7 @@ public class TransactionProxyTest extends AbstractActorTest { doReturn(writeDataReply()).when(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef)), eqWriteData(nodeToWrite)); - doReturn(readyTxReply(actorRef.path())).when(mockActorContext).executeOperationAsync( + doReturn(readyTxReply(actorRef.path().toString())).when(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef)), isA(ReadyTransaction.SERIALIZABLE_CLASS)); TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, @@ -688,7 +682,7 @@ public class TransactionProxyTest extends AbstractActorTest { verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(), WriteDataReply.SERIALIZABLE_CLASS); - verifyCohortPathFutures(proxy, actorRef.path()); + verifyCohortFutures(proxy, getSystem().actorSelection(actorRef.path())); } @SuppressWarnings("unchecked") @@ -704,7 +698,7 @@ public class TransactionProxyTest extends AbstractActorTest { doReturn(Futures.failed(new TestException())).when(mockActorContext). executeOperationAsync(eq(actorSelection(actorRef)), eqWriteData(nodeToWrite)); - doReturn(readyTxReply(actorRef.path())).when(mockActorContext).executeOperationAsync( + doReturn(readyTxReply(actorRef.path().toString())).when(mockActorContext).executeOperationAsync( eq(actorSelection(actorRef)), isA(ReadyTransaction.SERIALIZABLE_CLASS)); TransactionProxy transactionProxy = new TransactionProxy(mockActorContext, @@ -723,7 +717,7 @@ public class TransactionProxyTest extends AbstractActorTest { verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(), MergeDataReply.SERIALIZABLE_CLASS, TestException.class); - verifyCohortPathFutures(proxy, TestException.class); + verifyCohortFutures(proxy, TestException.class); } @SuppressWarnings("unchecked") @@ -754,7 +748,7 @@ public class TransactionProxyTest extends AbstractActorTest { verifyRecordingOperationFutures(transactionProxy.getRecordedOperationFutures(), MergeDataReply.SERIALIZABLE_CLASS); - verifyCohortPathFutures(proxy, TestException.class); + verifyCohortFutures(proxy, TestException.class); } @Test @@ -781,7 +775,7 @@ public class TransactionProxyTest extends AbstractActorTest { ThreePhaseCommitCohortProxy proxy = (ThreePhaseCommitCohortProxy) ready; - verifyCohortPathFutures(proxy, PrimaryNotFoundException.class); + verifyCohortFutures(proxy, PrimaryNotFoundException.class); } @SuppressWarnings("unchecked") @@ -809,7 +803,7 @@ public class TransactionProxyTest extends AbstractActorTest { ThreePhaseCommitCohortProxy proxy = (ThreePhaseCommitCohortProxy) ready; - verifyCohortPathFutures(proxy, IllegalArgumentException.class); + verifyCohortFutures(proxy, IllegalArgumentException.class); } @Test 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 fa6d0b060f..8426b03a37 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 @@ -2,12 +2,12 @@ package org.opendaylight.controller.cluster.datastore.utils; import akka.actor.ActorRef; import akka.actor.ActorSelection; -import akka.actor.ActorSystem; import akka.actor.Props; import akka.actor.UntypedActor; import akka.japi.Creator; import akka.testkit.JavaTestKit; import com.google.common.base.Optional; + import org.junit.Test; import org.opendaylight.controller.cluster.datastore.AbstractActorTest; import org.opendaylight.controller.cluster.datastore.ClusterWrapper; @@ -26,40 +26,6 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; public class ActorContextTest extends AbstractActorTest{ - @Test - public void testResolvePathForRemoteActor(){ - ActorContext actorContext = - new ActorContext(mock(ActorSystem.class), 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); - - System.out.println(actorContext - .actorFor("akka://system/user/shardmanager/shard/transaction")); - } - private static class MockShardManager extends UntypedActor {