From 118cd0216b0c6b0ec1a01689ec2025a13e090861 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 9 Mar 2022 07:59:30 +0100 Subject: [PATCH] Use Empty instead of Void in cohorts Void is inherently null-happy, switch to Empty, which has a proper value. Change-Id: I6ce60a0933e15e7b779fcbef149481c59aa93970 Signed-off-by: Robert Varga --- .../databroker/ConcurrentDOMDataBroker.java | 29 ++++----- .../actors/dds/AbstractProxyTransaction.java | 5 +- .../dds/AbstractTransactionCommitCohort.java | 3 +- .../dds/ClientTransactionCommitCohort.java | 16 +++-- .../dds/DirectTransactionCommitCohort.java | 14 ++-- .../dds/EmptyTransactionCommitCohort.java | 14 ++-- .../databroker/actors/dds/VotingFuture.java | 13 ++-- .../AbstractThreePhaseCommitCohort.java | 8 ++- .../datastore/ChainedCommitCohort.java | 5 +- .../cluster/datastore/CohortEntry.java | 5 +- .../datastore/CompositeDataTreeCohort.java | 19 +++--- .../DebugThreePhaseCommitCohort.java | 10 +-- .../FrontendReadWriteTransaction.java | 13 ++-- .../LocalThreePhaseCommitCohort.java | 8 ++- .../NoOpDOMStoreThreePhaseCommitCohort.java | 14 ++-- .../datastore/ShardCommitCoordinator.java | 9 +-- .../cluster/datastore/ShardDataTree.java | 5 +- .../datastore/ShardDataTreeCohort.java | 5 +- .../datastore/SimpleShardDataTreeCohort.java | 27 ++++---- .../datastore/SingleCommitCohortProxy.java | 19 +++--- .../ThreePhaseCommitCohortProxy.java | 64 ++++++++++--------- .../dds/AbstractProxyTransactionTest.java | 5 +- .../ClientTransactionCommitCohortTest.java | 9 ++- .../actors/dds/ClientTransactionTest.java | 10 +-- .../DirectTransactionCommitCohortTest.java | 14 ++-- .../dds/EmptyTransactionCommitCohortTest.java | 13 ++-- .../databroker/actors/dds/TestUtils.java | 7 +- .../cluster/datastore/AbstractShardTest.java | 9 +-- .../datastore/ShardDataTreeMocking.java | 17 ++--- .../cluster/datastore/ShardDataTreeTest.java | 33 +++++----- .../SimpleShardDataTreeCohortTest.java | 15 +++-- 31 files changed, 235 insertions(+), 202 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java index b5ec6083be..36b47eff69 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBroker.java @@ -37,6 +37,7 @@ import org.opendaylight.mdsal.dom.broker.TransactionCommitFailedExceptionMapper; import org.opendaylight.mdsal.dom.spi.store.DOMStore; import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; import org.opendaylight.yangtools.util.DurationStatisticsTracker; +import org.opendaylight.yangtools.yang.common.Empty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -137,15 +138,14 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { final Iterator cohortIterator = cohorts.iterator(); // Not using Futures.allAsList here to avoid its internal overhead. - FutureCallback futureCallback = new FutureCallback<>() { + FutureCallback futureCallback = new FutureCallback<>() { @Override - public void onSuccess(final Void notUsed) { + public void onSuccess(final Empty result) { if (!cohortIterator.hasNext()) { // All cohorts completed successfully - we can move on to the commit phase doCommit(startTime, clientSubmitFuture, transaction, cohorts); } else { - ListenableFuture preCommitFuture = cohortIterator.next().preCommit(); - Futures.addCallback(preCommitFuture, this, MoreExecutors.directExecutor()); + Futures.addCallback(cohortIterator.next().preCommit(), this, MoreExecutors.directExecutor()); } } @@ -155,8 +155,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { } }; - ListenableFuture preCommitFuture = cohortIterator.next().preCommit(); - Futures.addCallback(preCommitFuture, futureCallback, MoreExecutors.directExecutor()); + Futures.addCallback(cohortIterator.next().preCommit(), futureCallback, MoreExecutors.directExecutor()); } private void doCommit(final long startTime, final AsyncNotifyingSettableFuture clientSubmitFuture, @@ -166,17 +165,16 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { final Iterator cohortIterator = cohorts.iterator(); // Not using Futures.allAsList here to avoid its internal overhead. - FutureCallback futureCallback = new FutureCallback<>() { + final FutureCallback futureCallback = new FutureCallback<>() { @Override - public void onSuccess(final Void notUsed) { + public void onSuccess(final CommitInfo result) { if (!cohortIterator.hasNext()) { // All cohorts completed successfully - we're done. commitStatsTracker.addDuration(System.nanoTime() - startTime); clientSubmitFuture.set(); } else { - ListenableFuture commitFuture = cohortIterator.next().commit(); - Futures.addCallback(commitFuture, this, MoreExecutors.directExecutor()); + Futures.addCallback(cohortIterator.next().commit(), this, MoreExecutors.directExecutor()); } } @@ -186,8 +184,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { } }; - ListenableFuture commitFuture = cohortIterator.next().commit(); - Futures.addCallback(commitFuture, futureCallback, MoreExecutors.directExecutor()); + Futures.addCallback(cohortIterator.next().commit(), futureCallback, MoreExecutors.directExecutor()); } @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", @@ -210,7 +207,7 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { // Transaction failed - tell all cohorts to abort. @SuppressWarnings("unchecked") - ListenableFuture[] canCommitFutures = new ListenableFuture[cohorts.size()]; + ListenableFuture[] canCommitFutures = new ListenableFuture[cohorts.size()]; int index = 0; for (DOMStoreThreePhaseCommitCohort cohort : cohorts) { canCommitFutures[index++] = cohort.abort(); @@ -227,10 +224,10 @@ public class ConcurrentDOMDataBroker extends AbstractDOMBroker { } clientSubmitFuture.setException(exMapper.apply(e)); - ListenableFuture> combinedFuture = Futures.allAsList(canCommitFutures); - Futures.addCallback(combinedFuture, new FutureCallback>() { + ListenableFuture> combinedFuture = Futures.allAsList(canCommitFutures); + Futures.addCallback(combinedFuture, new FutureCallback>() { @Override - public void onSuccess(final List notUsed) { + public void onSuccess(final List result) { // Propagate the original exception to the client. LOG.debug("Tx: {} aborted successfully", transaction.getIdentifier()); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java index 8fb042fba1..461c90f605 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransaction.java @@ -49,6 +49,7 @@ import org.opendaylight.controller.cluster.access.concepts.RequestFailure; import org.opendaylight.controller.cluster.access.concepts.Response; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.yangtools.concepts.Identifiable; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.slf4j.Logger; @@ -157,7 +158,7 @@ abstract class AbstractProxyTransaction implements Identifiable ret) { + final void abort(final VotingFuture ret) { checkSealed(); sendDoAbort(t -> { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractTransactionCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractTransactionCommitCohort.java index b2f66d5d31..77de1e45d8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractTransactionCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractTransactionCommitCohort.java @@ -14,6 +14,7 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; +import org.opendaylight.yangtools.yang.common.Empty; /** * Base class for internal {@link DOMStoreThreePhaseCommitCohort} implementation. It contains utility constants for @@ -23,7 +24,7 @@ import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; */ abstract class AbstractTransactionCommitCohort implements DOMStoreThreePhaseCommitCohort { static final ListenableFuture TRUE_FUTURE = Futures.immediateFuture(Boolean.TRUE); - static final ListenableFuture VOID_FUTURE = Futures.immediateFuture(null); + static final ListenableFuture EMPTY_FUTURE = Futures.immediateFuture(Empty.value()); private final AbstractClientHistory parent; private final TransactionIdentifier txId; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohort.java index a4eb5e074f..7887577a93 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohort.java @@ -12,6 +12,8 @@ import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; import java.util.Collection; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.yangtools.yang.common.Empty; final class ClientTransactionCommitCohort extends AbstractTransactionCommitCohort { private final Collection proxies; @@ -35,14 +37,14 @@ final class ClientTransactionCommitCohort extends AbstractTransactionCommitCohor return ret; } - private ListenableFuture addComplete(final ListenableFuture future) { + private ListenableFuture addComplete(final ListenableFuture future) { future.addListener(this::complete, MoreExecutors.directExecutor()); return future; } @Override - public ListenableFuture preCommit() { - final VotingFuture ret = new VotingFuture<>(null, proxies.size()); + public ListenableFuture preCommit() { + final var ret = new VotingFuture<>(Empty.value(), proxies.size()); for (AbstractProxyTransaction proxy : proxies) { proxy.preCommit(ret); } @@ -51,8 +53,8 @@ final class ClientTransactionCommitCohort extends AbstractTransactionCommitCohor } @Override - public ListenableFuture commit() { - final VotingFuture ret = new VotingFuture<>(null, proxies.size()); + public ListenableFuture commit() { + final var ret = new VotingFuture<>(CommitInfo.empty(), proxies.size()); for (AbstractProxyTransaction proxy : proxies) { proxy.doCommit(ret); } @@ -61,8 +63,8 @@ final class ClientTransactionCommitCohort extends AbstractTransactionCommitCohor } @Override - public ListenableFuture abort() { - final VotingFuture ret = new VotingFuture<>(null, proxies.size()); + public ListenableFuture abort() { + final var ret = new VotingFuture<>(Empty.value(), proxies.size()); for (AbstractProxyTransaction proxy : proxies) { proxy.abort(ret); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/DirectTransactionCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/DirectTransactionCommitCohort.java index 9b21b98682..5b5ff5864a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/DirectTransactionCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/DirectTransactionCommitCohort.java @@ -11,6 +11,8 @@ import static java.util.Objects.requireNonNull; import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.yangtools.yang.common.Empty; /** * An {@link AbstractTransactionCommitCohort} implementation for transactions which contain a single proxy. Since there @@ -33,19 +35,19 @@ final class DirectTransactionCommitCohort extends AbstractTransactionCommitCohor } @Override - public ListenableFuture preCommit() { - return VOID_FUTURE; + public ListenableFuture preCommit() { + return EMPTY_FUTURE; } @Override - public ListenableFuture abort() { + public ListenableFuture abort() { complete(); - return VOID_FUTURE; + return EMPTY_FUTURE; } @Override - public ListenableFuture commit() { + public ListenableFuture commit() { complete(); - return VOID_FUTURE; + return CommitInfo.emptyFluentFuture(); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohort.java index 7193dd053f..5b11d8679e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohort.java @@ -9,6 +9,8 @@ package org.opendaylight.controller.cluster.databroker.actors.dds; import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.yangtools.yang.common.Empty; /** * An {@link AbstractTransactionCommitCohort} for use with empty transactions. This relies on the fact that no backends @@ -30,19 +32,19 @@ final class EmptyTransactionCommitCohort extends AbstractTransactionCommitCohort } @Override - public ListenableFuture preCommit() { - return VOID_FUTURE; + public ListenableFuture preCommit() { + return EMPTY_FUTURE; } @Override - public ListenableFuture abort() { + public ListenableFuture abort() { complete(); - return VOID_FUTURE; + return EMPTY_FUTURE; } @Override - public ListenableFuture commit() { + public ListenableFuture commit() { complete(); - return VOID_FUTURE; + return CommitInfo.emptyFluentFuture(); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/VotingFuture.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/VotingFuture.java index f9fffea025..6433b6b587 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/VotingFuture.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/VotingFuture.java @@ -7,8 +7,10 @@ */ package org.opendaylight.controller.cluster.databroker.actors.dds; -import com.google.common.base.Preconditions; -import com.google.common.base.Verify; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Verify.verify; +import static java.util.Objects.requireNonNull; + import com.google.common.util.concurrent.AbstractFuture; import java.util.ArrayList; import java.util.Collection; @@ -44,11 +46,10 @@ class VotingFuture extends AbstractFuture { private volatile int neededVotes; VotingFuture(final T result, final int requiredVotes) { - Preconditions.checkArgument(requiredVotes > 0); + this.result = requireNonNull(result); + checkArgument(requiredVotes > 0); this.neededVotes = requiredVotes; - // null is okay to allow Void type - this.result = result; } void voteYes() { @@ -70,7 +71,7 @@ class VotingFuture extends AbstractFuture { private boolean castVote() { final int votes = VOTES_UPDATER.decrementAndGet(this); - Verify.verify(votes >= 0); + verify(votes >= 0); return votes == 0; } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractThreePhaseCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractThreePhaseCommitCohort.java index 7ef1cd4985..49b398f3fc 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractThreePhaseCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractThreePhaseCommitCohort.java @@ -10,7 +10,9 @@ package org.opendaylight.controller.cluster.datastore; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import java.util.List; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; +import org.opendaylight.yangtools.yang.common.Empty; import scala.concurrent.Future; /** @@ -19,8 +21,10 @@ import scala.concurrent.Future; * futures. */ public abstract class AbstractThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort { - protected static final ListenableFuture IMMEDIATE_VOID_SUCCESS = Futures.immediateFuture(null); - protected static final ListenableFuture IMMEDIATE_BOOLEAN_SUCCESS = Futures.immediateFuture(Boolean.TRUE); + protected static final @NonNull ListenableFuture IMMEDIATE_EMPTY_SUCCESS = + Futures.immediateFuture(Empty.value()); + protected static final @NonNull ListenableFuture IMMEDIATE_BOOLEAN_SUCCESS = + Futures.immediateFuture(Boolean.TRUE); abstract List> getCohortFutures(); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ChainedCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ChainedCommitCohort.java index 851eb8733a..ed82bd843a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ChainedCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ChainedCommitCohort.java @@ -14,6 +14,7 @@ import com.google.common.util.concurrent.FutureCallback; import java.util.Optional; import java.util.SortedSet; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateTip; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; @@ -57,7 +58,7 @@ final class ChainedCommitCohort extends ShardDataTreeCohort { } @Override - public void canCommit(final FutureCallback callback) { + public void canCommit(final FutureCallback callback) { delegate.canCommit(callback); } @@ -67,7 +68,7 @@ final class ChainedCommitCohort extends ShardDataTreeCohort { } @Override - public void abort(final FutureCallback callback) { + public void abort(final FutureCallback callback) { delegate.abort(callback); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java index da10ba05f2..de325279b7 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CohortEntry.java @@ -19,6 +19,7 @@ import java.util.SortedSet; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.ShardCommitCoordinator.CohortDecorator; import org.opendaylight.controller.cluster.datastore.modification.Modification; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; @@ -105,7 +106,7 @@ final class CohortEntry { } } - void canCommit(final FutureCallback callback) { + void canCommit(final FutureCallback callback) { cohort.canCommit(callback); } @@ -117,7 +118,7 @@ final class CohortEntry { cohort.commit(callback); } - void abort(final FutureCallback callback) { + void abort(final FutureCallback callback) { cohort.abort(callback); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CompositeDataTreeCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CompositeDataTreeCohort.java index f9f3022dab..2aab8260f3 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CompositeDataTreeCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/CompositeDataTreeCohort.java @@ -20,7 +20,6 @@ import akka.dispatch.Recover; import akka.pattern.Patterns; import akka.util.Timeout; import com.google.common.collect.Lists; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.AbstractMap.SimpleImmutableEntry; import java.util.ArrayList; import java.util.Collection; @@ -35,6 +34,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.CanCommit; import org.opendaylight.controller.cluster.datastore.DataTreeCohortActor.Success; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; @@ -137,7 +137,7 @@ class CompositeDataTreeCohort { state = State.IDLE; } - Optional> canCommit(final DataTreeCandidate tip) { + Optional> canCommit(final DataTreeCandidate tip) { if (LOG.isTraceEnabled()) { LOG.trace("{}: canCommit - candidate: {}", txId, tip); } else { @@ -165,7 +165,7 @@ class CompositeDataTreeCohort { return Optional.of(processResponses(futures, State.CAN_COMMIT_SENT, State.CAN_COMMIT_SUCCESSFUL)); } - Optional> preCommit() { + Optional> preCommit() { LOG.debug("{}: preCommit - successfulFromPrevious: {}", txId, successfulFromPrevious); if (successfulFromPrevious.isEmpty()) { @@ -179,7 +179,7 @@ class CompositeDataTreeCohort { return Optional.of(processResponses(futures, State.PRE_COMMIT_SENT, State.PRE_COMMIT_SUCCESSFUL)); } - Optional> commit() { + Optional> commit() { LOG.debug("{}: commit - successfulFromPrevious: {}", txId, successfulFromPrevious); if (successfulFromPrevious.isEmpty()) { changeStateFrom(State.PRE_COMMIT_SUCCESSFUL, State.COMMITED); @@ -220,10 +220,10 @@ class CompositeDataTreeCohort { return ret; } - private @NonNull CompletionStage processResponses(final List>> futures, + private @NonNull CompletionStage processResponses(final List>> futures, final State currentState, final State afterState) { LOG.debug("{}: processResponses - currentState: {}, afterState: {}", txId, currentState, afterState); - final CompletableFuture returnFuture = new CompletableFuture<>(); + final CompletableFuture returnFuture = new CompletableFuture<>(); Future> aggregateFuture = Futures.sequence(Lists.transform(futures, Entry::getValue), ExecutionContexts.global()); @@ -238,11 +238,8 @@ class CompositeDataTreeCohort { return returnFuture; } - // FB issues violation for passing null to CompletableFuture#complete but it is valid and necessary when the - // generic type is Void. - @SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION") private void processResponses(final Throwable failure, final Iterable results, - final State currentState, final State afterState, final CompletableFuture resultFuture) { + final State currentState, final State afterState, final CompletableFuture resultFuture) { if (failure != null) { successfulFromPrevious = List.of(); resultFuture.completeExceptionally(failure); @@ -276,7 +273,7 @@ class CompositeDataTreeCohort { } else { successfulFromPrevious = successful; changeStateFrom(currentState, afterState); - resultFuture.complete(null); + resultFuture.complete(Empty.value()); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DebugThreePhaseCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DebugThreePhaseCommitCohort.java index afb5773f43..4562ed13c5 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DebugThreePhaseCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DebugThreePhaseCommitCohort.java @@ -17,6 +17,8 @@ import com.google.common.util.concurrent.MoreExecutors; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.List; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.yangtools.yang.common.Empty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scala.concurrent.Future; @@ -67,17 +69,17 @@ class DebugThreePhaseCommitCohort extends AbstractThreePhaseCommitCohort } @Override - public ListenableFuture preCommit() { + public ListenableFuture preCommit() { return addFutureCallback(delegate.preCommit()); } @Override - public ListenableFuture commit() { + public ListenableFuture commit() { return addFutureCallback(delegate.commit()); } @Override - public ListenableFuture abort() { + public ListenableFuture abort() { return delegate.abort(); } @@ -89,6 +91,6 @@ class DebugThreePhaseCommitCohort extends AbstractThreePhaseCommitCohort @VisibleForTesting void setLogger(final Logger logger) { - this.log = logger; + log = logger; } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java index 85bee6833d..dfe0632244 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java @@ -42,6 +42,7 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; import org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; @@ -349,9 +350,9 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { final Ready ready = checkReady(); startAbort(); - ready.readyCohort.abort(new FutureCallback() { + ready.readyCohort.abort(new FutureCallback<>() { @Override - public void onSuccess(final Void result) { + public void onSuccess(final Empty result) { recordAndSendSuccess(envelope, now, new TransactionAbortSuccess(getIdentifier(), sequence)); finishAbort(); } @@ -377,9 +378,9 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { case READY: ready.stage = CommitStage.CAN_COMMIT_PENDING; LOG.debug("{}: Transaction {} initiating canCommit", persistenceId(), getIdentifier()); - checkReady().readyCohort.canCommit(new FutureCallback() { + checkReady().readyCohort.canCommit(new FutureCallback<>() { @Override - public void onSuccess(final Void result) { + public void onSuccess(final Empty result) { successfulCanCommit(envelope, now); } @@ -429,9 +430,9 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { case READY: ready.stage = CommitStage.CAN_COMMIT_PENDING; LOG.debug("{}: Transaction {} initiating direct canCommit", persistenceId(), getIdentifier()); - ready.readyCohort.canCommit(new FutureCallback() { + ready.readyCohort.canCommit(new FutureCallback<>() { @Override - public void onSuccess(final Void result) { + public void onSuccess(final Empty result) { successfulDirectCanCommit(envelope, now); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalThreePhaseCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalThreePhaseCommitCohort.java index 6b813c4578..091bfa01e4 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalThreePhaseCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalThreePhaseCommitCohort.java @@ -19,8 +19,10 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply; import org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction; import org.opendaylight.controller.cluster.datastore.utils.ActorUtils; +import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -122,19 +124,19 @@ class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort { } @Override - public final ListenableFuture preCommit() { + public final ListenableFuture preCommit() { // Intended no-op throw new UnsupportedOperationException(); } @Override - public final ListenableFuture abort() { + public final ListenableFuture abort() { // Intended no-op throw new UnsupportedOperationException(); } @Override - public final ListenableFuture commit() { + public final ListenableFuture commit() { // Intended no-op throw new UnsupportedOperationException(); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpDOMStoreThreePhaseCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpDOMStoreThreePhaseCommitCohort.java index 1f5f5bcf79..9b477320e5 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpDOMStoreThreePhaseCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpDOMStoreThreePhaseCommitCohort.java @@ -10,6 +10,8 @@ package org.opendaylight.controller.cluster.datastore; import com.google.common.util.concurrent.ListenableFuture; import java.util.Collections; import java.util.List; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.yangtools.yang.common.Empty; import scala.concurrent.Future; /** @@ -29,18 +31,18 @@ final class NoOpDOMStoreThreePhaseCommitCohort extends AbstractThreePhaseCommitC } @Override - public ListenableFuture preCommit() { - return IMMEDIATE_VOID_SUCCESS; + public ListenableFuture preCommit() { + return IMMEDIATE_EMPTY_SUCCESS; } @Override - public ListenableFuture abort() { - return IMMEDIATE_VOID_SUCCESS; + public ListenableFuture abort() { + return IMMEDIATE_EMPTY_SUCCESS; } @Override - public ListenableFuture commit() { - return IMMEDIATE_VOID_SUCCESS; + public ListenableFuture commit() { + return CommitInfo.emptyFluentFuture(); } @Override diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java index d18c0ba611..5177f7ed2b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardCommitCoordinator.java @@ -38,6 +38,7 @@ import org.opendaylight.controller.cluster.datastore.messages.ReadyTransactionRe import org.opendaylight.controller.cluster.datastore.messages.VersionedExternalizableMessage; import org.opendaylight.controller.cluster.datastore.utils.AbstractBatchedModificationsCursor; import org.opendaylight.yangtools.concepts.Identifier; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; import org.slf4j.Logger; @@ -236,9 +237,9 @@ final class ShardCommitCoordinator { } private void handleCanCommit(final CohortEntry cohortEntry) { - cohortEntry.canCommit(new FutureCallback() { + cohortEntry.canCommit(new FutureCallback<>() { @Override - public void onSuccess(final Void result) { + public void onSuccess(final Empty result) { log.debug("{}: canCommit for {}: success", name, cohortEntry.getTransactionId()); if (cohortEntry.isDoImmediateCommit()) { @@ -371,9 +372,9 @@ final class ShardCommitCoordinator { log.debug("{}: Aborting transaction {}", name, transactionID); final ActorRef self = shard.getSelf(); - cohortEntry.abort(new FutureCallback() { + cohortEntry.abort(new FutureCallback<>() { @Override - public void onSuccess(final Void result) { + public void onSuccess(final Empty result) { if (sender != null) { sender.tell(AbortTransactionReply.instance(cohortEntry.getClientVersion()).toSerializable(), self); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java index 2a0195d43b..c1b83923a6 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java @@ -76,6 +76,7 @@ import org.opendaylight.mdsal.common.api.TransactionCommitFailedException; import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener; import org.opendaylight.yangtools.concepts.Identifier; import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion; @@ -1034,9 +1035,9 @@ public class ShardDataTree extends ShardDataTreeTransactionParent { return; } - cohort.userPreCommit(candidate, new FutureCallback() { + cohort.userPreCommit(candidate, new FutureCallback<>() { @Override - public void onSuccess(final Void noop) { + public void onSuccess(final Empty result) { // Set the tip of the data tree. tip = verifyNotNull(candidate); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeCohort.java index f73e73323e..77b8db9209 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeCohort.java @@ -16,6 +16,7 @@ import java.util.Optional; import java.util.SortedSet; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.yangtools.concepts.Identifiable; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateTip; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; @@ -49,13 +50,13 @@ public abstract class ShardDataTreeCohort implements Identifiable callback); + public abstract void canCommit(FutureCallback callback); @VisibleForTesting public abstract void preCommit(FutureCallback callback); @VisibleForTesting - public abstract void abort(FutureCallback callback); + public abstract void abort(FutureCallback callback); @VisibleForTesting public abstract void commit(FutureCallback callback); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java index a65cef8228..07a6d686d0 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java @@ -19,6 +19,7 @@ import java.util.SortedSet; import java.util.concurrent.CompletionStage; import org.eclipse.jdt.annotation.Nullable; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateTip; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; @@ -85,7 +86,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { } @Override - public void canCommit(final FutureCallback newCallback) { + public void canCommit(final FutureCallback newCallback) { if (state == State.CAN_COMMIT_PENDING) { return; } @@ -115,9 +116,9 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { } @Override - public void abort(final FutureCallback abortCallback) { + public void abort(final FutureCallback abortCallback) { if (!dataTree.startAbort(this)) { - abortCallback.onSuccess(null); + abortCallback.onSuccess(Empty.value()); return; } @@ -126,7 +127,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { final Optional> maybeAborts = userCohorts.abort(); if (!maybeAborts.isPresent()) { - abortCallback.onSuccess(null); + abortCallback.onSuccess(Empty.value()); return; } @@ -134,7 +135,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { if (failure != null) { abortCallback.onFailure(failure); } else { - abortCallback.onSuccess(null); + abortCallback.onSuccess(Empty.value()); } }); } @@ -167,7 +168,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { } void successfulCanCommit() { - switchState(State.CAN_COMMIT_COMPLETE).onSuccess(null); + switchState(State.CAN_COMMIT_COMPLETE).onSuccess(Empty.value()); } void failedCanCommit(final Exception cause) { @@ -181,10 +182,10 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { * @param dataTreeCandidate {@link DataTreeCandidate} under consideration * @param futureCallback the callback to invoke on completion, which may be immediate or async. */ - void userPreCommit(final DataTreeCandidate dataTreeCandidate, final FutureCallback futureCallback) { + void userPreCommit(final DataTreeCandidate dataTreeCandidate, final FutureCallback futureCallback) { userCohorts.reset(); - final Optional> maybeCanCommitFuture = userCohorts.canCommit(dataTreeCandidate); + final Optional> maybeCanCommitFuture = userCohorts.canCommit(dataTreeCandidate); if (!maybeCanCommitFuture.isPresent()) { doUserPreCommit(futureCallback); return; @@ -199,10 +200,10 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { }); } - private void doUserPreCommit(final FutureCallback futureCallback) { - final Optional> maybePreCommitFuture = userCohorts.preCommit(); + private void doUserPreCommit(final FutureCallback futureCallback) { + final Optional> maybePreCommitFuture = userCohorts.preCommit(); if (!maybePreCommitFuture.isPresent()) { - futureCallback.onSuccess(null); + futureCallback.onSuccess(Empty.value()); return; } @@ -210,7 +211,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { if (failure != null) { futureCallback.onFailure(failure); } else { - futureCallback.onSuccess(null); + futureCallback.onSuccess(Empty.value()); } }); } @@ -233,7 +234,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { } void successfulCommit(final UnsignedLong journalIndex, final Runnable onComplete) { - final Optional> maybeCommitFuture = userCohorts.commit(); + final Optional> maybeCommitFuture = userCohorts.commit(); if (!maybeCommitFuture.isPresent()) { finishSuccessfulCommit(journalIndex, onComplete); return; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SingleCommitCohortProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SingleCommitCohortProxy.java index 5e8a95405b..c099c45cdb 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SingleCommitCohortProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SingleCommitCohortProxy.java @@ -12,11 +12,12 @@ import static java.util.Objects.requireNonNull; import akka.dispatch.OnComplete; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; -import java.util.Arrays; import java.util.List; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.utils.ActorUtils; +import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; +import org.opendaylight.yangtools.yang.common.Empty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scala.concurrent.Future; @@ -37,8 +38,8 @@ class SingleCommitCohortProxy extends AbstractThreePhaseCommitCohort { private volatile DOMStoreThreePhaseCommitCohort delegateCohort = NoOpDOMStoreThreePhaseCommitCohort.INSTANCE; private final OperationCallback.Reference operationCallbackRef; - SingleCommitCohortProxy(ActorUtils actorUtils, Future cohortFuture, TransactionIdentifier transactionId, - OperationCallback.Reference operationCallbackRef) { + SingleCommitCohortProxy(final ActorUtils actorUtils, final Future cohortFuture, + final TransactionIdentifier transactionId, final OperationCallback.Reference operationCallbackRef) { this.actorUtils = actorUtils; this.cohortFuture = cohortFuture; this.transactionId = requireNonNull(transactionId); @@ -51,9 +52,9 @@ class SingleCommitCohortProxy extends AbstractThreePhaseCommitCohort { final SettableFuture returnFuture = SettableFuture.create(); - cohortFuture.onComplete(new OnComplete() { + cohortFuture.onComplete(new OnComplete<>() { @Override - public void onComplete(Throwable failure, Object cohortResponse) { + public void onComplete(final Throwable failure, final Object cohortResponse) { if (failure != null) { operationCallbackRef.get().failure(); returnFuture.setException(failure); @@ -77,22 +78,22 @@ class SingleCommitCohortProxy extends AbstractThreePhaseCommitCohort { } @Override - public ListenableFuture preCommit() { + public ListenableFuture preCommit() { return delegateCohort.preCommit(); } @Override - public ListenableFuture abort() { + public ListenableFuture abort() { return delegateCohort.abort(); } @Override - public ListenableFuture commit() { + public ListenableFuture commit() { return delegateCohort.commit(); } @Override List> getCohortFutures() { - return Arrays.asList(cohortFuture); + return List.of(cohortFuture); } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java index cd79ad6f19..cdd57df000 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java @@ -30,6 +30,8 @@ import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransacti import org.opendaylight.controller.cluster.datastore.messages.CommitTransaction; import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply; import org.opendaylight.controller.cluster.datastore.utils.ActorUtils; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.yangtools.yang.common.Empty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scala.concurrent.Future; @@ -67,7 +69,7 @@ public class ThreePhaseCommitCohortProxy extends AbstractThreePhaseCommitCohort< private final ActorUtils actorUtils; private final List cohorts; - private final SettableFuture cohortsResolvedFuture = SettableFuture.create(); + private final SettableFuture cohortsResolvedFuture = SettableFuture.create(); private final TransactionIdentifier transactionId; private volatile OperationCallback commitOperationCallback; @@ -78,11 +80,11 @@ public class ThreePhaseCommitCohortProxy extends AbstractThreePhaseCommitCohort< this.transactionId = requireNonNull(transactionId); if (cohorts.isEmpty()) { - cohortsResolvedFuture.set(null); + cohortsResolvedFuture.set(Empty.value()); } } - private ListenableFuture resolveCohorts() { + private ListenableFuture resolveCohorts() { if (cohortsResolvedFuture.isDone()) { return cohortsResolvedFuture; } @@ -104,7 +106,7 @@ public class ThreePhaseCommitCohortProxy extends AbstractThreePhaseCommitCohort< info.setResolvedActor(actor); if (done) { LOG.debug("Tx {}: successfully resolved all cohort actors", transactionId); - cohortsResolvedFuture.set(null); + cohortsResolvedFuture.set(Empty.value()); } } } @@ -127,9 +129,9 @@ public class ThreePhaseCommitCohortProxy extends AbstractThreePhaseCommitCohort< // extracted from ReadyTransactionReply messages by the Futures that were obtained earlier // and passed to us from upstream processing. If any one fails then we'll fail canCommit. - Futures.addCallback(resolveCohorts(), new FutureCallback() { + Futures.addCallback(resolveCohorts(), new FutureCallback<>() { @Override - public void onSuccess(final Void notUsed) { + public void onSuccess(final Empty result) { finishCanCommit(returnFuture); } @@ -226,35 +228,34 @@ public class ThreePhaseCommitCohortProxy extends AbstractThreePhaseCommitCohort< } @Override - public ListenableFuture preCommit() { - // We don't need to do anything here - preCommit is done atomically with the commit phase - // by the shard. - return IMMEDIATE_VOID_SUCCESS; + public ListenableFuture preCommit() { + // We don't need to do anything here - preCommit is done atomically with the commit phase by the shard. + return IMMEDIATE_EMPTY_SUCCESS; } @Override - public ListenableFuture abort() { + public ListenableFuture abort() { // Note - we pass false for propagateException. In the front-end data broker, this method // is called when one of the 3 phases fails with an exception. We'd rather have that // original exception propagated to the client. If our abort fails and we propagate the // exception then that exception will supersede and suppress the original exception. But // it's the original exception that is the root cause and of more interest to the client. - return voidOperation("abort", ABORT_MESSAGE_SUPPLIER, - AbortTransactionReply.class, false, OperationCallback.NO_OP_CALLBACK); + return operation("abort", Empty.value(), ABORT_MESSAGE_SUPPLIER, AbortTransactionReply.class, false, + OperationCallback.NO_OP_CALLBACK); } @Override - public ListenableFuture commit() { + public ListenableFuture commit() { OperationCallback operationCallback = commitOperationCallback != null ? commitOperationCallback : OperationCallback.NO_OP_CALLBACK; - return voidOperation("commit", COMMIT_MESSAGE_SUPPLIER, - CommitTransactionReply.class, true, operationCallback); + return operation("commit", CommitInfo.empty(), COMMIT_MESSAGE_SUPPLIER, CommitTransactionReply.class, true, + operationCallback); } @SuppressWarnings("checkstyle:IllegalCatch") - private static boolean successfulFuture(final ListenableFuture future) { + private static boolean successfulFuture(final ListenableFuture future) { if (!future.isDone()) { return false; } @@ -267,26 +268,26 @@ public class ThreePhaseCommitCohortProxy extends AbstractThreePhaseCommitCohort< } } - private ListenableFuture voidOperation(final String operationName, + private ListenableFuture operation(final String operationName, final T futureValue, final MessageSupplier messageSupplier, final Class expectedResponseClass, final boolean propagateException, final OperationCallback callback) { LOG.debug("Tx {} {}", transactionId, operationName); - final SettableFuture returnFuture = SettableFuture.create(); + final SettableFuture returnFuture = SettableFuture.create(); // The cohort actor list should already be built at this point by the canCommit phase but, // if not for some reason, we'll try to build it here. - ListenableFuture future = resolveCohorts(); + ListenableFuture future = resolveCohorts(); if (successfulFuture(future)) { - finishVoidOperation(operationName, messageSupplier, expectedResponseClass, propagateException, - returnFuture, callback); + finishOperation(operationName, messageSupplier, expectedResponseClass, propagateException, returnFuture, + futureValue, callback); } else { - Futures.addCallback(future, new FutureCallback() { + Futures.addCallback(future, new FutureCallback<>() { @Override - public void onSuccess(final Void notUsed) { - finishVoidOperation(operationName, messageSupplier, expectedResponseClass, - propagateException, returnFuture, callback); + public void onSuccess(final Empty result) { + finishOperation(operationName, messageSupplier, expectedResponseClass, propagateException, + returnFuture, futureValue, callback); } @Override @@ -296,7 +297,7 @@ public class ThreePhaseCommitCohortProxy extends AbstractThreePhaseCommitCohort< if (propagateException) { returnFuture.setException(failure); } else { - returnFuture.set(null); + returnFuture.set(futureValue); } } }, MoreExecutors.directExecutor()); @@ -305,9 +306,10 @@ public class ThreePhaseCommitCohortProxy extends AbstractThreePhaseCommitCohort< return returnFuture; } - private void finishVoidOperation(final String operationName, final MessageSupplier messageSupplier, + private void finishOperation(final String operationName, final MessageSupplier messageSupplier, final Class expectedResponseClass, final boolean propagateException, - final SettableFuture returnFuture, final OperationCallback callback) { + final SettableFuture returnFuture, final T futureValue, + final OperationCallback callback) { LOG.debug("Tx {} finish {}", transactionId, operationName); callback.resume(); @@ -338,14 +340,14 @@ public class ThreePhaseCommitCohortProxy extends AbstractThreePhaseCommitCohort< // Since the caller doesn't want us to propagate the exception we'll also // not log it normally. But it's usually not good to totally silence // exceptions so we'll log it to debug level. - returnFuture.set(null); + returnFuture.set(futureValue); } callback.failure(); } else { LOG.debug("Tx {}: {} succeeded", transactionId, operationName); - returnFuture.set(null); + returnFuture.set(futureValue); callback.success(); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransactionTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransactionTest.java index 8b5629d7ad..c01d84e7f8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransactionTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractProxyTransactionTest.java @@ -60,6 +60,7 @@ import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifie import org.opendaylight.controller.cluster.access.concepts.RequestEnvelope; import org.opendaylight.controller.cluster.access.concepts.Response; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; @@ -232,11 +233,11 @@ public abstract class AbstractProxyTransactionTest> void testRequestResponse(final Consumer> consumer, + protected > void testRequestResponse(final Consumer> consumer, final Class expectedRequest, final BiFunction> replySupplier) { final TransactionTester tester = getTester(); - final VotingFuture future = mock(VotingFuture.class); + final VotingFuture future = mock(VotingFuture.class); transaction.seal(); consumer.accept(future); final TransactionRequest req = tester.expectTransactionRequest(expectedRequest); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java index 8b58e15877..409dcb58a1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionCommitCohortTest.java @@ -48,6 +48,8 @@ import org.opendaylight.controller.cluster.access.commands.TransactionPreCommitR import org.opendaylight.controller.cluster.access.commands.TransactionPreCommitSuccess; import org.opendaylight.controller.cluster.access.concepts.RequestSuccess; import org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.yangtools.yang.common.Empty; @RunWith(MockitoJUnitRunner.StrictStubs.class) public class ClientTransactionCommitCohortTest { @@ -97,7 +99,7 @@ public class ClientTransactionCommitCohortTest { @Test public void testPreCommit() throws Exception { testOpSuccess(ClientTransactionCommitCohort::preCommit, this::expectPreCommit, this::replyPreCommitSuccess, - null); + Empty.value()); } @Test @@ -107,7 +109,8 @@ public class ClientTransactionCommitCohortTest { @Test public void testCommit() throws Exception { - testOpSuccess(ClientTransactionCommitCohort::commit, this::expectCommit, this::replyCommitSuccess, null); + testOpSuccess(ClientTransactionCommitCohort::commit, this::expectCommit, this::replyCommitSuccess, + CommitInfo.empty()); } @Test @@ -117,7 +120,7 @@ public class ClientTransactionCommitCohortTest { @Test public void testAbort() throws Exception { - testOpSuccess(ClientTransactionCommitCohort::abort, this::expectAbort, this::replyAbortSuccess, null); + testOpSuccess(ClientTransactionCommitCohort::abort, this::expectAbort, this::replyAbortSuccess, Empty.value()); } @Test diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionTest.java index 3fc3c9c325..f8c469e3d2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/ClientTransactionTest.java @@ -23,7 +23,9 @@ import org.junit.Test; import org.mockito.Mock; import org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest; import org.opendaylight.controller.cluster.access.commands.TransactionCommitSuccess; +import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; @@ -99,8 +101,8 @@ public class ClientTransactionTest extends AbstractClientHandleTest preCommit = cohort.preCommit(); - assertNull(getWithTimeout(preCommit)); + final ListenableFuture preCommit = cohort.preCommit(); + assertNotNull(getWithTimeout(preCommit)); } @Test public void testAbort() throws Exception { - final ListenableFuture abort = cohort.abort(); + final ListenableFuture abort = cohort.abort(); verify(history).onTransactionComplete(transaction.getTransaction().getIdentifier()); - assertNull(getWithTimeout(abort)); + assertNotNull(getWithTimeout(abort)); } @Test public void testCommit() throws Exception { - final ListenableFuture commit = cohort.commit(); + final ListenableFuture commit = cohort.commit(); verify(history).onTransactionComplete(transaction.getTransaction().getIdentifier()); - assertNull(getWithTimeout(commit)); + assertNotNull(getWithTimeout(commit)); } private static TransactionTester createTransactionTester(final TestProbe backendProbe, diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohortTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohortTest.java index 60408ae149..fbfdc0a924 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohortTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/EmptyTransactionCommitCohortTest.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.cluster.databroker.actors.dds; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.verify; import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.TRANSACTION_ID; import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.getWithTimeout; @@ -40,22 +40,21 @@ public class EmptyTransactionCommitCohortTest { @Test public void testPreCommit() throws Exception { - final ListenableFuture preCommit = cohort.preCommit(); - assertNull(getWithTimeout(preCommit)); + assertNotNull(getWithTimeout(cohort.preCommit())); } @Test public void testAbort() throws Exception { - final ListenableFuture abort = cohort.abort(); + final ListenableFuture abort = cohort.abort(); verify(history).onTransactionComplete(TRANSACTION_ID); - assertNull(getWithTimeout(abort)); + assertNotNull(getWithTimeout(abort)); } @Test public void testCommit() throws Exception { - final ListenableFuture commit = cohort.commit(); + final ListenableFuture commit = cohort.commit(); verify(history).onTransactionComplete(TRANSACTION_ID); - assertNull(getWithTimeout(commit)); + assertNotNull(getWithTimeout(commit)); } } \ No newline at end of file diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/TestUtils.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/TestUtils.java index 092d262ae8..f4e0be9c3d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/TestUtils.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/actors/dds/TestUtils.java @@ -7,9 +7,10 @@ */ package org.opendaylight.controller.cluster.databroker.actors.dds; +import static org.junit.Assert.assertEquals; + import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import org.junit.Assert; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier; import org.opendaylight.controller.cluster.access.concepts.FrontendType; @@ -45,8 +46,8 @@ final class TestUtils { * @param type * @throws Exception exception */ - static void assertFutureEquals(final T expected, final Future actual) throws Exception { - Assert.assertEquals(expected, getWithTimeout(actual)); + static void assertFutureEquals(final T expected, final Future actual) throws Exception { + assertEquals(expected, getWithTimeout(actual)); } /** diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java index 9e91ce173c..a39b81e1ca 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java @@ -66,6 +66,7 @@ import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal; import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore; import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; @@ -446,7 +447,7 @@ public abstract class AbstractShardTest extends AbstractActorTest { public static class CapturingShardDataTreeCohort extends ShardDataTreeCohort { private volatile ShardDataTreeCohort delegate; - private FutureCallback canCommit; + private FutureCallback canCommit; private FutureCallback preCommit; private FutureCallback commit; @@ -454,7 +455,7 @@ public abstract class AbstractShardTest extends AbstractActorTest { this.delegate = delegate; } - public FutureCallback getCanCommit() { + public FutureCallback getCanCommit() { assertNotNull("canCommit was not invoked", canCommit); return canCommit; } @@ -485,7 +486,7 @@ public abstract class AbstractShardTest extends AbstractActorTest { } @Override - public void canCommit(final FutureCallback callback) { + public void canCommit(final FutureCallback callback) { canCommit = mockFutureCallback(callback); delegate.canCommit(canCommit); } @@ -519,7 +520,7 @@ public abstract class AbstractShardTest extends AbstractActorTest { } @Override - public void abort(final FutureCallback callback) { + public void abort(final FutureCallback callback) { delegate.abort(callback); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMocking.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMocking.java index b05fa9fab4..234c69e011 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMocking.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMocking.java @@ -23,6 +23,7 @@ import org.mockito.InOrder; import org.mockito.invocation.InvocationOnMock; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.persisted.CommitTransactionPayload; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; public final class ShardDataTreeMocking { @@ -37,18 +38,18 @@ public final class ShardDataTreeMocking { } public static ShardDataTreeCohort immediateCanCommit(final ShardDataTreeCohort cohort) { - final FutureCallback callback = mockCallback(); - doNothing().when(callback).onSuccess(null); + final FutureCallback callback = mockCallback(); + doNothing().when(callback).onSuccess(Empty.value()); cohort.canCommit(callback); - verify(callback).onSuccess(null); + verify(callback).onSuccess(Empty.value()); verifyNoMoreInteractions(callback); return cohort; } - public static FutureCallback coordinatedCanCommit(final ShardDataTreeCohort cohort) { - final FutureCallback callback = mockCallback(); - doNothing().when(callback).onSuccess(null); + public static FutureCallback coordinatedCanCommit(final ShardDataTreeCohort cohort) { + final FutureCallback callback = mockCallback(); + doNothing().when(callback).onSuccess(Empty.value()); doNothing().when(callback).onFailure(any(Throwable.class)); cohort.canCommit(callback); return callback; @@ -102,11 +103,11 @@ public final class ShardDataTreeMocking { }).when(preCommitCallback).onSuccess(any(DataTreeCandidate.class)); doNothing().when(preCommitCallback).onFailure(any(Throwable.class)); - final FutureCallback canCommit = mockCallback(); + final FutureCallback canCommit = mockCallback(); doAnswer(invocation -> { cohort.preCommit(preCommitCallback); return null; - }).when(canCommit).onSuccess(null); + }).when(canCommit).onSuccess(Empty.value()); doNothing().when(canCommit).onFailure(any(Throwable.class)); cohort.canCommit(canCommit); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTest.java index 099f514e66..ce07093632 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTest.java @@ -57,6 +57,7 @@ import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; import org.opendaylight.controller.md.cluster.datastore.model.PeopleModel; import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.common.Uint64; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; @@ -244,21 +245,21 @@ public class ShardDataTreeTest extends AbstractTest { final ShardDataTreeCohort cohort4 = newShardDataTreeCohort(snapshot -> snapshot.write(carPath, carNode)); immediateCanCommit(cohort1); - final FutureCallback canCommitCallback2 = coordinatedCanCommit(cohort2); - final FutureCallback canCommitCallback3 = coordinatedCanCommit(cohort3); - final FutureCallback canCommitCallback4 = coordinatedCanCommit(cohort4); + final FutureCallback canCommitCallback2 = coordinatedCanCommit(cohort2); + final FutureCallback canCommitCallback3 = coordinatedCanCommit(cohort3); + final FutureCallback canCommitCallback4 = coordinatedCanCommit(cohort4); final FutureCallback preCommitCallback1 = coordinatedPreCommit(cohort1); verify(preCommitCallback1).onSuccess(cohort1.getCandidate()); - verify(canCommitCallback2).onSuccess(null); + verify(canCommitCallback2).onSuccess(Empty.value()); final FutureCallback preCommitCallback2 = coordinatedPreCommit(cohort2); verify(preCommitCallback2).onSuccess(cohort2.getCandidate()); - verify(canCommitCallback3).onSuccess(null); + verify(canCommitCallback3).onSuccess(Empty.value()); final FutureCallback preCommitCallback3 = coordinatedPreCommit(cohort3); verify(preCommitCallback3).onSuccess(cohort3.getCandidate()); - verify(canCommitCallback4).onSuccess(null); + verify(canCommitCallback4).onSuccess(Empty.value()); final FutureCallback preCommitCallback4 = coordinatedPreCommit(cohort4); verify(preCommitCallback4).onSuccess(cohort4.getCandidate()); @@ -293,7 +294,7 @@ public class ShardDataTreeTest extends AbstractTest { final ShardDataTreeCohort cohort5 = newShardDataTreeCohort(snapshot -> snapshot.merge(CarsModel.BASE_PATH, CarsModel.emptyContainer())); - final FutureCallback canCommitCallback5 = coordinatedCanCommit(cohort5); + final FutureCallback canCommitCallback5 = coordinatedCanCommit(cohort5); // The payload instance doesn't matter - it just needs to be of type CommitTransactionPayload. CommitTransactionPayload mockPayload = CommitTransactionPayload.create(nextTransactionId(), @@ -309,7 +310,7 @@ public class ShardDataTreeTest extends AbstractTest { inOrder.verify(commitCallback3).onSuccess(any(UnsignedLong.class)); inOrder.verify(commitCallback4).onSuccess(any(UnsignedLong.class)); - verify(canCommitCallback5).onSuccess(null); + verify(canCommitCallback5).onSuccess(Empty.value()); final DataTreeSnapshot snapshot = shardDataTree.newReadOnlyTransaction(nextTransactionId()).getSnapshot(); @@ -418,10 +419,10 @@ public class ShardDataTreeTest extends AbstractTest { coordinatedPreCommit(cohort2); coordinatedPreCommit(cohort3); - FutureCallback mockAbortCallback = mock(FutureCallback.class); - doNothing().when(mockAbortCallback).onSuccess(null); + FutureCallback mockAbortCallback = mock(FutureCallback.class); + doNothing().when(mockAbortCallback).onSuccess(Empty.value()); cohort2.abort(mockAbortCallback); - verify(mockAbortCallback).onSuccess(null); + verify(mockAbortCallback).onSuccess(Empty.value()); coordinatedPreCommit(cohort4); coordinatedCommit(cohort1); @@ -466,15 +467,15 @@ public class ShardDataTreeTest extends AbstractTest { snapshot.write(PeopleModel.BASE_PATH, peopleNode)); immediateCanCommit(cohort1); - FutureCallback canCommitCallback2 = coordinatedCanCommit(cohort2); + FutureCallback canCommitCallback2 = coordinatedCanCommit(cohort2); coordinatedPreCommit(cohort1); - verify(canCommitCallback2).onSuccess(null); + verify(canCommitCallback2).onSuccess(Empty.value()); - FutureCallback mockAbortCallback = mock(FutureCallback.class); - doNothing().when(mockAbortCallback).onSuccess(null); + FutureCallback mockAbortCallback = mock(FutureCallback.class); + doNothing().when(mockAbortCallback).onSuccess(Empty.value()); cohort1.abort(mockAbortCallback); - verify(mockAbortCallback).onSuccess(null); + verify(mockAbortCallback).onSuccess(Empty.value()); FutureCallback preCommitCallback2 = coordinatedPreCommit(cohort2); verify(preCommitCallback2).onFailure(any(Throwable.class)); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohortTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohortTest.java index 9214f1fe5a..99b02f1cdd 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohortTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohortTest.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.opendaylight.yangtools.yang.common.Empty; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException; import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; @@ -75,10 +76,10 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { }).when(mockShardDataTree).startCanCommit(cohort); @SuppressWarnings("unchecked") - final FutureCallback callback = mock(FutureCallback.class); + final FutureCallback callback = mock(FutureCallback.class); cohort.canCommit(callback); - verify(callback).onSuccess(null); + verify(callback).onSuccess(Empty.value()); verifyNoMoreInteractions(callback); } @@ -89,7 +90,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { }).when(mockShardDataTree).startCanCommit(cohort); @SuppressWarnings("unchecked") - final FutureCallback callback = mock(FutureCallback.class); + final FutureCallback callback = mock(FutureCallback.class); cohort.canCommit(callback); verify(callback).onFailure(cause); @@ -209,11 +210,11 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest { } private static Future abort(final ShardDataTreeCohort cohort) { - final CompletableFuture f = new CompletableFuture<>(); - cohort.abort(new FutureCallback() { + final CompletableFuture f = new CompletableFuture<>(); + cohort.abort(new FutureCallback<>() { @Override - public void onSuccess(final Void result) { - f.complete(null); + public void onSuccess(final Empty result) { + f.complete(result); } @Override -- 2.36.6