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%2FShardedDOMDataTreeTest.java;h=6cc21b8d0575cc74c256393402e887a9bdbf7411;hb=2edcadb19348d7ad4f9d6b00c96ddce2d0320214;hp=b7383043b58e96292e23596431cfdf919a1a3c16;hpb=28da9390c5cea9a731776b470b6c467a023d3935;p=mdsal.git diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTreeTest.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTreeTest.java index b7383043b5..6cc21b8d05 100644 --- a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTreeTest.java +++ b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/ShardedDOMDataTreeTest.java @@ -92,7 +92,7 @@ public class ShardedDOMDataTreeTest { 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(); @@ -109,6 +109,38 @@ public class ShardedDOMDataTreeTest { dataTreeService.createProducer(Collections.singletonList(TEST_ID)); } + @Test + public void testShardRegistrationClose() throws Exception { + rootShardReg.close(); + + final InMemoryDOMDataTreeShard newRootShard = InMemoryDOMDataTreeShard.create(ROOT_ID, executor, 1); + newRootShard.onGlobalContextUpdated(schemaContext); + final DOMDataTreeProducer shardRegProducer = dataTreeService.createProducer(Collections.singletonList(ROOT_ID)); + + final ListenerRegistration newRootShardReg = + dataTreeService.registerDataTreeShard(ROOT_ID, rootShard, shardRegProducer); + shardRegProducer.close(); + + final InMemoryDOMDataTreeShard innerShard = InMemoryDOMDataTreeShard.create(INNER_CONTAINER_ID, executor, 1); + innerShard.onGlobalContextUpdated(schemaContext); + final DOMDataTreeProducer shardRegProducer2 = dataTreeService.createProducer(Collections.singletonList(INNER_CONTAINER_ID)); + ListenerRegistration innerShardReg = dataTreeService.registerDataTreeShard(INNER_CONTAINER_ID, innerShard, shardRegProducer2); + + innerShardReg.close(); + // try to register the shard again + innerShardReg = dataTreeService.registerDataTreeShard(INNER_CONTAINER_ID, innerShard, shardRegProducer2); + final DOMDataTreeCursorAwareTransaction tx = shardRegProducer2.createTransaction(false); + final DOMDataTreeWriteCursor cursor = tx.createCursor(INNER_CONTAINER_ID); + assertNotNull(cursor); + + cursor.close(); + tx.cancel(); + shardRegProducer2.close(); + + innerShardReg.close(); + newRootShardReg.close(); + } + @Test public void testSingleShardWrite() throws Exception { final DOMDataTreeListener mockedDataTreeListener = Mockito.mock(DOMDataTreeListener.class); @@ -141,11 +173,11 @@ public class ShardedDOMDataTreeTest { cursor.close(); tx.submit().checkedGet(); - verify(mockedDataTreeListener, timeout(1000).times(2)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture()); + verify(mockedDataTreeListener, timeout(1000).times(3)).onDataTreeChanged(captorForChanges.capture(), captorForSubtrees.capture()); final List> capturedValue = captorForChanges.getAllValues(); - assertTrue(capturedValue.size() == 2); + assertTrue(capturedValue.size() == 3); - final ContainerNode capturedChange = (ContainerNode) capturedValue.get(0).iterator().next().getRootNode().getDataAfter().get(); + final ContainerNode capturedChange = (ContainerNode) capturedValue.get(1).iterator().next().getRootNode().getDataAfter().get(); final ContainerNode innerContainerVerify = (ContainerNode) crossShardContainer.getChild(TestModel.INNER_CONTAINER_PATH.getLastPathArgument()).get(); assertEquals(innerContainerVerify, capturedChange);