Fix unit test CS warnings in sal-distributed-datastore 83/47483/3
authorTom Pantelis <tpanteli@brocade.com>
Tue, 25 Oct 2016 10:04:11 +0000 (06:04 -0400)
committerTom Pantelis <tpanteli@brocade.com>
Tue, 25 Oct 2016 17:11:45 +0000 (17:11 +0000)
Fixed checkstyle warnings in unit tests. Most of the
warnings/changes were for:
 - white space before if/for/while/catch
 - white space before beginning brace
 - line too long
 - illegal catching of Exception (suppressed)
 - illegal throwing of Throwable (changed to Exception)
 - variable name too short
 - indentation, mostly due to nested code inside anonymous JavaTestKit
   instances
 - separator wrapping: '.', '+', '&&' should be on a new line
 - local vars/params hiding a field
 - putting overloaded methods close to one another
 - remove unused vars
 - convert functional interfaces to lambdas (eclipse save action)
 - adding final for locals declared too far from first usage

Also 3 classes are no longer used so I removed them rather than fix warnings.

Change-Id: Ie1507e36c67a2b58f7efb62378212976b962f9fe
Signed-off-by: Tom Pantelis <tpanteli@brocade.com>
109 files changed:
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/databroker/ConcurrentDOMDataBrokerTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerSupportTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeCandidatePayloadTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerActorTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerRegistrationActorTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupportTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataTreeCohortIntegrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextConfigAdminOverlayTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextIntrospectorTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreSnapshotRestoreTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DebugThreePhaseCommitCohortTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreIntegrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/IntegrationTestKit.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/MemberNode.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/OperationLimiterTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/RoleChangeNotifierTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeMocking.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardDataTreeTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardRecoveryCoordinatorTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTestKit.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohortTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapperTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionRateLimitingCallbackTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActorTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/config/ConfigurationImplTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/AbstractEntityOwnershipTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListenerTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipIntegrationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipServiceTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnerChangeListenerTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipListenerActorTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipListenerSupportTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipShardTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipStatisticsTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/EntityOwnerSelectionStrategyConfigReaderTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/LeastLoadedCandidateSelectionStrategyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/identifiers/ShardIdentifierTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/identifiers/ShardManagerIdentifierTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStatsTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/AbortTransactionReplyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/AbortTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/BatchedModificationsTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CanCommitTransactionReplyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CanCommitTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionChainTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CloseTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CommitTransactionReplyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CommitTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CreateTransactionReplyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/CreateTransactionTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/DataChangedTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/DataExistsReplyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/DataExistsTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/FindPrimaryTest.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/ReadDataReplyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/ReadDataTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/ReadyLocalTransactionSerializerTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/messages/ReadyTransactionReplyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/AbstractModificationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/DeleteModificationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/MergeModificationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/MutableCompositeModificationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/WriteModificationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/AbortTransactionPayloadTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/CommitTransactionPayloadTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/FrontendShardDataTreeSnapshotMetadataTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/persisted/ShardDataTreeSnapshotTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerGetSnapshotReplyActorTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardPeerAddressResolverTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategyTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategyFactoryTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ActorContextTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/DispatchersTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/ForwardingActor.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/MockActorContext.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/MockClusterWrapper.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/MockConfiguration.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/MockDataChangeListener.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/MockDataTreeChangeListener.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/NormalizedNodeAggregatorTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PrimaryShardInfoFutureCacheTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/PruningDataTreeModificationTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/TestUtils.java [deleted file]
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/utils/TransactionRateLimiterTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/CarsModel.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/CompositeModel.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/PeopleModel.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SampleModelsTest.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/SchemaContextHelper.java
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/md/cluster/datastore/model/TestModel.java

index 8686cc4..d86f358 100644 (file)
@@ -19,6 +19,8 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+
+import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.FutureCallback;
@@ -42,7 +44,6 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.InOrder;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
 import org.opendaylight.controller.md.sal.common.api.data.DataStoreUnavailableException;
@@ -84,7 +85,8 @@ public class ConcurrentDOMDataBrokerTest {
         DOMStore store = new InMemoryDOMDataStore("OPER",
             MoreExecutors.newDirectExecutorService());
 
-        coordinator = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, store), futureExecutor);
+        coordinator = new ConcurrentDOMDataBroker(ImmutableMap.of(LogicalDatastoreType.OPERATIONAL, store),
+                futureExecutor);
     }
 
     @After
@@ -93,36 +95,33 @@ public class ConcurrentDOMDataBrokerTest {
     }
 
     @Test
-    public void testSuccessfulSubmitAsync() throws Throwable {
+    public void testSuccessfulSubmitAsync() throws Exception {
         testSuccessfulSubmit(true);
     }
 
     @Test
-    public void testSuccessfulSubmitSync() throws Throwable {
+    public void testSuccessfulSubmitSync() throws Exception {
         testSuccessfulSubmit(false);
     }
 
-    private void testSuccessfulSubmit(final boolean doAsync) throws Throwable {
+    private void testSuccessfulSubmit(final boolean doAsync) throws InterruptedException {
         final CountDownLatch asyncCanCommitContinue = new CountDownLatch(1);
-        Answer<ListenableFuture<Boolean>> asyncCanCommit = new Answer<ListenableFuture<Boolean>>() {
-            @Override
-            public ListenableFuture<Boolean> answer(final InvocationOnMock invocation) {
-                final SettableFuture<Boolean> future = SettableFuture.create();
-                if(doAsync) {
-                    new Thread() {
-                        @Override
-                        public void run() {
-                            Uninterruptibles.awaitUninterruptibly(asyncCanCommitContinue,
-                                    10, TimeUnit.SECONDS);
-                            future.set(true);
-                        }
-                    }.start();
-                } else {
-                    future.set(true);
-                }
-
-                return future;
+        Answer<ListenableFuture<Boolean>> asyncCanCommit = invocation -> {
+            final SettableFuture<Boolean> future = SettableFuture.create();
+            if (doAsync) {
+                new Thread() {
+                    @Override
+                    public void run() {
+                        Uninterruptibles.awaitUninterruptibly(asyncCanCommitContinue,
+                                10, TimeUnit.SECONDS);
+                        future.set(true);
+                    }
+                }.start();
+            } else {
+                future.set(true);
             }
+
+            return future;
         };
 
         doAnswer(asyncCanCommit).when(mockCohort1).canCommit();
@@ -145,8 +144,8 @@ public class ConcurrentDOMDataBrokerTest {
             }
 
             @Override
-            public void onFailure(final Throwable t) {
-                caughtEx.set(t);
+            public void onFailure(final Throwable failure) {
+                caughtEx.set(failure);
                 doneLatch.countDown();
             }
         });
@@ -155,8 +154,8 @@ public class ConcurrentDOMDataBrokerTest {
 
         assertEquals("Submit complete", true, doneLatch.await(5, TimeUnit.SECONDS));
 
-        if(caughtEx.get() != null) {
-            throw caughtEx.get();
+        if (caughtEx.get() != null) {
+            Throwables.propagate(caughtEx.get());
         }
 
         assertEquals("Task count", doAsync ? 1 : 0, futureExecutor.getTaskCount());
@@ -195,12 +194,12 @@ public class ConcurrentDOMDataBrokerTest {
             future.checkedGet(5, TimeUnit.SECONDS);
             fail("Expected TransactionCommitFailedException");
         } catch (TransactionCommitFailedException e) {
-            if(expCause != null) {
+            if (expCause != null) {
                 assertSame("Expected cause", expCause.getClass(), e.getCause().getClass());
             }
 
             InOrder inOrder = inOrder((Object[])mockCohorts);
-            for(DOMStoreThreePhaseCommitCohort c: mockCohorts) {
+            for (DOMStoreThreePhaseCommitCohort c: mockCohorts) {
                 inOrder.verify(c).abort();
             }
         } catch (TimeoutException e) {
@@ -251,8 +250,8 @@ public class ConcurrentDOMDataBrokerTest {
 
         DOMStoreThreePhaseCommitCohort mockCohort3 = mock(DOMStoreThreePhaseCommitCohort.class);
         doReturn(Futures.immediateFuture(true)).when(mockCohort3).canCommit();
-        doReturn(Futures.immediateFailedFuture(new IllegalStateException("mock2"))).
-                when(mockCohort3).preCommit();
+        doReturn(Futures.immediateFailedFuture(new IllegalStateException("mock2")))
+                .when(mockCohort3).preCommit();
         doReturn(Futures.immediateFuture(null)).when(mockCohort3).abort();
 
         CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(
@@ -277,8 +276,8 @@ public class ConcurrentDOMDataBrokerTest {
         DOMStoreThreePhaseCommitCohort mockCohort3 = mock(DOMStoreThreePhaseCommitCohort.class);
         doReturn(Futures.immediateFuture(true)).when(mockCohort3).canCommit();
         doReturn(Futures.immediateFuture(null)).when(mockCohort3).preCommit();
-        doReturn(Futures.immediateFailedFuture(new IllegalStateException("mock2"))).
-                when(mockCohort3).commit();
+        doReturn(Futures.immediateFailedFuture(new IllegalStateException("mock2")))
+                .when(mockCohort3).commit();
         doReturn(Futures.immediateFuture(null)).when(mockCohort3).abort();
 
         CheckedFuture<Void, TransactionCommitFailedException> future = coordinator.submit(
@@ -290,8 +289,8 @@ public class ConcurrentDOMDataBrokerTest {
     @Test
     public void testSubmitWithAbortException() throws Exception {
         doReturn(Futures.immediateFuture(true)).when(mockCohort1).canCommit();
-        doReturn(Futures.immediateFailedFuture(new IllegalStateException("mock abort error"))).
-                when(mockCohort1).abort();
+        doReturn(Futures.immediateFailedFuture(new IllegalStateException("mock abort error")))
+                .when(mockCohort1).abort();
 
         IllegalStateException cause = new IllegalStateException("mock canCommit error");
         doReturn(Futures.immediateFailedFuture(cause)).when(mockCohort2).canCommit();
@@ -304,7 +303,7 @@ public class ConcurrentDOMDataBrokerTest {
     }
 
     @Test
-    public void testCreateReadWriteTransaction(){
+    public void testCreateReadWriteTransaction() {
         DOMStore domStore = mock(DOMStore.class);
         try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
                 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
@@ -316,7 +315,7 @@ public class ConcurrentDOMDataBrokerTest {
     }
 
     @Test
-    public void testCreateWriteOnlyTransaction(){
+    public void testCreateWriteOnlyTransaction() {
         DOMStore domStore = mock(DOMStore.class);
         try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
                 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
@@ -328,7 +327,7 @@ public class ConcurrentDOMDataBrokerTest {
     }
 
     @Test
-    public void testCreateReadOnlyTransaction(){
+    public void testCreateReadOnlyTransaction() {
         DOMStore domStore = mock(DOMStore.class);
         try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
                 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
@@ -340,7 +339,7 @@ public class ConcurrentDOMDataBrokerTest {
     }
 
     @Test
-    public void testLazySubTransactionCreationForReadWriteTransactions(){
+    public void testLazySubTransactionCreationForReadWriteTransactions() {
         DOMStore configDomStore = mock(DOMStore.class);
         DOMStore operationalDomStore = mock(DOMStore.class);
         DOMStoreReadWriteTransaction storeTxn = mock(DOMStoreReadWriteTransaction.class);
@@ -369,7 +368,7 @@ public class ConcurrentDOMDataBrokerTest {
     }
 
     @Test
-    public void testLazySubTransactionCreationForWriteOnlyTransactions(){
+    public void testLazySubTransactionCreationForWriteOnlyTransactions() {
         DOMStore configDomStore = mock(DOMStore.class);
         DOMStore operationalDomStore = mock(DOMStore.class);
         DOMStoreWriteTransaction storeTxn = mock(DOMStoreWriteTransaction.class);
@@ -396,7 +395,7 @@ public class ConcurrentDOMDataBrokerTest {
     }
 
     @Test
-    public void testLazySubTransactionCreationForReadOnlyTransactions(){
+    public void testLazySubTransactionCreationForReadOnlyTransactions() {
         DOMStore configDomStore = mock(DOMStore.class);
         DOMStore operationalDomStore = mock(DOMStore.class);
         DOMStoreReadTransaction storeTxn = mock(DOMStoreReadTransaction.class);
@@ -441,10 +440,11 @@ public class ConcurrentDOMDataBrokerTest {
                 LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION,
                 configDomStore), futureExecutor) {
             @Override
-            public CheckedFuture<Void, TransactionCommitFailedException> submit(DOMDataWriteTransaction transaction, Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
+            public CheckedFuture<Void, TransactionCommitFailedException> submit(DOMDataWriteTransaction writeTx,
+                    Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
                 commitCohorts.addAll(cohorts);
                 latch.countDown();
-                return super.submit(transaction, cohorts);
+                return super.submit(writeTx, cohorts);
             }
         }) {
             DOMDataReadWriteTransaction domDataReadWriteTransaction = dataBroker.newReadWriteTransaction();
@@ -453,7 +453,7 @@ public class ConcurrentDOMDataBrokerTest {
 
             domDataReadWriteTransaction.submit();
 
-            latch.await(10, TimeUnit.SECONDS);
+            assertTrue(latch.await(10, TimeUnit.SECONDS));
 
             assertTrue(commitCohorts.size() == 1);
         }
@@ -486,7 +486,8 @@ public class ConcurrentDOMDataBrokerTest {
                 LogicalDatastoreType.OPERATIONAL, operationalDomStore, LogicalDatastoreType.CONFIGURATION,
                 configDomStore), futureExecutor) {
             @Override
-            public CheckedFuture<Void, TransactionCommitFailedException> submit(DOMDataWriteTransaction transaction, Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
+            public CheckedFuture<Void, TransactionCommitFailedException> submit(DOMDataWriteTransaction transaction,
+                    Collection<DOMStoreThreePhaseCommitCohort> cohorts) {
                 commitCohorts.addAll(cohorts);
                 latch.countDown();
                 return super.submit(transaction, cohorts);
@@ -494,19 +495,21 @@ public class ConcurrentDOMDataBrokerTest {
         }) {
             DOMDataReadWriteTransaction domDataReadWriteTransaction = dataBroker.newReadWriteTransaction();
 
-            domDataReadWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY, mock(NormalizedNode.class));
-            domDataReadWriteTransaction.merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY, mock(NormalizedNode.class));
+            domDataReadWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY,
+                    mock(NormalizedNode.class));
+            domDataReadWriteTransaction.merge(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY,
+                    mock(NormalizedNode.class));
 
             domDataReadWriteTransaction.submit();
 
-            latch.await(10, TimeUnit.SECONDS);
+            assertTrue(latch.await(10, TimeUnit.SECONDS));
 
             assertTrue(commitCohorts.size() == 2);
         }
     }
 
     @Test
-    public void testCreateTransactionChain(){
+    public void testCreateTransactionChain() {
         DOMStore domStore = mock(DOMStore.class);
         try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
                 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
@@ -520,7 +523,7 @@ public class ConcurrentDOMDataBrokerTest {
     }
 
     @Test
-    public void testCreateTransactionOnChain(){
+    public void testCreateTransactionOnChain() {
         DOMStore domStore = mock(DOMStore.class);
         try (ConcurrentDOMDataBroker dataBroker = new ConcurrentDOMDataBroker(ImmutableMap.of(
                 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
@@ -532,13 +535,15 @@ public class ConcurrentDOMDataBrokerTest {
             doReturn(mockChain).when(domStore).createTransactionChain();
             doReturn(operationalTransaction).when(mockChain).newWriteOnlyTransaction();
 
-            DOMTransactionChain transactionChain = dataBroker.createTransactionChain(mock(TransactionChainListener.class));
+            DOMTransactionChain transactionChain = dataBroker.createTransactionChain(
+                    mock(TransactionChainListener.class));
 
             DOMDataWriteTransaction domDataWriteTransaction = transactionChain.newWriteOnlyTransaction();
 
             verify(mockChain, never()).newWriteOnlyTransaction();
 
-            domDataWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY, mock(NormalizedNode.class));
+            domDataWriteTransaction.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY,
+                    mock(NormalizedNode.class));
         }
     }
 
@@ -549,13 +554,15 @@ public class ConcurrentDOMDataBrokerTest {
                 LogicalDatastoreType.OPERATIONAL, domStore, LogicalDatastoreType.CONFIGURATION, domStore),
                 futureExecutor)) {
 
-            CheckedFuture<Void, TransactionCommitFailedException> submit1 = dataBroker.newWriteOnlyTransaction().submit();
+            CheckedFuture<Void, TransactionCommitFailedException> submit1 =
+                    dataBroker.newWriteOnlyTransaction().submit();
 
             assertNotNull(submit1);
 
             submit1.get();
 
-            CheckedFuture<Void, TransactionCommitFailedException> submit2 = dataBroker.newReadWriteTransaction().submit();
+            CheckedFuture<Void, TransactionCommitFailedException> submit2 =
+                    dataBroker.newReadWriteTransaction().submit();
 
             assertNotNull(submit2);
 
index 6f07390..d0302eb 100644 (file)
@@ -19,6 +19,7 @@ import static org.opendaylight.controller.cluster.datastore.DataStoreVersions.CU
 import static org.opendaylight.controller.cluster.datastore.ShardDataTreeMocking.successfulCanCommit;
 import static org.opendaylight.controller.cluster.datastore.ShardDataTreeMocking.successfulCommit;
 import static org.opendaylight.controller.cluster.datastore.ShardDataTreeMocking.successfulPreCommit;
+
 import akka.actor.ActorRef;
 import akka.actor.PoisonPill;
 import akka.actor.Props;
@@ -63,7 +64,6 @@ 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.concepts.Identifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
@@ -90,7 +90,7 @@ import scala.concurrent.duration.Duration;
  *
  * @author Thomas Pantelis
  */
-public abstract class AbstractShardTest extends AbstractActorTest{
+public abstract class AbstractShardTest extends AbstractActorTest {
     protected static final SchemaContext SCHEMA_CONTEXT = TestModel.createTestContext();
 
     private static final AtomicInteger NEXT_SHARD_NUM = new AtomicInteger();
@@ -98,9 +98,8 @@ public abstract class AbstractShardTest extends AbstractActorTest{
     protected final ShardIdentifier shardID = ShardIdentifier.create("inventory", MemberName.forName("member-1"),
         "config" + NEXT_SHARD_NUM.getAndIncrement());
 
-    protected final Builder dataStoreContextBuilder = DatastoreContext.newBuilder().
-            shardJournalRecoveryLogBatchSize(3).shardSnapshotBatchCount(5000).
-            shardHeartbeatIntervalInMillis(100);
+    protected final Builder dataStoreContextBuilder = DatastoreContext.newBuilder()
+            .shardJournalRecoveryLogBatchSize(3).shardSnapshotBatchCount(5000).shardHeartbeatIntervalInMillis(100);
 
     protected final TestActorFactory actorFactory = new TestActorFactory(getSystem());
 
@@ -136,25 +135,20 @@ public abstract class AbstractShardTest extends AbstractActorTest{
 
         final CountDownLatch recoveryComplete = new CountDownLatch(1);
 
-        @SuppressWarnings("serial")
-        final Creator<Shard> creator = new Creator<Shard>() {
+        final Creator<Shard> creator = () -> new Shard(newShardBuilder()) {
             @Override
-            public Shard create() throws Exception {
-                return new Shard(newShardBuilder()) {
-                    @Override
-                    protected void onRecoveryComplete() {
-                        try {
-                            super.onRecoveryComplete();
-                        } finally {
-                            recoveryComplete.countDown();
-                        }
-                    }
-                };
+            protected void onRecoveryComplete() {
+                try {
+                    super.onRecoveryComplete();
+                } finally {
+                    recoveryComplete.countDown();
+                }
             }
         };
 
         final TestActorRef<Shard> shard = TestActorRef.create(getSystem(),
-                Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()), "testRecovery");
+                Props.create(new DelegatingShardCreator(creator)).withDispatcher(Dispatchers.DefaultDispatcherId()),
+                "testRecovery");
 
         assertEquals("Recovery complete", true, recoveryComplete.await(5, TimeUnit.SECONDS));
 
@@ -164,7 +158,7 @@ public abstract class AbstractShardTest extends AbstractActorTest{
         assertNotNull(TestModel.OUTER_LIST_QNAME.getLocalName() + " not found", outerList);
         assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " value is not Iterable",
                 outerList.getValue() instanceof Iterable);
-        for(final Object entry: (Iterable<?>) outerList.getValue()) {
+        for (final Object entry: (Iterable<?>) outerList.getValue()) {
             assertTrue(TestModel.OUTER_LIST_QNAME.getLocalName() + " entry is not MapEntryNode",
                     entry instanceof MapEntryNode);
             final MapEntryNode mapEntry = (MapEntryNode)entry;
@@ -172,13 +166,12 @@ public abstract class AbstractShardTest extends AbstractActorTest{
                     mapEntry.getChild(new YangInstanceIdentifier.NodeIdentifier(TestModel.ID_QNAME));
             assertTrue("Missing leaf " + TestModel.ID_QNAME.getLocalName(), idLeaf.isPresent());
             final Object value = idLeaf.get().getValue();
-            assertTrue("Unexpected value for leaf "+ TestModel.ID_QNAME.getLocalName() + ": " + value,
+            assertTrue("Unexpected value for leaf " + TestModel.ID_QNAME.getLocalName() + ": " + value,
                     listEntryKeys.remove(value));
         }
 
-        if(!listEntryKeys.isEmpty()) {
-            fail("Missing " + TestModel.OUTER_LIST_QNAME.getLocalName() + " entries with keys: " +
-                    listEntryKeys);
+        if (!listEntryKeys.isEmpty()) {
+            fail("Missing " + TestModel.OUTER_LIST_QNAME.getLocalName() + " entries with keys: " + listEntryKeys);
         }
 
         assertEquals("Last log index", nListEntries,
@@ -193,9 +186,9 @@ public abstract class AbstractShardTest extends AbstractActorTest{
 
     protected void verifyLastApplied(final TestActorRef<Shard> shard, final long expectedValue) {
         long lastApplied = -1;
-        for(int i = 0; i < 20 * 5; i++) {
+        for (int i = 0; i < 20 * 5; i++) {
             lastApplied = shard.underlyingActor().getShardMBean().getLastApplied();
-            if(lastApplied == expectedValue) {
+            if (lastApplied == expectedValue) {
                 return;
             }
             Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
@@ -251,17 +244,14 @@ public abstract class AbstractShardTest extends AbstractActorTest{
     protected Map<TransactionIdentifier, CapturingShardDataTreeCohort> setupCohortDecorator(final Shard shard,
             final TransactionIdentifier... transactionIDs) {
         final Map<TransactionIdentifier, CapturingShardDataTreeCohort> cohortMap = new HashMap<>();
-        for(TransactionIdentifier id: transactionIDs) {
+        for (TransactionIdentifier id: transactionIDs) {
             cohortMap.put(id, new CapturingShardDataTreeCohort());
         }
 
-        shard.getCommitCoordinator().setCohortDecorator(new ShardCommitCoordinator.CohortDecorator() {
-            @Override
-            public ShardDataTreeCohort decorate(final Identifier transactionID, final ShardDataTreeCohort actual) {
-                CapturingShardDataTreeCohort cohort = cohortMap.get(transactionID);
-                cohort.setDelegate(actual);
-                return cohort;
-            }
+        shard.getCommitCoordinator().setCohortDecorator((transactionID, actual) -> {
+            CapturingShardDataTreeCohort cohort = cohortMap.get(transactionID);
+            cohort.setDelegate(actual);
+            return cohort;
         });
 
         return cohortMap;
@@ -293,14 +283,14 @@ public abstract class AbstractShardTest extends AbstractActorTest{
     protected static ForwardedReadyTransaction prepareForwardedReadyTransaction(final TestActorRef<Shard> shard,
             final TransactionIdentifier transactionID, final YangInstanceIdentifier path,
             final NormalizedNode<?, ?> data, final boolean doCommitOnReady) {
-        ReadWriteShardDataTreeTransaction rwTx = shard.underlyingActor().getDataStore().
-                newReadWriteTransaction(transactionID);
+        ReadWriteShardDataTreeTransaction rwTx = shard.underlyingActor().getDataStore()
+                .newReadWriteTransaction(transactionID);
         rwTx.getSnapshot().write(path, data);
         return new ForwardedReadyTransaction(transactionID, CURRENT_VERSION, rwTx, doCommitOnReady);
     }
 
-    public static NormalizedNode<?,?> readStore(final TestActorRef<? extends Shard> shard, final YangInstanceIdentifier id)
-            throws ExecutionException, InterruptedException {
+    public static NormalizedNode<?,?> readStore(final TestActorRef<? extends Shard> shard,
+            final YangInstanceIdentifier id) throws ExecutionException, InterruptedException {
         return shard.underlyingActor().getDataStore().readNode(id).orNull();
     }
 
@@ -310,11 +300,11 @@ public abstract class AbstractShardTest extends AbstractActorTest{
 
     public void writeToStore(final TestActorRef<Shard> shard, final YangInstanceIdentifier id,
             final NormalizedNode<?,?> node) throws InterruptedException, ExecutionException {
-        Future<Object> future = Patterns.ask(shard, newBatchedModifications(nextTransactionId(), id, node, true, true, 1),
-                new Timeout(5, TimeUnit.SECONDS));
+        Future<Object> future = Patterns.ask(shard, newBatchedModifications(nextTransactionId(),
+                id, node, true, true, 1), new Timeout(5, TimeUnit.SECONDS));
         try {
             Await.ready(future, Duration.create(5, TimeUnit.SECONDS));
-        } catch(TimeoutException e) {
+        } catch (TimeoutException e) {
             throw new ExecutionException(e);
         }
     }
@@ -327,6 +317,17 @@ public abstract class AbstractShardTest extends AbstractActorTest{
         store.commit(modification);
     }
 
+    public static void writeToStore(final DataTree store, final YangInstanceIdentifier id,
+            final NormalizedNode<?,?> node) throws DataValidationFailedException {
+        final DataTreeModification transaction = store.takeSnapshot().newModification();
+
+        transaction.write(id, node);
+        transaction.ready();
+        store.validate(transaction);
+        final DataTreeCandidate candidate = store.prepare(transaction);
+        store.commit(candidate);
+    }
+
     public void mergeToStore(final ShardDataTree store, final YangInstanceIdentifier id,
             final NormalizedNode<?,?> node) throws Exception {
         final BatchedModifications batched = new BatchedModifications(nextTransactionId(), CURRENT_VERSION);
@@ -340,17 +341,6 @@ public abstract class AbstractShardTest extends AbstractActorTest{
         store.commit(modification);
     }
 
-    public static void writeToStore(final DataTree store, final YangInstanceIdentifier id,
-            final NormalizedNode<?,?> node) throws DataValidationFailedException {
-        final DataTreeModification transaction = store.takeSnapshot().newModification();
-
-        transaction.write(id, node);
-        transaction.ready();
-        store.validate(transaction);
-        final DataTreeCandidate candidate = store.prepare(transaction);
-        store.commit(candidate);
-    }
-
     DataTree setupInMemorySnapshotStore() throws DataValidationFailedException {
         final DataTree testStore = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
         testStore.setSchemaContext(SCHEMA_CONTEXT);
@@ -374,8 +364,8 @@ public abstract class AbstractShardTest extends AbstractActorTest{
     }
 
     static BatchedModifications newBatchedModifications(final TransactionIdentifier transactionID,
-            final YangInstanceIdentifier path, final NormalizedNode<?, ?> data, final boolean ready, final boolean doCommitOnReady,
-            final int messagesSent) {
+            final YangInstanceIdentifier path, final NormalizedNode<?, ?> data, final boolean ready,
+            final boolean doCommitOnReady, final int messagesSent) {
         final BatchedModifications batched = new BatchedModifications(transactionID, CURRENT_VERSION);
         batched.addModification(new WriteModification(path, data));
         batched.setReady(ready);
@@ -404,7 +394,8 @@ public abstract class AbstractShardTest extends AbstractActorTest{
         final DataTreeCandidateTip mockCandidate = mock(DataTreeCandidateTip.class, name);
         final DataTreeCandidateNode mockCandidateNode = mock(DataTreeCandidateNode.class, name + "-node");
         doReturn(ModificationType.WRITE).when(mockCandidateNode).getModificationType();
-        doReturn(Optional.of(ImmutableNodes.containerNode(CarsModel.CARS_QNAME))).when(mockCandidateNode).getDataAfter();
+        doReturn(Optional.of(ImmutableNodes.containerNode(CarsModel.CARS_QNAME)))
+                .when(mockCandidateNode).getDataAfter();
         doReturn(CarsModel.BASE_PATH).when(mockCandidate).getRootPath();
         doReturn(mockCandidateNode).when(mockCandidate).getRootNode();
         return mockCandidate;
@@ -419,7 +410,8 @@ public abstract class AbstractShardTest extends AbstractActorTest{
         return mockCandidate;
     }
 
-    static void commitTransaction(final DataTree store, final DataTreeModification modification) throws DataValidationFailedException {
+    static void commitTransaction(final DataTree store, final DataTreeModification modification)
+            throws DataValidationFailedException {
         modification.ready();
         store.validate(modification);
         store.commit(store.prepare(modification));
index 73eb410..ade3022 100644 (file)
@@ -17,6 +17,7 @@ import static org.mockito.Matchers.isA;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+
 import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
 import akka.actor.ActorSystem;
@@ -26,6 +27,7 @@ import akka.testkit.JavaTestKit;
 import akka.util.Timeout;
 import com.codahale.metrics.MetricRegistry;
 import com.codahale.metrics.Timer;
+import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.typesafe.config.Config;
@@ -95,18 +97,8 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
 
     private final Configuration configuration = new MockConfiguration() {
         Map<String, ShardStrategy> strategyMap = ImmutableMap.<String, ShardStrategy>builder().put(
-                "junk", new ShardStrategy() {
-                    @Override
-                    public String findShard(YangInstanceIdentifier path) {
-                        return "junk";
-                    }
-                }).put(
-                "cars", new ShardStrategy() {
-                    @Override
-                    public String findShard(YangInstanceIdentifier path) {
-                        return "cars";
-                    }
-                }).build();
+                "junk", path -> "junk").put(
+                "cars", path -> "cars").build();
 
         @Override
         public ShardStrategy getStrategyForModule(String moduleName) {
@@ -115,9 +107,9 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
 
         @Override
         public String getModuleNameFromNameSpace(String nameSpace) {
-            if(TestModel.JUNK_QNAME.getNamespace().toASCIIString().equals(nameSpace)) {
+            if (TestModel.JUNK_QNAME.getNamespace().toASCIIString().equals(nameSpace)) {
                 return "junk";
-            } else if(CarsModel.BASE_QNAME.getNamespace().toASCIIString().equals(nameSpace)){
+            } else if (CarsModel.BASE_QNAME.getNamespace().toASCIIString().equals(nameSpace)) {
                 return "cars";
             }
             return null;
@@ -143,10 +135,10 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
     @BeforeClass
     public static void setUpClass() throws IOException {
 
-        Config config = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder().
-                put("akka.actor.default-dispatcher.type",
-                        "akka.testkit.CallingThreadDispatcherConfigurator").build()).
-                withFallback(ConfigFactory.load());
+        Config config = ConfigFactory.parseMap(ImmutableMap.<String, Object>builder()
+                .put("akka.actor.default-dispatcher.type",
+                        "akka.testkit.CallingThreadDispatcherConfigurator").build())
+                .withFallback(ConfigFactory.load());
         system = ActorSystem.create("test", config);
     }
 
@@ -157,7 +149,7 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
     }
 
     @Before
-    public void setUp(){
+    public void setUp() {
         MockitoAnnotations.initMocks(this);
 
         schemaContext = TestModel.createTestContext();
@@ -183,15 +175,15 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
         return system;
     }
 
-    protected CreateTransaction eqCreateTransaction(final String memberName,
+    protected CreateTransaction eqCreateTransaction(final String expMemberName,
             final TransactionType type) {
         ArgumentMatcher<CreateTransaction> matcher = new ArgumentMatcher<CreateTransaction>() {
             @Override
             public boolean matches(Object argument) {
-                if(CreateTransaction.class.equals(argument.getClass())) {
+                if (CreateTransaction.class.equals(argument.getClass())) {
                     CreateTransaction obj = CreateTransaction.fromSerializable(argument);
-                    return obj.getTransactionId().getHistoryId().getClientId().getFrontendId().getMemberName().getName().equals(memberName) &&
-                            obj.getTransactionType() == type.ordinal();
+                    return obj.getTransactionId().getHistoryId().getClientId().getFrontendId().getMemberName()
+                            .getName().equals(expMemberName) && obj.getTransactionType() == type.ordinal();
                 }
 
                 return false;
@@ -205,8 +197,7 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
         ArgumentMatcher<DataExists> matcher = new ArgumentMatcher<DataExists>() {
             @Override
             public boolean matches(Object argument) {
-                return (argument instanceof DataExists) &&
-                    ((DataExists)argument).getPath().equals(TestModel.TEST_PATH);
+                return argument instanceof DataExists && ((DataExists)argument).getPath().equals(TestModel.TEST_PATH);
             }
         };
 
@@ -221,7 +212,7 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
         ArgumentMatcher<ReadData> matcher = new ArgumentMatcher<ReadData>() {
             @Override
             public boolean matches(Object argument) {
-                return (argument instanceof ReadData) && ((ReadData)argument).getPath().equals(path);
+                return argument instanceof ReadData && ((ReadData)argument).getPath().equals(path);
             }
         };
 
@@ -259,6 +250,11 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
                 eq(actorSelection(actorRef)), isA(BatchedModifications.class), any(Timeout.class));
     }
 
+    protected void expectBatchedModifications(int count) {
+        doReturn(batchedModificationsReply(count)).when(mockActorContext).executeOperationAsync(
+                any(ActorSelection.class), isA(BatchedModifications.class), any(Timeout.class));
+    }
+
     protected void expectBatchedModificationsReady(ActorRef actorRef) {
         expectBatchedModificationsReady(actorRef, false);
     }
@@ -269,11 +265,6 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
                     eq(actorSelection(actorRef)), isA(BatchedModifications.class), any(Timeout.class));
     }
 
-    protected void expectBatchedModifications(int count) {
-        doReturn(batchedModificationsReply(count)).when(mockActorContext).executeOperationAsync(
-                any(ActorSelection.class), isA(BatchedModifications.class), any(Timeout.class));
-    }
-
     protected void expectIncompleteBatchedModifications() {
         doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
                 any(ActorSelection.class), isA(BatchedModifications.class), any(Timeout.class));
@@ -290,7 +281,7 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
                     eq(actorSelection(actorRef)), isA(ReadyLocalTransaction.class), any(Timeout.class));
     }
 
-    protected CreateTransactionReply createTransactionReply(ActorRef actorRef, short transactionVersion){
+    protected CreateTransactionReply createTransactionReply(ActorRef actorRef, short transactionVersion) {
         return new CreateTransactionReply(actorRef.path().toString(), nextTransactionId(), transactionVersion);
     }
 
@@ -298,18 +289,9 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
         return setupActorContextWithoutInitialCreateTransaction(actorSystem, DefaultShardStrategy.DEFAULT_SHARD);
     }
 
-    protected Future<PrimaryShardInfo> primaryShardInfoReply(ActorSystem actorSystem, ActorRef actorRef) {
-        return primaryShardInfoReply(actorSystem, actorRef, DataStoreVersions.CURRENT_VERSION);
-    }
-
-    protected Future<PrimaryShardInfo> primaryShardInfoReply(ActorSystem actorSystem, ActorRef actorRef,
-            short transactionVersion) {
-        return Futures.successful(new PrimaryShardInfo(actorSystem.actorSelection(actorRef.path()),
-                transactionVersion));
-    }
-
     protected ActorRef setupActorContextWithoutInitialCreateTransaction(ActorSystem actorSystem, String shardName) {
-        return setupActorContextWithoutInitialCreateTransaction(actorSystem, shardName, DataStoreVersions.CURRENT_VERSION);
+        return setupActorContextWithoutInitialCreateTransaction(actorSystem, shardName,
+                DataStoreVersions.CURRENT_VERSION);
     }
 
     protected ActorRef setupActorContextWithoutInitialCreateTransaction(ActorSystem actorSystem, String shardName,
@@ -317,15 +299,25 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
         ActorRef actorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
         log.info("Created mock shard actor {}", actorRef);
 
-        doReturn(actorSystem.actorSelection(actorRef.path())).
-                when(mockActorContext).actorSelection(actorRef.path().toString());
+        doReturn(actorSystem.actorSelection(actorRef.path()))
+                .when(mockActorContext).actorSelection(actorRef.path().toString());
 
-        doReturn(primaryShardInfoReply(actorSystem, actorRef, transactionVersion)).
-                when(mockActorContext).findPrimaryShardAsync(eq(shardName));
+        doReturn(primaryShardInfoReply(actorSystem, actorRef, transactionVersion))
+                .when(mockActorContext).findPrimaryShardAsync(eq(shardName));
 
         return actorRef;
     }
 
+    protected Future<PrimaryShardInfo> primaryShardInfoReply(ActorSystem actorSystem, ActorRef actorRef) {
+        return primaryShardInfoReply(actorSystem, actorRef, DataStoreVersions.CURRENT_VERSION);
+    }
+
+    protected Future<PrimaryShardInfo> primaryShardInfoReply(ActorSystem actorSystem, ActorRef actorRef,
+            short transactionVersion) {
+        return Futures.successful(new PrimaryShardInfo(actorSystem.actorSelection(actorRef.path()),
+                transactionVersion));
+    }
+
     protected ActorRef setupActorContextWithInitialCreateTransaction(ActorSystem actorSystem,
             TransactionType type, short transactionVersion, String shardName) {
         ActorRef shardActorRef = setupActorContextWithoutInitialCreateTransaction(actorSystem, shardName,
@@ -339,18 +331,18 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
             TransactionType type, short transactionVersion, String prefix, ActorRef shardActorRef) {
 
         ActorRef txActorRef;
-        if(type == TransactionType.WRITE_ONLY &&
-                dataStoreContextBuilder.build().isWriteOnlyTransactionOptimizationsEnabled()) {
+        if (type == TransactionType.WRITE_ONLY
+                && dataStoreContextBuilder.build().isWriteOnlyTransactionOptimizationsEnabled()) {
             txActorRef = shardActorRef;
         } else {
             txActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
             log.info("Created mock shard Tx actor {}", txActorRef);
 
-            doReturn(actorSystem.actorSelection(txActorRef.path())).
-                when(mockActorContext).actorSelection(txActorRef.path().toString());
+            doReturn(actorSystem.actorSelection(txActorRef.path()))
+                .when(mockActorContext).actorSelection(txActorRef.path().toString());
 
-            doReturn(Futures.successful(createTransactionReply(txActorRef, transactionVersion))).when(mockActorContext).
-                executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())),
+            doReturn(Futures.successful(createTransactionReply(txActorRef, transactionVersion))).when(mockActorContext)
+                .executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())),
                         eqCreateTransaction(prefix, type), any(Timeout.class));
         }
 
@@ -368,19 +360,21 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
                 shardName);
     }
 
-    protected void propagateReadFailedExceptionCause(CheckedFuture<?, ReadFailedException> future)
-            throws Throwable {
-
+    protected void propagateReadFailedExceptionCause(CheckedFuture<?, ReadFailedException> future) throws Exception {
         try {
             future.checkedGet(5, TimeUnit.SECONDS);
             fail("Expected ReadFailedException");
-        } catch(ReadFailedException e) {
+        } catch (ReadFailedException e) {
             assertNotNull("Expected a cause", e.getCause());
-            if(e.getCause().getCause() != null) {
-                throw e.getCause().getCause();
+            Throwable cause;
+            if (e.getCause().getCause() != null) {
+                cause = e.getCause().getCause();
             } else {
-                throw e.getCause();
+                cause = e.getCause();
             }
+
+            Throwables.propagateIfInstanceOf(cause, Exception.class);
+            Throwables.propagate(cause);
         }
     }
 
@@ -397,8 +391,8 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
 
     protected <T> List<T> filterCaptured(ArgumentCaptor<T> captor, Class<T> type) {
         List<T> captured = new ArrayList<>();
-        for(T c: captor.getAllValues()) {
-            if(type.isInstance(c)) {
+        for (T c: captor.getAllValues()) {
+            if (type.isInstance(c)) {
                 captured.add(c);
             }
         }
@@ -424,56 +418,57 @@ public abstract class AbstractTransactionProxyTest extends AbstractTest {
         assertEquals("BatchedModifications size", expected.length, batchedModifications.getModifications().size());
         assertEquals("isReady", expIsReady, batchedModifications.isReady());
         assertEquals("isDoCommitOnReady", expIsDoCommitOnReady, batchedModifications.isDoCommitOnReady());
-        for(int i = 0; i < batchedModifications.getModifications().size(); i++) {
+        for (int i = 0; i < batchedModifications.getModifications().size(); i++) {
             Modification actual = batchedModifications.getModifications().get(i);
             assertEquals("Modification type", expected[i].getClass(), actual.getClass());
             assertEquals("getPath", ((AbstractModification)expected[i]).getPath(),
                     ((AbstractModification)actual).getPath());
-            if(actual instanceof WriteModification) {
+            if (actual instanceof WriteModification) {
                 assertEquals("getData", ((WriteModification)expected[i]).getData(),
                         ((WriteModification)actual).getData());
             }
         }
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     protected void verifyCohortFutures(AbstractThreePhaseCommitCohort<?> proxy,
             Object... expReplies) throws Exception {
-            assertEquals("getReadyOperationFutures size", expReplies.length,
-                    proxy.getCohortFutures().size());
-
-            List<Object> futureResults = new ArrayList<>();
-            for( Future<?> future: proxy.getCohortFutures()) {
-                assertNotNull("Ready operation Future is null", future);
-                try {
-                    futureResults.add(Await.result(future, Duration.create(5, TimeUnit.SECONDS)));
-                } catch(Exception e) {
-                    futureResults.add(e);
-                }
+        assertEquals("getReadyOperationFutures size", expReplies.length,
+                proxy.getCohortFutures().size());
+
+        List<Object> futureResults = new ArrayList<>();
+        for (Future<?> future : proxy.getCohortFutures()) {
+            assertNotNull("Ready operation Future is null", future);
+            try {
+                futureResults.add(Await.result(future, Duration.create(5, TimeUnit.SECONDS)));
+            } catch (Exception e) {
+                futureResults.add(e);
             }
+        }
 
-            for (Object expReply : expReplies) {
-                boolean found = false;
-                Iterator<?> iter = futureResults.iterator();
-                while(iter.hasNext()) {
-                    Object actual = iter.next();
-                    if(CommitTransactionReply.isSerializedType(expReply) &&
-                       CommitTransactionReply.isSerializedType(actual)) {
-                        found = true;
-                    } else if(expReply instanceof ActorSelection && Objects.equals(expReply, actual)) {
-                        found = true;
-                    } else if(expReply instanceof Class && ((Class<?>)expReply).isInstance(actual)) {
-                        found = true;
-                    }
-
-                    if(found) {
-                        iter.remove();
-                        break;
-                    }
+        for (Object expReply : expReplies) {
+            boolean found = false;
+            Iterator<?> iter = futureResults.iterator();
+            while (iter.hasNext()) {
+                Object actual = iter.next();
+                if (CommitTransactionReply.isSerializedType(expReply)
+                        && CommitTransactionReply.isSerializedType(actual)) {
+                    found = true;
+                } else if (expReply instanceof ActorSelection && Objects.equals(expReply, actual)) {
+                    found = true;
+                } else if (expReply instanceof Class && ((Class<?>) expReply).isInstance(actual)) {
+                    found = true;
                 }
 
-                if(!found) {
-                    fail(String.format("No cohort Future response found for %s. Actual: %s", expReply, futureResults));
+                if (found) {
+                    iter.remove();
+                    break;
                 }
             }
+
+            if (!found) {
+                fail(String.format("No cohort Future response found for %s. Actual: %s", expReply, futureResults));
+            }
         }
+    }
 }
index ee06b68..2991754 100644 (file)
@@ -27,52 +27,53 @@ import org.opendaylight.controller.md.cluster.datastore.model.CompositeModel;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-public class DataChangeListenerProxyTest extends AbstractActorTest {
-
-  private static class MockDataChangedEvent implements AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> {
-    Map<YangInstanceIdentifier,NormalizedNode<?,?>> createdData = new HashMap<>();
-    Map<YangInstanceIdentifier,NormalizedNode<?,?>> updatedData = new HashMap<>();
-    Map<YangInstanceIdentifier,NormalizedNode<?,?>> originalData = new HashMap<>();
-
-
 
-    @Override
-    public Map<YangInstanceIdentifier, NormalizedNode<?, ?>> getCreatedData() {
-      createdData.put(YangInstanceIdentifier.EMPTY, CompositeModel.createDocumentOne(CompositeModel.createTestContext()));
-      return createdData;
-    }
-
-    @Override
-    public Map<YangInstanceIdentifier, NormalizedNode<?, ?>> getUpdatedData() {
-      updatedData.put(YangInstanceIdentifier.EMPTY, CompositeModel.createTestContainer());
-      return updatedData;
-
-    }
-
-    @Override
-    public Set<YangInstanceIdentifier> getRemovedPaths() {
-      Set<YangInstanceIdentifier>ids = new HashSet<>();
-      ids.add( CompositeModel.TEST_PATH);
-      return ids;
-    }
-
-    @Override
-    public Map<YangInstanceIdentifier, NormalizedNode<?, ?>> getOriginalData() {
-      originalData.put(YangInstanceIdentifier.EMPTY, CompositeModel.createFamily());
-      return originalData;
-    }
-
-    @Override public NormalizedNode<?, ?> getOriginalSubtree() {
-      return CompositeModel.createFamily() ;
-    }
+public class DataChangeListenerProxyTest extends AbstractActorTest {
 
-    @Override public NormalizedNode<?, ?> getUpdatedSubtree() {
-      return CompositeModel.createTestContainer();
+    private static class MockDataChangedEvent
+            implements AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> {
+        Map<YangInstanceIdentifier,NormalizedNode<?,?>> createdData = new HashMap<>();
+        Map<YangInstanceIdentifier,NormalizedNode<?,?>> updatedData = new HashMap<>();
+        Map<YangInstanceIdentifier,NormalizedNode<?,?>> originalData = new HashMap<>();
+
+        @Override
+        public Map<YangInstanceIdentifier, NormalizedNode<?, ?>> getCreatedData() {
+            createdData.put(YangInstanceIdentifier.EMPTY, CompositeModel.createDocumentOne(
+                    CompositeModel.createTestContext()));
+            return createdData;
+        }
+
+        @Override
+        public Map<YangInstanceIdentifier, NormalizedNode<?, ?>> getUpdatedData() {
+            updatedData.put(YangInstanceIdentifier.EMPTY, CompositeModel.createTestContainer());
+            return updatedData;
+
+        }
+
+        @Override
+        public Set<YangInstanceIdentifier> getRemovedPaths() {
+            Set<YangInstanceIdentifier> ids = new HashSet<>();
+            ids.add( CompositeModel.TEST_PATH);
+            return ids;
+        }
+
+        @Override
+        public Map<YangInstanceIdentifier, NormalizedNode<?, ?>> getOriginalData() {
+            originalData.put(YangInstanceIdentifier.EMPTY, CompositeModel.createFamily());
+            return originalData;
+        }
+
+        @Override public NormalizedNode<?, ?> getOriginalSubtree() {
+            return CompositeModel.createFamily() ;
+        }
+
+        @Override public NormalizedNode<?, ?> getUpdatedSubtree() {
+            return CompositeModel.createTestContainer();
+        }
     }
-  }
 
 
-  @Test
+    @Test
     public void testOnDataChanged() throws Exception {
         final Props props = Props.create(MessageCollectorActor.class);
         final ActorRef actorRef = getSystem().actorOf(props);
@@ -83,8 +84,8 @@ public class DataChangeListenerProxyTest extends AbstractActorTest {
         dataChangeListenerProxy.onDataChanged(new MockDataChangedEvent());
 
         //Check if it was received by the remote actor
-        ActorContext
-            testContext = new ActorContext(getSystem(), getSystem().actorOf(Props.create(DoNothingActor.class)), new MockClusterWrapper(), new MockConfiguration());
+        ActorContext testContext = new ActorContext(getSystem(), getSystem().actorOf(
+                Props.create(DoNothingActor.class)), new MockClusterWrapper(), new MockConfiguration());
         Object messages = testContext
             .executeOperation(actorRef, MessageCollectorActor.GET_ALL_MESSAGES);
 
index b5567fa..1c733cc 100644 (file)
@@ -12,6 +12,7 @@ import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
+
 import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.actor.Props;
@@ -26,7 +27,6 @@ import java.util.concurrent.TimeUnit;
 import org.junit.Assert;
 import org.junit.Test;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.cluster.datastore.config.Configuration;
 import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException;
@@ -63,260 +63,274 @@ public class DataChangeListenerRegistrationProxyTest extends AbstractActorTest {
 
     @Test
     public void testGetInstance() throws Exception {
-        DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
-                "shard", Mockito.mock(ActorContext.class), mockListener);
-
-        Assert.assertEquals(mockListener, proxy.getInstance());
+        try (DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
+                "shard", Mockito.mock(ActorContext.class), mockListener)) {
+            Assert.assertEquals(mockListener, proxy.getInstance());
+        }
     }
 
-    @Test(timeout=10000)
+    @Test(timeout = 10000)
     public void testSuccessfulRegistration() {
-        new JavaTestKit(getSystem()) {{
-            ActorContext actorContext = new ActorContext(getSystem(), getRef(),
-                    mock(ClusterWrapper.class), mock(Configuration.class));
+        new JavaTestKit(getSystem()) {
+            {
+                ActorContext actorContext = new ActorContext(getSystem(), getRef(),
+                        mock(ClusterWrapper.class), mock(Configuration.class));
 
-            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
-                    "shard-1", actorContext, mockListener);
+                final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
+                        "shard-1", actorContext, mockListener);
 
-            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
-            final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
-            new Thread() {
-                @Override
-                public void run() {
-                    proxy.init(path, scope);
-                }
+                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();
+                }.start();
 
-            FiniteDuration timeout = duration("5 seconds");
-            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
-            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
+                FiniteDuration timeout = duration("5 seconds");
+                FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
+                Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
 
-            reply(new LocalShardFound(getRef()));
+                reply(new LocalShardFound(getRef()));
 
-            RegisterChangeListener registerMsg = expectMsgClass(timeout, RegisterChangeListener.class);
-            Assert.assertEquals("getPath", path, registerMsg.getPath());
-            Assert.assertEquals("getScope", scope, registerMsg.getScope());
-            Assert.assertEquals("isRegisterOnAllInstances", false, registerMsg.isRegisterOnAllInstances());
+                RegisterChangeListener registerMsg = expectMsgClass(timeout, RegisterChangeListener.class);
+                Assert.assertEquals("getPath", path, registerMsg.getPath());
+                Assert.assertEquals("getScope", scope, registerMsg.getScope());
+                Assert.assertEquals("isRegisterOnAllInstances", false, registerMsg.isRegisterOnAllInstances());
 
-            reply(new RegisterChangeListenerReply(getRef()));
+                reply(new RegisterChangeListenerReply(getRef()));
 
-            for(int i = 0; (i < 20 * 5) && proxy.getListenerRegistrationActor() == null; i++) {
-                Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
-            }
+                for (int i = 0; i < 20 * 5 && proxy.getListenerRegistrationActor() == null; i++) {
+                    Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
+                }
 
-            Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()),
-                    proxy.getListenerRegistrationActor());
+                Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()),
+                        proxy.getListenerRegistrationActor());
 
-            watch(proxy.getDataChangeListenerActor());
+                watch(proxy.getDataChangeListenerActor());
 
-            proxy.close();
+                proxy.close();
 
-            // The listener registration actor should get a Close message
-            expectMsgClass(timeout, CloseDataChangeListenerRegistration.class);
+                // The listener registration actor should get a Close message
+                expectMsgClass(timeout, CloseDataChangeListenerRegistration.class);
 
-            // The DataChangeListener actor should be terminated
-            expectMsgClass(timeout, Terminated.class);
+                // The DataChangeListener actor should be terminated
+                expectMsgClass(timeout, Terminated.class);
 
-            proxy.close();
+                proxy.close();
 
-            expectNoMsg();
-        }};
+                expectNoMsg();
+            }
+        };
     }
 
-    @Test(timeout=10000)
+    @Test(timeout = 10000)
     public void testSuccessfulRegistrationForClusteredListener() {
-        new JavaTestKit(getSystem()) {{
-            ActorContext actorContext = new ActorContext(getSystem(), getRef(),
-                mock(ClusterWrapper.class), mock(Configuration.class));
-
-            AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> mockClusteredListener =
-                Mockito.mock(ClusteredDOMDataChangeListener.class);
-
-            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
-                "shard-1", actorContext, mockClusteredListener);
-
-            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();
-
-            FiniteDuration timeout = duration("5 seconds");
-            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
-            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
+        new JavaTestKit(getSystem()) {
+            {
+                ActorContext actorContext = new ActorContext(getSystem(), getRef(),
+                    mock(ClusterWrapper.class), mock(Configuration.class));
 
-            reply(new LocalShardFound(getRef()));
+                AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> mockClusteredListener =
+                        Mockito.mock(ClusteredDOMDataChangeListener.class);
 
-            RegisterChangeListener registerMsg = expectMsgClass(timeout, RegisterChangeListener.class);
-            Assert.assertEquals("getPath", path, registerMsg.getPath());
-            Assert.assertEquals("getScope", scope, registerMsg.getScope());
-            Assert.assertEquals("isRegisterOnAllInstances", true, registerMsg.isRegisterOnAllInstances());
+                final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
+                        "shard-1", actorContext, mockClusteredListener);
 
-            reply(new RegisterChangeListenerReply(getRef()));
+                final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
+                final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
+                new Thread() {
+                    @Override
+                    public void run() {
+                        proxy.init(path, scope);
+                    }
 
-            for(int i = 0; (i < 20 * 5) && proxy.getListenerRegistrationActor() == null; i++) {
-                Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
-            }
+                }.start();
 
-            Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()),
-                proxy.getListenerRegistrationActor());
+                FiniteDuration timeout = duration("5 seconds");
+                FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
+                Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
 
-            watch(proxy.getDataChangeListenerActor());
+                reply(new LocalShardFound(getRef()));
 
-            proxy.close();
+                RegisterChangeListener registerMsg = expectMsgClass(timeout, RegisterChangeListener.class);
+                Assert.assertEquals("getPath", path, registerMsg.getPath());
+                Assert.assertEquals("getScope", scope, registerMsg.getScope());
+                Assert.assertEquals("isRegisterOnAllInstances", true, registerMsg.isRegisterOnAllInstances());
 
-            // The listener registration actor should get a Close message
-            expectMsgClass(timeout, CloseDataChangeListenerRegistration.class);
+                reply(new RegisterChangeListenerReply(getRef()));
 
-            // The DataChangeListener actor should be terminated
-            expectMsgClass(timeout, Terminated.class);
+                for (int i = 0; i < 20 * 5 && proxy.getListenerRegistrationActor() == null; i++) {
+                    Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
+                }
 
-            proxy.close();
+                Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()),
+                        proxy.getListenerRegistrationActor());
 
-            expectNoMsg();
-        }};
-    }
+                watch(proxy.getDataChangeListenerActor());
 
-    @Test(timeout=10000)
-    public void testLocalShardNotFound() {
-        new JavaTestKit(getSystem()) {{
-            ActorContext actorContext = new ActorContext(getSystem(), getRef(),
-                    mock(ClusterWrapper.class), mock(Configuration.class));
+                proxy.close();
 
-            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
-                    "shard-1", actorContext, mockListener);
+                // The listener registration actor should get a Close message
+                expectMsgClass(timeout, CloseDataChangeListenerRegistration.class);
 
-            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
-            final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
-            new Thread() {
-                @Override
-                public void run() {
-                    proxy.init(path, scope);
-                }
+                // The DataChangeListener actor should be terminated
+                expectMsgClass(timeout, Terminated.class);
 
-            }.start();
+                proxy.close();
 
-            FiniteDuration timeout = duration("5 seconds");
-            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
-            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
+                expectNoMsg();
+            }
+        };
+    }
 
-            reply(new LocalShardNotFound("shard-1"));
+    @Test(timeout = 10000)
+    public void testLocalShardNotFound() {
+        new JavaTestKit(getSystem()) {
+            {
+                ActorContext actorContext = new ActorContext(getSystem(), getRef(),
+                        mock(ClusterWrapper.class), mock(Configuration.class));
 
-            expectNoMsg(duration("1 seconds"));
-        }};
-    }
+                final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
+                        "shard-1", actorContext, mockListener);
 
-    @Test(timeout=10000)
-    public void testLocalShardNotInitialized() {
-        new JavaTestKit(getSystem()) {{
-            ActorContext actorContext = new ActorContext(getSystem(), getRef(),
-                    mock(ClusterWrapper.class), mock(Configuration.class));
+                final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
+                final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
+                new Thread() {
+                    @Override
+                    public void run() {
+                        proxy.init(path, scope);
+                    }
 
-            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
-                    "shard-1", actorContext, mockListener);
+                }.start();
 
-            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
-            final DataChangeScope scope = AsyncDataBroker.DataChangeScope.ONE;
-            new Thread() {
-                @Override
-                public void run() {
-                    proxy.init(path, scope);
-                }
+                FiniteDuration timeout = duration("5 seconds");
+                FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
+                Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
 
-            }.start();
+                reply(new LocalShardNotFound("shard-1"));
 
-            FiniteDuration timeout = duration("5 seconds");
-            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
-            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
+                expectNoMsg(duration("1 seconds"));
 
-            reply(new NotInitializedException("not initialized"));
+                proxy.close();
+            }
+        };
+    }
 
-            new Within(duration("1 seconds")) {
-                @Override
-                protected void run() {
-                    expectNoMsg();
-                }
-            };
-        }};
+    @Test(timeout = 10000)
+    public void testLocalShardNotInitialized() {
+        new JavaTestKit(getSystem()) {
+            {
+                ActorContext actorContext = new ActorContext(getSystem(), getRef(),
+                        mock(ClusterWrapper.class), mock(Configuration.class));
+
+                final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
+                        "shard-1", actorContext, mockListener);
+
+                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();
+
+                FiniteDuration timeout = duration("5 seconds");
+                FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
+                Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
+
+                reply(new NotInitializedException("not initialized"));
+
+                new Within(duration("1 seconds")) {
+                    @Override
+                    protected void run() {
+                        expectNoMsg();
+                    }
+                };
+
+                proxy.close();
+            }
+        };
     }
 
     @Test
     public void testFailedRegistration() {
-        new JavaTestKit(getSystem()) {{
-            ActorSystem mockActorSystem = mock(ActorSystem.class);
+        new JavaTestKit(getSystem()) {
+            {
+                ActorSystem mockActorSystem = mock(ActorSystem.class);
 
-            ActorRef mockActor = getSystem().actorOf(Props.create(DoNothingActor.class),
-                    "testFailedRegistration");
-            doReturn(mockActor).when(mockActorSystem).actorOf(any(Props.class));
-            ExecutionContextExecutor executor = ExecutionContexts.fromExecutor(
-                    MoreExecutors.directExecutor());
+                ActorRef mockActor = getSystem().actorOf(Props.create(DoNothingActor.class),
+                        "testFailedRegistration");
+                doReturn(mockActor).when(mockActorSystem).actorOf(any(Props.class));
+                ExecutionContextExecutor executor = ExecutionContexts.fromExecutor(
+                        MoreExecutors.directExecutor());
 
 
-            ActorContext actorContext = mock(ActorContext.class);
+                ActorContext actorContext = mock(ActorContext.class);
 
-            doReturn(executor).when(actorContext).getClientDispatcher();
+                doReturn(executor).when(actorContext).getClientDispatcher();
 
-            String shardName = "shard-1";
-            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
-                    shardName, actorContext, mockListener);
+                String shardName = "shard-1";
+                final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
+                        shardName, actorContext, mockListener);
 
-            doReturn(mockActorSystem).when(actorContext).getActorSystem();
-            doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
-            doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
-            doReturn(Futures.failed(new RuntimeException("mock"))).
-                    when(actorContext).executeOperationAsync(any(ActorRef.class),
-                            any(Object.class), any(Timeout.class));
-            doReturn(mock(DatastoreContext.class)).when(actorContext).getDatastoreContext();
+                doReturn(mockActorSystem).when(actorContext).getActorSystem();
+                doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
+                doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
+                doReturn(Futures.failed(new RuntimeException("mock")))
+                    .when(actorContext).executeOperationAsync(any(ActorRef.class),
+                        any(Object.class), any(Timeout.class));
+                doReturn(mock(DatastoreContext.class)).when(actorContext).getDatastoreContext();
 
-            proxy.init(YangInstanceIdentifier.of(TestModel.TEST_QNAME),
-                    AsyncDataBroker.DataChangeScope.ONE);
+                proxy.init(YangInstanceIdentifier.of(TestModel.TEST_QNAME),
+                        AsyncDataBroker.DataChangeScope.ONE);
 
-            Assert.assertEquals("getListenerRegistrationActor", null,
-                    proxy.getListenerRegistrationActor());
-        }};
+                Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor());
+
+                proxy.close();
+            }
+        };
     }
 
     @Test
     public void testCloseBeforeRegistration() {
-        new JavaTestKit(getSystem()) {{
-            ActorContext actorContext = mock(ActorContext.class);
-
-            String shardName = "shard-1";
-            final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
-                    shardName, actorContext, mockListener);
-
-            doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
-            doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(actorContext).getClientDispatcher();
-            doReturn(getSystem()).when(actorContext).getActorSystem();
-            doReturn(Dispatchers.DEFAULT_DISPATCHER_PATH).when(actorContext).getNotificationDispatcherPath();
-            doReturn(getSystem().actorSelection(getRef().path())).
-                    when(actorContext).actorSelection(getRef().path());
-            doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
-            doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
-
-            Answer<Future<Object>> answer = new Answer<Future<Object>>() {
-                @Override
-                public Future<Object> answer(InvocationOnMock invocation) {
+        new JavaTestKit(getSystem()) {
+            {
+                ActorContext actorContext = mock(ActorContext.class);
+
+                String shardName = "shard-1";
+                final DataChangeListenerRegistrationProxy proxy = new DataChangeListenerRegistrationProxy(
+                        shardName, actorContext, mockListener);
+
+                doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
+                doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(actorContext).getClientDispatcher();
+                doReturn(getSystem()).when(actorContext).getActorSystem();
+                doReturn(Dispatchers.DEFAULT_DISPATCHER_PATH).when(actorContext).getNotificationDispatcherPath();
+                doReturn(getSystem().actorSelection(getRef().path()))
+                    .when(actorContext).actorSelection(getRef().path());
+                doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
+                doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
+
+                Answer<Future<Object>> answer = invocation -> {
                     proxy.close();
                     return Futures.successful((Object)new RegisterChangeListenerReply(getRef()));
-                }
-            };
+                };
 
-            doAnswer(answer).when(actorContext).executeOperationAsync(any(ActorRef.class),
-                    any(Object.class), any(Timeout.class));
+                doAnswer(answer).when(actorContext).executeOperationAsync(any(ActorRef.class),
+                        any(Object.class), any(Timeout.class));
 
-            proxy.init(YangInstanceIdentifier.of(TestModel.TEST_QNAME),
-                    AsyncDataBroker.DataChangeScope.ONE);
+                proxy.init(YangInstanceIdentifier.of(TestModel.TEST_QNAME),
+                        AsyncDataBroker.DataChangeScope.ONE);
 
-            expectMsgClass(duration("5 seconds"), CloseDataChangeListenerRegistration.class);
+                expectMsgClass(duration("5 seconds"), CloseDataChangeListenerRegistration.class);
 
-            Assert.assertEquals("getListenerRegistrationActor", null,
-                    proxy.getListenerRegistrationActor());
-        }};
+                Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor());
+                proxy.close();
+            }
+        };
     }
 }
index a2bd569..d23cfea 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.controller.cluster.datastore;
 
 import static org.junit.Assert.assertEquals;
+
 import akka.actor.ActorRef;
 import akka.actor.Props;
 import akka.testkit.JavaTestKit;
@@ -18,63 +19,58 @@ import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeLis
 import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistrationReply;
 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
 public class DataChangeListenerRegistrationTest extends AbstractActorTest {
-  private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService());
-
-  static {
-    store.onGlobalContextUpdated(TestModel.createTestContext());
-  }
-
-
-  @Test
-  public void testOnReceiveCloseListenerRegistration() throws Exception {
-    new JavaTestKit(getSystem()) {{
-      final Props props = DataChangeListenerRegistrationActor.props(store
-          .registerChangeListener(TestModel.TEST_PATH, noOpDataChangeListener(),
-              AsyncDataBroker.DataChangeScope.BASE));
-      final ActorRef subject = getSystem().actorOf(props, "testCloseListenerRegistration");
-
-      new Within(duration("1 seconds")) {
-        @Override
-        protected void run() {
-
-          subject.tell(CloseDataChangeListenerRegistration.INSTANCE, getRef());
-
-          final String out = new ExpectMsg<String>(duration("1 seconds"), "match hint") {
-            // do not put code outside this method, will run afterwards
-            @Override
-            protected String match(final Object in) {
-              if (in.getClass().equals(CloseDataChangeListenerRegistrationReply.class)) {
-                return "match";
-              } else {
-                throw noMatch();
-              }
+    private static final InMemoryDOMDataStore STORE = new InMemoryDOMDataStore("OPER",
+            MoreExecutors.newDirectExecutorService());
+
+    static {
+        STORE.onGlobalContextUpdated(TestModel.createTestContext());
+    }
+
+    @Test
+    public void testOnReceiveCloseListenerRegistration() throws Exception {
+        new JavaTestKit(getSystem()) {
+            {
+                final Props props = DataChangeListenerRegistrationActor.props(STORE.registerChangeListener(
+                        TestModel.TEST_PATH, noOpDataChangeListener(), AsyncDataBroker.DataChangeScope.BASE));
+                final ActorRef subject = getSystem().actorOf(props, "testCloseListenerRegistration");
+
+                new Within(duration("1 seconds")) {
+                    @Override
+                    protected void run() {
+
+                        subject.tell(CloseDataChangeListenerRegistration.INSTANCE, getRef());
+
+                        final String out = new ExpectMsg<String>(duration("1 seconds"), "match hint") {
+                            // do not put code outside this method, will run
+                            // afterwards
+                            @Override
+                            protected String match(final Object in) {
+                                if (in.getClass().equals(CloseDataChangeListenerRegistrationReply.class)) {
+                                    return "match";
+                                } else {
+                                    throw noMatch();
+                                }
+                            }
+                        }.get(); // this extracts the received message
+
+                        assertEquals("match", out);
+
+                        expectNoMsg();
+                    }
+
+                };
             }
-          }.get(); // this extracts the received message
-
-          assertEquals("match", out);
-
-          expectNoMsg();
-        }
-
-
-      };
-    }};
-  }
-
-  private static AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> noOpDataChangeListener(){
-    return new AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>() {
-      @Override
-      public void onDataChanged(final AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change) {
-
-      }
-    };
-  }
+        };
+    }
 
+    private static AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>> noOpDataChangeListener() {
+        return change -> {
+        };
+    }
 }
index ce8b521..fc70e33 100644 (file)
@@ -21,6 +21,7 @@ import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.o
 import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.outerNode;
 import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.outerNodeEntry;
 import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.testNodeWithOuter;
+
 import akka.actor.ActorRef;
 import akka.dispatch.Dispatchers;
 import akka.testkit.TestActorRef;
@@ -55,7 +56,8 @@ public class DataChangeListenerSupportTest extends AbstractShardTest {
                 final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener),
                         "testChangeListenerWithNoInitialData-DataChangeListener");
                 final DataChangeListenerSupport support = new DataChangeListenerSupport(shard);
-                support.onMessage(new RegisterChangeListener(TEST_PATH, dclActor, DataChangeScope.ONE, false),true,true);
+                support.onMessage(new RegisterChangeListener(TEST_PATH, dclActor, DataChangeScope.ONE, false),
+                        true,true);
 
                 listener.expectNoMoreChanges("Unexpected initial change event");
             }
@@ -80,7 +82,8 @@ public class DataChangeListenerSupportTest extends AbstractShardTest {
                 final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener),
                         "testInitialChangeListenerEventWithContainerPath-DataChangeListener");
                 final DataChangeListenerSupport support = new DataChangeListenerSupport(shard);
-                support.onMessage(new RegisterChangeListener(TEST_PATH, dclActor, DataChangeScope.ONE, false),true,true);
+                support.onMessage(new RegisterChangeListener(TEST_PATH, dclActor, DataChangeScope.ONE, false),
+                        true,true);
 
                 listener.waitForChangeEvents(TEST_PATH);
             }
@@ -169,8 +172,9 @@ public class DataChangeListenerSupportTest extends AbstractShardTest {
                 final ActorRef dclActor = actorFactory.createActor(DataChangeListener.props(listener),
                         "testInitialChangeListenerEventWithNestedWildcardedListsPath-DataChangeListener");
                 final DataChangeListenerSupport support = new DataChangeListenerSupport(shard);
-                support.onMessage(new RegisterChangeListener(OUTER_LIST_PATH.node(OUTER_LIST_QNAME).node(INNER_LIST_QNAME).node(INNER_LIST_QNAME), dclActor,
-                        DataChangeScope.ONE, false), true, true);
+                support.onMessage(new RegisterChangeListener(OUTER_LIST_PATH.node(OUTER_LIST_QNAME)
+                        .node(INNER_LIST_QNAME).node(INNER_LIST_QNAME), dclActor, DataChangeScope.ONE, false),
+                            true, true);
 
 
                 listener.waitForChangeEvents();
@@ -234,6 +238,5 @@ public class DataChangeListenerSupportTest extends AbstractShardTest {
                 listener.verifyCreatedData(0, innerEntryPath(2, "four"));
             }
         };
-
     }
 }
index 91cac88..544a566 100644 (file)
@@ -18,120 +18,123 @@ import org.mockito.Mockito;
 import org.opendaylight.controller.cluster.datastore.messages.DataChanged;
 import org.opendaylight.controller.cluster.datastore.messages.DataChangedReply;
 import org.opendaylight.controller.cluster.datastore.messages.EnableNotification;
-import org.opendaylight.controller.md.cluster.datastore.model.CompositeModel;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class DataChangeListenerTest extends AbstractActorTest {
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test
-    public void testDataChangedWhenNotificationsAreEnabled(){
-        new JavaTestKit(getSystem()) {{
-            final AsyncDataChangeEvent mockChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
-            final AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
-            final Props props = DataChangeListener.props(mockListener);
-            final ActorRef subject = getSystem().actorOf(props, "testDataChangedNotificationsEnabled");
+    public void testDataChangedWhenNotificationsAreEnabled() {
+        new JavaTestKit(getSystem()) {
+            {
+                final AsyncDataChangeEvent mockChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
+                final AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
+                final Props props = DataChangeListener.props(mockListener);
+                final ActorRef subject = getSystem().actorOf(props, "testDataChangedNotificationsEnabled");
 
-            // Let the DataChangeListener know that notifications should be enabled
-            subject.tell(new EnableNotification(true), getRef());
+                // Let the DataChangeListener know that notifications should be
+                // enabled
+                subject.tell(new EnableNotification(true), getRef());
 
-            subject.tell(new DataChanged(mockChangeEvent),
-                    getRef());
+                subject.tell(new DataChanged(mockChangeEvent), getRef());
 
-            expectMsgClass(DataChangedReply.class);
+                expectMsgClass(DataChangedReply.class);
 
-            Mockito.verify(mockListener).onDataChanged(mockChangeEvent);
-        }};
+                Mockito.verify(mockListener).onDataChanged(mockChangeEvent);
+            }
+        };
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test
-    public void testDataChangedWhenNotificationsAreDisabled(){
-        new JavaTestKit(getSystem()) {{
-            final AsyncDataChangeEvent mockChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
-            final AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
-            final Props props = DataChangeListener.props(mockListener);
-            final ActorRef subject =
-                getSystem().actorOf(props, "testDataChangedNotificationsDisabled");
-
-            subject.tell(new DataChanged(mockChangeEvent),
-                    getRef());
-
-            new Within(duration("1 seconds")) {
-                @Override
-                protected void run() {
-                    expectNoMsg();
-
-                    Mockito.verify(mockListener, Mockito.never()).onDataChanged(
-                            Mockito.any(AsyncDataChangeEvent.class));
-                }
-            };
-        }};
+    public void testDataChangedWhenNotificationsAreDisabled() {
+        new JavaTestKit(getSystem()) {
+            {
+                final AsyncDataChangeEvent mockChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
+                final AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
+                final Props props = DataChangeListener.props(mockListener);
+                final ActorRef subject = getSystem().actorOf(props, "testDataChangedNotificationsDisabled");
+
+                subject.tell(new DataChanged(mockChangeEvent), getRef());
+
+                new Within(duration("1 seconds")) {
+                    @Override
+                    protected void run() {
+                        expectNoMsg();
+
+                        Mockito.verify(mockListener, Mockito.never())
+                                .onDataChanged(Mockito.any(AsyncDataChangeEvent.class));
+                    }
+                };
+            }
+        };
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test
-    public void testDataChangedWithNoSender(){
-        new JavaTestKit(getSystem()) {{
-            final AsyncDataChangeEvent mockChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
-            final AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
-            final Props props = DataChangeListener.props(mockListener);
-            final ActorRef subject = getSystem().actorOf(props, "testDataChangedWithNoSender");
-
-            getSystem().eventStream().subscribe(getRef(), DeadLetter.class);
-
-            subject.tell(new DataChanged(mockChangeEvent), ActorRef.noSender());
-
-            // Make sure no DataChangedReply is sent to DeadLetters.
-            while(true) {
-                DeadLetter deadLetter;
-                try {
-                    deadLetter = expectMsgClass(duration("1 seconds"), DeadLetter.class);
-                } catch (AssertionError e) {
-                    // Timed out - got no DeadLetter - this is good
-                    break;
+    public void testDataChangedWithNoSender() {
+        new JavaTestKit(getSystem()) {
+            {
+                final AsyncDataChangeEvent mockChangeEvent = Mockito.mock(AsyncDataChangeEvent.class);
+                final AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
+                final Props props = DataChangeListener.props(mockListener);
+                final ActorRef subject = getSystem().actorOf(props, "testDataChangedWithNoSender");
+
+                getSystem().eventStream().subscribe(getRef(), DeadLetter.class);
+
+                subject.tell(new DataChanged(mockChangeEvent), ActorRef.noSender());
+
+                // Make sure no DataChangedReply is sent to DeadLetters.
+                while (true) {
+                    DeadLetter deadLetter;
+                    try {
+                        deadLetter = expectMsgClass(duration("1 seconds"), DeadLetter.class);
+                    } catch (AssertionError e) {
+                        // Timed out - got no DeadLetter - this is good
+                        break;
+                    }
+
+                    // We may get DeadLetters for other messages we don't care
+                    // about.
+                    Assert.assertFalse("Unexpected DataChangedReply", deadLetter.message() instanceof DataChangedReply);
                 }
-
-                // We may get DeadLetters for other messages we don't care about.
-                Assert.assertFalse("Unexpected DataChangedReply",
-                        deadLetter.message() instanceof DataChangedReply);
             }
-        }};
+        };
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test
-    public void testDataChangedWithListenerRuntimeEx(){
-        new JavaTestKit(getSystem()) {{
-            AsyncDataChangeEvent mockChangeEvent1 = Mockito.mock(AsyncDataChangeEvent.class);
-            AsyncDataChangeEvent mockChangeEvent2 = Mockito.mock(AsyncDataChangeEvent.class);
-            AsyncDataChangeEvent mockChangeEvent3 = Mockito.mock(AsyncDataChangeEvent.class);
-
-            AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
-            Mockito.doThrow(new RuntimeException("mock")).when(mockListener).onDataChanged(mockChangeEvent2);
+    public void testDataChangedWithListenerRuntimeEx() {
+        new JavaTestKit(getSystem()) {
+            {
+                final AsyncDataChangeEvent mockChangeEvent1 = Mockito.mock(AsyncDataChangeEvent.class);
+                final AsyncDataChangeEvent mockChangeEvent2 = Mockito.mock(AsyncDataChangeEvent.class);
+                final AsyncDataChangeEvent mockChangeEvent3 = Mockito.mock(AsyncDataChangeEvent.class);
 
-            Props props = DataChangeListener.props(mockListener);
-            ActorRef subject = getSystem().actorOf(props, "testDataChangedWithListenerRuntimeEx");
+                AsyncDataChangeListener mockListener = Mockito.mock(AsyncDataChangeListener.class);
+                Mockito.doThrow(new RuntimeException("mock")).when(mockListener).onDataChanged(mockChangeEvent2);
 
-            // Let the DataChangeListener know that notifications should be enabled
-            subject.tell(new EnableNotification(true), getRef());
+                Props props = DataChangeListener.props(mockListener);
+                ActorRef subject = getSystem().actorOf(props, "testDataChangedWithListenerRuntimeEx");
 
-            SchemaContext schemaContext = CompositeModel.createTestContext();
+                // Let the DataChangeListener know that notifications should be
+                // enabled
+                subject.tell(new EnableNotification(true), getRef());
 
-            subject.tell(new DataChanged(mockChangeEvent1),getRef());
-            expectMsgClass(DataChangedReply.class);
+                subject.tell(new DataChanged(mockChangeEvent1), getRef());
+                expectMsgClass(DataChangedReply.class);
 
-            subject.tell(new DataChanged(mockChangeEvent2),getRef());
-            expectMsgClass(DataChangedReply.class);
+                subject.tell(new DataChanged(mockChangeEvent2), getRef());
+                expectMsgClass(DataChangedReply.class);
 
-            subject.tell(new DataChanged(mockChangeEvent3),getRef());
-            expectMsgClass(DataChangedReply.class);
+                subject.tell(new DataChanged(mockChangeEvent3), getRef());
+                expectMsgClass(DataChangedReply.class);
 
-            Mockito.verify(mockListener).onDataChanged(mockChangeEvent1);
-            Mockito.verify(mockListener).onDataChanged(mockChangeEvent2);
-            Mockito.verify(mockListener).onDataChanged(mockChangeEvent3);
-        }};
+                Mockito.verify(mockListener).onDataChanged(mockChangeEvent1);
+                Mockito.verify(mockListener).onDataChanged(mockChangeEvent2);
+                Mockito.verify(mockListener).onDataChanged(mockChangeEvent3);
+            }
+        };
     }
 }
index 3a7b89f..c7e20bb 100644 (file)
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
+
 import java.io.IOException;
 import java.util.Collection;
 import org.apache.commons.lang3.SerializationUtils;
@@ -36,7 +37,8 @@ public class DataTreeCandidatePayloadTest {
 
     private DataTreeCandidate candidate;
 
-    private static DataTreeCandidateNode findNode(final Collection<DataTreeCandidateNode> nodes, final PathArgument arg) {
+    private static DataTreeCandidateNode findNode(final Collection<DataTreeCandidateNode> nodes,
+            final PathArgument arg) {
         for (DataTreeCandidateNode node : nodes) {
             if (arg.equals(node.getIdentifier())) {
                 return node;
@@ -68,36 +70,37 @@ public class DataTreeCandidatePayloadTest {
         assertEquals("root type", expRoot.getModificationType(), actRoot.getModificationType());
 
         switch (actRoot.getModificationType()) {
-        case DELETE:
-        case WRITE:
-            assertEquals("root data", expRoot.getDataAfter(), actRoot.getDataAfter());
-            break;
-        case SUBTREE_MODIFIED:
-            assertChildrenEquals(expRoot.getChildNodes(), actRoot.getChildNodes());
-            break;
-        default:
-            fail("Unexpect root type " + actRoot.getModificationType());
-            break;
+            case DELETE:
+            case WRITE:
+                assertEquals("root data", expRoot.getDataAfter(), actRoot.getDataAfter());
+                break;
+            case SUBTREE_MODIFIED:
+                assertChildrenEquals(expRoot.getChildNodes(), actRoot.getChildNodes());
+                break;
+            default:
+                fail("Unexpect root type " + actRoot.getModificationType());
+                break;
         }
 
         assertCandidateNodeEquals(expected.getRootNode(), actual.getRootNode());
     }
 
-    private static void assertCandidateNodeEquals(final DataTreeCandidateNode expected, final DataTreeCandidateNode actual) {
+    private static void assertCandidateNodeEquals(final DataTreeCandidateNode expected,
+            final DataTreeCandidateNode actual) {
         assertEquals("child type", expected.getModificationType(), actual.getModificationType());
         assertEquals("child identifier", expected.getIdentifier(), actual.getIdentifier());
 
         switch (actual.getModificationType()) {
-        case DELETE:
-        case WRITE:
-            assertEquals("child data", expected.getDataAfter(), actual.getDataAfter());
-            break;
-        case SUBTREE_MODIFIED:
-            assertChildrenEquals(expected.getChildNodes(), actual.getChildNodes());
-            break;
-        default:
-            fail("Unexpect root type " + actual.getModificationType());
-            break;
+            case DELETE:
+            case WRITE:
+                assertEquals("child data", expected.getDataAfter(), actual.getDataAfter());
+                break;
+            case SUBTREE_MODIFIED:
+                assertChildrenEquals(expected.getChildNodes(), actual.getChildNodes());
+                break;
+            default:
+                fail("Unexpect root type " + actual.getModificationType());
+                break;
         }
     }
 
@@ -105,8 +108,8 @@ public class DataTreeCandidatePayloadTest {
     public void setUp() {
         final YangInstanceIdentifier writePath = TestModel.TEST_PATH;
         final NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
-                new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
-                withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
+                new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
+                    .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
         candidate = DataTreeCandidates.fromNormalizedNode(writePath, writeData);
     }
 
@@ -135,10 +138,10 @@ public class DataTreeCandidatePayloadTest {
         YangInstanceIdentifier leafSetEntryPath = YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(LEAF_SET)
                 .node(entryPathArg).build();
 
-        NormalizedNode<?, ?> leafSetEntryNode = Builders.leafSetEntryBuilder().
-                withNodeIdentifier(entryPathArg).withValue("one").build();
+        NormalizedNode<?, ?> leafSetEntryNode = Builders.leafSetEntryBuilder()
+                .withNodeIdentifier(entryPathArg).withValue("one").build();
 
-        DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode(leafSetEntryPath, leafSetEntryNode);
+        candidate = DataTreeCandidates.fromNormalizedNode(leafSetEntryPath, leafSetEntryNode);
         DataTreeCandidatePayload payload = DataTreeCandidatePayload.create(candidate);
         assertCandidateEquals(candidate, payload.getCandidate());
     }
@@ -149,8 +152,8 @@ public class DataTreeCandidatePayloadTest {
         YangInstanceIdentifier.NodeWithValue entryPathArg = new YangInstanceIdentifier.NodeWithValue(LEAF_SET, "one");
         YangInstanceIdentifier leafSetPath = YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(LEAF_SET).build();
 
-        LeafSetEntryNode leafSetEntryNode = Builders.leafSetEntryBuilder().
-                withNodeIdentifier(entryPathArg).withValue("one").build();
+        LeafSetEntryNode leafSetEntryNode = Builders.leafSetEntryBuilder()
+                .withNodeIdentifier(entryPathArg).withValue("one").build();
         NormalizedNode<?, ?> leafSetNode = Builders.leafSetBuilder().withNodeIdentifier(
                 new YangInstanceIdentifier.NodeIdentifier(LEAF_SET)).withChild(leafSetEntryNode).build();
 
@@ -165,23 +168,24 @@ public class DataTreeCandidatePayloadTest {
         YangInstanceIdentifier.NodeWithValue entryPathArg = new YangInstanceIdentifier.NodeWithValue(LEAF_SET, "one");
         YangInstanceIdentifier leafSetPath = YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(LEAF_SET).build();
 
-        LeafSetEntryNode leafSetEntryNode = Builders.leafSetEntryBuilder().
-                withNodeIdentifier(entryPathArg).withValue("one").build();
+        LeafSetEntryNode leafSetEntryNode = Builders.leafSetEntryBuilder()
+                .withNodeIdentifier(entryPathArg).withValue("one").build();
         NormalizedNode<?, ?> leafSetNode = Builders.orderedLeafSetBuilder().withNodeIdentifier(
                 new YangInstanceIdentifier.NodeIdentifier(LEAF_SET)).withChild(leafSetEntryNode).build();
 
-        DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode(leafSetPath, leafSetNode);
+        candidate = DataTreeCandidates.fromNormalizedNode(leafSetPath, leafSetNode);
         DataTreeCandidatePayload payload = DataTreeCandidatePayload.create(candidate);
         assertCandidateEquals(candidate, payload.getCandidate());
     }
 
     @Test
     public void testLeafNodeCandidate() throws Exception {
-        YangInstanceIdentifier leafPath = YangInstanceIdentifier.builder(TestModel.TEST_PATH).node(TestModel.DESC_QNAME).build();
+        YangInstanceIdentifier leafPath = YangInstanceIdentifier.builder(TestModel.TEST_PATH)
+                .node(TestModel.DESC_QNAME).build();
         LeafNode<Object> leafNode = Builders.leafBuilder().withNodeIdentifier(
                 new YangInstanceIdentifier.NodeIdentifier(TestModel.DESC_QNAME)).withValue("test").build();
 
-        DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode(leafPath, leafNode);
+        candidate = DataTreeCandidates.fromNormalizedNode(leafPath, leafNode);
         DataTreeCandidatePayload payload = DataTreeCandidatePayload.create(candidate);
         assertCandidateEquals(candidate, payload.getCandidate());
     }
index 73d520d..6b8658c 100644 (file)
@@ -25,112 +25,120 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 public class DataTreeChangeListenerActorTest extends AbstractActorTest {
 
     @Test
-    public void testDataChangedWhenNotificationsAreEnabled(){
-        new JavaTestKit(getSystem()) {{
-            final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class);
-            final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate);
-            final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
-            final Props props = DataTreeChangeListenerActor.props(mockListener);
-            final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedNotificationsEnabled");
+    public void testDataChangedWhenNotificationsAreEnabled() {
+        new JavaTestKit(getSystem()) {
+            {
+                final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class);
+                final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate);
+                final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
+                final Props props = DataTreeChangeListenerActor.props(mockListener);
+                final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedNotificationsEnabled");
 
-            // Let the DataChangeListener know that notifications should be enabled
-            subject.tell(new EnableNotification(true), getRef());
+                // Let the DataChangeListener know that notifications should be
+                // enabled
+                subject.tell(new EnableNotification(true), getRef());
 
-            subject.tell(new DataTreeChanged(mockCandidates),
-                    getRef());
+                subject.tell(new DataTreeChanged(mockCandidates), getRef());
 
-            expectMsgClass(DataTreeChangedReply.class);
+                expectMsgClass(DataTreeChangedReply.class);
 
-            Mockito.verify(mockListener).onDataTreeChanged(mockCandidates);
-        }};
+                Mockito.verify(mockListener).onDataTreeChanged(mockCandidates);
+            }
+        };
     }
 
     @Test
-    public void testDataChangedWhenNotificationsAreDisabled(){
-        new JavaTestKit(getSystem()) {{
-            final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class);
-            final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate);
-            final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
-            final Props props = DataTreeChangeListenerActor.props(mockListener);
-            final ActorRef subject =
-                    getSystem().actorOf(props, "testDataTreeChangedNotificationsDisabled");
-
-            subject.tell(new DataTreeChanged(mockCandidates),
-                    getRef());
-
-            new Within(duration("1 seconds")) {
-                @Override
-                protected void run() {
-                    expectNoMsg();
-
-                    Mockito.verify(mockListener, Mockito.never()).onDataTreeChanged(
-                            Matchers.anyCollectionOf(DataTreeCandidate.class));
-                }
-            };
-        }};
+    public void testDataChangedWhenNotificationsAreDisabled() {
+        new JavaTestKit(getSystem()) {
+            {
+                final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class);
+                final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate);
+                final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
+                final Props props = DataTreeChangeListenerActor.props(mockListener);
+                final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedNotificationsDisabled");
+
+                subject.tell(new DataTreeChanged(mockCandidates), getRef());
+
+                new Within(duration("1 seconds")) {
+                    @Override
+                    protected void run() {
+                        expectNoMsg();
+
+                        Mockito.verify(mockListener, Mockito.never())
+                                .onDataTreeChanged(Matchers.anyCollectionOf(DataTreeCandidate.class));
+                    }
+                };
+            }
+        };
     }
 
     @Test
-    public void testDataChangedWithNoSender(){
-        new JavaTestKit(getSystem()) {{
-            final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class);
-            final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate);
-            final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
-            final Props props = DataTreeChangeListenerActor.props(mockListener);
-            final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedWithNoSender");
-
-            getSystem().eventStream().subscribe(getRef(), DeadLetter.class);
-
-            subject.tell(new DataTreeChanged(mockCandidates), ActorRef.noSender());
-
-            // Make sure no DataChangedReply is sent to DeadLetters.
-            while(true) {
-                DeadLetter deadLetter;
-                try {
-                    deadLetter = expectMsgClass(duration("1 seconds"), DeadLetter.class);
-                } catch (AssertionError e) {
-                    // Timed out - got no DeadLetter - this is good
-                    break;
+    public void testDataChangedWithNoSender() {
+        new JavaTestKit(getSystem()) {
+            {
+                final DataTreeCandidate mockTreeCandidate = Mockito.mock(DataTreeCandidate.class);
+                final ImmutableList<DataTreeCandidate> mockCandidates = ImmutableList.of(mockTreeCandidate);
+                final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
+                final Props props = DataTreeChangeListenerActor.props(mockListener);
+                final ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedWithNoSender");
+
+                getSystem().eventStream().subscribe(getRef(), DeadLetter.class);
+
+                subject.tell(new DataTreeChanged(mockCandidates), ActorRef.noSender());
+
+                // Make sure no DataChangedReply is sent to DeadLetters.
+                while (true) {
+                    DeadLetter deadLetter;
+                    try {
+                        deadLetter = expectMsgClass(duration("1 seconds"), DeadLetter.class);
+                    } catch (AssertionError e) {
+                        // Timed out - got no DeadLetter - this is good
+                        break;
+                    }
+
+                    // We may get DeadLetters for other messages we don't care
+                    // about.
+                    Assert.assertFalse("Unexpected DataTreeChangedReply",
+                            deadLetter.message() instanceof DataTreeChangedReply);
                 }
-
-                // We may get DeadLetters for other messages we don't care about.
-                Assert.assertFalse("Unexpected DataTreeChangedReply",
-                        deadLetter.message() instanceof DataTreeChangedReply);
             }
-        }};
+        };
     }
 
     @Test
-    public void testDataChangedWithListenerRuntimeEx(){
-        new JavaTestKit(getSystem()) {{
-            final DataTreeCandidate mockTreeCandidate1 = Mockito.mock(DataTreeCandidate.class);
-            final ImmutableList<DataTreeCandidate> mockCandidates1 = ImmutableList.of(mockTreeCandidate1);
-            final DataTreeCandidate mockTreeCandidate2 = Mockito.mock(DataTreeCandidate.class);
-            final ImmutableList<DataTreeCandidate> mockCandidates2 = ImmutableList.of(mockTreeCandidate2);
-            final DataTreeCandidate mockTreeCandidate3 = Mockito.mock(DataTreeCandidate.class);
-            final ImmutableList<DataTreeCandidate> mockCandidates3 = ImmutableList.of(mockTreeCandidate3);
-
-            final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
-            Mockito.doThrow(new RuntimeException("mock")).when(mockListener).onDataTreeChanged(mockCandidates2);
-
-            Props props = DataTreeChangeListenerActor.props(mockListener);
-            ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedWithListenerRuntimeEx");
-
-            // Let the DataChangeListener know that notifications should be enabled
-            subject.tell(new EnableNotification(true), getRef());
-
-            subject.tell(new DataTreeChanged(mockCandidates1),getRef());
-            expectMsgClass(DataTreeChangedReply.class);
-
-            subject.tell(new DataTreeChanged(mockCandidates2),getRef());
-            expectMsgClass(DataTreeChangedReply.class);
-
-            subject.tell(new DataTreeChanged(mockCandidates3),getRef());
-            expectMsgClass(DataTreeChangedReply.class);
-
-            Mockito.verify(mockListener).onDataTreeChanged(mockCandidates1);
-            Mockito.verify(mockListener).onDataTreeChanged(mockCandidates2);
-            Mockito.verify(mockListener).onDataTreeChanged(mockCandidates3);
-        }};
+    public void testDataChangedWithListenerRuntimeEx() {
+        new JavaTestKit(getSystem()) {
+            {
+                final DataTreeCandidate mockTreeCandidate1 = Mockito.mock(DataTreeCandidate.class);
+                final ImmutableList<DataTreeCandidate> mockCandidates1 = ImmutableList.of(mockTreeCandidate1);
+                final DataTreeCandidate mockTreeCandidate2 = Mockito.mock(DataTreeCandidate.class);
+                final ImmutableList<DataTreeCandidate> mockCandidates2 = ImmutableList.of(mockTreeCandidate2);
+                final DataTreeCandidate mockTreeCandidate3 = Mockito.mock(DataTreeCandidate.class);
+                final ImmutableList<DataTreeCandidate> mockCandidates3 = ImmutableList.of(mockTreeCandidate3);
+
+                final DOMDataTreeChangeListener mockListener = Mockito.mock(DOMDataTreeChangeListener.class);
+                Mockito.doThrow(new RuntimeException("mock")).when(mockListener).onDataTreeChanged(mockCandidates2);
+
+                Props props = DataTreeChangeListenerActor.props(mockListener);
+                ActorRef subject = getSystem().actorOf(props, "testDataTreeChangedWithListenerRuntimeEx");
+
+                // Let the DataChangeListener know that notifications should be
+                // enabled
+                subject.tell(new EnableNotification(true), getRef());
+
+                subject.tell(new DataTreeChanged(mockCandidates1), getRef());
+                expectMsgClass(DataTreeChangedReply.class);
+
+                subject.tell(new DataTreeChanged(mockCandidates2), getRef());
+                expectMsgClass(DataTreeChangedReply.class);
+
+                subject.tell(new DataTreeChanged(mockCandidates3), getRef());
+                expectMsgClass(DataTreeChangedReply.class);
+
+                Mockito.verify(mockListener).onDataTreeChanged(mockCandidates1);
+                Mockito.verify(mockListener).onDataTreeChanged(mockCandidates2);
+                Mockito.verify(mockListener).onDataTreeChanged(mockCandidates3);
+            }
+        };
     }
 }
index 5dcc39d..8cf0d83 100644 (file)
@@ -12,6 +12,7 @@ import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
+
 import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.actor.Props;
@@ -25,7 +26,6 @@ import com.google.common.util.concurrent.Uninterruptibles;
 import java.util.concurrent.TimeUnit;
 import org.junit.Assert;
 import org.junit.Test;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.cluster.datastore.config.Configuration;
 import org.opendaylight.controller.cluster.datastore.exceptions.NotInitializedException;
@@ -49,226 +49,238 @@ import scala.concurrent.duration.FiniteDuration;
 public class DataTreeChangeListenerProxyTest extends AbstractActorTest {
     private final DOMDataTreeChangeListener mockListener = mock(DOMDataTreeChangeListener.class);
 
-    @Test(timeout=10000)
+    @Test(timeout = 10000)
     public void testSuccessfulRegistration() {
-        new JavaTestKit(getSystem()) {{
-            ActorContext actorContext = new ActorContext(getSystem(), getRef(),
-                    mock(ClusterWrapper.class), mock(Configuration.class));
-
-            final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy =
-                    new DataTreeChangeListenerProxy<>(actorContext, mockListener);
-
-            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
-            new Thread() {
-                @Override
-                public void run() {
-                    proxy.init("shard-1", path);
-                }
+        new JavaTestKit(getSystem()) {
+            {
+                ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class),
+                        mock(Configuration.class));
 
-            }.start();
+                final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(
+                        actorContext, mockListener);
 
-            FiniteDuration timeout = duration("5 seconds");
-            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
-            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
+                final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
+                new Thread() {
+                    @Override
+                    public void run() {
+                        proxy.init("shard-1", path);
+                    }
 
-            reply(new LocalShardFound(getRef()));
+                }.start();
 
-            RegisterDataTreeChangeListener registerMsg = expectMsgClass(timeout, RegisterDataTreeChangeListener.class);
-            Assert.assertEquals("getPath", path, registerMsg.getPath());
-            Assert.assertEquals("isRegisterOnAllInstances", false, registerMsg.isRegisterOnAllInstances());
+                FiniteDuration timeout = duration("5 seconds");
+                FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
+                Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
 
-            reply(new RegisterDataTreeChangeListenerReply(getRef()));
+                reply(new LocalShardFound(getRef()));
 
+                RegisterDataTreeChangeListener registerMsg = expectMsgClass(timeout,
+                        RegisterDataTreeChangeListener.class);
+                Assert.assertEquals("getPath", path, registerMsg.getPath());
+                Assert.assertEquals("isRegisterOnAllInstances", false, registerMsg.isRegisterOnAllInstances());
 
-            for(int i = 0; (i < 20 * 5) && proxy.getListenerRegistrationActor() == null; i++) {
-                Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
-            }
+                reply(new RegisterDataTreeChangeListenerReply(getRef()));
 
-            Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()),
-                    proxy.getListenerRegistrationActor());
+                for (int i = 0; i < 20 * 5 && proxy.getListenerRegistrationActor() == null; i++) {
+                    Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
+                }
+
+                Assert.assertEquals("getListenerRegistrationActor", getSystem().actorSelection(getRef().path()),
+                        proxy.getListenerRegistrationActor());
 
-            watch(proxy.getDataChangeListenerActor());
+                watch(proxy.getDataChangeListenerActor());
 
-            proxy.close();
+                proxy.close();
 
-            // The listener registration actor should get a Close message
-            expectMsgClass(timeout, CloseDataTreeChangeListenerRegistration.class);
+                // The listener registration actor should get a Close message
+                expectMsgClass(timeout, CloseDataTreeChangeListenerRegistration.class);
 
-            // The DataChangeListener actor should be terminated
-            expectMsgClass(timeout, Terminated.class);
+                // The DataChangeListener actor should be terminated
+                expectMsgClass(timeout, Terminated.class);
 
-            proxy.close();
+                proxy.close();
 
-            expectNoMsg();
-        }};
+                expectNoMsg();
+            }
+        };
     }
 
-    @Test(timeout=10000)
+    @Test(timeout = 10000)
     public void testSuccessfulRegistrationForClusteredListener() {
-        new JavaTestKit(getSystem()) {{
-            ActorContext actorContext = new ActorContext(getSystem(), getRef(),
-                    mock(ClusterWrapper.class), mock(Configuration.class));
+        new JavaTestKit(getSystem()) {
+            {
+                ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class),
+                        mock(Configuration.class));
 
-            ClusteredDOMDataTreeChangeListener mockClusteredListener = mock(ClusteredDOMDataTreeChangeListener.class);
+                ClusteredDOMDataTreeChangeListener mockClusteredListener = mock(
+                        ClusteredDOMDataTreeChangeListener.class);
 
-            final DataTreeChangeListenerProxy<ClusteredDOMDataTreeChangeListener> proxy =
-                    new DataTreeChangeListenerProxy<>(actorContext, mockClusteredListener);
+                final DataTreeChangeListenerProxy<ClusteredDOMDataTreeChangeListener> proxy =
+                        new DataTreeChangeListenerProxy<>(actorContext, mockClusteredListener);
 
-            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
-            new Thread() {
-                @Override
-                public void run() {
-                    proxy.init("shard-1", path);
-                }
+                final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
+                new Thread() {
+                    @Override
+                    public void run() {
+                        proxy.init("shard-1", path);
+                    }
+
+                }.start();
 
-            }.start();
+                FiniteDuration timeout = duration("5 seconds");
+                FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
+                Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
 
-            FiniteDuration timeout = duration("5 seconds");
-            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
-            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
+                reply(new LocalShardFound(getRef()));
 
-            reply(new LocalShardFound(getRef()));
+                RegisterDataTreeChangeListener registerMsg = expectMsgClass(timeout,
+                        RegisterDataTreeChangeListener.class);
+                Assert.assertEquals("getPath", path, registerMsg.getPath());
+                Assert.assertEquals("isRegisterOnAllInstances", true, registerMsg.isRegisterOnAllInstances());
 
-            RegisterDataTreeChangeListener registerMsg = expectMsgClass(timeout, RegisterDataTreeChangeListener.class);
-            Assert.assertEquals("getPath", path, registerMsg.getPath());
-            Assert.assertEquals("isRegisterOnAllInstances", true, registerMsg.isRegisterOnAllInstances());
-        }};
+                proxy.close();
+            }
+        };
     }
 
-    @Test(timeout=10000)
+    @Test(timeout = 10000)
     public void testLocalShardNotFound() {
-        new JavaTestKit(getSystem()) {{
-            ActorContext actorContext = new ActorContext(getSystem(), getRef(),
-                    mock(ClusterWrapper.class), mock(Configuration.class));
-
-            final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy =
-                    new DataTreeChangeListenerProxy<>(actorContext, mockListener);
-
-            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
-            new Thread() {
-                @Override
-                public void run() {
-                    proxy.init("shard-1", path);
-                }
+        new JavaTestKit(getSystem()) {
+            {
+                ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class),
+                        mock(Configuration.class));
+
+                final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(
+                        actorContext, mockListener);
+
+                final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
+                new Thread() {
+                    @Override
+                    public void run() {
+                        proxy.init("shard-1", path);
+                    }
 
-            }.start();
+                }.start();
 
-            FiniteDuration timeout = duration("5 seconds");
-            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
-            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
+                FiniteDuration timeout = duration("5 seconds");
+                FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
+                Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
 
-            reply(new LocalShardNotFound("shard-1"));
+                reply(new LocalShardNotFound("shard-1"));
 
-            expectNoMsg(duration("1 seconds"));
-        }};
+                expectNoMsg(duration("1 seconds"));
+
+                proxy.close();
+            }
+        };
     }
 
-    @Test(timeout=10000)
+    @Test(timeout = 10000)
     public void testLocalShardNotInitialized() {
-        new JavaTestKit(getSystem()) {{
-            ActorContext actorContext = new ActorContext(getSystem(), getRef(),
-                    mock(ClusterWrapper.class), mock(Configuration.class));
-
-            final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy =
-                    new DataTreeChangeListenerProxy<>(actorContext, mockListener);
-
-            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
-            new Thread() {
-                @Override
-                public void run() {
-                    proxy.init("shard-1", path);
-                }
+        new JavaTestKit(getSystem()) {
+            {
+                ActorContext actorContext = new ActorContext(getSystem(), getRef(), mock(ClusterWrapper.class),
+                        mock(Configuration.class));
 
-            }.start();
+                final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(
+                        actorContext, mockListener);
 
-            FiniteDuration timeout = duration("5 seconds");
-            FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
-            Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
+                final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
+                new Thread() {
+                    @Override
+                    public void run() {
+                        proxy.init("shard-1", path);
+                    }
 
-            reply(new NotInitializedException("not initialized"));
+                }.start();
 
-            new Within(duration("1 seconds")) {
-                @Override
-                protected void run() {
-                    expectNoMsg();
-                }
-            };
-        }};
+                FiniteDuration timeout = duration("5 seconds");
+                FindLocalShard findLocalShard = expectMsgClass(timeout, FindLocalShard.class);
+                Assert.assertEquals("getShardName", "shard-1", findLocalShard.getShardName());
+
+                reply(new NotInitializedException("not initialized"));
+
+                new Within(duration("1 seconds")) {
+                    @Override
+                    protected void run() {
+                        expectNoMsg();
+                    }
+                };
+
+                proxy.close();
+            }
+        };
     }
 
     @Test
     public void testFailedRegistration() {
-        new JavaTestKit(getSystem()) {{
-            ActorSystem mockActorSystem = mock(ActorSystem.class);
+        new JavaTestKit(getSystem()) {
+            {
+                ActorSystem mockActorSystem = mock(ActorSystem.class);
 
-            ActorRef mockActor = getSystem().actorOf(Props.create(DoNothingActor.class),
-                    "testFailedRegistration");
-            doReturn(mockActor).when(mockActorSystem).actorOf(any(Props.class));
-            ExecutionContextExecutor executor = ExecutionContexts.fromExecutor(
-                    MoreExecutors.directExecutor());
+                ActorRef mockActor = getSystem().actorOf(Props.create(DoNothingActor.class), "testFailedRegistration");
+                doReturn(mockActor).when(mockActorSystem).actorOf(any(Props.class));
+                ExecutionContextExecutor executor = ExecutionContexts.fromExecutor(MoreExecutors.directExecutor());
 
+                ActorContext actorContext = mock(ActorContext.class);
+                final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
 
-            ActorContext actorContext = mock(ActorContext.class);
-            final YangInstanceIdentifier path = YangInstanceIdentifier.of(TestModel.TEST_QNAME);
+                doReturn(executor).when(actorContext).getClientDispatcher();
+                doReturn(mockActorSystem).when(actorContext).getActorSystem();
 
-            doReturn(executor).when(actorContext).getClientDispatcher();
-            doReturn(mockActorSystem).when(actorContext).getActorSystem();
+                String shardName = "shard-1";
+                final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(
+                        actorContext, mockListener);
 
-            String shardName = "shard-1";
-            final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy =
-                    new DataTreeChangeListenerProxy<>(actorContext, mockListener);
+                doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
+                doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
+                doReturn(Futures.failed(new RuntimeException("mock"))).when(actorContext)
+                        .executeOperationAsync(any(ActorRef.class), any(Object.class), any(Timeout.class));
+                doReturn(mock(DatastoreContext.class)).when(actorContext).getDatastoreContext();
 
-            doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
-            doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
-            doReturn(Futures.failed(new RuntimeException("mock"))).
-                    when(actorContext).executeOperationAsync(any(ActorRef.class),
-                    any(Object.class), any(Timeout.class));
-            doReturn(mock(DatastoreContext.class)).when(actorContext).getDatastoreContext();
+                proxy.init("shard-1", path);
 
-            proxy.init("shard-1", path);
+                Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor());
 
-            Assert.assertEquals("getListenerRegistrationActor", null,
-                    proxy.getListenerRegistrationActor());
-        }};
+                proxy.close();
+            }
+        };
     }
 
     @Test
     public void testCloseBeforeRegistration() {
-        new JavaTestKit(getSystem()) {{
-            ActorContext actorContext = mock(ActorContext.class);
+        new JavaTestKit(getSystem()) {
+            {
+                ActorContext actorContext = mock(ActorContext.class);
 
-            String shardName = "shard-1";
+                String shardName = "shard-1";
 
-            doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
-            doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(actorContext).getClientDispatcher();
-            doReturn(getSystem()).when(actorContext).getActorSystem();
-            doReturn(Dispatchers.DEFAULT_DISPATCHER_PATH).when(actorContext).getNotificationDispatcherPath();
-            doReturn(getSystem().actorSelection(getRef().path())).
-                    when(actorContext).actorSelection(getRef().path());
-            doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
-            doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
+                doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext();
+                doReturn(getSystem().dispatchers().defaultGlobalDispatcher()).when(actorContext).getClientDispatcher();
+                doReturn(getSystem()).when(actorContext).getActorSystem();
+                doReturn(Dispatchers.DEFAULT_DISPATCHER_PATH).when(actorContext).getNotificationDispatcherPath();
+                doReturn(getSystem().actorSelection(getRef().path())).when(actorContext)
+                        .actorSelection(getRef().path());
+                doReturn(duration("5 seconds")).when(actorContext).getOperationDuration();
+                doReturn(Futures.successful(getRef())).when(actorContext).findLocalShardAsync(eq(shardName));
 
-            final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy =
-                    new DataTreeChangeListenerProxy<>(actorContext, mockListener);
+                final DataTreeChangeListenerProxy<DOMDataTreeChangeListener> proxy = new DataTreeChangeListenerProxy<>(
+                        actorContext, mockListener);
 
-
-            Answer<Future<Object>> answer = new Answer<Future<Object>>() {
-                @Override
-                public Future<Object> answer(InvocationOnMock invocation) {
+                Answer<Future<Object>> answer = invocation -> {
                     proxy.close();
-                    return Futures.successful((Object)new RegisterDataTreeChangeListenerReply(getRef()));
-                }
-            };
+                    return Futures.successful((Object) new RegisterDataTreeChangeListenerReply(getRef()));
+                };
 
-            doAnswer(answer).when(actorContext).executeOperationAsync(any(ActorRef.class),
-                    any(Object.class), any(Timeout.class));
+                doAnswer(answer).when(actorContext).executeOperationAsync(any(ActorRef.class), any(Object.class),
+                        any(Timeout.class));
 
-            proxy.init(shardName, YangInstanceIdentifier.of(TestModel.TEST_QNAME));
+                proxy.init(shardName, YangInstanceIdentifier.of(TestModel.TEST_QNAME));
 
-            expectMsgClass(duration("5 seconds"), CloseDataTreeChangeListenerRegistration.class);
+                expectMsgClass(duration("5 seconds"), CloseDataTreeChangeListenerRegistration.class);
 
-            Assert.assertEquals("getListenerRegistrationActor", null,
-                    proxy.getListenerRegistrationActor());
-        }};
+                Assert.assertEquals("getListenerRegistrationActor", null, proxy.getListenerRegistrationActor());
+            }
+        };
     }
 }
index 0d33609..9259a61 100644 (file)
@@ -20,25 +20,28 @@ import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
 public class DataTreeChangeListenerRegistrationActorTest extends AbstractActorTest {
-    private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.newDirectExecutorService());
+    private static final InMemoryDOMDataStore STORE = new InMemoryDOMDataStore("OPER",
+            MoreExecutors.newDirectExecutorService());
 
     static {
-        store.onGlobalContextUpdated(TestModel.createTestContext());
+        STORE.onGlobalContextUpdated(TestModel.createTestContext());
     }
 
-    @SuppressWarnings("rawtypes")
+    @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test
     public void testOnReceiveCloseListenerRegistration() throws Exception {
-        new JavaTestKit(getSystem()) {{
-            final ListenerRegistration mockListenerReg = Mockito.mock(ListenerRegistration.class);
-            final Props props = DataTreeChangeListenerRegistrationActor.props(mockListenerReg);
-            final ActorRef subject = getSystem().actorOf(props, "testCloseListenerRegistration");
+        new JavaTestKit(getSystem()) {
+            {
+                final ListenerRegistration mockListenerReg = Mockito.mock(ListenerRegistration.class);
+                final Props props = DataTreeChangeListenerRegistrationActor.props(mockListenerReg);
+                final ActorRef subject = getSystem().actorOf(props, "testCloseListenerRegistration");
 
-            subject.tell(CloseDataTreeChangeListenerRegistration.getInstance(), getRef());
+                subject.tell(CloseDataTreeChangeListenerRegistration.getInstance(), getRef());
 
-            expectMsgClass(duration("1 second"), CloseDataTreeChangeListenerRegistrationReply.class);
+                expectMsgClass(duration("1 second"), CloseDataTreeChangeListenerRegistrationReply.class);
 
-            Mockito.verify(mockListenerReg).close();
-        }};
+                Mockito.verify(mockListenerReg).close();
+            }
+        };
     }
 }
index a11fc6b..a69179e 100644 (file)
@@ -19,6 +19,7 @@ import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.o
 import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.outerNode;
 import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.outerNodeEntry;
 import static org.opendaylight.controller.md.cluster.datastore.model.TestModel.testNodeWithOuter;
+
 import akka.actor.ActorRef;
 import akka.testkit.TestActorRef;
 import org.junit.After;
@@ -26,7 +27,6 @@ import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener;
 import org.opendaylight.controller.cluster.datastore.utils.MockDataTreeChangeListener;
-import org.opendaylight.controller.cluster.raft.TestActorFactory;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 
@@ -36,8 +36,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
  * @author Thomas Pantelis
  */
 public class DataTreeChangeListenerSupportTest extends AbstractShardTest {
-    private final TestActorFactory actorFactory = new TestActorFactory(getSystem());
-
     private Shard shard;
     private DataTreeChangeListenerSupport support;
 
index 720cd01..21c8497 100644 (file)
@@ -14,18 +14,17 @@ import static org.junit.Assert.assertSame;
 import static org.junit.Assert.fail;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
+
 import akka.actor.ActorSystem;
 import akka.actor.Address;
 import akka.actor.AddressFromURIString;
 import akka.cluster.Cluster;
 import akka.testkit.JavaTestKit;
-import akka.util.Timeout;
 import com.google.common.base.Throwables;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
 import com.typesafe.config.ConfigFactory;
 import java.io.IOException;
-import java.util.concurrent.TimeUnit;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -46,7 +45,6 @@ import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import scala.concurrent.duration.Duration;
 
 public class DataTreeCohortIntegrationTest {
 
@@ -58,8 +56,6 @@ public class DataTreeCohortIntegrationTest {
     private static final DOMDataTreeIdentifier TEST_ID =
             new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
 
-    private static final Timeout TIMEOUT = new Timeout(Duration.create(5, TimeUnit.SECONDS));
-
     private static ActorSystem system;
 
     private final DatastoreContext.Builder datastoreContextBuilder =
@@ -90,20 +86,23 @@ public class DataTreeCohortIntegrationTest {
         ArgumentCaptor<DOMDataTreeCandidate> candidateCapt = ArgumentCaptor.forClass(DOMDataTreeCandidate.class);
         new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
             {
-                try (final DistributedDataStore dataStore = setupDistributedDataStore("transactionIntegrationTest", "test-1")) {
-                    final ObjectRegistration<DOMDataTreeCommitCohort> cohortReg = dataStore.registerCommitCohort(TEST_ID, cohort);
+                try (final DistributedDataStore dataStore = setupDistributedDataStore("transactionIntegrationTest",
+                        "test-1")) {
+                    final ObjectRegistration<DOMDataTreeCommitCohort> cohortReg =
+                            dataStore.registerCommitCohort(TEST_ID, cohort);
                     Thread.sleep(1000); // Registration is asynchronous
                     assertNotNull(cohortReg);
                     testWriteTransaction(dataStore, TestModel.TEST_PATH,
                         ImmutableNodes.containerNode(TestModel.TEST_QNAME));
-                    Mockito.verify(cohort).canCommit(any(Object.class), candidateCapt.capture(), any(SchemaContext.class));
+                    Mockito.verify(cohort).canCommit(any(Object.class), candidateCapt.capture(),
+                            any(SchemaContext.class));
                     DOMDataTreeCandidate candidate = candidateCapt.getValue();
                     assertNotNull(candidate);
                     assertEquals(TEST_ID, candidate.getRootPath());
                     testWriteTransaction(dataStore, TestModel.OUTER_LIST_PATH,
                         ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
-                    Mockito.verify(cohort, Mockito.times(2)).canCommit(any(Object.class), any(DOMDataTreeCandidate.class),
-                        any(SchemaContext.class));
+                    Mockito.verify(cohort, Mockito.times(2)).canCommit(any(Object.class),
+                            any(DOMDataTreeCandidate.class), any(SchemaContext.class));
                     cohortReg.close();
                     testWriteTransaction(dataStore, TestModel.TEST_PATH,
                         ImmutableNodes.containerNode(TestModel.TEST_QNAME));
@@ -114,6 +113,7 @@ public class DataTreeCohortIntegrationTest {
     }
 
     @Test
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void failCanCommitTest() throws Exception {
         final DOMDataTreeCommitCohort failedCohort = mock(DOMDataTreeCommitCohort.class);
 
@@ -144,10 +144,8 @@ public class DataTreeCohortIntegrationTest {
     }
 
     /**
-     *
      * FIXME: Weird thing is that invoking canCommit on front-end invokes also preCommit on backend
      * so we can not test abort after can commit.
-     *
      */
     @Test
     @Ignore
index 700b96a..d694cb6 100644 (file)
@@ -14,6 +14,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+
 import java.io.IOException;
 import java.util.Dictionary;
 import java.util.Hashtable;
@@ -89,7 +90,7 @@ public class DatastoreContextConfigAdminOverlayTest {
 
     @Test
     public void testUpdateOnConfigurationEvent() {
-        DatastoreContextConfigAdminOverlay overlay = new DatastoreContextConfigAdminOverlay(
+        final DatastoreContextConfigAdminOverlay overlay = new DatastoreContextConfigAdminOverlay(
                 mockIntrospector, mockBundleContext);
 
         reset(mockIntrospector);
@@ -135,7 +136,7 @@ public class DatastoreContextConfigAdminOverlayTest {
 
     @Test
     public void testConfigurationEventWithDifferentPid() {
-        DatastoreContextConfigAdminOverlay overlay = new DatastoreContextConfigAdminOverlay(
+        final DatastoreContextConfigAdminOverlay overlay = new DatastoreContextConfigAdminOverlay(
                 mockIntrospector, mockBundleContext);
 
         reset(mockIntrospector);
@@ -159,7 +160,7 @@ public class DatastoreContextConfigAdminOverlayTest {
 
     @Test
     public void testConfigurationEventWithNonUpdateEventType() {
-        DatastoreContextConfigAdminOverlay overlay = new DatastoreContextConfigAdminOverlay(
+        final DatastoreContextConfigAdminOverlay overlay = new DatastoreContextConfigAdminOverlay(
                 mockIntrospector, mockBundleContext);
 
         reset(mockIntrospector);
index ea7afbf..b470018 100644 (file)
@@ -14,6 +14,7 @@ import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEF
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE;
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT;
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS;
+
 import java.util.Dictionary;
 import java.util.Hashtable;
 import org.junit.Test;
@@ -29,8 +30,8 @@ public class DatastoreContextIntrospectorTest {
 
     @Test
     public void testUpdate() {
-        DatastoreContext context = DatastoreContext.newBuilder().
-                logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
+        DatastoreContext context = DatastoreContext.newBuilder()
+                .logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
         DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context );
 
         Dictionary<String, Object> properties = new Hashtable<>();
@@ -119,8 +120,8 @@ public class DatastoreContextIntrospectorTest {
 
     @Test
     public void testUpdateWithInvalidValues() {
-        DatastoreContext context = DatastoreContext.newBuilder().
-                logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
+        DatastoreContext context = DatastoreContext.newBuilder()
+                .logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
         DatastoreContextIntrospector introspector = new DatastoreContextIntrospector(context );
 
         Dictionary<String, Object> properties = new Hashtable<>();
@@ -145,7 +146,8 @@ public class DatastoreContextIntrospectorTest {
         assertEquals(DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS, context.getShardTransactionCommitTimeoutInSeconds());
         assertEquals(212, context.getShardRaftConfig().getSnapshotBatchCount());
         assertEquals(DEFAULT_OPERATION_TIMEOUT_IN_MS, context.getOperationTimeoutInMillis());
-        assertEquals(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS, context.getShardRaftConfig().getHeartBeatInterval().length());
+        assertEquals(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS,
+                context.getShardRaftConfig().getHeartBeatInterval().length());
         assertEquals(567, context.getShardTransactionCommitQueueCapacity());
         assertEquals(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE,
                 context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
@@ -168,8 +170,8 @@ public class DatastoreContextIntrospectorTest {
         properties.put("persistent", "false"); // global setting
         properties.put("operational.Persistent", "true"); // operational override
 
-        DatastoreContext operContext = DatastoreContext.newBuilder().
-                logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
+        DatastoreContext operContext = DatastoreContext.newBuilder()
+                .logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
         DatastoreContextIntrospector operIntrospector = new DatastoreContextIntrospector(operContext);
         boolean updated = operIntrospector.update(properties);
         assertEquals("updated", true, updated);
@@ -199,8 +201,8 @@ public class DatastoreContextIntrospectorTest {
         properties.put("config.shard-transaction-idle-timeout-in-minutes", "44"); // config override
         properties.put("topology.shard-transaction-idle-timeout-in-minutes", "55"); // global shard override
 
-        DatastoreContext operContext = DatastoreContext.newBuilder().
-                logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
+        DatastoreContext operContext = DatastoreContext.newBuilder()
+                .logicalStoreType(LogicalDatastoreType.OPERATIONAL).build();
         DatastoreContextIntrospector operIntrospector = new DatastoreContextIntrospector(operContext);
 
         DatastoreContext shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology");
@@ -213,8 +215,8 @@ public class DatastoreContextIntrospectorTest {
         shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology");
         assertEquals(55, shardContext.getShardTransactionIdleTimeout().toMinutes());
 
-        DatastoreContext configContext = DatastoreContext.newBuilder().
-                logicalStoreType(LogicalDatastoreType.CONFIGURATION).build();
+        DatastoreContext configContext = DatastoreContext.newBuilder()
+                .logicalStoreType(LogicalDatastoreType.CONFIGURATION).build();
         DatastoreContextIntrospector configIntrospector = new DatastoreContextIntrospector(configContext);
         configIntrospector.update(properties);
         configContext = configIntrospector.getContext();
@@ -223,8 +225,10 @@ public class DatastoreContextIntrospectorTest {
         shardContext = configIntrospector.newContextFactory().getShardDatastoreContext("topology");
         assertEquals(55, shardContext.getShardTransactionIdleTimeout().toMinutes());
 
-        properties.put("operational.topology.shard-transaction-idle-timeout-in-minutes", "66"); // operational shard override
-        properties.put("config.topology.shard-transaction-idle-timeout-in-minutes", "77"); // config shard override
+        // operational shard override
+        properties.put("operational.topology.shard-transaction-idle-timeout-in-minutes", "66");
+        // config shard override
+        properties.put("config.topology.shard-transaction-idle-timeout-in-minutes", "77");
 
         operIntrospector.update(properties);
         shardContext = operIntrospector.newContextFactory().getShardDatastoreContext("topology");
index 6d4c5cc..2aa9a45 100644 (file)
@@ -19,13 +19,14 @@ import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEF
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR;
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_INITIALIZATION_TIMEOUT;
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_LEADER_ELECTION_TIMEOUT;
+import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE;
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE;
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT;
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TX_COMMIT_QUEUE_CAPACITY;
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS;
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SNAPSHOT_BATCH_COUNT;
 import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT;
-import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE;
+
 import java.util.concurrent.TimeUnit;
 import org.junit.Assert;
 import org.junit.Test;
@@ -40,9 +41,11 @@ public class DatastoreContextTest {
         assertEquals(DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT, context.getShardTransactionIdleTimeout());
         assertEquals(DEFAULT_OPERATION_TIMEOUT_IN_MS, context.getOperationTimeoutInMillis());
         assertEquals(DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS, context.getShardTransactionCommitTimeoutInSeconds());
-        assertEquals(DEFAULT_JOURNAL_RECOVERY_BATCH_SIZE, context.getShardRaftConfig().getJournalRecoveryLogBatchSize());
+        assertEquals(DEFAULT_JOURNAL_RECOVERY_BATCH_SIZE,
+                context.getShardRaftConfig().getJournalRecoveryLogBatchSize());
         assertEquals(DEFAULT_SNAPSHOT_BATCH_COUNT, context.getShardRaftConfig().getSnapshotBatchCount());
-        assertEquals(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS, context.getShardRaftConfig().getHeartBeatInterval().length());
+        assertEquals(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS,
+                context.getShardRaftConfig().getHeartBeatInterval().length());
         assertEquals(DEFAULT_SHARD_TX_COMMIT_QUEUE_CAPACITY, context.getShardTransactionCommitQueueCapacity());
         assertEquals(DEFAULT_SHARD_INITIALIZATION_TIMEOUT.duration().toMillis(),
                 context.getShardInitializationTimeout().duration().toMillis());
@@ -50,11 +53,14 @@ public class DatastoreContextTest {
                 context.getShardLeaderElectionTimeout().duration().toMillis());
         assertEquals(DEFAULT_PERSISTENT, context.isPersistent());
         assertEquals(DEFAULT_CONFIGURATION_READER, context.getConfigurationReader());
-        assertEquals(DEFAULT_ISOLATED_LEADER_CHECK_INTERVAL_IN_MILLIS, context.getShardRaftConfig().getIsolatedCheckIntervalInMillis());
-        assertEquals(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE, context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
+        assertEquals(DEFAULT_ISOLATED_LEADER_CHECK_INTERVAL_IN_MILLIS,
+                context.getShardRaftConfig().getIsolatedCheckIntervalInMillis());
+        assertEquals(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE,
+                context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
         assertEquals(DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR, context.getShardRaftConfig().getElectionTimeoutFactor());
         assertEquals(DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT, context.getTransactionCreationInitialRateLimit());
-        assertEquals(DatastoreContext.DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT, context.getShardBatchedModificationCount());
+        assertEquals(DatastoreContext.DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT,
+                context.getShardBatchedModificationCount());
         assertEquals(InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE,
                 context.getDataStoreProperties().getMaxDataChangeExecutorPoolSize());
         assertEquals(InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_EXECUTOR_QUEUE_SIZE,
@@ -78,8 +84,8 @@ public class DatastoreContextTest {
         builder.shardSnapshotBatchCount(DEFAULT_SNAPSHOT_BATCH_COUNT + 1);
         builder.shardHeartbeatIntervalInMillis(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS + 1);
         builder.shardTransactionCommitQueueCapacity(DEFAULT_SHARD_TX_COMMIT_QUEUE_CAPACITY + 1);
-        builder.shardInitializationTimeout(DEFAULT_SHARD_INITIALIZATION_TIMEOUT.
-                duration().toMillis() + 1, TimeUnit.MILLISECONDS);
+        builder.shardInitializationTimeout(DEFAULT_SHARD_INITIALIZATION_TIMEOUT
+                .duration().toMillis() + 1, TimeUnit.MILLISECONDS);
         builder.shardInitializationTimeout(DEFAULT_SHARD_INITIALIZATION_TIMEOUT.duration().toMillis() + 1,
                 TimeUnit.MILLISECONDS);
         builder.shardLeaderElectionTimeout(DEFAULT_SHARD_LEADER_ELECTION_TIMEOUT.duration().toMillis() + 1,
@@ -98,7 +104,7 @@ public class DatastoreContextTest {
                 InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_LISTENER_QUEUE_SIZE + 1);
         builder.maxShardDataStoreExecutorQueueSize(
                 InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE + 1);
-        builder.shardSnapshotChunkSize(DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE+1);
+        builder.shardSnapshotChunkSize(DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE + 1);
 
         DatastoreContext context = builder.build();
 
@@ -136,7 +142,8 @@ public class DatastoreContextTest {
                 context.getShardRaftConfig().getIsolatedCheckIntervalInMillis());
         assertEquals(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE + 1,
                 context.getShardRaftConfig().getSnapshotDataThresholdPercentage());
-        assertEquals(DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR + 1, context.getShardRaftConfig().getElectionTimeoutFactor());
+        assertEquals(DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR + 1,
+                context.getShardRaftConfig().getElectionTimeoutFactor());
         assertEquals(DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT + 1, context.getTransactionCreationInitialRateLimit());
         assertEquals(DatastoreContext.DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT + 1,
                 context.getShardBatchedModificationCount());
index 9f0b1b5..3feb906 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+
 import java.io.File;
 import java.io.FileOutputStream;
 import java.util.ArrayList;
@@ -48,7 +49,7 @@ public class DatastoreSnapshotRestoreTest {
         List<ShardSnapshot> shardSnapshots = new ArrayList<>();
         shardSnapshots.add(new ShardSnapshot("cars", new byte[]{1,2}));
         shardSnapshots.add(new ShardSnapshot("people", new byte[]{3,4}));
-        DatastoreSnapshot configSnapshot = new DatastoreSnapshot("config", null, shardSnapshots );
+        final DatastoreSnapshot configSnapshot = new DatastoreSnapshot("config", null, shardSnapshots );
 
         shardSnapshots = new ArrayList<>();
         shardSnapshots.add(new ShardSnapshot("cars", new byte[]{5,6}));
@@ -60,8 +61,7 @@ public class DatastoreSnapshotRestoreTest {
         snapshotList.add(configSnapshot);
         snapshotList.add(operSnapshot);
 
-        File backupFile = new File(restoreDirectoryFile, "backup");
-        try(FileOutputStream fos = new FileOutputStream(backupFile)) {
+        try (FileOutputStream fos = new FileOutputStream(backupFile)) {
             SerializationUtils.serialize(snapshotList, fos);
         }
 
@@ -85,11 +85,11 @@ public class DatastoreSnapshotRestoreTest {
         assertTrue("ShardManager snapshots don't match", Objects.deepEquals(expected.getShardManagerSnapshot(),
                 actual.getShardManagerSnapshot()));
         assertEquals("ShardSnapshots size", expected.getShardSnapshots().size(), actual.getShardSnapshots().size());
-        for(int i = 0; i < expected.getShardSnapshots().size(); i++) {
+        for (int i = 0; i < expected.getShardSnapshots().size(); i++) {
             assertEquals("ShardSnapshot " + (i + 1) + " name", expected.getShardSnapshots().get(i).getName(),
                     actual.getShardSnapshots().get(i).getName());
-            assertArrayEquals("ShardSnapshot " + (i + 1) + " snapshot", expected.getShardSnapshots().get(i).getSnapshot(),
-                    actual.getShardSnapshots().get(i).getSnapshot());
+            assertArrayEquals("ShardSnapshot " + (i + 1) + " snapshot",
+                    expected.getShardSnapshots().get(i).getSnapshot(), actual.getShardSnapshots().get(i).getSnapshot());
         }
     }
 }
index 43fbfea..194f484 100644 (file)
@@ -16,6 +16,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.verify;
+
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
@@ -50,7 +51,7 @@ public class DebugThreePhaseCommitCohortTest {
         doReturn(expCohortFutures).when(mockDelegate).getCohortFutures();
 
         Throwable debugContext = new RuntimeException("mock");
-        DebugThreePhaseCommitCohort cohort = new DebugThreePhaseCommitCohort(transactionId , mockDelegate , debugContext);
+        DebugThreePhaseCommitCohort cohort = new DebugThreePhaseCommitCohort(transactionId, mockDelegate, debugContext);
 
         Logger mockLogger = mock(Logger.class);
         cohort.setLogger(mockLogger);
index 47cc359..4d81442 100644 (file)
@@ -16,12 +16,14 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
+
 import akka.actor.ActorSystem;
 import akka.actor.Address;
 import akka.actor.AddressFromURIString;
 import akka.cluster.Cluster;
 import akka.testkit.JavaTestKit;
 import com.google.common.base.Optional;
+import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.ListenableFuture;
@@ -89,8 +91,8 @@ public class DistributedDataStoreIntegrationTest {
 
     private static ActorSystem system;
 
-    private final DatastoreContext.Builder datastoreContextBuilder =
-            DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100);
+    private final DatastoreContext.Builder datastoreContextBuilder = DatastoreContext.newBuilder()
+            .shardHeartbeatIntervalInMillis(100);
 
     @BeforeClass
     public static void setUpClass() throws IOException {
@@ -110,289 +112,303 @@ public class DistributedDataStoreIntegrationTest {
     }
 
     @Test
-    public void testWriteTransactionWithSingleShard() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore =
-                    setupDistributedDataStore("transactionIntegrationTest", "test-1")) {
+    public void testWriteTransactionWithSingleShard() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore("transactionIntegrationTest",
+                        "test-1")) {
 
-                testWriteTransaction(dataStore, TestModel.TEST_PATH,
-                    ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+                    testWriteTransaction(dataStore, TestModel.TEST_PATH,
+                            ImmutableNodes.containerNode(TestModel.TEST_QNAME));
 
-                testWriteTransaction(dataStore, TestModel.OUTER_LIST_PATH,
-                    ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+                    testWriteTransaction(dataStore, TestModel.OUTER_LIST_PATH,
+                            ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testWriteTransactionWithMultipleShards() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore =
-                    setupDistributedDataStore("testWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
+    public void testWriteTransactionWithMultipleShards() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
 
-                DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
-                assertNotNull("newWriteOnlyTransaction returned null", writeTx);
+                    DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
+                    assertNotNull("newWriteOnlyTransaction returned null", writeTx);
 
-                writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
-                writeTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
+                    writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
+                    writeTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
 
-                doCommit(writeTx.ready());
+                    doCommit(writeTx.ready());
 
-                writeTx = dataStore.newWriteOnlyTransaction();
+                    writeTx = dataStore.newWriteOnlyTransaction();
 
-                writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
-                writeTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
+                    writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
+                    writeTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
 
-                doCommit(writeTx.ready());
+                    doCommit(writeTx.ready());
 
-                writeTx = dataStore.newWriteOnlyTransaction();
+                    writeTx = dataStore.newWriteOnlyTransaction();
 
-                MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
-                YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
-                writeTx.write(carPath, car);
+                    MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+                    YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
+                    writeTx.write(carPath, car);
 
-                MapEntryNode person = PeopleModel.newPersonEntry("jack");
-                YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
-                writeTx.write(personPath, person);
+                    MapEntryNode person = PeopleModel.newPersonEntry("jack");
+                    YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
+                    writeTx.write(personPath, person);
 
-                doCommit(writeTx.ready());
+                    doCommit(writeTx.ready());
 
-                // Verify the data in the store
+                    // Verify the data in the store
 
-                DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+                    DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
 
-                Optional<NormalizedNode<?, ?>> optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", car, optional.get());
+                    Optional<NormalizedNode<?, ?>> optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", car, optional.get());
 
-                optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", person, optional.get());
+                    optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", person, optional.get());
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testReadWriteTransactionWithSingleShard() throws Exception{
+    public void testReadWriteTransactionWithSingleShard() throws Exception {
         System.setProperty("shard.persistent", "true");
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore =
-                    setupDistributedDataStore("testReadWriteTransactionWithSingleShard", "test-1")) {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testReadWriteTransactionWithSingleShard", "test-1")) {
 
-                // 1. Create a read-write Tx
+                    // 1. Create a read-write Tx
 
-                DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
-                assertNotNull("newReadWriteTransaction returned null", readWriteTx);
+                    DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
+                    assertNotNull("newReadWriteTransaction returned null", readWriteTx);
 
-                // 2. Write some data
+                    // 2. Write some data
 
-                YangInstanceIdentifier nodePath = TestModel.TEST_PATH;
-                NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
-                readWriteTx.write(nodePath, nodeToWrite );
+                    YangInstanceIdentifier nodePath = TestModel.TEST_PATH;
+                    NormalizedNode<?, ?> nodeToWrite = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+                    readWriteTx.write(nodePath, nodeToWrite);
 
-                // 3. Read the data from Tx
+                    // 3. Read the data from Tx
 
-                Boolean exists = readWriteTx.exists(nodePath).checkedGet(5, TimeUnit.SECONDS);
-                assertEquals("exists", true, exists);
+                    Boolean exists = readWriteTx.exists(nodePath).checkedGet(5, TimeUnit.SECONDS);
+                    assertEquals("exists", true, exists);
 
-                Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(nodePath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", nodeToWrite, optional.get());
+                    Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(nodePath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", nodeToWrite, optional.get());
 
-                // 4. Ready the Tx for commit
+                    // 4. Ready the Tx for commit
 
-                DOMStoreThreePhaseCommitCohort cohort = readWriteTx.ready();
+                    DOMStoreThreePhaseCommitCohort cohort = readWriteTx.ready();
 
-                // 5. Commit the Tx
+                    // 5. Commit the Tx
 
-                doCommit(cohort);
+                    doCommit(cohort);
 
-                // 6. Verify the data in the store
+                    // 6. Verify the data in the store
 
-                DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+                    DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
 
-                optional = readTx.read(nodePath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", nodeToWrite, optional.get());
+                    optional = readTx.read(nodePath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", nodeToWrite, optional.get());
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testReadWriteTransactionWithMultipleShards() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore =
-                    setupDistributedDataStore("testReadWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
+    public void testReadWriteTransactionWithMultipleShards() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testReadWriteTransactionWithMultipleShards", "cars-1", "people-1")) {
 
-                DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
-                assertNotNull("newReadWriteTransaction returned null", readWriteTx);
+                    DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
+                    assertNotNull("newReadWriteTransaction returned null", readWriteTx);
 
-                readWriteTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
-                readWriteTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
+                    readWriteTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
+                    readWriteTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
 
-                doCommit(readWriteTx.ready());
+                    doCommit(readWriteTx.ready());
 
-                readWriteTx = dataStore.newReadWriteTransaction();
+                    readWriteTx = dataStore.newReadWriteTransaction();
 
-                readWriteTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
-                readWriteTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
+                    readWriteTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
+                    readWriteTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
 
-                doCommit(readWriteTx.ready());
+                    doCommit(readWriteTx.ready());
 
-                readWriteTx = dataStore.newReadWriteTransaction();
+                    readWriteTx = dataStore.newReadWriteTransaction();
 
-                MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
-                YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
-                readWriteTx.write(carPath, car);
+                    MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+                    YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
+                    readWriteTx.write(carPath, car);
 
-                MapEntryNode person = PeopleModel.newPersonEntry("jack");
-                YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
-                readWriteTx.write(personPath, person);
+                    MapEntryNode person = PeopleModel.newPersonEntry("jack");
+                    YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
+                    readWriteTx.write(personPath, person);
 
-                Boolean exists = readWriteTx.exists(carPath).checkedGet(5, TimeUnit.SECONDS);
-                assertEquals("exists", true, exists);
+                    Boolean exists = readWriteTx.exists(carPath).checkedGet(5, TimeUnit.SECONDS);
+                    assertEquals("exists", true, exists);
 
-                Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", car, optional.get());
+                    Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", car, optional.get());
 
-                doCommit(readWriteTx.ready());
+                    doCommit(readWriteTx.ready());
 
-                // Verify the data in the store
+                    // Verify the data in the store
 
-                DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+                    DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
 
-                optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", car, optional.get());
+                    optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", car, optional.get());
 
-                optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", person, optional.get());
+                    optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", person, optional.get());
 
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testSingleTransactionsWritesInQuickSuccession() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore = setupDistributedDataStore(
-                    "testSingleTransactionsWritesInQuickSuccession", "cars-1")) {
+    public void testSingleTransactionsWritesInQuickSuccession() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testSingleTransactionsWritesInQuickSuccession", "cars-1")) {
 
-                DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+                    DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
 
-                DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
-                writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
-                writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
-                doCommit(writeTx.ready());
+                    DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+                    writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
+                    writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
+                    doCommit(writeTx.ready());
 
-                writeTx = txChain.newWriteOnlyTransaction();
+                    writeTx = txChain.newWriteOnlyTransaction();
 
-                int nCars = 5;
-                for(int i = 0; i < nCars; i++) {
-                    writeTx.write(CarsModel.newCarPath("car" + i),
-                        CarsModel.newCarEntry("car" + i, BigInteger.valueOf(20000)));
-                }
+                    int numCars = 5;
+                    for (int i = 0; i < numCars; i++) {
+                        writeTx.write(CarsModel.newCarPath("car" + i),
+                                CarsModel.newCarEntry("car" + i, BigInteger.valueOf(20000)));
+                    }
 
-                doCommit(writeTx.ready());
+                    doCommit(writeTx.ready());
 
-                Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction().read(
-                    CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("# cars", nCars, ((Collection<?>)optional.get().getValue()).size());
+                    Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction()
+                            .read(CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("# cars", numCars, ((Collection<?>) optional.get().getValue()).size());
+                }
             }
-        }};
+        };
     }
 
-    private void testTransactionWritesWithShardNotInitiallyReady(final String testName,
-            final boolean writeOnly) throws Exception {
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            String shardName = "test-1";
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    private void testTransactionWritesWithShardNotInitiallyReady(final String testName, final boolean writeOnly)
+            throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                String shardName = "test-1";
 
-            // Setup the InMemoryJournal to block shard recovery to ensure the shard isn't
-            // initialized until we create and submit the write the Tx.
-            String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
-            CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
-            InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
+                // Setup the InMemoryJournal to block shard recovery to ensure
+                // the shard isn't
+                // initialized until we create and submit the write the Tx.
+                String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
+                CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
+                InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
 
-            try (DistributedDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
 
-                // Create the write Tx
+                    // Create the write Tx
 
-                final DOMStoreWriteTransaction writeTx = writeOnly ? dataStore.newWriteOnlyTransaction() :
-                    dataStore.newReadWriteTransaction();
-                assertNotNull("newReadWriteTransaction returned null", writeTx);
+                    final DOMStoreWriteTransaction writeTx = writeOnly ? dataStore.newWriteOnlyTransaction()
+                            : dataStore.newReadWriteTransaction();
+                    assertNotNull("newReadWriteTransaction returned null", writeTx);
 
-                // Do some modification operations and ready the Tx on a separate thread.
+                    // Do some modification operations and ready the Tx on a
+                    // separate thread.
 
-                final YangInstanceIdentifier listEntryPath = YangInstanceIdentifier.builder(
-                    TestModel.OUTER_LIST_PATH).nodeWithKey(TestModel.OUTER_LIST_QNAME,
-                        TestModel.ID_QNAME, 1).build();
+                    final YangInstanceIdentifier listEntryPath = YangInstanceIdentifier
+                            .builder(TestModel.OUTER_LIST_PATH)
+                            .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).build();
 
-                final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
-                final AtomicReference<Exception> caughtEx = new AtomicReference<>();
-                final CountDownLatch txReady = new CountDownLatch(1);
-                Thread txThread = new Thread() {
-                    @Override
-                    public void run() {
-                        try {
-                            writeTx.write(TestModel.TEST_PATH,
-                                ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+                    final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
+                    final AtomicReference<Exception> caughtEx = new AtomicReference<>();
+                    final CountDownLatch txReady = new CountDownLatch(1);
+                    Thread txThread = new Thread() {
+                        @Override
+                        public void run() {
+                            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);
-                            return;
-                        } finally {
-                            txReady.countDown();
+                                txCohort.set(writeTx.ready());
+                            } catch (Exception e) {
+                                caughtEx.set(e);
+                                return;
+                            } finally {
+                                txReady.countDown();
+                            }
                         }
-                    }
-                };
+                    };
 
-                txThread.start();
+                    txThread.start();
 
-                // Wait for the Tx operations to complete.
+                    // Wait for the Tx operations to complete.
 
-                boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
-                if(caughtEx.get() != null) {
-                    throw caughtEx.get();
-                }
+                    boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
+                    if (caughtEx.get() != null) {
+                        throw caughtEx.get();
+                    }
 
-                assertEquals("Tx ready", true, done);
+                    assertEquals("Tx ready", true, done);
 
-                // At this point the Tx operations should be waiting for the shard to initialize so
-                // trigger the latch to let the shard recovery to continue.
+                    // At this point the Tx operations should be waiting for the
+                    // shard to initialize so
+                    // trigger the latch to let the shard recovery to continue.
 
-                blockRecoveryLatch.countDown();
+                    blockRecoveryLatch.countDown();
 
-                // Wait for the Tx commit to complete.
+                    // Wait for the Tx commit to complete.
 
-                doCommit(txCohort.get());
+                    doCommit(txCohort.get());
 
-                // Verify the data in the store
+                    // Verify the data in the store
 
-                DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+                    DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
 
-                Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).
-                        get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
+                    Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
 
-                optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
+                    optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
 
-                optional = readTx.read(listEntryPath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", false, optional.isPresent());
+                    optional = readTx.read(listEntryPath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", false, optional.isPresent());
+                }
             }
-        }};
+        };
     }
 
     @Test
@@ -407,266 +423,209 @@ public class DistributedDataStoreIntegrationTest {
     }
 
     @Test
+    @SuppressWarnings("checkstyle:IllegalCatch")
     public void testTransactionReadsWithShardNotInitiallyReady() throws Exception {
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            String testName = "testTransactionReadsWithShardNotInitiallyReady";
-            String shardName = "test-1";
-
-            // Setup the InMemoryJournal to block shard recovery to ensure the shard isn't
-            // initialized until we create the Tx.
-            String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
-            CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
-            InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
-
-            try (DistributedDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
-
-                // Create the read-write Tx
-
-                final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
-                assertNotNull("newReadWriteTransaction returned null", readWriteTx);
-
-                // Do some reads on the Tx on a separate thread.
-
-                final AtomicReference<CheckedFuture<Boolean, ReadFailedException>> txExistsFuture =
-                        new AtomicReference<>();
-                final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>>
-                txReadFuture = new AtomicReference<>();
-                final AtomicReference<Exception> caughtEx = new AtomicReference<>();
-                final CountDownLatch txReadsDone = new CountDownLatch(1);
-                Thread txThread = new Thread() {
-                    @Override
-                    public void run() {
-                        try {
-                            readWriteTx.write(TestModel.TEST_PATH,
-                                ImmutableNodes.containerNode(TestModel.TEST_QNAME));
-
-                            txExistsFuture.set(readWriteTx.exists(TestModel.TEST_PATH));
-
-                            txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
-                        } catch(Exception e) {
-                            caughtEx.set(e);
-                            return;
-                        } finally {
-                            txReadsDone.countDown();
-                        }
-                    }
-                };
-
-                txThread.start();
-
-                // Wait for the Tx operations to complete.
-
-                boolean done = Uninterruptibles.awaitUninterruptibly(txReadsDone, 5, TimeUnit.SECONDS);
-                if(caughtEx.get() != null) {
-                    throw caughtEx.get();
-                }
-
-                assertEquals("Tx reads done", true, done);
-
-                // At this point the Tx operations should be waiting for the shard to initialize so
-                // trigger the latch to let the shard recovery to continue.
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                String testName = "testTransactionReadsWithShardNotInitiallyReady";
+                String shardName = "test-1";
 
-                blockRecoveryLatch.countDown();
+                // Setup the InMemoryJournal to block shard recovery to ensure
+                // the shard isn't
+                // initialized until we create the Tx.
+                String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
+                CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
+                InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
 
-                // Wait for the reads to complete and verify.
+                try (DistributedDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
 
-                assertEquals("exists", true, txExistsFuture.get().checkedGet(5, TimeUnit.SECONDS));
-                assertEquals("read", true, txReadFuture.get().checkedGet(5, TimeUnit.SECONDS).isPresent());
-
-                readWriteTx.close();
-            }
-        }};
-    }
+                    // Create the read-write Tx
 
-    @Test(expected=NotInitializedException.class)
-    public void testTransactionCommitFailureWithShardNotInitialized() throws Throwable{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            String testName = "testTransactionCommitFailureWithShardNotInitialized";
-            String shardName = "test-1";
+                    final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
+                    assertNotNull("newReadWriteTransaction returned null", readWriteTx);
 
-            // Set the shard initialization timeout low for the test.
+                    // Do some reads on the Tx on a separate thread.
 
-            datastoreContextBuilder.shardInitializationTimeout(300, TimeUnit.MILLISECONDS);
-
-            // Setup the InMemoryJournal to block shard recovery indefinitely.
-
-            String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
-            CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
-            InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
-
-            InMemoryJournal.addEntry(persistentID, 1, "Dummy data so akka will read from persistence");
+                    final AtomicReference<CheckedFuture<Boolean, ReadFailedException>> txExistsFuture =
+                            new AtomicReference<>();
+                    final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>>
+                            txReadFuture = new AtomicReference<>();
+                    final AtomicReference<Exception> caughtEx = new AtomicReference<>();
+                    final CountDownLatch txReadsDone = new CountDownLatch(1);
+                    Thread txThread = new Thread() {
+                        @Override
+                        public void run() {
+                            try {
+                                readWriteTx.write(TestModel.TEST_PATH,
+                                        ImmutableNodes.containerNode(TestModel.TEST_QNAME));
 
-            try (DistributedDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
+                                txExistsFuture.set(readWriteTx.exists(TestModel.TEST_PATH));
 
-                // Create the write Tx
+                                txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
+                            } catch (Exception e) {
+                                caughtEx.set(e);
+                                return;
+                            } finally {
+                                txReadsDone.countDown();
+                            }
+                        }
+                    };
 
-                final DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
-                assertNotNull("newReadWriteTransaction returned null", writeTx);
+                    txThread.start();
 
-                // Do some modifications and ready the Tx on a separate thread.
+                    // Wait for the Tx operations to complete.
 
-                final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
-                final AtomicReference<Exception> caughtEx = new AtomicReference<>();
-                final CountDownLatch txReady = new CountDownLatch(1);
-                Thread txThread = new Thread() {
-                    @Override
-                    public void run() {
-                        try {
-                            writeTx.write(TestModel.TEST_PATH,
-                                ImmutableNodes.containerNode(TestModel.TEST_QNAME));
-
-                            txCohort.set(writeTx.ready());
-                        } catch(Exception e) {
-                            caughtEx.set(e);
-                            return;
-                        } finally {
-                            txReady.countDown();
-                        }
+                    boolean done = Uninterruptibles.awaitUninterruptibly(txReadsDone, 5, TimeUnit.SECONDS);
+                    if (caughtEx.get() != null) {
+                        throw caughtEx.get();
                     }
-                };
 
-                txThread.start();
+                    assertEquals("Tx reads done", true, done);
 
-                // Wait for the Tx operations to complete.
+                    // At this point the Tx operations should be waiting for the
+                    // shard to initialize so
+                    // trigger the latch to let the shard recovery to continue.
 
-                boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
-                if(caughtEx.get() != null) {
-                    throw caughtEx.get();
-                }
+                    blockRecoveryLatch.countDown();
 
-                assertEquals("Tx ready", true, done);
+                    // Wait for the reads to complete and verify.
 
-                // Wait for the commit to complete. Since the shard never initialized, the Tx should
-                // have timed out and throw an appropriate exception cause.
+                    assertEquals("exists", true, txExistsFuture.get().checkedGet(5, TimeUnit.SECONDS));
+                    assertEquals("read", true, txReadFuture.get().checkedGet(5, TimeUnit.SECONDS).isPresent());
 
-                try {
-                    txCohort.get().canCommit().get(5, TimeUnit.SECONDS);
-                } catch(ExecutionException e) {
-                    throw e.getCause();
-                } finally {
-                    blockRecoveryLatch.countDown();
+                    readWriteTx.close();
                 }
             }
-        }};
+        };
     }
 
-    @Test(expected=NotInitializedException.class)
-    public void testTransactionReadFailureWithShardNotInitialized() throws Throwable{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            String testName = "testTransactionReadFailureWithShardNotInitialized";
-            String shardName = "test-1";
+    @Test(expected = NotInitializedException.class)
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    public void testTransactionCommitFailureWithShardNotInitialized() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                String testName = "testTransactionCommitFailureWithShardNotInitialized";
+                String shardName = "test-1";
 
-            // Set the shard initialization timeout low for the test.
+                // Set the shard initialization timeout low for the test.
 
-            datastoreContextBuilder.shardInitializationTimeout(300, TimeUnit.MILLISECONDS);
+                datastoreContextBuilder.shardInitializationTimeout(300, TimeUnit.MILLISECONDS);
 
-            // Setup the InMemoryJournal to block shard recovery indefinitely.
+                // Setup the InMemoryJournal to block shard recovery
+                // indefinitely.
 
-            String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
-            CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
-            InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
+                String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
+                CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
+                InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
 
-            InMemoryJournal.addEntry(persistentID, 1, "Dummy data so akka will read from persistence");
+                InMemoryJournal.addEntry(persistentID, 1, "Dummy data so akka will read from persistence");
 
-            try (DistributedDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
 
-                // Create the read-write Tx
+                    // Create the write Tx
 
-                final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
-                assertNotNull("newReadWriteTransaction returned null", readWriteTx);
+                    final DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
+                    assertNotNull("newReadWriteTransaction returned null", writeTx);
 
-                // Do a read on the Tx on a separate thread.
+                    // Do some modifications and ready the Tx on a separate
+                    // thread.
 
-                final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>>
-                txReadFuture = new AtomicReference<>();
-                final AtomicReference<Exception> caughtEx = new AtomicReference<>();
-                final CountDownLatch txReadDone = new CountDownLatch(1);
-                Thread txThread = new Thread() {
-                    @Override
-                    public void run() {
-                        try {
-                            readWriteTx.write(TestModel.TEST_PATH,
-                                ImmutableNodes.containerNode(TestModel.TEST_QNAME));
-
-                            txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
+                    final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
+                    final AtomicReference<Exception> caughtEx = new AtomicReference<>();
+                    final CountDownLatch txReady = new CountDownLatch(1);
+                    Thread txThread = new Thread() {
+                        @Override
+                        public void run() {
+                            try {
+                                writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
 
-                            readWriteTx.close();
-                        } catch(Exception e) {
-                            caughtEx.set(e);
-                            return;
-                        } finally {
-                            txReadDone.countDown();
+                                txCohort.set(writeTx.ready());
+                            } catch (Exception e) {
+                                caughtEx.set(e);
+                                return;
+                            } finally {
+                                txReady.countDown();
+                            }
                         }
-                    }
-                };
+                    };
 
-                txThread.start();
+                    txThread.start();
 
-                // Wait for the Tx operations to complete.
+                    // Wait for the Tx operations to complete.
 
-                boolean done = Uninterruptibles.awaitUninterruptibly(txReadDone, 5, TimeUnit.SECONDS);
-                if(caughtEx.get() != null) {
-                    throw caughtEx.get();
-                }
+                    boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
+                    if (caughtEx.get() != null) {
+                        throw caughtEx.get();
+                    }
 
-                assertEquals("Tx read done", true, done);
+                    assertEquals("Tx ready", true, done);
 
-                // Wait for the read to complete. Since the shard never initialized, the Tx should
-                // have timed out and throw an appropriate exception cause.
+                    // Wait for the commit to complete. Since the shard never
+                    // initialized, the Tx should
+                    // have timed out and throw an appropriate exception cause.
 
-                try {
-                    txReadFuture.get().checkedGet(5, TimeUnit.SECONDS);
-                } catch(ReadFailedException e) {
-                    throw e.getCause();
-                } finally {
-                    blockRecoveryLatch.countDown();
+                    try {
+                        txCohort.get().canCommit().get(5, TimeUnit.SECONDS);
+                    } catch (ExecutionException e) {
+                        Throwables.propagateIfInstanceOf(e.getCause(), Exception.class);
+                        Throwables.propagate(e.getCause());
+                    } finally {
+                        blockRecoveryLatch.countDown();
+                    }
                 }
             }
-        }};
+        };
     }
 
-    private void testTransactionCommitFailureWithNoShardLeader(final boolean writeOnly, final String testName) throws Throwable {
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            String shardName = "default";
+    @Test(expected = NotInitializedException.class)
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    public void testTransactionReadFailureWithShardNotInitialized() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                String testName = "testTransactionReadFailureWithShardNotInitialized";
+                String shardName = "test-1";
 
-            // We don't want the shard to become the leader so prevent shard elections.
-            datastoreContextBuilder.customRaftPolicyImplementation(
-                    "org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy");
+                // Set the shard initialization timeout low for the test.
 
-            // The ShardManager uses the election timeout for FindPrimary so reset it low so it will timeout quickly.
-            datastoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(1).
-                    shardInitializationTimeout(200, TimeUnit.MILLISECONDS);
+                datastoreContextBuilder.shardInitializationTimeout(300, TimeUnit.MILLISECONDS);
 
-            try (DistributedDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
+                // Setup the InMemoryJournal to block shard recovery
+                // indefinitely.
 
-                Object result = dataStore.getActorContext().executeOperation(
-                    dataStore.getActorContext().getShardManager(), new FindLocalShard(shardName, true));
-                assertTrue("Expected LocalShardFound. Actual: " + result, result instanceof LocalShardFound);
+                String persistentID = String.format("member-1-shard-%s-%s", shardName, testName);
+                CountDownLatch blockRecoveryLatch = new CountDownLatch(1);
+                InMemoryJournal.addBlockReadMessagesLatch(persistentID, blockRecoveryLatch);
 
-                // Create the write Tx.
+                InMemoryJournal.addEntry(persistentID, 1, "Dummy data so akka will read from persistence");
 
-                try (final DOMStoreWriteTransaction writeTx = writeOnly ? dataStore.newWriteOnlyTransaction() :
-                    dataStore.newReadWriteTransaction()) {
-                    assertNotNull("newReadWriteTransaction returned null", writeTx);
+                try (DistributedDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
 
-                    // Do some modifications and ready the Tx on a separate thread.
+                    // Create the read-write Tx
 
-                    final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
+                    final DOMStoreReadWriteTransaction readWriteTx = dataStore.newReadWriteTransaction();
+                    assertNotNull("newReadWriteTransaction returned null", readWriteTx);
+
+                    // Do a read on the Tx on a separate thread.
+
+                    final AtomicReference<CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException>>
+                            txReadFuture = new AtomicReference<>();
                     final AtomicReference<Exception> caughtEx = new AtomicReference<>();
-                    final CountDownLatch txReady = new CountDownLatch(1);
+                    final CountDownLatch txReadDone = new CountDownLatch(1);
                     Thread txThread = new Thread() {
                         @Override
                         public void run() {
                             try {
-                                writeTx.write(TestModel.JUNK_PATH,
-                                    ImmutableNodes.containerNode(TestModel.JUNK_QNAME));
+                                readWriteTx.write(TestModel.TEST_PATH,
+                                        ImmutableNodes.containerNode(TestModel.TEST_QNAME));
 
-                                txCohort.set(writeTx.ready());
-                            } catch(Exception e) {
+                                txReadFuture.set(readWriteTx.read(TestModel.TEST_PATH));
+
+                                readWriteTx.close();
+                            } catch (Exception e) {
                                 caughtEx.set(e);
                                 return;
                             } finally {
-                                txReady.countDown();
+                                txReadDone.countDown();
                             }
                         }
                     };
@@ -675,535 +634,660 @@ public class DistributedDataStoreIntegrationTest {
 
                     // Wait for the Tx operations to complete.
 
-                    boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
-                    if(caughtEx.get() != null) {
+                    boolean done = Uninterruptibles.awaitUninterruptibly(txReadDone, 5, TimeUnit.SECONDS);
+                    if (caughtEx.get() != null) {
                         throw caughtEx.get();
                     }
 
-                    assertEquals("Tx ready", true, done);
+                    assertEquals("Tx read done", true, done);
 
-                    // Wait for the commit to complete. Since no shard leader was elected in time, the Tx
-                    // should have timed out and throw an appropriate exception cause.
+                    // Wait for the read to complete. Since the shard never
+                    // initialized, the Tx should
+                    // have timed out and throw an appropriate exception cause.
 
                     try {
-                        txCohort.get().canCommit().get(5, TimeUnit.SECONDS);
-                    } catch(ExecutionException e) {
-                        throw e.getCause();
+                        txReadFuture.get().checkedGet(5, TimeUnit.SECONDS);
+                    } catch (ReadFailedException e) {
+                        Throwables.propagateIfInstanceOf(e.getCause(), Exception.class);
+                        Throwables.propagate(e.getCause());
+                    } finally {
+                        blockRecoveryLatch.countDown();
                     }
                 }
             }
-        }};
+        };
     }
 
-    @Test(expected=NoShardLeaderException.class)
-    public void testWriteOnlyTransactionCommitFailureWithNoShardLeader() throws Throwable {
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    private void testTransactionCommitFailureWithNoShardLeader(final boolean writeOnly, final String testName)
+            throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                String shardName = "default";
+
+                // We don't want the shard to become the leader so prevent shard
+                // elections.
+                datastoreContextBuilder.customRaftPolicyImplementation(
+                        "org.opendaylight.controller.cluster.raft.policy.DisableElectionsRaftPolicy");
+
+                // The ShardManager uses the election timeout for FindPrimary so
+                // reset it low so it will timeout quickly.
+                datastoreContextBuilder.shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(1)
+                        .shardInitializationTimeout(200, TimeUnit.MILLISECONDS);
+
+                try (DistributedDataStore dataStore = setupDistributedDataStore(testName, false, shardName)) {
+
+                    Object result = dataStore.getActorContext().executeOperation(
+                            dataStore.getActorContext().getShardManager(), new FindLocalShard(shardName, true));
+                    assertTrue("Expected LocalShardFound. Actual: " + result, result instanceof LocalShardFound);
+
+                    // Create the write Tx.
+
+                    try (final DOMStoreWriteTransaction writeTx = writeOnly ? dataStore.newWriteOnlyTransaction()
+                            : dataStore.newReadWriteTransaction()) {
+                        assertNotNull("newReadWriteTransaction returned null", writeTx);
+
+                        // Do some modifications and ready the Tx on a separate
+                        // thread.
+
+                        final AtomicReference<DOMStoreThreePhaseCommitCohort> txCohort = new AtomicReference<>();
+                        final AtomicReference<Exception> caughtEx = new AtomicReference<>();
+                        final CountDownLatch txReady = new CountDownLatch(1);
+                        Thread txThread = new Thread() {
+                            @Override
+                            public void run() {
+                                try {
+                                    writeTx.write(TestModel.JUNK_PATH,
+                                            ImmutableNodes.containerNode(TestModel.JUNK_QNAME));
+
+                                    txCohort.set(writeTx.ready());
+                                } catch (Exception e) {
+                                    caughtEx.set(e);
+                                    return;
+                                } finally {
+                                    txReady.countDown();
+                                }
+                            }
+                        };
+
+                        txThread.start();
+
+                        // Wait for the Tx operations to complete.
+
+                        boolean done = Uninterruptibles.awaitUninterruptibly(txReady, 5, TimeUnit.SECONDS);
+                        if (caughtEx.get() != null) {
+                            throw caughtEx.get();
+                        }
+
+                        assertEquals("Tx ready", true, done);
+
+                        // Wait for the commit to complete. Since no shard
+                        // leader was elected in time, the Tx
+                        // should have timed out and throw an appropriate
+                        // exception cause.
+
+                        try {
+                            txCohort.get().canCommit().get(5, TimeUnit.SECONDS);
+                        } catch (ExecutionException e) {
+                            Throwables.propagateIfInstanceOf(e.getCause(), Exception.class);
+                            Throwables.propagate(e.getCause());
+                        }
+                    }
+                }
+            }
+        };
+    }
+
+    @Test(expected = NoShardLeaderException.class)
+    public void testWriteOnlyTransactionCommitFailureWithNoShardLeader() throws Exception {
         datastoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true);
         testTransactionCommitFailureWithNoShardLeader(true, "testWriteOnlyTransactionCommitFailureWithNoShardLeader");
     }
 
-    @Test(expected=NoShardLeaderException.class)
-    public void testReadWriteTransactionCommitFailureWithNoShardLeader() throws Throwable {
+    @Test(expected = NoShardLeaderException.class)
+    public void testReadWriteTransactionCommitFailureWithNoShardLeader() throws Exception {
         testTransactionCommitFailureWithNoShardLeader(false, "testReadWriteTransactionCommitFailureWithNoShardLeader");
     }
 
     @Test
-    public void testTransactionAbort() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore =
-                    setupDistributedDataStore("transactionAbortIntegrationTest", "test-1")) {
+    public void testTransactionAbort() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore("transactionAbortIntegrationTest",
+                        "test-1")) {
 
-                DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
-                assertNotNull("newWriteOnlyTransaction returned null", writeTx);
+                    DOMStoreWriteTransaction writeTx = dataStore.newWriteOnlyTransaction();
+                    assertNotNull("newWriteOnlyTransaction returned null", writeTx);
 
-                writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+                    writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
 
-                DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
+                    DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
 
-                cohort.canCommit().get(5, TimeUnit.SECONDS);
+                    cohort.canCommit().get(5, TimeUnit.SECONDS);
 
-                cohort.abort().get(5, TimeUnit.SECONDS);
+                    cohort.abort().get(5, TimeUnit.SECONDS);
 
-                testWriteTransaction(dataStore, TestModel.TEST_PATH,
-                    ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+                    testWriteTransaction(dataStore, TestModel.TEST_PATH,
+                            ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testTransactionChainWithSingleShard() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore =
-                    setupDistributedDataStore("testTransactionChainWithSingleShard", "test-1")) {
+    @SuppressWarnings("checkstyle:IllegalCatch")
+    public void testTransactionChainWithSingleShard() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore("testTransactionChainWithSingleShard",
+                        "test-1")) {
 
-                // 1. Create a Tx chain and write-only Tx
+                    // 1. Create a Tx chain and write-only Tx
 
-                DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+                    DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
 
-                DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
-                assertNotNull("newWriteOnlyTransaction returned null", writeTx);
+                    DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+                    assertNotNull("newWriteOnlyTransaction returned null", writeTx);
 
-                // 2. Write some data
+                    // 2. Write some data
 
-                NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
-                writeTx.write(TestModel.TEST_PATH, testNode);
+                    NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+                    writeTx.write(TestModel.TEST_PATH, testNode);
 
-                // 3. Ready the Tx for commit
+                    // 3. Ready the Tx for commit
 
-                final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
+                    final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
 
-                // 4. Commit the Tx on another thread that first waits for the second read Tx.
+                    // 4. Commit the Tx on another thread that first waits for
+                    // the second read Tx.
 
-                final CountDownLatch continueCommit1 = new CountDownLatch(1);
-                final CountDownLatch commit1Done = new CountDownLatch(1);
-                final AtomicReference<Exception> commit1Error = new AtomicReference<>();
-                new Thread() {
-                    @Override
-                    public void run() {
-                        try {
-                            continueCommit1.await();
-                            doCommit(cohort1);
-                        } catch (Exception e) {
-                            commit1Error.set(e);
-                        } finally {
-                            commit1Done.countDown();
+                    final CountDownLatch continueCommit1 = new CountDownLatch(1);
+                    final CountDownLatch commit1Done = new CountDownLatch(1);
+                    final AtomicReference<Exception> commit1Error = new AtomicReference<>();
+                    new Thread() {
+                        @Override
+                        public void run() {
+                            try {
+                                continueCommit1.await();
+                                doCommit(cohort1);
+                            } catch (Exception e) {
+                                commit1Error.set(e);
+                            } finally {
+                                commit1Done.countDown();
+                            }
                         }
-                    }
-                }.start();
+                    }.start();
 
-                // 5. Create a new read Tx from the chain to read and verify the data from the first
-                // Tx is visible after being readied.
+                    // 5. Create a new read Tx from the chain to read and verify
+                    // the data from the first
+                    // Tx is visible after being readied.
 
-                DOMStoreReadTransaction readTx = txChain.newReadOnlyTransaction();
-                Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", testNode, optional.get());
+                    DOMStoreReadTransaction readTx = txChain.newReadOnlyTransaction();
+                    Optional<NormalizedNode<?, ?>> optional = readTx.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", testNode, optional.get());
 
-                // 6. Create a new RW Tx from the chain, write more data, and ready it
+                    // 6. Create a new RW Tx from the chain, write more data,
+                    // and ready it
 
-                DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
-                MapNode outerNode = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
-                rwTx.write(TestModel.OUTER_LIST_PATH, outerNode);
+                    DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
+                    MapNode outerNode = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
+                    rwTx.write(TestModel.OUTER_LIST_PATH, outerNode);
 
-                DOMStoreThreePhaseCommitCohort cohort2 = rwTx.ready();
+                    final DOMStoreThreePhaseCommitCohort cohort2 = rwTx.ready();
 
-                // 7. Create a new read Tx from the chain to read the data from the last RW Tx to
-                // verify it is visible.
+                    // 7. Create a new read Tx from the chain to read the data
+                    // from the last RW Tx to
+                    // verify it is visible.
 
-                readTx = txChain.newReadWriteTransaction();
-                optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", outerNode, optional.get());
+                    readTx = txChain.newReadWriteTransaction();
+                    optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", outerNode, optional.get());
 
-                // 8. Wait for the 2 commits to complete and close the chain.
+                    // 8. Wait for the 2 commits to complete and close the
+                    // chain.
 
-                continueCommit1.countDown();
-                Uninterruptibles.awaitUninterruptibly(commit1Done, 5, TimeUnit.SECONDS);
+                    continueCommit1.countDown();
+                    Uninterruptibles.awaitUninterruptibly(commit1Done, 5, TimeUnit.SECONDS);
 
-                if(commit1Error.get() != null) {
-                    throw commit1Error.get();
-                }
+                    if (commit1Error.get() != null) {
+                        throw commit1Error.get();
+                    }
 
-                doCommit(cohort2);
+                    doCommit(cohort2);
 
-                txChain.close();
+                    txChain.close();
 
-                // 9. Create a new read Tx from the data store and verify committed data.
+                    // 9. Create a new read Tx from the data store and verify
+                    // committed data.
 
-                readTx = dataStore.newReadOnlyTransaction();
-                optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", outerNode, optional.get());
+                    readTx = dataStore.newReadOnlyTransaction();
+                    optional = readTx.read(TestModel.OUTER_LIST_PATH).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", outerNode, optional.get());
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testTransactionChainWithMultipleShards() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore = setupDistributedDataStore("testTransactionChainWithMultipleShards",
-                    "cars-1", "people-1")) {
+    public void testTransactionChainWithMultipleShards() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testTransactionChainWithMultipleShards", "cars-1", "people-1")) {
 
-                DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+                    DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
 
-                DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
-                assertNotNull("newWriteOnlyTransaction returned null", writeTx);
+                    DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+                    assertNotNull("newWriteOnlyTransaction returned null", writeTx);
 
-                writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
-                writeTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
+                    writeTx.write(CarsModel.BASE_PATH, CarsModel.emptyContainer());
+                    writeTx.write(PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
 
-                writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
-                writeTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
+                    writeTx.write(CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
+                    writeTx.write(PeopleModel.PERSON_LIST_PATH, PeopleModel.newPersonMapNode());
 
-                DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
+                    final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
 
-                DOMStoreReadWriteTransaction readWriteTx = txChain.newReadWriteTransaction();
+                    DOMStoreReadWriteTransaction readWriteTx = txChain.newReadWriteTransaction();
 
-                MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
-                YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
-                readWriteTx.write(carPath, car);
+                    MapEntryNode car = CarsModel.newCarEntry("optima", BigInteger.valueOf(20000));
+                    YangInstanceIdentifier carPath = CarsModel.newCarPath("optima");
+                    readWriteTx.write(carPath, car);
 
-                MapEntryNode person = PeopleModel.newPersonEntry("jack");
-                YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
-                readWriteTx.merge(personPath, person);
+                    MapEntryNode person = PeopleModel.newPersonEntry("jack");
+                    YangInstanceIdentifier personPath = PeopleModel.newPersonPath("jack");
+                    readWriteTx.merge(personPath, person);
 
-                Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", car, optional.get());
+                    Optional<NormalizedNode<?, ?>> optional = readWriteTx.read(carPath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", car, optional.get());
 
-                optional = readWriteTx.read(personPath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", person, optional.get());
+                    optional = readWriteTx.read(personPath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", person, optional.get());
 
-                DOMStoreThreePhaseCommitCohort cohort2 = readWriteTx.ready();
+                    DOMStoreThreePhaseCommitCohort cohort2 = readWriteTx.ready();
 
-                writeTx = txChain.newWriteOnlyTransaction();
+                    writeTx = txChain.newWriteOnlyTransaction();
 
-                writeTx.delete(carPath);
+                    writeTx.delete(carPath);
 
-                DOMStoreThreePhaseCommitCohort cohort3 = writeTx.ready();
+                    DOMStoreThreePhaseCommitCohort cohort3 = writeTx.ready();
 
-                ListenableFuture<Boolean> canCommit1 = cohort1.canCommit();
-                ListenableFuture<Boolean> canCommit2 = cohort2.canCommit();
+                    ListenableFuture<Boolean> canCommit1 = cohort1.canCommit();
+                    ListenableFuture<Boolean> canCommit2 = cohort2.canCommit();
 
-                doCommit(canCommit1, cohort1);
-                doCommit(canCommit2, cohort2);
-                doCommit(cohort3);
+                    doCommit(canCommit1, cohort1);
+                    doCommit(canCommit2, cohort2);
+                    doCommit(cohort3);
 
-                txChain.close();
+                    txChain.close();
 
-                DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+                    DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
 
-                optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", false, optional.isPresent());
+                    optional = readTx.read(carPath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", false, optional.isPresent());
 
-                optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", person, optional.get());
+                    optional = readTx.read(personPath).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", person, optional.get());
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testCreateChainedTransactionsInQuickSuccession() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore = setupDistributedDataStore(
-                    "testCreateChainedTransactionsInQuickSuccession", "cars-1")) {
+    public void testCreateChainedTransactionsInQuickSuccession() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testCreateChainedTransactionsInQuickSuccession", "cars-1")) {
 
-                ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
-                    ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(
-                        LogicalDatastoreType.CONFIGURATION, dataStore).build(), MoreExecutors.directExecutor());
+                    ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
+                            ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
+                                    .put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
+                            MoreExecutors.directExecutor());
 
-                TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
-                DOMTransactionChain txChain = broker.createTransactionChain(listener);
+                    TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+                    DOMTransactionChain txChain = broker.createTransactionChain(listener);
 
-                List<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
+                    List<CheckedFuture<Void, TransactionCommitFailedException>> futures = new ArrayList<>();
 
-                DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
-                writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, CarsModel.emptyContainer());
-                writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
-                futures.add(writeTx.submit());
+                    DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+                    writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, CarsModel.emptyContainer());
+                    writeTx.put(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH, CarsModel.newCarMapNode());
+                    futures.add(writeTx.submit());
 
-                int nCars = 100;
-                for(int i = 0; i < nCars; i++) {
-                    DOMDataReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
+                    int numCars = 100;
+                    for (int i = 0; i < numCars; i++) {
+                        DOMDataReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
 
-                    rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.newCarPath("car" + i),
-                        CarsModel.newCarEntry("car" + i, BigInteger.valueOf(20000)));
+                        rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.newCarPath("car" + i),
+                                CarsModel.newCarEntry("car" + i, BigInteger.valueOf(20000)));
 
-                    futures.add(rwTx.submit());
-                }
+                        futures.add(rwTx.submit());
+                    }
 
-                for(CheckedFuture<Void, TransactionCommitFailedException> f: futures) {
-                    f.checkedGet();
-                }
+                    for (CheckedFuture<Void, TransactionCommitFailedException> f : futures) {
+                        f.checkedGet();
+                    }
 
-                Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction().read(
-                    LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("# cars", nCars, ((Collection<?>)optional.get().getValue()).size());
+                    Optional<NormalizedNode<?, ?>> optional = txChain.newReadOnlyTransaction()
+                            .read(LogicalDatastoreType.CONFIGURATION, CarsModel.CAR_LIST_PATH).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("# cars", numCars, ((Collection<?>) optional.get().getValue()).size());
 
-                txChain.close();
+                    txChain.close();
 
-                broker.close();
+                    broker.close();
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testCreateChainedTransactionAfterEmptyTxReadied() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore = setupDistributedDataStore(
-                    "testCreateChainedTransactionAfterEmptyTxReadied", "test-1")) {
+    public void testCreateChainedTransactionAfterEmptyTxReadied() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testCreateChainedTransactionAfterEmptyTxReadied", "test-1")) {
 
-                DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+                    DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
 
-                DOMStoreReadWriteTransaction rwTx1 = txChain.newReadWriteTransaction();
+                    DOMStoreReadWriteTransaction rwTx1 = txChain.newReadWriteTransaction();
 
-                rwTx1.ready();
+                    rwTx1.ready();
 
-                DOMStoreReadWriteTransaction rwTx2 = txChain.newReadWriteTransaction();
+                    DOMStoreReadWriteTransaction rwTx2 = txChain.newReadWriteTransaction();
 
-                Optional<NormalizedNode<?, ?>> optional = rwTx2.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", false, optional.isPresent());
+                    Optional<NormalizedNode<?, ?>> optional = rwTx2.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", false, optional.isPresent());
 
-                txChain.close();
+                    txChain.close();
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testCreateChainedTransactionWhenPreviousNotReady() throws Throwable {
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore = setupDistributedDataStore(
-                "testCreateChainedTransactionWhenPreviousNotReady", "test-1")) {
+    public void testCreateChainedTransactionWhenPreviousNotReady() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testCreateChainedTransactionWhenPreviousNotReady", "test-1")) {
 
-                final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+                    final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
 
-                DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
-                assertNotNull("newWriteOnlyTransaction returned null", writeTx);
+                    DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+                    assertNotNull("newWriteOnlyTransaction returned null", writeTx);
 
-                writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+                    writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
 
-                // Try to create another Tx of each type - each should fail b/c the previous Tx wasn't
-                // readied.
+                    // Try to create another Tx of each type - each should fail
+                    // b/c the previous Tx wasn't
+                    // readied.
 
-                assertExceptionOnTxChainCreates(txChain, IllegalStateException.class);
+                    assertExceptionOnTxChainCreates(txChain, IllegalStateException.class);
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testCreateChainedTransactionAfterClose() throws Throwable {
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore = setupDistributedDataStore(
-                "testCreateChainedTransactionAfterClose", "test-1")) {
+    public void testCreateChainedTransactionAfterClose() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testCreateChainedTransactionAfterClose", "test-1")) {
 
-                DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+                    DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
 
-                txChain.close();
+                    txChain.close();
 
-                // Try to create another Tx of each type - should fail b/c the previous Tx was closed.
+                    // Try to create another Tx of each type - should fail b/c
+                    // the previous Tx was closed.
 
-                assertExceptionOnTxChainCreates(txChain, TransactionChainClosedException.class);
+                    assertExceptionOnTxChainCreates(txChain, TransactionChainClosedException.class);
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testChainWithReadOnlyTxAfterPreviousReady() throws Throwable {
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore = setupDistributedDataStore(
-                "testChainWithReadOnlyTxAfterPreviousReady", "test-1")) {
+    public void testChainWithReadOnlyTxAfterPreviousReady() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testChainWithReadOnlyTxAfterPreviousReady", "test-1")) {
 
-                final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+                    final DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
 
-                // Create a write tx and submit.
+                    // Create a write tx and submit.
 
-                DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
-                writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
-                DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
+                    DOMStoreWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+                    writeTx.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+                    final DOMStoreThreePhaseCommitCohort cohort1 = writeTx.ready();
 
-                // Create read-only tx's and issue a read.
+                    // Create read-only tx's and issue a read.
 
-                CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture1 =
-                        txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
+                    CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture1 = txChain
+                            .newReadOnlyTransaction().read(TestModel.TEST_PATH);
 
-                CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture2 =
-                        txChain.newReadOnlyTransaction().read(TestModel.TEST_PATH);
+                    CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readFuture2 = txChain
+                            .newReadOnlyTransaction().read(TestModel.TEST_PATH);
 
-                // Create another write tx and issue the write.
+                    // Create another write tx and issue the write.
 
-                DOMStoreWriteTransaction writeTx2 = txChain.newWriteOnlyTransaction();
-                writeTx2.write(TestModel.OUTER_LIST_PATH,
-                    ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+                    DOMStoreWriteTransaction writeTx2 = txChain.newWriteOnlyTransaction();
+                    writeTx2.write(TestModel.OUTER_LIST_PATH,
+                            ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
 
-                // Ensure the reads succeed.
+                    // Ensure the reads succeed.
 
-                assertEquals("isPresent", true, readFuture1.checkedGet(5, TimeUnit.SECONDS).isPresent());
-                assertEquals("isPresent", true, readFuture2.checkedGet(5, TimeUnit.SECONDS).isPresent());
+                    assertEquals("isPresent", true, readFuture1.checkedGet(5, TimeUnit.SECONDS).isPresent());
+                    assertEquals("isPresent", true, readFuture2.checkedGet(5, TimeUnit.SECONDS).isPresent());
 
-                // Ensure the writes succeed.
+                    // Ensure the writes succeed.
 
-                DOMStoreThreePhaseCommitCohort cohort2 = writeTx2.ready();
+                    DOMStoreThreePhaseCommitCohort cohort2 = writeTx2.ready();
 
-                doCommit(cohort1);
-                doCommit(cohort2);
+                    doCommit(cohort1);
+                    doCommit(cohort2);
 
-                assertEquals("isPresent", true, txChain.newReadOnlyTransaction().read(TestModel.OUTER_LIST_PATH).
-                    checkedGet(5, TimeUnit.SECONDS).isPresent());
+                    assertEquals("isPresent", true, txChain.newReadOnlyTransaction().read(TestModel.OUTER_LIST_PATH)
+                            .checkedGet(5, TimeUnit.SECONDS).isPresent());
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testChainedTransactionFailureWithSingleShard() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore = setupDistributedDataStore(
-                    "testChainedTransactionFailureWithSingleShard", "cars-1")) {
+    public void testChainedTransactionFailureWithSingleShard() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testChainedTransactionFailureWithSingleShard", "cars-1")) {
 
-                ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
-                    ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(
-                        LogicalDatastoreType.CONFIGURATION, dataStore).build(), MoreExecutors.directExecutor());
+                    ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
+                            ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
+                                    .put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
+                            MoreExecutors.directExecutor());
 
-                TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
-                DOMTransactionChain txChain = broker.createTransactionChain(listener);
+                    TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+                    DOMTransactionChain txChain = broker.createTransactionChain(listener);
 
-                DOMDataReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
+                    DOMDataReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
 
-                ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
-                    new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).
-                        withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
+                    ContainerNode invalidData = ImmutableContainerNodeBuilder.create()
+                            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
+                            .withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
 
-                rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
+                    rwTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
 
-                try {
-                    rwTx.submit().checkedGet(5, TimeUnit.SECONDS);
-                    fail("Expected TransactionCommitFailedException");
-                } catch (TransactionCommitFailedException e) {
-                    // Expected
-                }
+                    try {
+                        rwTx.submit().checkedGet(5, TimeUnit.SECONDS);
+                        fail("Expected TransactionCommitFailedException");
+                    } catch (TransactionCommitFailedException e) {
+                        // Expected
+                    }
 
-                verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(rwTx), any(Throwable.class));
+                    verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(rwTx),
+                            any(Throwable.class));
 
-                txChain.close();
-                broker.close();
+                    txChain.close();
+                    broker.close();
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testChainedTransactionFailureWithMultipleShards() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore = setupDistributedDataStore(
-                    "testChainedTransactionFailureWithMultipleShards", "cars-1", "people-1")) {
+    public void testChainedTransactionFailureWithMultipleShards() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore(
+                        "testChainedTransactionFailureWithMultipleShards", "cars-1", "people-1")) {
 
-                ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
-                    ImmutableMap.<LogicalDatastoreType, DOMStore>builder().put(
-                        LogicalDatastoreType.CONFIGURATION, dataStore).build(), MoreExecutors.directExecutor());
+                    ConcurrentDOMDataBroker broker = new ConcurrentDOMDataBroker(
+                            ImmutableMap.<LogicalDatastoreType, DOMStore>builder()
+                                    .put(LogicalDatastoreType.CONFIGURATION, dataStore).build(),
+                            MoreExecutors.directExecutor());
 
-                TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
-                DOMTransactionChain txChain = broker.createTransactionChain(listener);
+                    TransactionChainListener listener = Mockito.mock(TransactionChainListener.class);
+                    DOMTransactionChain txChain = broker.createTransactionChain(listener);
 
-                DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
+                    DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
 
-                writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH, PeopleModel.emptyContainer());
+                    writeTx.put(LogicalDatastoreType.CONFIGURATION, PeopleModel.BASE_PATH,
+                            PeopleModel.emptyContainer());
 
-                ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
-                    new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME)).
-                        withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
+                    ContainerNode invalidData = ImmutableContainerNodeBuilder.create()
+                            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CarsModel.BASE_QNAME))
+                            .withChild(ImmutableNodes.leafNode(TestModel.JUNK_QNAME, "junk")).build();
 
-                // Note that merge will validate the data and fail but put succeeds b/c deep validation is not
-                // done for put for performance reasons.
-                writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
+                    // Note that merge will validate the data and fail but put
+                    // succeeds b/c deep validation is not
+                    // done for put for performance reasons.
+                    writeTx.merge(LogicalDatastoreType.CONFIGURATION, CarsModel.BASE_PATH, invalidData);
 
-                try {
-                    writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
-                    fail("Expected TransactionCommitFailedException");
-                } catch (TransactionCommitFailedException e) {
-                    // Expected
-                }
+                    try {
+                        writeTx.submit().checkedGet(5, TimeUnit.SECONDS);
+                        fail("Expected TransactionCommitFailedException");
+                    } catch (TransactionCommitFailedException e) {
+                        // Expected
+                    }
 
-                verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx), any(Throwable.class));
+                    verify(listener, timeout(5000)).onTransactionChainFailed(eq(txChain), eq(writeTx),
+                            any(Throwable.class));
 
-                txChain.close();
-                broker.close();
+                    txChain.close();
+                    broker.close();
+                }
             }
-        }};
+        };
     }
 
     @Test
-    public void testChangeListenerRegistration() throws Exception{
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            try (DistributedDataStore dataStore =
-                    setupDistributedDataStore("testChangeListenerRegistration", "test-1")) {
+    public void testChangeListenerRegistration() throws Exception {
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                try (DistributedDataStore dataStore = setupDistributedDataStore("testChangeListenerRegistration",
+                        "test-1")) {
 
-                testWriteTransaction(dataStore, TestModel.TEST_PATH,
-                    ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+                    testWriteTransaction(dataStore, TestModel.TEST_PATH,
+                            ImmutableNodes.containerNode(TestModel.TEST_QNAME));
 
-                MockDataChangeListener listener = new MockDataChangeListener(1);
+                    MockDataChangeListener listener = new MockDataChangeListener(1);
 
-                ListenerRegistration<MockDataChangeListener>
-                listenerReg = dataStore.registerChangeListener(TestModel.TEST_PATH, listener,
-                    DataChangeScope.SUBTREE);
+                    ListenerRegistration<MockDataChangeListener> listenerReg = dataStore
+                            .registerChangeListener(TestModel.TEST_PATH, listener, DataChangeScope.SUBTREE);
 
-                assertNotNull("registerChangeListener returned null", listenerReg);
+                    assertNotNull("registerChangeListener returned null", listenerReg);
 
-                // Wait for the initial notification
+                    // Wait for the initial notification
 
-                listener.waitForChangeEvents(TestModel.TEST_PATH);
+                    listener.waitForChangeEvents(TestModel.TEST_PATH);
 
-                listener.reset(2);
+                    listener.reset(2);
 
-                // Write 2 updates.
+                    // Write 2 updates.
 
-                testWriteTransaction(dataStore, TestModel.OUTER_LIST_PATH,
-                    ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
+                    testWriteTransaction(dataStore, TestModel.OUTER_LIST_PATH,
+                            ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
 
-                YangInstanceIdentifier listPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH).
-                        nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).build();
-                testWriteTransaction(dataStore, listPath,
-                    ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1));
+                    YangInstanceIdentifier listPath = YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
+                            .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1).build();
+                    testWriteTransaction(dataStore, listPath,
+                            ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1));
 
-                // Wait for the 2 updates.
+                    // Wait for the 2 updates.
 
-                listener.waitForChangeEvents(TestModel.OUTER_LIST_PATH, listPath);
+                    listener.waitForChangeEvents(TestModel.OUTER_LIST_PATH, listPath);
 
-                listenerReg.close();
+                    listenerReg.close();
 
-                testWriteTransaction(dataStore, YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH).
-                    nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).build(),
-                    ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2));
+                    testWriteTransaction(dataStore,
+                            YangInstanceIdentifier.builder(TestModel.OUTER_LIST_PATH)
+                                    .nodeWithKey(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2).build(),
+                            ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2));
 
-                listener.expectNoMoreChanges("Received unexpected change after close");
+                    listener.expectNoMoreChanges("Received unexpected change after close");
+                }
             }
-        }};
+        };
     }
 
     @Test
     public void testRestoreFromDatastoreSnapshot() throws Exception {
-        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {{
-            String name = "transactionIntegrationTest";
-
-            ContainerNode carsNode = CarsModel.newCarsNode(CarsModel.newCarsMapNode(
-                    CarsModel.newCarEntry("optima", BigInteger.valueOf(20000L)),
-                    CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000L))));
-
-            DataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
-            dataTree.setSchemaContext(SchemaContextHelper.full());
-            AbstractShardTest.writeToStore(dataTree, CarsModel.BASE_PATH, carsNode);
-            NormalizedNode<?, ?> root = AbstractShardTest.readStore(dataTree, YangInstanceIdentifier.EMPTY);
-
-            Snapshot carsSnapshot = Snapshot.create(new MetadataShardDataTreeSnapshot(root).serialize(),
-                    Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1");
-
-            NormalizedNode<?, ?> peopleNode = PeopleModel.create();
-            dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
-            dataTree.setSchemaContext(SchemaContextHelper.full());
-            AbstractShardTest.writeToStore(dataTree, PeopleModel.BASE_PATH, peopleNode);
-            root = AbstractShardTest.readStore(dataTree, YangInstanceIdentifier.EMPTY);
-
-            Snapshot peopleSnapshot = Snapshot.create(new MetadataShardDataTreeSnapshot(root).serialize(),
-                    Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1");
-
-            restoreFromSnapshot = new DatastoreSnapshot(name, null, Arrays.asList(
-                    new DatastoreSnapshot.ShardSnapshot("cars",
-                            org.apache.commons.lang3.SerializationUtils.serialize(carsSnapshot)),
-                    new DatastoreSnapshot.ShardSnapshot("people",
-                            org.apache.commons.lang3.SerializationUtils.serialize(peopleSnapshot))));
-
-            try (DistributedDataStore dataStore = setupDistributedDataStore(name, "module-shards-member1.conf",
-                    true, "cars", "people")) {
-
-                DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
-
-                Optional<NormalizedNode<?, ?>> optional = readTx.read(CarsModel.BASE_PATH).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", carsNode, optional.get());
-
-                optional = readTx.read(PeopleModel.BASE_PATH).get(5, TimeUnit.SECONDS);
-                assertEquals("isPresent", true, optional.isPresent());
-                assertEquals("Data node", peopleNode, optional.get());
+        new IntegrationTestKit(getSystem(), datastoreContextBuilder) {
+            {
+                final String name = "transactionIntegrationTest";
+
+                ContainerNode carsNode = CarsModel.newCarsNode(
+                        CarsModel.newCarsMapNode(CarsModel.newCarEntry("optima", BigInteger.valueOf(20000L)),
+                                CarsModel.newCarEntry("sportage", BigInteger.valueOf(30000L))));
+
+                DataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+                dataTree.setSchemaContext(SchemaContextHelper.full());
+                AbstractShardTest.writeToStore(dataTree, CarsModel.BASE_PATH, carsNode);
+                NormalizedNode<?, ?> root = AbstractShardTest.readStore(dataTree, YangInstanceIdentifier.EMPTY);
+
+                final Snapshot carsSnapshot = Snapshot.create(new MetadataShardDataTreeSnapshot(root).serialize(),
+                        Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1");
+
+                NormalizedNode<?, ?> peopleNode = PeopleModel.create();
+                dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+                dataTree.setSchemaContext(SchemaContextHelper.full());
+                AbstractShardTest.writeToStore(dataTree, PeopleModel.BASE_PATH, peopleNode);
+                root = AbstractShardTest.readStore(dataTree, YangInstanceIdentifier.EMPTY);
+
+                Snapshot peopleSnapshot = Snapshot.create(new MetadataShardDataTreeSnapshot(root).serialize(),
+                        Collections.<ReplicatedLogEntry>emptyList(), 2, 1, 2, 1, 1, "member-1");
+
+                restoreFromSnapshot = new DatastoreSnapshot(name, null,
+                        Arrays.asList(
+                                new DatastoreSnapshot.ShardSnapshot("cars",
+                                        org.apache.commons.lang3.SerializationUtils.serialize(carsSnapshot)),
+                                new DatastoreSnapshot.ShardSnapshot("people",
+                                        org.apache.commons.lang3.SerializationUtils.serialize(peopleSnapshot))));
+
+                try (DistributedDataStore dataStore = setupDistributedDataStore(name, "module-shards-member1.conf",
+                        true, "cars", "people")) {
+
+                    DOMStoreReadTransaction readTx = dataStore.newReadOnlyTransaction();
+
+                    Optional<NormalizedNode<?, ?>> optional = readTx.read(CarsModel.BASE_PATH).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", carsNode, optional.get());
+
+                    optional = readTx.read(PeopleModel.BASE_PATH).get(5, TimeUnit.SECONDS);
+                    assertEquals("isPresent", true, optional.isPresent());
+                    assertEquals("Data node", peopleNode, optional.get());
+                }
             }
-        }};
+        };
     }
 }
index 4c0aac4..e157e42 100644 (file)
@@ -15,6 +15,7 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.timeout;
 import static org.mockito.Mockito.verify;
+
 import akka.actor.ActorRef;
 import akka.actor.ActorSelection;
 import akka.actor.ActorSystem;
@@ -27,6 +28,7 @@ import akka.pattern.Patterns;
 import akka.testkit.JavaTestKit;
 import com.google.common.base.Optional;
 import com.google.common.base.Supplier;
+import com.google.common.base.Throwables;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
@@ -100,8 +102,10 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
     private static final String[] CARS_AND_PEOPLE = {"cars", "people"};
     private static final String[] CARS = {"cars"};
 
-    private static final Address MEMBER_1_ADDRESS = AddressFromURIString.parse("akka.tcp://cluster-test@127.0.0.1:2558");
-    private static final Address MEMBER_2_ADDRESS = AddressFromURIString.parse("akka.tcp://cluster-test@127.0.0.1:2559");
+    private static final Address MEMBER_1_ADDRESS = AddressFromURIString.parse(
+            "akka.tcp://cluster-test@127.0.0.1:2558");
+    private static final Address MEMBER_2_ADDRESS = AddressFromURIString.parse(
+            "akka.tcp://cluster-test@127.0.0.1:2559");
 
     private static final String MODULE_SHARDS_CARS_ONLY_1_2 = "module-shards-cars-member-1-and-2.conf";
     private static final String MODULE_SHARDS_CARS_PEOPLE_1_2 = "module-shards-member1-and-2.conf";
@@ -115,8 +119,8 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
             DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(2);
 
     private final DatastoreContext.Builder followerDatastoreContextBuilder =
-            DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5).
-                customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName());
+            DatastoreContext.newBuilder().shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(5)
+                .customRaftPolicyImplementation(DisableElectionsRaftPolicy.class.getName());
     private final TransactionIdentifier tx1 = nextTransactionId();
     private final TransactionIdentifier tx2 = nextTransactionId();
 
@@ -165,7 +169,8 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
         leaderDistributedDataStore = leaderTestKit.setupDistributedDataStore(type, moduleShardsConfig, false, shards);
 
         followerTestKit = new IntegrationTestKit(followerSystem, followerDatastoreContextBuilder);
-        followerDistributedDataStore = followerTestKit.setupDistributedDataStore(type, moduleShardsConfig, false, shards);
+        followerDistributedDataStore = followerTestKit.setupDistributedDataStore(type, moduleShardsConfig, false,
+                shards);
 
         leaderTestKit.waitUntilLeader(leaderDistributedDataStore.getActorContext(), shards);
     }
@@ -175,15 +180,15 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
         assertEquals("isPresent", true, optional.isPresent());
 
         CollectionNodeBuilder<MapEntryNode, MapNode> listBuilder = ImmutableNodes.mapNodeBuilder(CarsModel.CAR_QNAME);
-        for(NormalizedNode<?, ?> entry: entries) {
+        for (NormalizedNode<?, ?> entry: entries) {
             listBuilder.withChild((MapEntryNode) entry);
         }
 
         assertEquals("Car list node", listBuilder.build(), optional.get());
     }
 
-    private static void verifyNode(DOMStoreReadTransaction readTx, YangInstanceIdentifier path, NormalizedNode<?, ?> expNode)
-            throws Exception {
+    private static void verifyNode(DOMStoreReadTransaction readTx, YangInstanceIdentifier path,
+            NormalizedNode<?, ?> expNode) throws Exception {
         Optional<NormalizedNode<?, ?>> optional = readTx.read(path).get(5, TimeUnit.SECONDS);
         assertEquals("isPresent", true, optional.isPresent());
         assertEquals("Data node", expNode, optional.get());
@@ -245,8 +250,8 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
 
         ActorSystem newSystem = ActorSystem.create("reinstated-member2", ConfigFactory.load().getConfig("Member2"));
 
-        try (DistributedDataStore member2Datastore = new IntegrationTestKit(newSystem, leaderDatastoreContextBuilder).
-                setupDistributedDataStore(testName, "module-shards-member2", true, CARS_AND_PEOPLE)) {
+        try (DistributedDataStore member2Datastore = new IntegrationTestKit(newSystem, leaderDatastoreContextBuilder)
+                .setupDistributedDataStore(testName, "module-shards-member2", true, CARS_AND_PEOPLE)) {
             verifyCars(member2Datastore.newReadOnlyTransaction(), car2);
         }
 
@@ -373,7 +378,7 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
     }
 
     @Test
-    public void testTransactionChainWithMultipleShards() throws Exception{
+    public void testTransactionChainWithMultipleShards() throws Exception {
         initDatastoresWithCarsAndPeople("testTransactionChainWithMultipleShards");
 
         DOMStoreTransactionChain txChain = followerDistributedDataStore.createTransactionChain();
@@ -442,8 +447,8 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest {
         DOMDataWriteTransaction writeTx = txChain.newWriteOnlyTransaction();
 
         ContainerNode invalidData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
-