X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fsharding%2FDistributedShardFrontendTest.java;h=aba233fe6f074ea6613f90b30433a8607e9b9e73;hp=53840049b4f9b283aabb1060069b935295208e3a;hb=da174be7e22b16d4ac80cccefdc52b209b700745;hpb=20f8f30f4bbf1e982672c1f883a6a18b0e4539de diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardFrontendTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardFrontendTest.java index 53840049b4..aba233fe6f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardFrontendTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/sharding/DistributedShardFrontendTest.java @@ -1,16 +1,17 @@ /* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.sharding; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -20,6 +21,7 @@ import static org.mockito.Mockito.verify; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import java.util.Collections; +import java.util.List; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -29,7 +31,7 @@ import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHist import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction; import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient; import org.opendaylight.controller.cluster.datastore.DistributedDataStore; -import org.opendaylight.controller.cluster.datastore.utils.ActorContext; +import org.opendaylight.controller.cluster.datastore.utils.ActorUtils; import org.opendaylight.controller.md.cluster.datastore.model.SchemaContextHelper; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; @@ -42,18 +44,19 @@ import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; -import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode; import org.opendaylight.yangtools.yang.data.api.schema.MapNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; +@Deprecated(forRemoval = true) public class DistributedShardFrontendTest { private static final DOMDataTreeIdentifier ROOT = - new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY); + new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty()); private static final ListenableFuture SUCCESS_FUTURE = Futures.immediateFuture(null); private ShardedDOMDataTree shardedDOMDataTree; @@ -64,19 +67,19 @@ public class DistributedShardFrontendTest { private DOMDataTreeWriteCursor cursor; private static final YangInstanceIdentifier OUTER_LIST_YID = TestModel.OUTER_LIST_PATH.node( - new NodeIdentifierWithPredicates(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)); + NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1)); private static final DOMDataTreeIdentifier OUTER_LIST_ID = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, OUTER_LIST_YID); @Captor - private ArgumentCaptor pathArgumentCaptor; + private ArgumentCaptor pathArgumentCaptor; @Captor private ArgumentCaptor> nodeCaptor; private DOMStoreThreePhaseCommitCohort commitCohort; @Before - public void setUp() throws Exception { + public void setUp() { MockitoAnnotations.initMocks(this); shardedDOMDataTree = new ShardedDOMDataTree(); client = mock(DataStoreClient.class); @@ -108,15 +111,14 @@ public class DistributedShardFrontendTest { @Test public void testClientTransaction() throws Exception { - final DistributedDataStore distributedDataStore = mock(DistributedDataStore.class); - final ActorContext context = mock(ActorContext.class); - doReturn(context).when(distributedDataStore).getActorContext(); + final ActorUtils context = mock(ActorUtils.class); + doReturn(context).when(distributedDataStore).getActorUtils(); doReturn(SchemaContextHelper.full()).when(context).getSchemaContext(); final DistributedShardFrontend rootShard = new DistributedShardFrontend(distributedDataStore, client, ROOT); - try (final DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(Collections.singletonList(ROOT))) { + try (DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(Collections.singletonList(ROOT))) { shardedDOMDataTree.registerDataTreeShard(ROOT, rootShard, producer); } @@ -142,42 +144,37 @@ public class DistributedShardFrontendTest { final DistributedShardFrontend outerListShard = new DistributedShardFrontend( distributedDataStore, outerListClient, OUTER_LIST_ID); - try (final DOMDataTreeProducer producer = + try (DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(Collections.singletonList(OUTER_LIST_ID))) { shardedDOMDataTree.registerDataTreeShard(OUTER_LIST_ID, outerListShard, producer); } final DOMDataTreeProducer producer = shardedDOMDataTree.createProducer(Collections.singletonList(ROOT)); final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(false); - final DOMDataTreeWriteCursor cursor = tx.createCursor(ROOT); + final DOMDataTreeWriteCursor txCursor = tx.createCursor(ROOT); - assertNotNull(cursor); - cursor.write(TestModel.TEST_PATH.getLastPathArgument(), createCrossShardContainer()); + assertNotNull(txCursor); + txCursor.write(TestModel.TEST_PATH.getLastPathArgument(), createCrossShardContainer()); //check the lower shard got the correct modification verify(outerListCursor, times(2)).write(pathArgumentCaptor.capture(), nodeCaptor.capture()); - final YangInstanceIdentifier.PathArgument expectedYid = new NodeIdentifier(TestModel.ID_QNAME); - final YangInstanceIdentifier.PathArgument actualIdYid = pathArgumentCaptor.getAllValues().get(0); - assertEquals(expectedYid, actualIdYid); - - final YangInstanceIdentifier.PathArgument expectedInnerYid = new NodeIdentifier(TestModel.INNER_LIST_QNAME); - final YangInstanceIdentifier.PathArgument actualInnerListYid = pathArgumentCaptor.getAllValues().get(1); - assertEquals(expectedInnerYid, actualInnerListYid); - - final LeafNode actualIdNode = (LeafNode) nodeCaptor.getAllValues().get(0); - assertEquals(ImmutableNodes.leafNode(TestModel.ID_QNAME, 1), actualIdNode); + final List capturedArgs = pathArgumentCaptor.getAllValues(); + assertEquals(2, capturedArgs.size()); + assertThat(capturedArgs, + hasItems(new NodeIdentifier(TestModel.ID_QNAME), new NodeIdentifier(TestModel.INNER_LIST_QNAME))); - final MapNode actualInnerListNode = (MapNode) nodeCaptor.getAllValues().get(1); - assertEquals(createInnerMapNode(1), actualInnerListNode); + final List> capturedValues = nodeCaptor.getAllValues(); + assertEquals(2, capturedValues.size()); + assertThat(capturedValues, + hasItems(ImmutableNodes.leafNode(TestModel.ID_QNAME, 1), createInnerMapNode(1))); - cursor.close(); - tx.submit().checkedGet(); + txCursor.close(); + tx.commit().get(); verify(commitCohort, times(2)).canCommit(); verify(commitCohort, times(2)).preCommit(); verify(commitCohort, times(2)).commit(); - } private static MapNode createInnerMapNode(final int id) { @@ -213,6 +210,4 @@ public class DistributedShardFrontendTest { return testContainer; } - - -} \ No newline at end of file +}