X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fstatistics%2FStatisticsGatheringUtilsTest.java;h=5e7fe6fb8cbc9f5ced805f95029085fc0acd02de;hb=21c984447de25eb251e2ed51b64f9ef486e8c3a4;hp=4b98af08211f1ff60a8094f08aa1b65594d738d9;hpb=8d0b3819bc847095e0fc971673c819a717a12305;p=openflowplugin.git diff --git a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtilsTest.java b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtilsTest.java old mode 100644 new mode 100755 index 4b98af0821..5e7fe6fb8c --- a/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtilsTest.java +++ b/openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtilsTest.java @@ -5,20 +5,19 @@ * 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.openflowplugin.impl.statistics; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import com.google.common.base.Optional; -import com.google.common.collect.Lists; -import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import java.math.BigInteger; -import java.util.Collections; +import com.google.common.util.concurrent.MoreExecutors; import java.util.List; +import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -27,14 +26,13 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatchers; import org.mockito.InOrder; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.mockito.junit.MockitoJUnitRunner; +import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.openflowplugin.api.OFConstants; import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; @@ -83,7 +81,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.No import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics; -import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.node.meter.statistics.MeterStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.FlowModFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupType; @@ -92,7 +90,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; @@ -120,7 +117,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter._case.multipart.reply.meter.meter.stats.MeterBandStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.MultipartReplyMeterConfigBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.MeterConfigBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.meter.config._case.multipart.reply.meter.config.meter.config.Bands; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.MultipartReplyPortStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.port.stats._case.multipart.reply.port.stats.PortStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.queue._case.MultipartReplyQueueBuilder; @@ -129,10 +125,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.table._case.multipart.reply.table.TableStatsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatistics; +import org.opendaylight.yangtools.util.concurrent.FluentFutures; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.util.BindingMap; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; - +import org.opendaylight.yangtools.yang.common.Uint32; +import org.opendaylight.yangtools.yang.common.Uint64; +import org.opendaylight.yangtools.yang.common.Uint8; @RunWith(MockitoJUnitRunner.class) public class StatisticsGatheringUtilsTest { @@ -159,7 +159,7 @@ public class StatisticsGatheringUtilsTest { @Mock private GetFeaturesOutput features; @Mock - private ReadOnlyTransaction readTx; + private ReadTransaction readTx; @Mock private ConnectionContext connectionAdapter; @Mock @@ -170,149 +170,153 @@ public class StatisticsGatheringUtilsTest { private MultipartWriterProvider provider; @Before - public void setUp() throws Exception { - when(deviceContext.getDeviceState()).thenReturn(deviceState); + public void setUp() { when(deviceContext.getDeviceInfo()).thenReturn(deviceInfo); when(deviceContext.getDeviceFlowRegistry()).thenReturn(deviceFlowRegistry); when(deviceContext.getDeviceGroupRegistry()).thenReturn(deviceGroupRegistry); when(deviceContext.getDeviceMeterRegistry()).thenReturn(deviceMeterRegistry); - when(deviceFlowRegistry.retrieveDescriptor(Matchers.any(FlowRegistryKey.class))).thenReturn(flowDescriptor); + when(deviceFlowRegistry.retrieveDescriptor(any(FlowRegistryKey.class))).thenReturn(flowDescriptor); + when(flowDescriptor.getFlowId()).thenReturn(new FlowId("MOCK_FLOW")); when(deviceContext.getReadTransaction()).thenReturn(readTx); when(deviceContext.getReadTransaction()).thenReturn(readTx); when(deviceContext.getPrimaryConnectionContext()).thenReturn(connectionAdapter); - when(connectionAdapter.getNodeId()).thenReturn(DUMMY_NODE_ID); + when(deviceContext.isTransactionsEnabled()).thenReturn(Boolean.TRUE); when(connectionAdapter.getFeatures()).thenReturn(features); - when(features.getDatapathId()).thenReturn(BigInteger.ONE); + when(features.getDatapathId()).thenReturn(Uint64.ONE); when(features.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); when(deviceInfo.getVersion()).thenReturn(OFConstants.OFP_VERSION_1_3); - when(deviceInfo.getDatapathId()).thenReturn(BigInteger.ONE); + when(deviceInfo.getDatapathId()).thenReturn(Uint64.ONE); when(deviceInfo.getNodeInstanceIdentifier()).thenReturn(dummyNodePath); when(deviceInfo.getNodeId()).thenReturn(DUMMY_NODE_ID); provider = MultipartWriterProviderFactory.createDefaultProvider(deviceContext); } @Test - public void testWriteFlowStatistics() throws Exception { + public void testWriteFlowStatistics() { final ArgumentCaptor dataStoreType = ArgumentCaptor.forClass(LogicalDatastoreType.class); final ArgumentCaptor flowPath = ArgumentCaptor.forClass(InstanceIdentifier.class); final ArgumentCaptor flow = ArgumentCaptor.forClass(Flow.class); - provider.lookup(MultipartType.OFPMPFLOW).get().write(prepareFlowStatisticsData().iterator().next(), false); + provider.lookup(MultipartType.OFPMPFLOW).orElseThrow().write(prepareFlowStatisticsData().iterator().next(), + false); Mockito.verify(deviceContext).writeToTransaction( dataStoreType.capture(), flowPath.capture(), flow.capture()); Assert.assertEquals(LogicalDatastoreType.OPERATIONAL, dataStoreType.getValue()); final InstanceIdentifier flowCapableNodePath = flowPath.getValue(); - Assert.assertEquals(DUMMY_NODE_ID, flowCapableNodePath.firstKeyOf(Node.class, NodeKey.class).getId()); + Assert.assertEquals(DUMMY_NODE_ID, flowCapableNodePath.firstKeyOf(Node.class).getId()); Assert.assertEquals(42, flow.getValue().getTableId().intValue()); } - private Iterable prepareFlowStatisticsData() { + private static Iterable prepareFlowStatisticsData() { final FlowAndStatisticsMapListBuilder flowAndStatsMapListBld = new FlowAndStatisticsMapListBuilder(); - flowAndStatsMapListBld.setTableId((short) 42); + flowAndStatsMapListBld.setTableId(Uint8.valueOf(42)); flowAndStatsMapListBld.setMatch(new MatchBuilder().build()); final FlowsStatisticsUpdateBuilder flowStatsUpdateBld1 = new FlowsStatisticsUpdateBuilder(); - flowStatsUpdateBld1.setFlowAndStatisticsMapList(Lists.newArrayList(flowAndStatsMapListBld.build())); + flowStatsUpdateBld1.setFlowAndStatisticsMapList(List.of(flowAndStatsMapListBld.build())); - return Lists.newArrayList(flowStatsUpdateBld1.build()); + return List.of(flowStatsUpdateBld1.build()); } - @Test public void testGatherStatistics_group() throws Exception { final MultipartType type = MultipartType.OFPMPGROUP; - final long groupIdValue = 19L; + final Uint32 groupIdValue = Uint32.valueOf(19); final GroupStatsBuilder groupStatsBld = new GroupStatsBuilder() - .setBucketStats(Lists.newArrayList(createBucketStat(21L, 42L))) - .setByteCount(BigInteger.valueOf(84L)) - .setPacketCount(BigInteger.valueOf(63L)) - .setDurationSec(11L) - .setDurationNsec(12L) - .setRefCount(13L) + .setBucketStats(List.of(createBucketStat(21L, 42L))) + .setByteCount(Uint64.valueOf(84)) + .setPacketCount(Uint64.valueOf(63)) + .setDurationSec(Uint32.valueOf(11)) + .setDurationNsec(Uint32.valueOf(12)) + .setRefCount(Uint32.valueOf(13)) .setGroupId(new GroupId(groupIdValue)); final MultipartReplyGroupBuilder mpReplyGroupBld = new MultipartReplyGroupBuilder(); - mpReplyGroupBld.setGroupStats(Lists.newArrayList(groupStatsBld.build())); + mpReplyGroupBld.setGroupStats(List.of(groupStatsBld.build())); final MultipartReplyGroupCaseBuilder mpReplyGroupCaseBld = new MultipartReplyGroupCaseBuilder(); mpReplyGroupCaseBld.setMultipartReplyGroup(mpReplyGroupBld.build()); final MultipartReply groupStatsUpdated = assembleMPReplyMessage(type, mpReplyGroupCaseBld.build()); - final List statsData = Collections.singletonList(groupStatsUpdated); + final List statsData = List.of(groupStatsUpdated); fireAndCheck(type, statsData); final InstanceIdentifier groupPath = dummyNodePath.augmentation(FlowCapableNode.class) - .child(Group.class, new GroupKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId(groupIdValue))) + .child(Group.class, new GroupKey(new org.opendaylight.yang.gen.v1.urn + .opendaylight.group.types.rev131018.GroupId(groupIdValue))) .augmentation(NodeGroupStatistics.class) .child(GroupStatistics.class); - verify(deviceContext).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), - Matchers.eq(groupPath), Matchers.any(GroupStatistics.class)); + verify(deviceContext).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), + eq(groupPath), any(GroupStatistics.class)); } @Test public void testGatherStatistics_groupDesc() throws Exception { final MultipartType type = MultipartType.OFPMPGROUPDESC; - final long groupIdValue = 27L; + final Uint32 groupIdValue = Uint32.valueOf(27); final BucketsListBuilder bucketsListBld = new BucketsListBuilder() - .setWatchPort(new PortNumber(5L)); + .setWatchPort(new PortNumber(Uint32.valueOf(5))); final GroupDescBuilder groupStatsBld = new GroupDescBuilder() - .setBucketsList(Lists.newArrayList(bucketsListBld.build())) + .setBucketsList(List.of(bucketsListBld.build())) .setGroupId(new GroupId(groupIdValue)) .setType(GroupType.OFPGTALL); final MultipartReplyGroupDescBuilder mpReplyGroupBld = new MultipartReplyGroupDescBuilder(); - mpReplyGroupBld.setGroupDesc(Lists.newArrayList(groupStatsBld.build())); + mpReplyGroupBld.setGroupDesc(List.of(groupStatsBld.build())); final MultipartReplyGroupDescCaseBuilder mpReplyGroupCaseBld = new MultipartReplyGroupDescCaseBuilder(); mpReplyGroupCaseBld.setMultipartReplyGroupDesc(mpReplyGroupBld.build()); final MultipartReply groupStatsUpdated = assembleMPReplyMessage(type, mpReplyGroupCaseBld.build()); - final List statsData = Collections.singletonList(groupStatsUpdated); + final List statsData = List.of(groupStatsUpdated); fireAndCheck(type, statsData); - final org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId storedGroupId = new org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId(groupIdValue); - final KeyedInstanceIdentifier groupPath = dummyNodePath.augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(storedGroupId)); + final org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId storedGroupId = + new org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId(groupIdValue); + final KeyedInstanceIdentifier groupPath = + dummyNodePath.augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(storedGroupId)); - verify(deviceContext, Mockito.never()).addDeleteToTxChain(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.> any()); - verify(deviceGroupRegistry).processMarks(); + verify(deviceContext, Mockito.never()).addDeleteToTxChain(eq(LogicalDatastoreType.OPERATIONAL), + ArgumentMatchers.>any()); verify(deviceGroupRegistry).store(storedGroupId); - verify(deviceContext).writeToTransaction( - Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.eq(groupPath), Matchers.any(Group.class)); + verify(deviceContext).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), + eq(groupPath), any(Group.class)); } @Test public void testGatherStatistics_meter() throws Exception { final MultipartType type = MultipartType.OFPMPMETER; - final long meterIdValue = 19L; + final Uint32 meterIdValue = Uint32.valueOf(19); final MeterBandStatsBuilder meterBandStatsBld = new MeterBandStatsBuilder() - .setByteBandCount(BigInteger.valueOf(91L)) - .setPacketBandCount(BigInteger.valueOf(92L)); + .setByteBandCount(Uint64.valueOf(91)) + .setPacketBandCount(Uint64.valueOf(92)); final MeterStatsBuilder meterStatsBld = new MeterStatsBuilder() .setMeterId(new MeterId(meterIdValue)) - .setByteInCount(BigInteger.valueOf(111L)) - .setDurationSec(112L) - .setDurationNsec(113L) - .setFlowCount(114L) - .setPacketInCount(BigInteger.valueOf(115L)) - .setMeterBandStats(Lists.newArrayList(meterBandStatsBld.build())); + .setByteInCount(Uint64.valueOf(111)) + .setDurationSec(Uint32.valueOf(112)) + .setDurationNsec(Uint32.valueOf(113)) + .setFlowCount(Uint32.valueOf(114)) + .setPacketInCount(Uint64.valueOf(115)) + .setMeterBandStats(List.of(meterBandStatsBld.build())); final MultipartReplyMeterBuilder mpReplyMeterBld = new MultipartReplyMeterBuilder(); - mpReplyMeterBld.setMeterStats(Lists.newArrayList(meterStatsBld.build())); + mpReplyMeterBld.setMeterStats(List.of(meterStatsBld.build())); final MultipartReplyMeterCaseBuilder mpReplyMeterCaseBld = new MultipartReplyMeterCaseBuilder(); mpReplyMeterCaseBld.setMultipartReplyMeter(mpReplyMeterBld.build()); final MultipartReply meterStatsUpdated = assembleMPReplyMessage(type, mpReplyMeterCaseBld.build()); - final List statsData = Collections.singletonList(meterStatsUpdated); + final List statsData = List.of(meterStatsUpdated); fireAndCheck(type, statsData); final InstanceIdentifier meterPath = dummyNodePath.augmentation(FlowCapableNode.class) - .child(Meter.class, new MeterKey(new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId(meterIdValue))) + .child(Meter.class, new MeterKey(new org.opendaylight.yang.gen.v1.urn + .opendaylight.meter.types.rev130918.MeterId(meterIdValue))) .augmentation(NodeMeterStatistics.class) .child(MeterStatistics.class); - verify(deviceContext).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), - Matchers.eq(meterPath), Matchers.any(MeterStatistics.class)); + verify(deviceContext).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), + eq(meterPath), any(MeterStatistics.class)); } @Test @@ -320,25 +324,26 @@ public class StatisticsGatheringUtilsTest { final MultipartType type = MultipartType.OFPMPPORTSTATS; final PortStatsBuilder portStatsBld = new PortStatsBuilder() - .setPortNo(11L); + .setPortNo(Uint32.valueOf(11)); final MultipartReplyPortStatsBuilder mpReplyMeterBld = new MultipartReplyPortStatsBuilder(); - mpReplyMeterBld.setPortStats(Lists.newArrayList(portStatsBld.build())); + mpReplyMeterBld.setPortStats(List.of(portStatsBld.build())); final MultipartReplyPortStatsCaseBuilder mpReplyMeterCaseBld = new MultipartReplyPortStatsCaseBuilder(); mpReplyMeterCaseBld.setMultipartReplyPortStats(mpReplyMeterBld.build()); final MultipartReply meterStatsUpdated = assembleMPReplyMessage(type, mpReplyMeterCaseBld.build()); - final List statsData = Collections.singletonList(meterStatsUpdated); + final List statsData = List.of(meterStatsUpdated); fireAndCheck(type, statsData); final InstanceIdentifier portPath = dummyNodePath - .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId("openflow:" + DUMMY_NODE_ID_VALUE + ":11"))) + .child(NodeConnector.class, + new NodeConnectorKey(new NodeConnectorId("openflow:" + DUMMY_NODE_ID_VALUE + ":11"))) .augmentation(FlowCapableNodeConnectorStatisticsData.class) .child(FlowCapableNodeConnectorStatistics.class); verify(deviceContext).writeToTransaction( - Matchers.eq(LogicalDatastoreType.OPERATIONAL), - Matchers.eq(portPath), - Matchers.any(FlowCapableNodeConnectorStatistics.class)); + eq(LogicalDatastoreType.OPERATIONAL), + eq(portPath), + any(FlowCapableNodeConnectorStatistics.class)); } @Test @@ -346,131 +351,137 @@ public class StatisticsGatheringUtilsTest { final MultipartType type = MultipartType.OFPMPTABLE; final TableStatsBuilder tableStatsBld = new TableStatsBuilder() - .setActiveCount(33L) - .setLookupCount(BigInteger.valueOf(34L)) - .setMatchedCount(BigInteger.valueOf(35L)) - .setTableId((short) 0); + .setActiveCount(Uint32.valueOf(33)) + .setLookupCount(Uint64.valueOf(34)) + .setMatchedCount(Uint64.valueOf(35)) + .setTableId(Uint8.ZERO); final MultipartReplyTableBuilder mpReplyTableBld = new MultipartReplyTableBuilder(); - mpReplyTableBld.setTableStats(Lists.newArrayList(tableStatsBld.build())); + mpReplyTableBld.setTableStats(List.of(tableStatsBld.build())); final MultipartReplyTableCaseBuilder mpReplyTableCaseBld = new MultipartReplyTableCaseBuilder(); mpReplyTableCaseBld.setMultipartReplyTable(mpReplyTableBld.build()); final MultipartReply meterStatsUpdated = assembleMPReplyMessage(type, mpReplyTableCaseBld.build()); - final List statsData = Collections.singletonList(meterStatsUpdated); + final List statsData = List.of(meterStatsUpdated); fireAndCheck(type, statsData); final InstanceIdentifier tablePath = dummyNodePath .augmentation(FlowCapableNode.class) - .child(Table.class, new TableKey((short) 0)) + .child(Table.class, new TableKey(Uint8.ZERO)) .augmentation(FlowTableStatisticsData.class) .child(FlowTableStatistics.class); verify(deviceContext).writeToTransaction( - Matchers.eq(LogicalDatastoreType.OPERATIONAL), - Matchers.eq(tablePath), - Matchers.any(FlowTableStatistics.class)); + eq(LogicalDatastoreType.OPERATIONAL), + eq(tablePath), + any(FlowTableStatistics.class)); } @Test public void testGatherStatistics_queue() throws Exception { final MultipartType type = MultipartType.OFPMPQUEUE; - final long queueIdValue = 4L; + final Uint32 queueIdValue = Uint32.valueOf(4); final QueueStatsBuilder queueStatsBld = new QueueStatsBuilder() - .setPortNo(11L) - .setTxBytes(BigInteger.valueOf(44L)) - .setTxErrors(BigInteger.valueOf(45L)) - .setTxPackets(BigInteger.valueOf(46L)) - .setDurationSec(47L) - .setDurationNsec(48L) + .setPortNo(Uint32.valueOf(11)) + .setTxBytes(Uint64.valueOf(44)) + .setTxErrors(Uint64.valueOf(45)) + .setTxPackets(Uint64.valueOf(46)) + .setDurationSec(Uint32.valueOf(47)) + .setDurationNsec(Uint32.valueOf(48)) .setQueueId(queueIdValue); final MultipartReplyQueueBuilder mpReplyQueueBld = new MultipartReplyQueueBuilder(); - mpReplyQueueBld.setQueueStats(Lists.newArrayList(queueStatsBld.build())); + mpReplyQueueBld.setQueueStats(List.of(queueStatsBld.build())); final MultipartReplyQueueCaseBuilder mpReplyQueueCaseBld = new MultipartReplyQueueCaseBuilder(); mpReplyQueueCaseBld.setMultipartReplyQueue(mpReplyQueueBld.build()); final MultipartReply meterStatsUpdated = assembleMPReplyMessage(type, mpReplyQueueCaseBld.build()); - final List statsData = Collections.singletonList(meterStatsUpdated); + final List statsData = List.of(meterStatsUpdated); fireAndCheck(type, statsData); final KeyedInstanceIdentifier queuePath = dummyNodePath - .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId("openflow:" + DUMMY_NODE_ID_VALUE + ":11"))) + .child(NodeConnector.class, + new NodeConnectorKey(new NodeConnectorId("openflow:" + DUMMY_NODE_ID_VALUE + ":11"))) .augmentation(FlowCapableNodeConnector.class) .child(Queue.class, new QueueKey(new QueueId(queueIdValue))); verify(deviceContext).writeToTransaction( - Matchers.eq(LogicalDatastoreType.OPERATIONAL), - Matchers.eq(queuePath), - Matchers.any(Queue.class)); + eq(LogicalDatastoreType.OPERATIONAL), + eq(queuePath), + any(Queue.class)); } @Test public void testGatherStatistics_flow() throws Exception { - final short tableId = 0; final MultipartType type = MultipartType.OFPMPFLOW; - final InstanceIdentifier nodePath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class); + final InstanceIdentifier nodePath = + deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class); final TableBuilder tableDataBld = new TableBuilder(); - tableDataBld.setId(tableId); + tableDataBld.setId(Uint8.ZERO); final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder(); - flowNodeBuilder.setTable(Collections.singletonList(tableDataBld.build())); + flowNodeBuilder.setTable(BindingMap.of(tableDataBld.build())); final Optional flowNodeOpt = Optional.of(flowNodeBuilder.build()); - final CheckedFuture, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt); - when(readTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture); + doReturn(FluentFutures.immediateFluentFuture(flowNodeOpt)).when(readTx) + .read(LogicalDatastoreType.OPERATIONAL, nodePath); when(flowDescriptor.getFlowId()).thenReturn(flowId); - final org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder matchBld = + final org.opendaylight.yang.gen.v1.urn + .opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder matchBld = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder() - .setMatchEntry(Collections.emptyList()); + .setMatchEntry(List.of()); final FlowStatsBuilder flowStatsBld = new FlowStatsBuilder() - .setByteCount(BigInteger.valueOf(55L)) - .setPacketCount(BigInteger.valueOf(56L)) - .setDurationSec(57L) - .setDurationNsec(58L) - .setTableId((short) 0) + .setByteCount(Uint64.valueOf(55)) + .setPacketCount(Uint64.valueOf(56)) + .setDurationSec(Uint32.valueOf(57)) + .setDurationNsec(Uint32.valueOf(58L)) + .setTableId(Uint8.ZERO) .setMatch(matchBld.build()) .setFlags(new FlowModFlags(true, false, false, false, true)); final MultipartReplyFlowBuilder mpReplyFlowBld = new MultipartReplyFlowBuilder(); - mpReplyFlowBld.setFlowStats(Lists.newArrayList(flowStatsBld.build())); + mpReplyFlowBld.setFlowStats(List.of(flowStatsBld.build())); final MultipartReplyFlowCaseBuilder mpReplyFlowCaseBld = new MultipartReplyFlowCaseBuilder(); mpReplyFlowCaseBld.setMultipartReplyFlow(mpReplyFlowBld.build()); final MultipartReply flowStatsUpdated = assembleMPReplyMessage(type, mpReplyFlowCaseBld.build()); - final List statsData = Collections.singletonList(flowStatsUpdated); + final List statsData = List.of(flowStatsUpdated); fireAndCheck(type, statsData); final FlowBuilder flowBld = new FlowBuilder() - .setTableId((short) 0) + .setTableId(Uint8.ZERO) .setMatch(new MatchBuilder().build()); final KeyedInstanceIdentifier tablePath = dummyNodePath.augmentation(FlowCapableNode.class) - .child(Table.class, new TableKey((short) 0)); + .child(Table.class, new TableKey(Uint8.ZERO)); final KeyedInstanceIdentifier flowPath = tablePath.child(Flow.class, new FlowKey(flowId)); - verify(deviceContext, Mockito.never()).addDeleteToTxChain(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.>any()); + verify(deviceContext, Mockito.never()).addDeleteToTxChain(eq(LogicalDatastoreType.OPERATIONAL), + ArgumentMatchers.>any()); final InOrder inOrder = Mockito.inOrder(deviceContext); - inOrder.verify(deviceContext).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.eq(tablePath), Matchers.any(Table.class)); + inOrder.verify(deviceContext).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), + any(), + any()); } @Test public void testGatherStatistics_meterConfig() throws Exception { final MultipartType type = MultipartType.OFPMPMETERCONFIG; - final Long meterIdValue = 55L; + final Uint32 meterIdValue = Uint32.valueOf(55); final MeterConfigBuilder meterConfigBld = new MeterConfigBuilder() .setMeterId(new MeterId(meterIdValue)) .setFlags(new MeterFlags(false, true, false, true)) - .setBands(Collections.emptyList()); + .setBands(List.of()); final MultipartReplyMeterConfigBuilder mpReplyMeterConfigBld = new MultipartReplyMeterConfigBuilder(); - mpReplyMeterConfigBld.setMeterConfig(Lists.newArrayList(meterConfigBld.build())); - final MultipartReplyMeterConfigCaseBuilder mpReplyMeterConfigCaseBld = new MultipartReplyMeterConfigCaseBuilder(); + mpReplyMeterConfigBld.setMeterConfig(List.of(meterConfigBld.build())); + final MultipartReplyMeterConfigCaseBuilder mpReplyMeterConfigCaseBld = + new MultipartReplyMeterConfigCaseBuilder(); mpReplyMeterConfigCaseBld.setMultipartReplyMeterConfig(mpReplyMeterConfigBld.build()); final MultipartReply meterConfigUpdated = assembleMPReplyMessage(type, mpReplyMeterConfigCaseBld.build()); - final List statsData = Collections.singletonList(meterConfigUpdated); + final List statsData = List.of(meterConfigUpdated); fireAndCheck(type, statsData); @@ -478,13 +489,16 @@ public class StatisticsGatheringUtilsTest { new org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId(meterIdValue); final KeyedInstanceIdentifier meterPath = dummyNodePath.augmentation(FlowCapableNode.class) .child(Meter.class, new MeterKey(meterId)); - verify(deviceContext, Mockito.never()).addDeleteToTxChain(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.>any()); + verify(deviceContext, Mockito.never()).addDeleteToTxChain(eq(LogicalDatastoreType.OPERATIONAL), + ArgumentMatchers.>any()); verify(deviceMeterRegistry).store(meterId); - verify(deviceContext).writeToTransaction(Matchers.eq(LogicalDatastoreType.OPERATIONAL), Matchers.eq(meterPath), Matchers.any(Meter.class)); + verify(deviceContext).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), + eq(meterPath), any(Meter.class)); } - private void fireAndCheck(final MultipartType type, final List statsData) throws InterruptedException, ExecutionException, TimeoutException { - when(statisticsService.getStatisticsOfType(Matchers.any(EventIdentifier.class), Matchers.eq(type))) + private void fireAndCheck(final MultipartType type, final List statsData) + throws InterruptedException, ExecutionException, TimeoutException { + when(statisticsService.getStatisticsOfType(any(EventIdentifier.class),eq(type))) .thenReturn(Futures.immediateFuture(RpcResultBuilder.success(statsData).build())); final ListenableFuture gatherStatisticsResult = StatisticsGatheringUtils.gatherStatistics( @@ -493,47 +507,45 @@ public class StatisticsGatheringUtilsTest { type, deviceContext, deviceContext, - false, ConvertorManagerFactory.createDefaultManager(), - provider); + provider, + MoreExecutors.directExecutor()); Assert.assertTrue(gatherStatisticsResult.get(1, TimeUnit.SECONDS)); verify(deviceContext).submitTransaction(); } - private static MultipartReplyMessage assembleMPReplyMessage(final MultipartType type, final MultipartReplyBody mpReplyGroupCaseBld) { + private static MultipartReplyMessage assembleMPReplyMessage(final MultipartType type, + final MultipartReplyBody mpReplyGroupCaseBld) { return new MultipartReplyMessageBuilder() .setMultipartReplyBody(mpReplyGroupCaseBld) .setType(type) .setFlags(new MultipartRequestFlags(false)) - .setXid(42L) + .setXid(Uint32.valueOf(42)) .build(); } private static BucketStats createBucketStat(final long byteCount, final long packetCount) { - return new BucketStatsBuilder().setByteCount(BigInteger.valueOf(byteCount)).setPacketCount(BigInteger.valueOf(packetCount)).build(); + return new BucketStatsBuilder() + .setByteCount(Uint64.valueOf(byteCount)).setPacketCount(Uint64.valueOf(packetCount)).build(); } @Test - public void testDeleteAllKnownFlows() throws Exception { - final short tableId = 0; - final InstanceIdentifier nodePath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class); + public void testDeleteAllKnownFlows() { + final InstanceIdentifier nodePath = + deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class); final TableBuilder tableDataBld = new TableBuilder(); - tableDataBld.setId(tableId); + tableDataBld.setId(Uint8.ZERO); final FlowCapableNodeBuilder flowNodeBuilder = new FlowCapableNodeBuilder(); - flowNodeBuilder.setTable(Collections.singletonList(tableDataBld.build())); + flowNodeBuilder.setTable(BindingMap.of(tableDataBld.build())); final Optional flowNodeOpt = Optional.of(flowNodeBuilder.build()); - final CheckedFuture, ReadFailedException> flowNodeFuture = Futures.immediateCheckedFuture(flowNodeOpt); - when(readTx.read(LogicalDatastoreType.OPERATIONAL, nodePath)).thenReturn(flowNodeFuture); - final KeyedInstanceIdentifier tablePath = deviceInfo.getNodeInstanceIdentifier() - .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)); - + doReturn(FluentFutures.immediateFluentFuture(flowNodeOpt)).when(readTx) + .read(LogicalDatastoreType.OPERATIONAL, nodePath); StatisticsGatheringUtils.deleteAllKnownFlows(deviceContext, deviceInfo.getNodeInstanceIdentifier() - .augmentation(FlowCapableNode.class), false); + .augmentation(FlowCapableNode.class), deviceFlowRegistry); - verify(deviceContext).writeToTransaction( - LogicalDatastoreType.OPERATIONAL, - tablePath, - tableDataBld.setFlow(Collections.emptyList()).build()); + verify(deviceContext).isTransactionsEnabled(); + verify(deviceContext).getReadTransaction(); + verify(deviceContext).writeToTransaction(eq(LogicalDatastoreType.OPERATIONAL), any(), any()); } }