Merge "Bug 1306: Fixed incorrect AD/MD-SAL flow conversion."
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / ThreePhaseCommitCohortProxyTest.java
1 package org.opendaylight.controller.cluster.datastore;
2
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;
8 import org.junit.Test;
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;
15
16 import java.util.Arrays;
17
18 import static org.junit.Assert.assertNotNull;
19
20 public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest {
21
22     private ThreePhaseCommitCohortProxy proxy;
23     private Props props;
24     private ActorRef actorRef;
25     private MockActorContext actorContext;
26
27     @Before
28     public void setUp(){
29         props = Props.create(MessageCollectorActor.class);
30         actorRef = getSystem().actorOf(props);
31         actorContext = new MockActorContext(this.getSystem());
32
33         proxy =
34             new ThreePhaseCommitCohortProxy(actorContext,
35                 Arrays.asList(actorRef.path()));
36
37     }
38
39     @Test
40     public void testCanCommit() throws Exception {
41         actorContext.setExecuteRemoteOperationResponse(new CanCommitTransactionReply(true));
42
43         ListenableFuture<Boolean> future = proxy.canCommit();
44
45         Assert.assertTrue(future.get().booleanValue());
46
47     }
48
49     @Test
50     public void testPreCommit() throws Exception {
51         actorContext.setExecuteRemoteOperationResponse(new PreCommitTransactionReply());
52
53         ListenableFuture<Void> future = proxy.preCommit();
54
55         future.get();
56
57     }
58
59     @Test
60     public void testAbort() throws Exception {
61         actorContext.setExecuteRemoteOperationResponse(new AbortTransactionReply());
62
63         ListenableFuture<Void> future = proxy.abort();
64
65         future.get();
66
67     }
68
69     @Test
70     public void testCommit() throws Exception {
71         actorContext.setExecuteRemoteOperationResponse(new CommitTransactionReply());
72
73         ListenableFuture<Void> future = proxy.commit();
74
75         future.get();
76     }
77
78     @Test
79     public void testGetCohortPaths() throws Exception {
80         assertNotNull(proxy.getCohortPaths());
81     }
82 }