From: Moiz Raja Date: Tue, 17 Jun 2014 23:11:35 +0000 (-0700) Subject: Implement basic ShardTransactionChain#CloseTransactionChain X-Git-Tag: release/helium~628^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=397fd5485d0041b98623732d7210cba2ecbdd808 Implement basic ShardTransactionChain#CloseTransactionChain Change-Id: I7acfe5d985b44f64a7e6b13a6434952ff7fe28d4 Signed-off-by: Moiz Raja --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChain.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChain.java index a42b51338b..83913fe416 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChain.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChain.java @@ -12,6 +12,8 @@ import akka.actor.ActorRef; import akka.actor.Props; import akka.actor.UntypedActor; import akka.japi.Creator; +import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain; +import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChainReply; import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction; import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; @@ -34,6 +36,9 @@ public class ShardTransactionChain extends UntypedActor{ DOMStoreReadWriteTransaction transaction = chain.newReadWriteTransaction(); ActorRef transactionActor = getContext().actorOf(ShardTransaction.props(transaction)); getSender().tell(new CreateTransactionReply(transactionActor.path()), getSelf()); + } else if (message instanceof CloseTransactionChain){ + chain.close(); + getSender().tell(new CloseTransactionChainReply(), getSelf()); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChain.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChain.java new file mode 100644 index 0000000000..04c422b68e --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChain.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.cluster.datastore.messages; + +public class CloseTransactionChain { +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainReply.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainReply.java new file mode 100644 index 0000000000..89fa93bf9a --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainReply.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.cluster.datastore.messages; + +public class CloseTransactionChainReply { +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChainTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChainTest.java index d8cb53d083..bc3a104656 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChainTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionChainTest.java @@ -6,11 +6,14 @@ import akka.testkit.JavaTestKit; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import org.junit.Test; +import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain; +import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChainReply; import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction; import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class ShardTransactionChainTest extends AbstractActorTest { @@ -50,6 +53,38 @@ public class ShardTransactionChainTest extends AbstractActorTest { } + }; + }}; + } + + @Test + public void testOnReceiveCloseTransactionChain() throws Exception { + new JavaTestKit(getSystem()) {{ + final Props props = ShardTransactionChain.props(store.createTransactionChain()); + final ActorRef subject = getSystem().actorOf(props, "testCloseTransactionChain"); + + new Within(duration("1 seconds")) { + protected void run() { + + subject.tell(new CloseTransactionChain(), getRef()); + + final String out = new ExpectMsg("match hint") { + // do not put code outside this method, will run afterwards + protected String match(Object in) { + if (in instanceof CloseTransactionChainReply) { + return "match"; + } else { + throw noMatch(); + } + } + }.get(); // this extracts the received message + + assertEquals("match", out); + // Will wait for the rest of the 3 seconds + expectNoMsg(); + } + + }; }}; }