1 package org.opendaylight.controller.cluster.datastore;
3 import akka.actor.ActorRef;
4 import akka.actor.Props;
6 import com.google.common.util.concurrent.ListenableFuture;
7 import com.google.common.util.concurrent.ListeningExecutorService;
8 import com.google.common.util.concurrent.MoreExecutors;
10 import junit.framework.Assert;
12 import org.junit.After;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.controller.cluster.datastore.messages.AbortTransactionReply;
16 import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransactionReply;
17 import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply;
18 import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransactionReply;
19 import org.opendaylight.controller.cluster.datastore.utils.MessageCollectorActor;
20 import org.opendaylight.controller.cluster.datastore.utils.MockActorContext;
22 import java.util.Arrays;
23 import java.util.concurrent.Executors;
25 import static org.junit.Assert.assertNotNull;
27 public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest {
29 private ThreePhaseCommitCohortProxy proxy;
31 private ActorRef actorRef;
32 private MockActorContext actorContext;
33 private final ListeningExecutorService executor = MoreExecutors.listeningDecorator(
34 Executors.newSingleThreadExecutor());
38 props = Props.create(MessageCollectorActor.class);
39 actorRef = getSystem().actorOf(props);
40 actorContext = new MockActorContext(this.getSystem());
43 new ThreePhaseCommitCohortProxy(actorContext,
44 Arrays.asList(actorRef.path()), "txn-1", executor);
49 public void tearDown() {
50 executor.shutdownNow();
54 public void testCanCommit() throws Exception {
55 actorContext.setExecuteRemoteOperationResponse(new CanCommitTransactionReply(true).toSerializable());
57 ListenableFuture<Boolean> future = proxy.canCommit();
59 Assert.assertTrue(future.get().booleanValue());
64 public void testPreCommit() throws Exception {
65 actorContext.setExecuteRemoteOperationResponse(new PreCommitTransactionReply().toSerializable());
67 ListenableFuture<Void> future = proxy.preCommit();
74 public void testAbort() throws Exception {
75 actorContext.setExecuteRemoteOperationResponse(new AbortTransactionReply().toSerializable());
77 ListenableFuture<Void> future = proxy.abort();
84 public void testCommit() throws Exception {
85 actorContext.setExecuteRemoteOperationResponse(new CommitTransactionReply().toSerializable());
87 ListenableFuture<Void> future = proxy.commit();
93 public void testGetCohortPaths() throws Exception {
94 assertNotNull(proxy.getCohortPaths());