1 package org.opendaylight.controller.cluster.datastore;
3 import akka.actor.ActorRef;
4 import akka.actor.Props;
5 import akka.testkit.JavaTestKit;
7 import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
8 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChain;
9 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChainReply;
10 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
11 import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener;
12 import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListenerReply;
13 import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
14 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
18 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import static org.junit.Assert.assertTrue;
23 public class ShardTest extends AbstractActorTest {
25 public void testOnReceiveCreateTransactionChain() throws Exception {
26 new JavaTestKit(getSystem()) {{
27 final Props props = Shard.props("config");
28 final ActorRef subject =
29 getSystem().actorOf(props, "testCreateTransactionChain");
31 new Within(duration("1 seconds")) {
32 protected void run() {
34 subject.tell(new CreateTransactionChain(), getRef());
36 final String out = new ExpectMsg<String>("match hint") {
37 // do not put code outside this method, will run afterwards
38 protected String match(Object in) {
39 if (in instanceof CreateTransactionChainReply) {
40 CreateTransactionChainReply reply =
41 (CreateTransactionChainReply) in;
42 return reply.getTransactionChainPath()
48 }.get(); // this extracts the received message
50 assertTrue(out.matches(
51 "akka:\\/\\/test\\/user\\/testCreateTransactionChain\\/\\$.*"));
52 // Will wait for the rest of the 3 seconds
62 public void testOnReceiveRegisterListener() throws Exception {
63 new JavaTestKit(getSystem()) {{
64 final Props props = Shard.props("config");
65 final ActorRef subject =
66 getSystem().actorOf(props, "testRegisterChangeListener");
68 new Within(duration("1 seconds")) {
69 protected void run() {
72 new UpdateSchemaContext(TestModel.createTestContext()),
75 subject.tell(new RegisterChangeListener(TestModel.TEST_PATH,
76 getRef().path(), AsyncDataBroker.DataChangeScope.BASE),
79 final String out = new ExpectMsg<String>("match hint") {
80 // do not put code outside this method, will run afterwards
81 protected String match(Object in) {
82 if (in instanceof RegisterChangeListenerReply) {
83 RegisterChangeListenerReply reply =
84 (RegisterChangeListenerReply) in;
85 return reply.getListenerRegistrationPath()
91 }.get(); // this extracts the received message
93 assertTrue(out.matches(
94 "akka:\\/\\/test\\/user\\/testRegisterChangeListener\\/\\$.*"));
95 // Will wait for the rest of the 3 seconds
105 public void testCreateTransaction(){
106 new JavaTestKit(getSystem()) {{
107 final Props props = Shard.props("config");
108 final ActorRef subject =
109 getSystem().actorOf(props, "testCreateTransaction");
111 new Within(duration("1 seconds")) {
112 protected void run() {
115 new UpdateSchemaContext(TestModel.createTestContext()),
118 subject.tell(new CreateTransaction(),
121 final String out = new ExpectMsg<String>("match hint") {
122 // do not put code outside this method, will run afterwards
123 protected String match(Object in) {
124 if (in instanceof CreateTransactionReply) {
125 CreateTransactionReply reply =
126 (CreateTransactionReply) in;
127 return reply.getTransactionPath()
133 }.get(); // this extracts the received message
135 assertTrue(out.matches(
136 "akka:\\/\\/test\\/user\\/testCreateTransaction\\/\\$.*"));
137 // Will wait for the rest of the 3 seconds
148 private AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>> noOpDataChangeListener() {
149 return new AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>() {
151 public void onDataChanged(
152 AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change) {