1 package org.opendaylight.controller.cluster.datastore;
3 import akka.actor.ActorRef;
4 import akka.actor.Props;
5 import com.google.common.util.concurrent.ListenableFuture;
6 import junit.framework.Assert;
7 import org.junit.Before;
9 import org.opendaylight.controller.cluster.datastore.messages.AbortTransactionReply;
10 import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply;
11 import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply;
12 import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransactionReply;
13 import org.opendaylight.controller.cluster.datastore.utils.MessageCollectorActor;
14 import org.opendaylight.controller.cluster.datastore.utils.MockActorContext;
16 import java.util.Arrays;
17 import java.util.concurrent.ExecutorService;
18 import java.util.concurrent.Executors;
20 import static org.junit.Assert.assertNotNull;
22 public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest {
24 private ThreePhaseCommitCohortProxy proxy;
26 private ActorRef actorRef;
27 private MockActorContext actorContext;
28 private ExecutorService executor = Executors.newSingleThreadExecutor();
32 props = Props.create(MessageCollectorActor.class);
33 actorRef = getSystem().actorOf(props);
34 actorContext = new MockActorContext(this.getSystem());
37 new ThreePhaseCommitCohortProxy(actorContext,
38 Arrays.asList(actorRef.path()), "txn-1", executor);
43 public void testCanCommit() throws Exception {
44 actorContext.setExecuteRemoteOperationResponse(new CanCommitTransactionReply(true));
46 ListenableFuture<Boolean> future = proxy.canCommit();
48 Assert.assertTrue(future.get().booleanValue());
53 public void testPreCommit() throws Exception {
54 actorContext.setExecuteRemoteOperationResponse(new PreCommitTransactionReply());
56 ListenableFuture<Void> future = proxy.preCommit();
63 public void testAbort() throws Exception {
64 actorContext.setExecuteRemoteOperationResponse(new AbortTransactionReply());
66 ListenableFuture<Void> future = proxy.abort();
73 public void testCommit() throws Exception {
74 actorContext.setExecuteRemoteOperationResponse(new CommitTransactionReply());
76 ListenableFuture<Void> future = proxy.commit();
82 public void testGetCohortPaths() throws Exception {
83 assertNotNull(proxy.getCohortPaths());