2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.datastore;
11 import akka.actor.ActorPath;
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSelection;
14 import akka.actor.Props;
15 import akka.testkit.JavaTestKit;
16 import junit.framework.Assert;
17 import org.junit.Test;
18 import org.opendaylight.controller.cluster.datastore.messages.CommitTransaction;
19 import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply;
20 import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
21 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChain;
22 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChainReply;
23 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
24 import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransaction;
25 import org.opendaylight.controller.cluster.datastore.messages.PreCommitTransactionReply;
26 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransaction;
27 import org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionReply;
28 import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
29 import org.opendaylight.controller.cluster.datastore.messages.WriteData;
30 import org.opendaylight.controller.cluster.datastore.messages.WriteDataReply;
31 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
32 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
34 public class BasicIntegrationTest extends AbstractActorTest {
37 public void integrationTest() {
40 // - initiate a transaction
42 // - read the transaction for commit
43 // - commit the transaction
46 new JavaTestKit(getSystem()) {{
47 final Props props = Shard.props("config");
48 final ActorRef shard = getSystem().actorOf(props);
50 new Within(duration("5 seconds")) {
51 protected void run() {
54 new UpdateSchemaContext(TestModel.createTestContext()),
57 shard.tell(new CreateTransactionChain(), getRef());
59 final ActorSelection transactionChain =
60 new ExpectMsg<ActorSelection>("match hint") {
61 protected ActorSelection match(Object in) {
62 if (in instanceof CreateTransactionChainReply) {
63 ActorPath transactionChainPath =
64 ((CreateTransactionChainReply) in)
65 .getTransactionChainPath();
67 .actorSelection(transactionChainPath);
72 }.get(); // this extracts the received message
74 Assert.assertNotNull(transactionChain);
76 transactionChain.tell(new CreateTransaction(), getRef());
78 final ActorSelection transaction =
79 new ExpectMsg<ActorSelection>("match hint") {
80 protected ActorSelection match(Object in) {
81 if (in instanceof CreateTransactionReply) {
82 ActorPath transactionPath =
83 ((CreateTransactionReply) in)
84 .getTransactionPath();
86 .actorSelection(transactionPath);
91 }.get(); // this extracts the received message
93 Assert.assertNotNull(transaction);
95 transaction.tell(new WriteData(TestModel.TEST_PATH,
96 ImmutableNodes.containerNode(TestModel.TEST_QNAME)),
99 Boolean writeDone = new ExpectMsg<Boolean>("match hint") {
100 protected Boolean match(Object in) {
101 if (in instanceof WriteDataReply) {
107 }.get(); // this extracts the received message
109 Assert.assertTrue(writeDone);
111 transaction.tell(new ReadyTransaction(), getRef());
113 final ActorSelection cohort =
114 new ExpectMsg<ActorSelection>("match hint") {
115 protected ActorSelection match(Object in) {
116 if (in instanceof ReadyTransactionReply) {
117 ActorPath cohortPath =
118 ((ReadyTransactionReply) in)
121 .actorSelection(cohortPath);
126 }.get(); // this extracts the received message
128 Assert.assertNotNull(cohort);
130 cohort.tell(new PreCommitTransaction(), getRef());
132 Boolean preCommitDone =
133 new ExpectMsg<Boolean>("match hint") {
134 protected Boolean match(Object in) {
135 if (in instanceof PreCommitTransactionReply) {
141 }.get(); // this extracts the received message
143 Assert.assertTrue(preCommitDone);
145 cohort.tell(new CommitTransaction(), getRef());
147 final Boolean commitDone =
148 new ExpectMsg<Boolean>("match hint") {
149 protected Boolean match(Object in) {
150 if (in instanceof CommitTransactionReply) {
156 }.get(); // this extracts the received message
158 Assert.assertTrue(commitDone);