Enhancements to actor naming, logging and monitoring
[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 import java.util.concurrent.ExecutorService;
18 import java.util.concurrent.Executors;
19
20 import static org.junit.Assert.assertNotNull;
21
22 public class ThreePhaseCommitCohortProxyTest extends AbstractActorTest {
23
24     private ThreePhaseCommitCohortProxy proxy;
25     private Props props;
26     private ActorRef actorRef;
27     private MockActorContext actorContext;
28     private ExecutorService executor = Executors.newSingleThreadExecutor();
29
30     @Before
31     public void setUp(){
32         props = Props.create(MessageCollectorActor.class);
33         actorRef = getSystem().actorOf(props);
34         actorContext = new MockActorContext(this.getSystem());
35
36         proxy =
37             new ThreePhaseCommitCohortProxy(actorContext,
38                 Arrays.asList(actorRef.path()), "txn-1", executor);
39
40     }
41
42     @Test
43     public void testCanCommit() throws Exception {
44         actorContext.setExecuteRemoteOperationResponse(new CanCommitTransactionReply(true));
45
46         ListenableFuture<Boolean> future = proxy.canCommit();
47
48         Assert.assertTrue(future.get().booleanValue());
49
50     }
51
52     @Test
53     public void testPreCommit() throws Exception {
54         actorContext.setExecuteRemoteOperationResponse(new PreCommitTransactionReply());
55
56         ListenableFuture<Void> future = proxy.preCommit();
57
58         future.get();
59
60     }
61
62     @Test
63     public void testAbort() throws Exception {
64         actorContext.setExecuteRemoteOperationResponse(new AbortTransactionReply());
65
66         ListenableFuture<Void> future = proxy.abort();
67
68         future.get();
69
70     }
71
72     @Test
73     public void testCommit() throws Exception {
74         actorContext.setExecuteRemoteOperationResponse(new CommitTransactionReply());
75
76         ListenableFuture<Void> future = proxy.commit();
77
78         future.get();
79     }
80
81     @Test
82     public void testGetCohortPaths() throws Exception {
83         assertNotNull(proxy.getCohortPaths());
84     }
85 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.