Align tested boolean/Boolean expectations
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / AbstractShardTest.java
index 1c8686c1b1daac3b34d546fc3fe40b1cbdfe2f72..9a7f7a9757b14b542a646fe91b484e7bd49938ac 100644 (file)
@@ -28,7 +28,6 @@ import akka.japi.Creator;
 import akka.pattern.Patterns;
 import akka.testkit.TestActorRef;
 import akka.util.Timeout;
-import com.google.common.base.Optional;
 import com.google.common.primitives.UnsignedLong;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Uninterruptibles;
@@ -36,7 +35,9 @@ import java.io.IOException;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
+import java.util.SortedSet;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
@@ -73,11 +74,10 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -95,11 +95,14 @@ public abstract class AbstractShardTest extends AbstractActorTest {
 
     private static final AtomicInteger NEXT_SHARD_NUM = new AtomicInteger();
 
+    protected static final int HEARTBEAT_MILLIS = 100;
+
     protected final ShardIdentifier shardID = ShardIdentifier.create("inventory", MemberName.forName("member-1"),
         "config" + NEXT_SHARD_NUM.getAndIncrement());
 
     protected final Builder dataStoreContextBuilder = DatastoreContext.newBuilder()
-            .shardJournalRecoveryLogBatchSize(3).shardSnapshotBatchCount(5000).shardHeartbeatIntervalInMillis(100);
+            .shardJournalRecoveryLogBatchSize(3).shardSnapshotBatchCount(5000)
+            .shardHeartbeatIntervalInMillis(HEARTBEAT_MILLIS);
 
     protected final TestActorFactory actorFactory = new TestActorFactory(getSystem());
 
@@ -151,7 +154,7 @@ public abstract class AbstractShardTest extends AbstractActorTest {
                 Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()),
                 "testRecovery");
 
-        assertEquals("Recovery complete", true, recoveryComplete.await(5, TimeUnit.SECONDS));
+        assertTrue("Recovery complete", recoveryComplete.await(5, TimeUnit.SECONDS));
 
         // Verify data in the data store.
 
@@ -198,9 +201,9 @@ public abstract class AbstractShardTest extends AbstractActorTest {
         Assert.fail(String.format("Expected last applied: %d, Actual: %d", expectedValue, lastApplied));
     }
 
-    protected TipProducingDataTree createDelegatingMockDataTree() throws Exception {
-        TipProducingDataTree actual = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION);
-        final TipProducingDataTree mock = mock(TipProducingDataTree.class);
+    protected DataTree createDelegatingMockDataTree() throws Exception {
+        final DataTree actual = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION);
+        final DataTree mock = mock(DataTree.class);
 
         doAnswer(invocation -> {
             actual.validate(invocation.getArgumentAt(0, DataTreeModification.class));
@@ -263,7 +266,7 @@ public abstract class AbstractShardTest extends AbstractActorTest {
                                                              final boolean doCommitOnReady) {
         final BatchedModifications batchedModifications = new BatchedModifications(transactionID, CURRENT_VERSION);
         batchedModifications.addModification(modification);
-        batchedModifications.setReady(true);
+        batchedModifications.setReady();
         batchedModifications.setDoCommitOnReady(doCommitOnReady);
         batchedModifications.setTotalMessagesSent(1);
         return batchedModifications;
@@ -282,16 +285,16 @@ public abstract class AbstractShardTest extends AbstractActorTest {
         ReadWriteShardDataTreeTransaction rwTx = shard.underlyingActor().getDataStore()
                 .newReadWriteTransaction(transactionID);
         rwTx.getSnapshot().write(path, data);
-        return new ForwardedReadyTransaction(transactionID, CURRENT_VERSION, rwTx, doCommitOnReady);
+        return new ForwardedReadyTransaction(transactionID, CURRENT_VERSION, rwTx, doCommitOnReady, Optional.empty());
     }
 
     public static NormalizedNode<?,?> readStore(final TestActorRef<? extends Shard> shard,
-            final YangInstanceIdentifier id) throws ExecutionException, InterruptedException {
+            final YangInstanceIdentifier id) {
         return shard.underlyingActor().getDataStore().readNode(id).orNull();
     }
 
     public static NormalizedNode<?,?> readStore(final DataTree store, final YangInstanceIdentifier id) {
-        return store.takeSnapshot().readNode(id).orNull();
+        return store.takeSnapshot().readNode(id).orElse(null);
     }
 
     public void writeToStore(final TestActorRef<Shard> shard, final YangInstanceIdentifier id,
@@ -306,11 +309,11 @@ public abstract class AbstractShardTest extends AbstractActorTest {
     }
 
     public static void writeToStore(final ShardDataTree store, final YangInstanceIdentifier id,
-            final NormalizedNode<?,?> node) throws Exception {
+            final NormalizedNode<?,?> node) throws DataValidationFailedException {
         BatchedModifications batched = newBatchedModifications(nextTransactionId(), id, node, true, true, 1);
         DataTreeModification modification = store.getDataTree().takeSnapshot().newModification();
         batched.apply(modification);
-        store.notifyListeners(store.commit(modification));
+        store.notifyListeners(commitTransaction(store.getDataTree(), modification));
     }
 
     public static void writeToStore(final DataTree store, final YangInstanceIdentifier id,
@@ -325,21 +328,21 @@ public abstract class AbstractShardTest extends AbstractActorTest {
     }
 
     public void mergeToStore(final ShardDataTree store, final YangInstanceIdentifier id,
-            final NormalizedNode<?,?> node) throws Exception {
+            final NormalizedNode<?,?> node) throws DataValidationFailedException {
         final BatchedModifications batched = new BatchedModifications(nextTransactionId(), CURRENT_VERSION);
         batched.addModification(new MergeModification(id, node));
-        batched.setReady(true);
+        batched.setReady();
         batched.setDoCommitOnReady(true);
         batched.setTotalMessagesSent(1);
 
         DataTreeModification modification = store.getDataTree().takeSnapshot().newModification();
         batched.apply(modification);
-        store.notifyListeners(store.commit(modification));
+        store.notifyListeners(commitTransaction(store.getDataTree(), modification));
     }
 
     DataTree setupInMemorySnapshotStore() throws DataValidationFailedException {
-        final DataTree testStore = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
-        testStore.setSchemaContext(SCHEMA_CONTEXT);
+        final DataTree testStore = new InMemoryDataTreeFactory().create(
+            DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
 
         writeToStore(testStore, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
 
@@ -364,14 +367,26 @@ public abstract class AbstractShardTest extends AbstractActorTest {
             final boolean doCommitOnReady, final int messagesSent) {
         final BatchedModifications batched = new BatchedModifications(transactionID, CURRENT_VERSION);
         batched.addModification(new WriteModification(path, data));
-        batched.setReady(ready);
+        if (ready) {
+            batched.setReady();
+        }
         batched.setDoCommitOnReady(doCommitOnReady);
         batched.setTotalMessagesSent(messagesSent);
         return batched;
     }
 
+    static BatchedModifications newReadyBatchedModifications(final TransactionIdentifier transactionID,
+            final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
+            final SortedSet<String> participatingShardNames) {
+        final BatchedModifications batched = new BatchedModifications(transactionID, CURRENT_VERSION);
+        batched.addModification(new WriteModification(path, data));
+        batched.setReady(Optional.of(participatingShardNames));
+        batched.setTotalMessagesSent(1);
+        return batched;
+    }
+
     @SuppressWarnings("unchecked")
-    static void verifyOuterListEntry(final TestActorRef<Shard> shard, final Object expIDValue) throws Exception {
+    static void verifyOuterListEntry(final TestActorRef<Shard> shard, final Object expIDValue) {
         final NormalizedNode<?, ?> outerList = readStore(shard, TestModel.OUTER_LIST_PATH);
         assertNotNull(TestModel.OUTER_LIST_QNAME.getLocalName() + " not found", outerList);
         assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " value is not Iterable",
@@ -406,11 +421,13 @@ public abstract class AbstractShardTest extends AbstractActorTest {
         return mockCandidate;
     }
 
-    static void commitTransaction(final DataTree store, final DataTreeModification modification)
+    static DataTreeCandidate commitTransaction(final DataTree store, final DataTreeModification modification)
             throws DataValidationFailedException {
         modification.ready();
         store.validate(modification);
-        store.commit(store.prepare(modification));
+        final DataTreeCandidate candidate = store.prepare(modification);
+        store.commit(candidate);
+        return candidate;
     }
 
     @SuppressWarnings("serial")
@@ -515,5 +532,10 @@ public abstract class AbstractShardTest extends AbstractActorTest {
         public State getState() {
             return delegate.getState();
         }
+
+        @Override
+        Optional<SortedSet<String>> getParticipatingShardNames() {
+            return delegate.getParticipatingShardNames();
+        }
     }
 }