BUG 932 - Swagger HTTP POST contains incorrect object
[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
6 import com.google.common.util.concurrent.ListenableFuture;
7 import com.google.common.util.concurrent.ListeningExecutorService;
8 import com.google.common.util.concurrent.MoreExecutors;
9
10 import junit.framework.Assert;
11
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;
21
22 import java.util.Arrays;
23 import java.util.concurrent.Executors;
24
25 import static org.junit.Assert.assertNotNull;
26
27 public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest {
28
29     private ThreePhaseCommitCohortProxy proxy;
30     private Props props;
31     private ActorRef actorRef;
32     private MockActorContext actorContext;
33     private final ListeningExecutorService executor = MoreExecutors.listeningDecorator(
34                         Executors.newSingleThreadExecutor());
35
36     @Before
37     public void setUp(){
38         props = Props.create(MessageCollectorActor.class);
39         actorRef = getSystem().actorOf(props);
40         actorContext = new MockActorContext(this.getSystem());
41
42         proxy =
43             new ThreePhaseCommitCohortProxy(actorContext,
44                 Arrays.asList(actorRef.path()), "txn-1", executor);
45
46     }
47
48     @After
49     public void tearDown() {
50         executor.shutdownNow();
51     }
52
53     @Test
54     public void testCanCommit() throws Exception {
55         actorContext.setExecuteRemoteOperationResponse(new CanCommitTransactionReply(true).toSerializable());
56
57         ListenableFuture<Boolean> future = proxy.canCommit();
58
59         Assert.assertTrue(future.get().booleanValue());
60
61     }
62
63     @Test
64     public void testPreCommit() throws Exception {
65         actorContext.setExecuteRemoteOperationResponse(new PreCommitTransactionReply().toSerializable());
66
67         ListenableFuture<Void> future = proxy.preCommit();
68
69         future.get();
70
71     }
72
73     @Test
74     public void testAbort() throws Exception {
75         actorContext.setExecuteRemoteOperationResponse(new AbortTransactionReply().toSerializable());
76
77         ListenableFuture<Void> future = proxy.abort();
78
79         future.get();
80
81     }
82
83     @Test
84     public void testCommit() throws Exception {
85         actorContext.setExecuteRemoteOperationResponse(new CommitTransactionReply().toSerializable());
86
87         ListenableFuture<Void> future = proxy.commit();
88
89         future.get();
90     }
91
92     @Test
93     public void testGetCohortPaths() throws Exception {
94         assertNotNull(proxy.getCohortPaths());
95     }
96 }