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.md.sal.common.api.data.AsyncDataBroker;
12 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
14 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import static org.junit.Assert.assertTrue;
19 public class ShardTest extends AbstractActorTest{
21 public void testOnReceiveCreateTransaction() throws Exception {
22 new JavaTestKit(getSystem()) {{
23 final Props props = Props.create(Shard.class);
24 final ActorRef subject = getSystem().actorOf(props, "testCreateTransaction");
26 new Within(duration("1 seconds")) {
27 protected void run() {
29 subject.tell(new CreateTransactionChain(), getRef());
31 final String out = new ExpectMsg<String>("match hint") {
32 // do not put code outside this method, will run afterwards
33 protected String match(Object in) {
34 if (in instanceof CreateTransactionChainReply) {
35 CreateTransactionChainReply reply = (CreateTransactionChainReply) in;
36 return reply.getTransactionChainPath().toString();
41 }.get(); // this extracts the received message
43 assertTrue(out.matches("akka:\\/\\/test\\/user\\/testCreateTransaction\\/\\$.*"));
44 // Will wait for the rest of the 3 seconds
54 public void testOnReceiveRegisterListener() throws Exception {
55 new JavaTestKit(getSystem()) {{
56 final Props props = Props.create(Shard.class);
57 final ActorRef subject = getSystem().actorOf(props, "testRegisterChangeListener");
59 new Within(duration("1 seconds")) {
60 protected void run() {
62 subject.tell(new RegisterChangeListener(InstanceIdentifier.builder().build(), noOpDataChangeListener() , AsyncDataBroker.DataChangeScope.BASE), getRef());
64 final String out = new ExpectMsg<String>("match hint") {
65 // do not put code outside this method, will run afterwards
66 protected String match(Object in) {
67 if (in instanceof RegisterChangeListenerReply) {
68 RegisterChangeListenerReply reply = (RegisterChangeListenerReply) in;
69 return reply.getListenerRegistrationPath().toString();
74 }.get(); // this extracts the received message
76 assertTrue(out.matches("akka:\\/\\/test\\/user\\/testRegisterChangeListener\\/\\$.*"));
77 // Will wait for the rest of the 3 seconds
86 private AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>> noOpDataChangeListener(){
87 return new AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>() {
89 public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change) {