X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FShardTransactionTest.java;h=f3acf29e7a846e05335b4bcb912bb9a9b47420fb;hb=f41c5e6e6f6e10b36b1e4b1992877e38e718c8fb;hp=f8997106f62e6124f0aedfcf0bd6abd4b09966e6;hpb=7eeebc36f171b7a56f2ebfc3eefbb66b51efe675;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java index f8997106f6..f3acf29e7a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java @@ -19,8 +19,8 @@ import akka.actor.Props; import akka.actor.Status.Failure; import akka.actor.Terminated; import akka.dispatch.Dispatchers; -import akka.testkit.JavaTestKit; import akka.testkit.TestActorRef; +import akka.testkit.javadsl.TestKit; import com.google.common.base.Throwables; import java.util.concurrent.TimeUnit; import org.junit.Before; @@ -50,6 +50,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; public class ShardTransactionTest extends AbstractActorTest { @@ -59,6 +60,7 @@ public class ShardTransactionTest extends AbstractActorTest { private static final ShardIdentifier SHARD_IDENTIFIER = ShardIdentifier.create("inventory", MEMBER_NAME, "config"); + private static final SchemaContext TEST_MODEL = TestModel.createTestContext(); private DatastoreContext datastoreContext = DatastoreContext.newBuilder().persistent(false).build(); @@ -70,7 +72,7 @@ public class ShardTransactionTest extends AbstractActorTest { @Before public void setUp() { shard = actorFactory.createTestActor(Shard.builder().id(SHARD_IDENTIFIER).datastoreContext(datastoreContext) - .schemaContext(TestModel.createTestContext()).props() + .schemaContextProvider(() -> TEST_MODEL).props() .withDispatcher(Dispatchers.DefaultDispatcherId())); ShardTestKit.waitUntilLeader(shard); store = shard.underlyingActor().getDataStore(); @@ -93,7 +95,7 @@ public class ShardTransactionTest extends AbstractActorTest { @Test public void testOnReceiveReadData() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { testOnReceiveReadData(newTransactionActor(RO, readOnlyTransaction(), "testReadDataRO")); @@ -113,7 +115,7 @@ public class ShardTransactionTest extends AbstractActorTest { @Test public void testOnReceiveReadDataWhenDataNotFound() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { testOnReceiveReadDataWhenDataNotFound( newTransactionActor(RO, readOnlyTransaction(), "testReadDataWhenDataNotFoundRO")); @@ -134,7 +136,7 @@ public class ShardTransactionTest extends AbstractActorTest { @Test public void testOnReceiveDataExistsPositive() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { testOnReceiveDataExistsPositive( newTransactionActor(RO, readOnlyTransaction(), "testDataExistsPositiveRO")); @@ -156,7 +158,7 @@ public class ShardTransactionTest extends AbstractActorTest { @Test public void testOnReceiveDataExistsNegative() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { testOnReceiveDataExistsNegative( newTransactionActor(RO, readOnlyTransaction(), "testDataExistsNegativeRO")); @@ -177,7 +179,7 @@ public class ShardTransactionTest extends AbstractActorTest { @Test public void testOnReceiveBatchedModifications() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ShardDataTreeTransactionParent parent = Mockito.mock(ShardDataTreeTransactionParent.class); DataTreeModification mockModification = Mockito.mock(DataTreeModification.class); @@ -219,12 +221,12 @@ public class ShardTransactionTest extends AbstractActorTest { @Test public void testOnReceiveBatchedModificationsReadyWithoutImmediateCommit() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithoutImmediateCommit"); - JavaTestKit watcher = new JavaTestKit(getSystem()); + TestKit watcher = new TestKit(getSystem()); watcher.watch(transaction); YangInstanceIdentifier writePath = TestModel.TEST_PATH; @@ -254,12 +256,12 @@ public class ShardTransactionTest extends AbstractActorTest { @Test public void testOnReceiveBatchedModificationsReadyWithImmediateCommit() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithImmediateCommit"); - JavaTestKit watcher = new JavaTestKit(getSystem()); + TestKit watcher = new TestKit(getSystem()); watcher.watch(transaction); YangInstanceIdentifier writePath = TestModel.TEST_PATH; @@ -283,7 +285,7 @@ public class ShardTransactionTest extends AbstractActorTest { @Test(expected = TestException.class) public void testOnReceiveBatchedModificationsFailure() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { ShardDataTreeTransactionParent parent = Mockito.mock(ShardDataTreeTransactionParent.class); @@ -293,7 +295,7 @@ public class ShardTransactionTest extends AbstractActorTest { final ActorRef transaction = newTransactionActor(RW, mockWriteTx, "testOnReceiveBatchedModificationsFailure"); - JavaTestKit watcher = new JavaTestKit(getSystem()); + TestKit watcher = new TestKit(getSystem()); watcher.watch(transaction); YangInstanceIdentifier path = TestModel.TEST_PATH; @@ -317,8 +319,8 @@ public class ShardTransactionTest extends AbstractActorTest { watcher.expectMsgClass(duration("5 seconds"), Terminated.class); if (failure != null) { - Throwables.propagateIfInstanceOf(failure.cause(), Exception.class); - Throwables.propagate(failure.cause()); + Throwables.propagateIfPossible(failure.cause(), Exception.class); + throw new RuntimeException(failure.cause()); } } }; @@ -326,13 +328,13 @@ public class ShardTransactionTest extends AbstractActorTest { @Test(expected = IllegalStateException.class) public void testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount"); - JavaTestKit watcher = new JavaTestKit(getSystem()); + TestKit watcher = new TestKit(getSystem()); watcher.watch(transaction); BatchedModifications batched = new BatchedModifications(nextTransactionId(), @@ -346,8 +348,9 @@ public class ShardTransactionTest extends AbstractActorTest { watcher.expectMsgClass(duration("5 seconds"), Terminated.class); if (failure != null) { - Throwables.propagateIfInstanceOf(failure.cause(), Exception.class); - Throwables.propagate(failure.cause()); + Throwables.throwIfInstanceOf(failure.cause(), Exception.class); + Throwables.throwIfUnchecked(failure.cause()); + throw new RuntimeException(failure.cause()); } } }; @@ -355,7 +358,7 @@ public class ShardTransactionTest extends AbstractActorTest { @Test public void testReadWriteTxOnReceiveCloseTransaction() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { final ActorRef transaction = newTransactionActor(RW, readWriteTransaction(), "testReadWriteTxOnReceiveCloseTransaction"); @@ -372,7 +375,7 @@ public class ShardTransactionTest extends AbstractActorTest { @Test public void testWriteOnlyTxOnReceiveCloseTransaction() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(), "testWriteTxOnReceiveCloseTransaction"); @@ -389,7 +392,7 @@ public class ShardTransactionTest extends AbstractActorTest { @Test public void testReadOnlyTxOnReceiveCloseTransaction() throws Exception { - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { final ActorRef transaction = newTransactionActor(TransactionType.READ_ONLY, readOnlyTransaction(), "testReadOnlyTxOnReceiveCloseTransaction"); @@ -408,7 +411,7 @@ public class ShardTransactionTest extends AbstractActorTest { datastoreContext = DatastoreContext.newBuilder().shardTransactionIdleTimeout( 500, TimeUnit.MILLISECONDS).build(); - new JavaTestKit(getSystem()) { + new TestKit(getSystem()) { { final ActorRef transaction = newTransactionActor(RW, readWriteTransaction(), "testShardTransactionInactivity");