From 5e7cf2452ef634dc934a3ea5a2dd95059fbab68c Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Tue, 16 May 2017 17:51:25 +0200 Subject: [PATCH] sal-distributed-datastore: use lambdas This series of patches uses lambdas instead of anonymous classes for functional interfaces when possible. Lambdas are replaced with method references when appropriate. Change-Id: Ib397cbe0e0179f2f47ef10f13301b604dc6db88b Signed-off-by: Stephen Kitt --- .../dds/AbstractDataStoreClientActor.java | 2 +- .../actors/dds/LocalProxyTransaction.java | 5 +- .../datastore/AbstractFrontendHistory.java | 10 ++-- .../datastore/CompositeDataTreeCohort.java | 2 +- .../RemoteTransactionContextSupport.java | 2 +- .../EntityOwnershipListenerSupport.java | 4 +- .../sharding/ShardedDataTreeActor.java | 12 ++-- .../ConcurrentDOMDataBrokerTest.java | 13 ++--- .../cluster/datastore/AbstractShardTest.java | 13 ++--- ...taChangeListenerRegistrationProxyTest.java | 32 ++--------- .../DataTreeChangeListenerProxyTest.java | 32 ++--------- .../DistributedDataStoreIntegrationTest.java | 56 +++++++++---------- .../datastore/ShardDataTreeMocking.java | 24 ++------ .../cluster/datastore/ShardTest.java | 26 ++++----- .../datastore/TransactionChainProxyTest.java | 38 ++++++------- .../shardmanager/ShardManagerTest.java | 2 +- 16 files changed, 92 insertions(+), 181 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractDataStoreClientActor.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractDataStoreClientActor.java index 5e7fade8eb..1143bab10c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractDataStoreClientActor.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/AbstractDataStoreClientActor.java @@ -24,7 +24,7 @@ import scala.concurrent.Await; import scala.concurrent.duration.Duration; public abstract class AbstractDataStoreClientActor extends AbstractClientActor { - private static final Function1 GET_CLIENT_FACTORY = ExplicitAsk.toScala(t -> new GetClientRequest(t)); + private static final Function1 GET_CLIENT_FACTORY = ExplicitAsk.toScala(GetClientRequest::new); private final ActorContext actorContext; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalProxyTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalProxyTransaction.java index b228293703..00b29e4c35 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalProxyTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/LocalProxyTransaction.java @@ -87,9 +87,8 @@ abstract class LocalProxyTransaction extends AbstractProxyTransaction { @Override final void doAbort() { - sendAbort(new AbortLocalTransactionRequest(identifier, localActor()), response -> { - LOG.debug("Transaction {} abort completed with {}", identifier, response); - }); + sendAbort(new AbortLocalTransactionRequest(identifier, localActor()), + response -> LOG.debug("Transaction {} abort completed with {}", identifier, response)); } @Override diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java index 6ca58888d3..f6dee7ce7b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java @@ -156,16 +156,14 @@ abstract class AbstractFrontendHistory implements Identifiable { - envelope.sendSuccess(new LocalHistorySuccess(getIdentifier(), sequence), readTime() - now); - }); + tree.closeTransactionChain(getIdentifier(), + () -> envelope.sendSuccess(new LocalHistorySuccess(getIdentifier(), sequence), readTime() - now)); } void purge(final long sequence, final RequestEnvelope envelope, final long now) { LOG.debug("{}: purging history {}", persistenceId(), getIdentifier()); - tree.purgeTransactionChain(getIdentifier(), () -> { - envelope.sendSuccess(new LocalHistorySuccess(getIdentifier(), sequence), readTime() - now); - }); + tree.purgeTransactionChain(getIdentifier(), + () -> envelope.sendSuccess(new LocalHistorySuccess(getIdentifier(), sequence), readTime() - now)); } private FrontendTransaction createTransaction(final TransactionRequest request, final TransactionIdentifier id) 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 338ae64534..e8c0567e06 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 @@ -224,7 +224,7 @@ class CompositeDataTreeCohort { final Iterable results; try { - results = Await.result(Futures.sequence(Lists.transform(futures, e -> e.getValue()), + results = Await.result(Futures.sequence(Lists.transform(futures, Entry::getValue), ExecutionContexts.global()), timeout.duration()); } catch (TimeoutException e) { successfulFromPrevious = null; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java index 1e0d1279e3..5bafef8a85 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java @@ -187,7 +187,7 @@ final class RemoteTransactionContextSupport { getActorContext().getActorSystem().scheduler().scheduleOnce( FiniteDuration.create(scheduleInterval, TimeUnit.MILLISECONDS), - () -> tryFindPrimaryShard(), getActorContext().getClientDispatcher()); + this::tryFindPrimaryShard, getActorContext().getClientDispatcher()); return; } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipListenerSupport.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipListenerSupport.java index d2b4dd3077..84a58d9594 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipListenerSupport.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipListenerSupport.java @@ -119,8 +119,8 @@ class EntityOwnershipListenerSupport extends EntityOwnershipChangePublisher { try { Collection listeners = entityTypeListenerMap.get(entity.getType()); if (!listeners.isEmpty()) { - notifyListeners(entity, wasOwner, isOwner, hasOwner, listeners.stream().map( - listener -> listenerActorMap.get(listener)).collect(Collectors.toList())); + notifyListeners(entity, wasOwner, isOwner, hasOwner, + listeners.stream().map(listenerActorMap::get).collect(Collectors.toList())); } } finally { listenerLock.readLock().unlock(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java index 671fbb8965..224ca0b3d0 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/sharding/ShardedDataTreeActor.java @@ -246,12 +246,12 @@ public class ShardedDataTreeActor extends AbstractUntypedPersistentActor { final CompletableFuture combinedFuture = CompletableFuture.allOf( futures.toArray(new CompletableFuture[futures.size()])); - combinedFuture.thenRun(() -> { - sender.tell(new Status.Success(null), noSender()); - }).exceptionally(throwable -> { - sender.tell(new Status.Failure(throwable), self()); - return null; - }); + combinedFuture + .thenRun(() -> sender.tell(new Success(null), noSender())) + .exceptionally(throwable -> { + sender.tell(new Status.Failure(throwable), self()); + return null; + }); } private void onNotifyProducerCreated(final NotifyProducerCreated message) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBrokerTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBrokerTest.java index 8aca70df01..bef18ffe20 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBrokerTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBrokerTest.java @@ -116,14 +116,11 @@ public class ConcurrentDOMDataBrokerTest { Answer> asyncCanCommit = invocation -> { final SettableFuture future = SettableFuture.create(); if (doAsync) { - new Thread() { - @Override - public void run() { - Uninterruptibles.awaitUninterruptibly(asyncCanCommitContinue, - 10, TimeUnit.SECONDS); - future.set(true); - } - }.start(); + new Thread(() -> { + Uninterruptibles.awaitUninterruptibly(asyncCanCommitContinue, + 10, TimeUnit.SECONDS); + future.set(true); + }).start(); } else { future.set(true); } 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 3a676586eb..4e29d4d5bb 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 @@ -206,9 +206,8 @@ public abstract class AbstractShardTest extends AbstractActorTest { return null; }).when(mock).validate(any(DataTreeModification.class)); - doAnswer(invocation -> { - return actual.prepare(invocation.getArgumentAt(0, DataTreeModification.class)); - }).when(mock).prepare(any(DataTreeModification.class)); + doAnswer(invocation -> actual.prepare(invocation.getArgumentAt(0, DataTreeModification.class))).when( + mock).prepare(any(DataTreeModification.class)); doAnswer(invocation -> { actual.commit(invocation.getArgumentAt(0, DataTreeCandidate.class)); @@ -220,13 +219,9 @@ public abstract class AbstractShardTest extends AbstractActorTest { return null; }).when(mock).setSchemaContext(any(SchemaContext.class)); - doAnswer(invocation -> { - return actual.takeSnapshot(); - }).when(mock).takeSnapshot(); + doAnswer(invocation -> actual.takeSnapshot()).when(mock).takeSnapshot(); - doAnswer(invocation -> { - return actual.getRootPath(); - }).when(mock).getRootPath(); + doAnswer(invocation -> actual.getRootPath()).when(mock).getRootPath(); return mock; } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationProxyTest.java index 64f088f136..fdebed167e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationProxyTest.java @@ -81,13 +81,7 @@ public class DataChangeListenerRegistrationProxyTest extends AbstractActorTest { final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE; - new Thread() { - @Override - public void run() { - proxy.init(path, scope); - } - - }.start(); + new Thread(() -> proxy.init(path, scope)).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); @@ -141,13 +135,7 @@ public class DataChangeListenerRegistrationProxyTest extends AbstractActorTest { final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE; - new Thread() { - @Override - public void run() { - proxy.init(path, scope); - } - - }.start(); + new Thread(() -> proxy.init(path, scope)).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); @@ -198,13 +186,7 @@ public class DataChangeListenerRegistrationProxyTest extends AbstractActorTest { final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE; - new Thread() { - @Override - public void run() { - proxy.init(path, scope); - } - - }.start(); + new Thread(() -> proxy.init(path, scope)).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); @@ -231,13 +213,7 @@ public class DataChangeListenerRegistrationProxyTest extends AbstractActorTest { final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME); final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE; - new Thread() { - @Override - public void run() { - proxy.init(path, scope); - } - - }.start(); + new Thread(() -> proxy.init(path, scope)).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java index 927f929797..c66c3cd0ae 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java @@ -60,13 +60,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( actorContext, mockListener, path); - new Thread() { - @Override - public void run() { - proxy.init("shard-1"); - } - - }.start(); + new Thread(() -> proxy.init("shard-1")).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); @@ -119,13 +113,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>(actorContext, mockClusteredListener, path); - new Thread() { - @Override - public void run() { - proxy.init("shard-1"); - } - - }.start(); + new Thread(() -> proxy.init("shard-1")).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); @@ -154,13 +142,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( actorContext, mockListener, path); - new Thread() { - @Override - public void run() { - proxy.init("shard-1"); - } - - }.start(); + new Thread(() -> proxy.init("shard-1")).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); @@ -186,13 +168,7 @@ public class DataTreeChangeListenerProxyTest extends AbstractActorTest { final DataTreeChangeListenerProxy proxy = new DataTreeChangeListenerProxy<>( actorContext, mockListener, path); - new Thread() { - @Override - public void run() { - proxy.init("shard-1"); - } - - }.start(); + new Thread(() -> proxy.init("shard-1")).start(); FiniteDuration timeout = duration("5 seconds"); FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java index 2cd2b29c8d..7773556eca 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java @@ -363,28 +363,25 @@ public class DistributedDataStoreIntegrationTest { final AtomicReference txCohort = new AtomicReference<>(); final AtomicReference caughtEx = new AtomicReference<>(); final CountDownLatch txReady = new CountDownLatch(1); - final Thread txThread = new Thread() { - @Override - public void run() { - try { - writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); + final Thread txThread = new Thread(() -> { + try { + writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - writeTx.merge(TestModel.OUTER_LIST_PATH, - ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); + writeTx.merge(TestModel.OUTER_LIST_PATH, + ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build()); - writeTx.write(listEntryPath, - ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)); + writeTx.write(listEntryPath, + ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)); - writeTx.delete(listEntryPath); + writeTx.delete(listEntryPath); - txCohort.set(writeTx.ready()); - } catch (Exception e) { - caughtEx.set(e); - } finally { - txReady.countDown(); - } + txCohort.set(writeTx.ready()); + } catch (Exception e) { + caughtEx.set(e); + } finally { + txReady.countDown(); } - }; + }); txThread.start(); @@ -460,23 +457,20 @@ public class DistributedDataStoreIntegrationTest { txReadFuture = new AtomicReference<>(); final AtomicReference caughtEx = new AtomicReference<>(); final CountDownLatch txReadsDone = new CountDownLatch(1); - final Thread txThread = new Thread() { - @Override - public void run() { - try { - readWriteTx.write(TestModel.TEST_PATH, - ImmutableNodes.containerNode(TestModel.TEST_QNAME)); + final Thread txThread = new Thread(() -> { + try { + readWriteTx.write(TestModel.TEST_PATH, + ImmutableNodes.containerNode(TestModel.TEST_QNAME)); - txExistsFuture.set(readWriteTx.exists(TestModel.TEST_PATH)); + txExistsFuture.set(readWriteTx.exists(TestModel.TEST_PATH)); - txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH)); - } catch (Exception e) { - caughtEx.set(e); - } finally { - txReadsDone.countDown(); - } + txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH)); + } catch (Exception e) { + caughtEx.set(e); + } finally { + txReadsDone.countDown(); } - }; + }); txThread.start(); 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 e2dc8143e5..0e1dd4448e 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 @@ -127,33 +127,25 @@ public final class ShardDataTreeMocking { @SuppressWarnings("unchecked") public static ShardDataTreeCohort failedCanCommit(final ShardDataTreeCohort mock) { - doAnswer(invocation -> { - return invokeFailure(invocation); - }).when(mock).canCommit(any(FutureCallback.class)); + doAnswer(ShardDataTreeMocking::invokeFailure).when(mock).canCommit(any(FutureCallback.class)); return mock; } @SuppressWarnings("unchecked") public static ShardDataTreeCohort failedPreCommit(final ShardDataTreeCohort mock) { - doAnswer(invocation -> { - return invokeFailure(invocation); - }).when(mock).preCommit(any(FutureCallback.class)); + doAnswer(ShardDataTreeMocking::invokeFailure).when(mock).preCommit(any(FutureCallback.class)); return mock; } @SuppressWarnings("unchecked") public static ShardDataTreeCohort failedCommit(final ShardDataTreeCohort mock) { - doAnswer(invocation -> { - return invokeFailure(invocation); - }).when(mock).commit(any(FutureCallback.class)); + doAnswer(ShardDataTreeMocking::invokeFailure).when(mock).commit(any(FutureCallback.class)); return mock; } @SuppressWarnings("unchecked") public static ShardDataTreeCohort successfulCanCommit(final ShardDataTreeCohort mock) { - doAnswer(invocation -> { - return invokeSuccess(invocation, null); - }).when(mock).canCommit(any(FutureCallback.class)); + doAnswer(invocation -> invokeSuccess(invocation, null)).when(mock).canCommit(any(FutureCallback.class)); return mock; } @@ -165,9 +157,7 @@ public final class ShardDataTreeMocking { @SuppressWarnings("unchecked") public static ShardDataTreeCohort successfulPreCommit(final ShardDataTreeCohort mock, final DataTreeCandidate candidate) { - doAnswer(invocation -> { - return invokeSuccess(invocation, candidate); - }).when(mock).preCommit(any(FutureCallback.class)); + doAnswer(invocation -> invokeSuccess(invocation, candidate)).when(mock).preCommit(any(FutureCallback.class)); return mock; } @@ -178,9 +168,7 @@ public final class ShardDataTreeMocking { @SuppressWarnings("unchecked") public static ShardDataTreeCohort successfulCommit(final ShardDataTreeCohort mock, final UnsignedLong index) { - doAnswer(invocation -> { - return invokeSuccess(invocation, index); - }).when(mock).commit(any(FutureCallback.class)); + doAnswer(invocation -> invokeSuccess(invocation, index)).when(mock).commit(any(FutureCallback.class)); return mock; } 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 ce2a43f015..f566ba8d07 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 @@ -198,14 +198,11 @@ public class ShardTest extends AbstractShardTest { // original ElectionTimeout message to proceed with the election. firstElectionTimeout = false; final ActorRef self = getSelf(); - new Thread() { - @Override - public void run() { - Uninterruptibles.awaitUninterruptibly( - onChangeListenerRegistered, 5, TimeUnit.SECONDS); - self.tell(message, self); - } - }.start(); + new Thread(() -> { + Uninterruptibles.awaitUninterruptibly( + onChangeListenerRegistered, 5, TimeUnit.SECONDS); + self.tell(message, self); + }).start(); onFirstElectionTimeout.countDown(); } else { @@ -307,14 +304,11 @@ public class ShardTest extends AbstractShardTest { if (message instanceof ElectionTimeout && firstElectionTimeout) { firstElectionTimeout = false; final ActorRef self = getSelf(); - new Thread() { - @Override - public void run() { - Uninterruptibles.awaitUninterruptibly( - onChangeListenerRegistered, 5, TimeUnit.SECONDS); - self.tell(message, self); - } - }.start(); + new Thread(() -> { + Uninterruptibles.awaitUninterruptibly( + onChangeListenerRegistered, 5, TimeUnit.SECONDS); + self.tell(message, self); + }).start(); onFirstElectionTimeout.countDown(); } else { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java index 78266df646..9fd0849bf1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java @@ -152,18 +152,15 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { final AtomicReference caughtEx = new AtomicReference<>(); final CountDownLatch write2Complete = new CountDownLatch(1); - new Thread() { - @Override - public void run() { - try { - writeTx2.write(TestModel.OUTER_LIST_PATH, writeNode2); - } catch (Exception e) { - caughtEx.set(e); - } finally { - write2Complete.countDown(); - } + new Thread(() -> { + try { + writeTx2.write(TestModel.OUTER_LIST_PATH, writeNode2); + } catch (Exception e) { + caughtEx.set(e); + } finally { + write2Complete.countDown(); } - }.start(); + }).start(); assertEquals("Tx 2 write should've completed", true, write2Complete.await(5, TimeUnit.SECONDS)); @@ -224,18 +221,15 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { final AtomicReference caughtEx = new AtomicReference<>(); final CountDownLatch write2Complete = new CountDownLatch(1); - new Thread() { - @Override - public void run() { - try { - writeTx2.write(TestModel.OUTER_LIST_PATH, writeNode2); - } catch (Exception e) { - caughtEx.set(e); - } finally { - write2Complete.countDown(); - } + new Thread(() -> { + try { + writeTx2.write(TestModel.OUTER_LIST_PATH, writeNode2); + } catch (Exception e) { + caughtEx.set(e); + } finally { + write2Complete.countDown(); } - }.start(); + }).start(); assertEquals("Tx 2 write should've completed", true, write2Complete.await(5, TimeUnit.SECONDS)); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerTest.java index 6e37a975ed..f40374b924 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerTest.java @@ -1328,7 +1328,7 @@ public class ShardManagerTest extends AbstractShardManagerTest { assertEquals("getType", shardMrgIDSuffix, datastoreSnapshot.getType()); assertNull("Expected null ShardManagerSnapshot", datastoreSnapshot.getShardManagerSnapshot()); - Function shardNameTransformer = s -> s.getName(); + Function shardNameTransformer = ShardSnapshot::getName; assertEquals("Shard names", Sets.newHashSet("shard1", "shard2"), Sets.newHashSet( Lists.transform(datastoreSnapshot.getShardSnapshots(), shardNameTransformer))); -- 2.36.6