import akka.actor.ActorRef;
import akka.actor.Props;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
+
import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.opendaylight.controller.cluster.datastore.messages.CloseTransaction;
import org.opendaylight.controller.cluster.datastore.messages.DeleteData;
import org.opendaylight.controller.cluster.datastore.messages.MergeData;
+import org.opendaylight.controller.cluster.datastore.messages.PrimaryFound;
import org.opendaylight.controller.cluster.datastore.messages.ReadDataReply;
import org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionReply;
import org.opendaylight.controller.cluster.datastore.messages.WriteData;
+import org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory;
import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor;
import org.opendaylight.controller.cluster.datastore.utils.MessageCollectorActor;
import org.opendaylight.controller.cluster.datastore.utils.MockActorContext;
+import org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper;
import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages.CreateTransactionReply;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import java.util.List;
-import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class TransactionProxyTest extends AbstractActorTest {
+ private final Configuration configuration = new MockConfiguration();
+
private final ActorContext testContext =
- new ActorContext(getSystem(), getSystem().actorOf(Props.create(DoNothingActor.class)), new MockConfiguration());
+ new ActorContext(getSystem(), getSystem().actorOf(Props.create(DoNothingActor.class)), new MockClusterWrapper(), configuration );
+
+ private final ListeningExecutorService transactionExecutor =
+ MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
- private ExecutorService transactionExecutor =
- Executors.newSingleThreadExecutor();
+ @Before
+ public void setUp(){
+ ShardStrategyFactory.setConfiguration(configuration);
+ }
+
+ @After
+ public void tearDown() {
+ transactionExecutor.shutdownNow();
+ }
@Test
public void testRead() throws Exception {
final ActorRef actorRef = getSystem().actorOf(props);
final MockActorContext actorContext = new MockActorContext(this.getSystem());
+ actorContext.setExecuteLocalOperationResponse(createPrimaryFound(actorRef));
actorContext.setExecuteShardOperationResponse(createTransactionReply(actorRef));
actorContext.setExecuteRemoteOperationResponse("message");
final ActorRef actorRef = getSystem().actorOf(props);
final MockActorContext actorContext = new MockActorContext(this.getSystem());
+ actorContext.setExecuteLocalOperationResponse(createPrimaryFound(actorRef));
actorContext.setExecuteShardOperationResponse(createTransactionReply(actorRef));
actorContext.setExecuteRemoteOperationResponse("message");
final ActorRef actorRef = getSystem().actorOf(props);
final MockActorContext actorContext = new MockActorContext(this.getSystem());
+ actorContext.setExecuteLocalOperationResponse(createPrimaryFound(actorRef));
actorContext.setExecuteShardOperationResponse(createTransactionReply(actorRef));
actorContext.setExecuteRemoteOperationResponse("message");
Assert.assertEquals(WriteData.SERIALIZABLE_CLASS, listMessages.get(0).getClass());
}
+ private Object createPrimaryFound(ActorRef actorRef) {
+ return new PrimaryFound(actorRef.path().toString()).toSerializable();
+ }
+
@Test
public void testMerge() throws Exception {
final Props props = Props.create(MessageCollectorActor.class);
final ActorRef actorRef = getSystem().actorOf(props);
final MockActorContext actorContext = new MockActorContext(this.getSystem());
+ actorContext.setExecuteLocalOperationResponse(createPrimaryFound(actorRef));
actorContext.setExecuteShardOperationResponse(createTransactionReply(actorRef));
actorContext.setExecuteRemoteOperationResponse("message");
final ActorRef actorRef = getSystem().actorOf(props);
final MockActorContext actorContext = new MockActorContext(this.getSystem());
+ actorContext.setExecuteLocalOperationResponse(createPrimaryFound(actorRef));
actorContext.setExecuteShardOperationResponse(createTransactionReply(actorRef));
actorContext.setExecuteRemoteOperationResponse("message");
final ActorRef doNothingActorRef = getSystem().actorOf(props);
final MockActorContext actorContext = new MockActorContext(this.getSystem());
+ actorContext.setExecuteLocalOperationResponse(createPrimaryFound(doNothingActorRef));
actorContext.setExecuteShardOperationResponse(createTransactionReply(doNothingActorRef));
- actorContext.setExecuteRemoteOperationResponse(new ReadyTransactionReply(doNothingActorRef.path()));
+ actorContext.setExecuteRemoteOperationResponse(new ReadyTransactionReply(doNothingActorRef.path()).toSerializable());
TransactionProxy transactionProxy =
new TransactionProxy(actorContext,
final ActorRef actorRef = getSystem().actorOf(props);
final MockActorContext actorContext = new MockActorContext(this.getSystem());
+ actorContext.setExecuteLocalOperationResponse(createPrimaryFound(actorRef));
actorContext.setExecuteShardOperationResponse(createTransactionReply(actorRef));
actorContext.setExecuteRemoteOperationResponse("message");
Assert.assertEquals(1, listMessages.size());
- Assert.assertTrue(listMessages.get(0) instanceof CloseTransaction);
+ Assert.assertTrue(listMessages.get(0).getClass().equals(CloseTransaction.SERIALIZABLE_CLASS));
}
private CreateTransactionReply createTransactionReply(ActorRef actorRef){