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%2FShardTest.java;h=bdae31c96fbc54fada222f51d3cf6aea9b61562c;hb=35235f427f3a056f85fe83ddd1133e67540328f7;hp=a90ec075ab6c7e3e1760e9bf22632c5e55aedb2c;hpb=9bce68c4712d00951d121be68b09578bc6e09151;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java index a90ec075ab..bdae31c96f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java @@ -33,6 +33,7 @@ import akka.util.Timeout; import com.google.common.base.Stopwatch; import com.google.common.base.Throwables; import com.google.common.util.concurrent.Uninterruptibles; +import java.time.Duration; import java.util.Collections; import java.util.HashSet; import java.util.Map; @@ -139,7 +140,7 @@ public class ShardTest extends AbstractShardTest { shard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, false), testKit.getRef()); - final RegisterDataTreeNotificationListenerReply reply = testKit.expectMsgClass(testKit.duration("3 seconds"), + final RegisterDataTreeNotificationListenerReply reply = testKit.expectMsgClass(Duration.ofSeconds(3), RegisterDataTreeNotificationListenerReply.class); final String replyPath = reply.getListenerRegistrationPath().toString(); assertTrue("Incorrect reply path: " + replyPath, @@ -197,13 +198,12 @@ public class ShardTest extends AbstractShardTest { assertTrue("Got first ElectionTimeout", onFirstElectionTimeout.await(5, TimeUnit.SECONDS)); shard.tell(new RegisterDataTreeChangeListener(path, dclActor, false), testKit.getRef()); - final RegisterDataTreeNotificationListenerReply reply = testKit.expectMsgClass(testKit.duration("5 seconds"), + final RegisterDataTreeNotificationListenerReply reply = testKit.expectMsgClass(Duration.ofSeconds(5), RegisterDataTreeNotificationListenerReply.class); assertNotNull("getListenerRegistratioznPath", reply.getListenerRegistrationPath()); shard.tell(FindLeader.INSTANCE, testKit.getRef()); - final FindLeaderReply findLeadeReply = testKit.expectMsgClass(testKit.duration("5 seconds"), - FindLeaderReply.class); + final FindLeaderReply findLeadeReply = testKit.expectMsgClass(Duration.ofSeconds(5), FindLeaderReply.class); assertFalse("Expected the shard not to be the leader", findLeadeReply.getLeaderActor().isPresent()); onChangeListenerRegistered.countDown(); @@ -224,7 +224,7 @@ public class ShardTest extends AbstractShardTest { shard.tell(new CreateTransaction(nextTransactionId(), TransactionType.READ_ONLY.ordinal(), DataStoreVersions.CURRENT_VERSION).toSerializable(), testKit.getRef()); - final CreateTransactionReply reply = testKit.expectMsgClass(testKit.duration("3 seconds"), + final CreateTransactionReply reply = testKit.expectMsgClass(Duration.ofSeconds(3), CreateTransactionReply.class); final String path = reply.getTransactionPath().toString(); @@ -243,7 +243,7 @@ public class ShardTest extends AbstractShardTest { shard.tell(new CreateTransaction(nextTransactionId(), TransactionType.READ_ONLY.ordinal(), DataStoreVersions.CURRENT_VERSION).toSerializable(), testKit.getRef()); - final CreateTransactionReply reply = testKit.expectMsgClass(testKit.duration("3 seconds"), + final CreateTransactionReply reply = testKit.expectMsgClass(Duration.ofSeconds(3), CreateTransactionReply.class); final String path = reply.getTransactionPath().toString(); @@ -387,8 +387,8 @@ public class ShardTest extends AbstractShardTest { final CountDownLatch commitLatch = new CountDownLatch(2); final long timeoutSec = 5; - final FiniteDuration duration = FiniteDuration.create(timeoutSec, TimeUnit.SECONDS); - final Timeout timeout = new Timeout(duration); + final Duration duration = Duration.ofSeconds(timeoutSec); + final Timeout timeout = Timeout.create(duration); final TestActorRef shard = actorFactory.createTestActor( newShardProps().withDispatcher(Dispatchers.DefaultDispatcherId()), @@ -552,7 +552,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); final TransactionIdentifier transactionID = nextTransactionId(); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); // Send a BatchedModifications to start a transaction. @@ -601,7 +601,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); final TransactionIdentifier transactionID = nextTransactionId(); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); // Send a BatchedModifications to start a transaction. @@ -645,7 +645,7 @@ public class ShardTest extends AbstractShardTest { shard.tell(batched, testKit.getRef()); - final Failure failure = testKit.expectMsgClass(testKit.duration("5 seconds"), Failure.class); + final Failure failure = testKit.expectMsgClass(Duration.ofSeconds(5), Failure.class); if (failure != null) { Throwables.propagateIfPossible(failure.cause(), Exception.class); @@ -675,7 +675,7 @@ public class ShardTest extends AbstractShardTest { BatchedModifications batched = new BatchedModifications(transactionID, CURRENT_VERSION); batched.addModification(new MergeModification(TestModel.TEST_PATH, invalidData)); shard.tell(batched, testKit.getRef()); - Failure failure = testKit.expectMsgClass(testKit.duration("5 seconds"), akka.actor.Status.Failure.class); + Failure failure = testKit.expectMsgClass(Duration.ofSeconds(5), akka.actor.Status.Failure.class); final Throwable cause = failure.cause(); @@ -685,7 +685,7 @@ public class ShardTest extends AbstractShardTest { shard.tell(batched, testKit.getRef()); - failure = testKit.expectMsgClass(testKit.duration("5 seconds"), akka.actor.Status.Failure.class); + failure = testKit.expectMsgClass(Duration.ofSeconds(5), akka.actor.Status.Failure.class); assertEquals("Failure cause", cause, failure.cause()); } @@ -702,7 +702,7 @@ public class ShardTest extends AbstractShardTest { final TransactionIdentifier transactionID1 = new TransactionIdentifier(historyId, 0); final TransactionIdentifier transactionID2 = new TransactionIdentifier(historyId, 1); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); // Send a BatchedModifications to start a chained write // transaction and ready it. @@ -717,12 +717,12 @@ public class ShardTest extends AbstractShardTest { shard.tell(new CreateTransaction(transactionID2, TransactionType.READ_ONLY.ordinal(), DataStoreVersions.CURRENT_VERSION).toSerializable(), testKit.getRef()); - final CreateTransactionReply createReply = testKit.expectMsgClass(testKit.duration("3 seconds"), + final CreateTransactionReply createReply = testKit.expectMsgClass(Duration.ofSeconds(3), CreateTransactionReply.class); getSystem().actorSelection(createReply.getTransactionPath()) .tell(new ReadData(path, DataStoreVersions.CURRENT_VERSION), testKit.getRef()); - final ReadDataReply readReply = testKit.expectMsgClass(testKit.duration("3 seconds"), ReadDataReply.class); + final ReadDataReply readReply = testKit.expectMsgClass(Duration.ofSeconds(3), ReadDataReply.class); assertEquals("Read node", containerNode, readReply.getNormalizedNode()); // Commit the write transaction. @@ -836,7 +836,7 @@ public class ShardTest extends AbstractShardTest { testKit.getRef()); } - testKit.expectMsgClass(testKit.duration("5 seconds"), CommitTransactionReply.class); + testKit.expectMsgClass(Duration.ofSeconds(5), CommitTransactionReply.class); final NormalizedNode actualNode = readStore(shard, TestModel.TEST_PATH); assertEquals(TestModel.TEST_QNAME.getLocalName(), containerNode, actualNode); @@ -857,7 +857,9 @@ public class ShardTest extends AbstractShardTest { final ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME); new WriteModification(TestModel.TEST_PATH, writeData).apply(modification); - final MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build(); + final MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME) + .addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 42)) + .build(); new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification); final TransactionIdentifier txId = nextTransactionId(); @@ -888,7 +890,9 @@ public class ShardTest extends AbstractShardTest { final ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME); new WriteModification(TestModel.TEST_PATH, writeData).apply(modification); - final MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build(); + final MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME) + .addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 42)) + .build(); new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification); final TransactionIdentifier txId = nextTransactionId(); @@ -928,7 +932,7 @@ public class ShardTest extends AbstractShardTest { // Setup a simulated transactions with a mock cohort. - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); final TransactionIdentifier transactionID = nextTransactionId(); final NormalizedNode containerNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME); @@ -971,7 +975,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); final TransactionIdentifier transactionID = nextTransactionId(); if (readWrite) { @@ -1025,8 +1029,8 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - final FiniteDuration duration = testKit.duration("5 seconds"); - final Timeout timeout = new Timeout(duration); + final Duration duration = Duration.ofSeconds(5); + final Timeout timeout = Timeout.create(duration); // Setup 2 simulated transactions with mock cohorts. The first // one fails in the @@ -1099,8 +1103,8 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - final FiniteDuration duration = testKit.duration("5 seconds"); - final Timeout timeout = new Timeout(duration); + final Duration duration = Duration.ofSeconds(5); + final Timeout timeout = Timeout.create(duration); doThrow(new RuntimeException("mock preCommit failure")).when(dataTree) .prepare(any(DataTreeModification.class)); @@ -1164,7 +1168,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); final TransactionIdentifier transactionID1 = nextTransactionId(); doThrow(new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock canCommit failure")) @@ -1211,7 +1215,7 @@ public class ShardTest extends AbstractShardTest { doThrow(new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock canCommit failure")) .doNothing().when(dataTree).validate(any(DataTreeModification.class)); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); final TransactionIdentifier transactionID1 = nextTransactionId(); @@ -1263,7 +1267,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); final TransactionIdentifier transactionID = nextTransactionId(); @@ -1297,7 +1301,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); writeToStore(shard, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); writeToStore(shard, TestModel.OUTER_LIST_PATH, @@ -1426,7 +1430,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); final TransactionIdentifier transactionID1 = nextTransactionId(); shard.tell(newBatchedModifications(transactionID1, TestModel.TEST_PATH, @@ -1462,7 +1466,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); final ShardDataTree dataStore = shard.underlyingActor().getDataStore(); @@ -1517,7 +1521,7 @@ public class ShardTest extends AbstractShardTest { "testCanCommitBeforeReadyFailure"); shard.tell(new CanCommitTransaction(nextTransactionId(), CURRENT_VERSION).toSerializable(), testKit.getRef()); - testKit.expectMsgClass(testKit.duration("5 seconds"), akka.actor.Status.Failure.class); + testKit.expectMsgClass(Duration.ofSeconds(5), akka.actor.Status.Failure.class); } @Test @@ -1528,8 +1532,8 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - final FiniteDuration duration = testKit.duration("5 seconds"); - final Timeout timeout = new Timeout(duration); + final Duration duration = Duration.ofSeconds(5); + final Timeout timeout = Timeout.create(duration); // Ready 2 transactions - the first one will be aborted. @@ -1566,7 +1570,8 @@ public class ShardTest extends AbstractShardTest { // Wait for the 2nd Tx to complete the canCommit phase. - canCommitReply = (CanCommitTransactionReply) Await.result(canCommitFuture, duration); + canCommitReply = (CanCommitTransactionReply) Await.result(canCommitFuture, + FiniteDuration.create(5, TimeUnit.SECONDS)); assertTrue("Can commit", canCommitReply.getCanCommit()); } @@ -1579,7 +1584,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); // Ready a tx. @@ -1620,7 +1625,7 @@ public class ShardTest extends AbstractShardTest { ShardTestKit.waitUntilLeader(shard); - final FiniteDuration duration = testKit.duration("5 seconds"); + final Duration duration = Duration.ofSeconds(5); // Ready 3 tx's. @@ -1712,8 +1717,6 @@ public class ShardTest extends AbstractShardTest { } } - final ShardTestKit testKit = new ShardTestKit(getSystem()); - final Creator creator = () -> new TestShard(newShardBuilder()); final TestActorRef shard = actorFactory.createTestActor(Props @@ -1891,7 +1894,7 @@ public class ShardTest extends AbstractShardTest { testKit.waitUntilNoLeader(shard); shard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, true), testKit.getRef()); - final RegisterDataTreeNotificationListenerReply reply = testKit.expectMsgClass(testKit.duration("5 seconds"), + final RegisterDataTreeNotificationListenerReply reply = testKit.expectMsgClass(Duration.ofSeconds(5), RegisterDataTreeNotificationListenerReply.class); assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath()); @@ -1921,7 +1924,7 @@ public class ShardTest extends AbstractShardTest { testKit.waitUntilNoLeader(shard); shard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, true), testKit.getRef()); - final RegisterDataTreeNotificationListenerReply reply = testKit.expectMsgClass(testKit.duration("5 seconds"), + final RegisterDataTreeNotificationListenerReply reply = testKit.expectMsgClass(Duration.ofSeconds(5), RegisterDataTreeNotificationListenerReply.class); assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath()); @@ -1970,7 +1973,7 @@ public class ShardTest extends AbstractShardTest { actorFactory.generateActorId(testName + "-DataTreeChangeListener")); followerShard.tell(new RegisterDataTreeChangeListener(TestModel.TEST_PATH, dclActor, true), testKit.getRef()); - final RegisterDataTreeNotificationListenerReply reply = testKit.expectMsgClass(testKit.duration("5 seconds"), + final RegisterDataTreeNotificationListenerReply reply = testKit.expectMsgClass(Duration.ofSeconds(5), RegisterDataTreeNotificationListenerReply.class); assertNotNull("getListenerRegistrationPath", reply.getListenerRegistrationPath());