X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=dom%2Fmdsal-dom-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fdom%2Fbroker%2FShardedDOMDataTreeProducerMultiShardTest.java;h=46ab94cc36795f0cd4fe4e8f84fb26c30db2e6a3;hb=c37d38386002ed12b279938051813f99a4de70ff;hp=444e0771e7886c075fadce8a566e89b3cb2060e7;hpb=28da9390c5cea9a731776b470b6c467a023d3935;p=mdsal.git diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTreeProducerMultiShardTest.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTreeProducerMultiShardTest.java index 444e0771e7..46ab94cc36 100644 --- a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTreeProducerMultiShardTest.java +++ b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTreeProducerMultiShardTest.java @@ -106,7 +106,7 @@ public class ShardedDOMDataTreeProducerMultiShardTest { public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - rootShard = InMemoryDOMDataTreeShard.create(ROOT_ID, executor, 1, 1); + rootShard = InMemoryDOMDataTreeShard.create(ROOT_ID, executor, 1); rootShard.onGlobalContextUpdated(schemaContext); final ShardedDOMDataTree dataTree = new ShardedDOMDataTree(); @@ -117,7 +117,7 @@ public class ShardedDOMDataTreeProducerMultiShardTest { dataTreeService = dataTree; } - @Test(expected=IllegalStateException.class) + @Test(expected = IllegalStateException.class) public void testTxReadyMultiples() throws Exception { final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID)); final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction(); @@ -132,7 +132,7 @@ public class ShardedDOMDataTreeProducerMultiShardTest { transaction.ready(); } - @Test(expected=IllegalStateException.class) + @Test(expected = IllegalStateException.class) public void testSubmitUnclosedCursor() throws Exception { final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID)); final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction(); @@ -151,7 +151,8 @@ public class ShardedDOMDataTreeProducerMultiShardTest { final DOMDataTreeListener mockedDataTreeListener = Mockito.mock(DOMDataTreeListener.class); doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap()); - dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID), true, Collections.emptyList()); + dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID), + true, Collections.emptyList()); final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID)); final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction(); @@ -179,11 +180,13 @@ public class ShardedDOMDataTreeProducerMultiShardTest { transaction.ready(); transaction.submit(); - verify(mockedDataTreeListener, timeout(1000)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture()); + verify(mockedDataTreeListener, timeout(1000).times(2)).onDataTreeChanged( + captorForChanges.capture(), captorForSubtrees.capture()); final Collection capturedValue = captorForChanges.getValue(); assertTrue(capturedValue.size() == 1); - final ContainerNode dataAfter = (ContainerNode) capturedValue.iterator().next().getRootNode().getDataAfter().get(); + final ContainerNode dataAfter = + (ContainerNode) capturedValue.iterator().next().getRootNode().getDataAfter().get(); assertEquals(innerContainer, dataAfter); verifyNoMoreInteractions(mockedDataTreeListener); } @@ -193,23 +196,28 @@ public class ShardedDOMDataTreeProducerMultiShardTest { final DOMDataTreeListener mockedDataTreeListener = Mockito.mock(DOMDataTreeListener.class); doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap()); - dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID), true, Collections.emptyList()); + dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID), true, + Collections.emptyList()); final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID)); final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction(); writeCrossShardContainer(transaction); - verify(mockedDataTreeListener, timeout(1000)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture()); + verify(mockedDataTreeListener, timeout(1000).times(2)).onDataTreeChanged( + captorForChanges.capture(), captorForSubtrees.capture()); final Collection capturedValue = captorForChanges.getValue(); assertTrue(capturedValue.size() == 1); - final ContainerNode dataAfter = (ContainerNode) capturedValue.iterator().next().getRootNode().getDataAfter().get(); - assertEquals(crossShardContainer.getChild(TestModel.INNER_CONTAINER_PATH.getLastPathArgument()).get(), dataAfter); + final ContainerNode dataAfter = + (ContainerNode) capturedValue.iterator().next().getRootNode().getDataAfter().get(); + assertEquals(crossShardContainer.getChild( + TestModel.INNER_CONTAINER_PATH.getLastPathArgument()).get(), dataAfter); final Map> capturedSubtrees = captorForSubtrees.getValue(); assertTrue(capturedSubtrees.size() == 1); assertTrue(capturedSubtrees.containsKey(INNER_CONTAINER_ID)); - assertEquals(crossShardContainer.getChild(TestModel.INNER_CONTAINER_PATH.getLastPathArgument()).get(), capturedSubtrees.get(INNER_CONTAINER_ID)); + assertEquals(crossShardContainer.getChild(TestModel.INNER_CONTAINER_PATH.getLastPathArgument()).get(), + capturedSubtrees.get(INNER_CONTAINER_ID)); verifyNoMoreInteractions(mockedDataTreeListener); } @@ -219,13 +227,15 @@ public class ShardedDOMDataTreeProducerMultiShardTest { final DOMDataTreeListener mockedDataTreeListener = Mockito.mock(DOMDataTreeListener.class); doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap()); - final InMemoryDOMDataTreeShard innerShard = InMemoryDOMDataTreeShard.create(INNER_CONTAINER_ID, executor, 1, 1); + final InMemoryDOMDataTreeShard innerShard = InMemoryDOMDataTreeShard.create(INNER_CONTAINER_ID, executor, 1); innerShard.onGlobalContextUpdated(schemaContext); - final DOMDataTreeProducer shardRegProducer = dataTreeService.createProducer(Collections.singletonList(INNER_CONTAINER_ID)); + final DOMDataTreeProducer shardRegProducer = + dataTreeService.createProducer(Collections.singletonList(INNER_CONTAINER_ID)); innerShardReg = dataTreeService.registerDataTreeShard(INNER_CONTAINER_ID, innerShard, shardRegProducer); shardRegProducer.close(); - dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID), true, Collections.emptyList()); + dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(TEST_ID), + true, Collections.emptyList()); final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID)); final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction(); @@ -236,19 +246,21 @@ public class ShardedDOMDataTreeProducerMultiShardTest { .build(); //verify listeners have been notified - verify(mockedDataTreeListener, timeout(1000).times(2)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture()); + verify(mockedDataTreeListener, timeout(1000).times(4)).onDataTreeChanged( + captorForChanges.capture(), captorForSubtrees.capture()); final List> capturedChanges = captorForChanges.getAllValues(); - final List>> capturedSubtrees = captorForSubtrees.getAllValues(); - final DataTreeCandidate firstNotificationCandidate = capturedChanges.get(0).iterator().next(); + final List>> capturedSubtrees = + captorForSubtrees.getAllValues(); + final DataTreeCandidate firstNotificationCandidate = capturedChanges.get(2).iterator().next(); - assertTrue(capturedSubtrees.get(0).size() == 1); + assertTrue(capturedSubtrees.get(2).size() == 1); assertEquals(testContainerVerificationNode, firstNotificationCandidate.getRootNode().getDataAfter().get()); - assertEquals(testContainerVerificationNode, capturedSubtrees.get(0).get(TEST_ID)); + assertEquals(testContainerVerificationNode, capturedSubtrees.get(2).get(TEST_ID)); - final DataTreeCandidate secondNotificationCandidate = capturedChanges.get(1).iterator().next(); - assertTrue(capturedSubtrees.get(1).size() == 1); + final DataTreeCandidate secondNotificationCandidate = capturedChanges.get(3).iterator().next(); + assertTrue(capturedSubtrees.get(3).size() == 1); assertEquals(crossShardContainer, secondNotificationCandidate.getRootNode().getDataAfter().get()); - assertEquals(crossShardContainer, capturedSubtrees.get(1).get(TEST_ID)); + assertEquals(crossShardContainer, capturedSubtrees.get(3).get(TEST_ID)); verifyNoMoreInteractions(mockedDataTreeListener); } @@ -258,7 +270,8 @@ public class ShardedDOMDataTreeProducerMultiShardTest { final DOMDataTreeListener mockedDataTreeListener = Mockito.mock(DOMDataTreeListener.class); doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap()); - dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID), true, Collections.emptyList()); + dataTreeService.registerListener(mockedDataTreeListener, Collections.singletonList(INNER_CONTAINER_ID), + true, Collections.emptyList()); final DOMDataTreeShardProducer producer = rootShard.createProducer(Collections.singletonList(TEST_ID)); final DOMDataTreeShardWriteTransaction transaction = producer.createTransaction(); @@ -288,11 +301,14 @@ public class ShardedDOMDataTreeProducerMultiShardTest { cursor.enter(TestModel.TEST_PATH.getLastPathArgument()); final LeafNode shardedValue1 = - ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.SHARDED_VALUE_1)).withValue("sharded value 1").build(); + ImmutableLeafNodeBuilder.create().withNodeIdentifier( + new NodeIdentifier(TestModel.SHARDED_VALUE_1)).withValue("sharded value 1").build(); final LeafNode shardedValue2 = - ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.SHARDED_VALUE_2)).withValue("sharded value 2").build(); + ImmutableLeafNodeBuilder.create().withNodeIdentifier( + new NodeIdentifier(TestModel.SHARDED_VALUE_2)).withValue("sharded value 2").build(); - final DataContainerNodeAttrBuilder containerNodeBuilder = ImmutableContainerNodeBuilder.create(); + final DataContainerNodeAttrBuilder containerNodeBuilder = + ImmutableContainerNodeBuilder.create(); final ContainerNode containerNode = containerNodeBuilder .withNodeIdentifier(new NodeIdentifier(TestModel.INNER_CONTAINER)) @@ -318,7 +334,8 @@ public class ShardedDOMDataTreeProducerMultiShardTest { final ContainerNode lowerShardContainer = ImmutableContainerNodeBuilder.create() .withNodeIdentifier(new NodeIdentifier(TestModel.ANOTHER_SHARD_CONTAINER)) - .withChild(ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.ANOTHER_SHARD_VALUE)).build()) + .withChild(ImmutableLeafNodeBuilder.create().withNodeIdentifier( + new NodeIdentifier(TestModel.ANOTHER_SHARD_VALUE)).build()) .build(); cursor.write(TestModel.ANOTHER_SHARD_PATH.getLastPathArgument(), lowerShardContainer); @@ -336,9 +353,11 @@ public class ShardedDOMDataTreeProducerMultiShardTest { private ContainerNode createCrossShardContainer() { final LeafNode shardedValue1 = - ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.SHARDED_VALUE_1)).withValue("sharded value 1").build(); + ImmutableLeafNodeBuilder.create().withNodeIdentifier( + new NodeIdentifier(TestModel.SHARDED_VALUE_1)).withValue("sharded value 1").build(); final LeafNode shardedValue2 = - ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(TestModel.SHARDED_VALUE_2)).withValue("sharded value 2").build(); + ImmutableLeafNodeBuilder.create().withNodeIdentifier(new NodeIdentifier( + TestModel.SHARDED_VALUE_2)).withValue("sharded value 2").build(); final ContainerNode lowerShardContainer = ImmutableContainerNodeBuilder.create() @@ -365,7 +384,7 @@ public class ShardedDOMDataTreeProducerMultiShardTest { return testContainer; } - private void writeCrossShardContainer(final DOMDataTreeShardWriteTransaction transaction) throws Exception{ + private void writeCrossShardContainer(final DOMDataTreeShardWriteTransaction transaction) throws Exception { final DOMDataTreeWriteCursor cursor = transaction.createCursor(ROOT_ID); cursor.write(TestModel.TEST_PATH.getLastPathArgument(), crossShardContainer);