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.CreateTransactionChain;
8 import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionChainReply;
9 import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener;
10 import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListenerReply;
11 import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
12 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
16 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import static org.junit.Assert.assertTrue;
21 public class ShardTest extends AbstractActorTest{
23 public void testOnReceiveCreateTransactionChain() throws Exception {
24 new JavaTestKit(getSystem()) {{
25 final Props props = Shard.props("config");
26 final ActorRef subject = getSystem().actorOf(props, "testCreateTransactionChain");
28 new Within(duration("1 seconds")) {
29 protected void run() {
31 subject.tell(new CreateTransactionChain(), getRef());
33 final String out = new ExpectMsg<String>("match hint") {
34 // do not put code outside this method, will run afterwards
35 protected String match(Object in) {
36 if (in instanceof CreateTransactionChainReply) {
37 CreateTransactionChainReply reply = (CreateTransactionChainReply) in;
38 return reply.getTransactionChainPath().toString();
43 }.get(); // this extracts the received message
45 assertTrue(out.matches("akka:\\/\\/test\\/user\\/testCreateTransactionChain\\/\\$.*"));
46 // Will wait for the rest of the 3 seconds
56 public void testOnReceiveRegisterListener() throws Exception {
57 new JavaTestKit(getSystem()) {{
58 final Props props = Shard.props("config");
59 final ActorRef subject = getSystem().actorOf(props, "testRegisterChangeListener");
61 new Within(duration("1 seconds")) {
62 protected void run() {
64 subject.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
66 subject.tell(new RegisterChangeListener(TestModel.TEST_PATH, getRef().path() , AsyncDataBroker.DataChangeScope.BASE), getRef());
68 final String out = new ExpectMsg<String>("match hint") {
69 // do not put code outside this method, will run afterwards
70 protected String match(Object in) {
71 if (in instanceof RegisterChangeListenerReply) {
72 RegisterChangeListenerReply reply = (RegisterChangeListenerReply) in;
73 return reply.getListenerRegistrationPath().toString();
78 }.get(); // this extracts the received message
80 assertTrue(out.matches("akka:\\/\\/test\\/user\\/testRegisterChangeListener\\/\\$.*"));
81 // Will wait for the rest of the 3 seconds
92 private AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>> noOpDataChangeListener(){
93 return new AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>() {
95 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change) {