From 5ea488b66faaf9851aef6f9d974aca5c8a27842e Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Fri, 10 Mar 2017 16:59:15 +0100 Subject: [PATCH] Bug 8055: various performance issues * Use Collections.singletonList() instead of Arrays.asList() with a single argument. * Avoid calling toString() on String objects. * Avoid constructing new Strings with String constants. * Avoid String concatenation in StringBuffer.append() calls. Change-Id: I9e1c338b89bc7e914092a388ccb6b3022c9992ff Signed-off-by: Stephen Kitt --- .../transact/PhysicalPortUpdateCommand.java | 2 +- .../transact/TransactInvokerImpl.java | 6 +++--- .../transactions/md/OvsdbQosUpdateCommand.java | 4 ++-- .../ovsdb/southbound/OvsdbConnectionManagerTest.java | 4 ++-- .../BridgeConfigReconciliationTaskTest.java | 6 +++--- .../ovsdb/southbound/it/SouthboundIT.java | 12 ++++++------ .../ovsdb/utils/mdsal/utils/MdsalUtilsAsyncTest.java | 11 ++++++----- 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/PhysicalPortUpdateCommand.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/PhysicalPortUpdateCommand.java index f029d18b4..1e4637d69 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/PhysicalPortUpdateCommand.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/PhysicalPortUpdateCommand.java @@ -145,7 +145,7 @@ public class PhysicalPortUpdateCommand extends AbstractTransactCommand { private void setDescription(PhysicalPort physicalPort, HwvtepPhysicalPortAugmentation inputPhysicalPort) { if (inputPhysicalPort.getHwvtepNodeDescription() != null) { - physicalPort.setDescription(inputPhysicalPort.getHwvtepNodeDescription().toString()); + physicalPort.setDescription(inputPhysicalPort.getHwvtepNodeDescription()); } } diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/TransactInvokerImpl.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/TransactInvokerImpl.java index ec2fb75f2..30d74d129 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/TransactInvokerImpl.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/TransactInvokerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright © 2015, 2017 Ericsson India Global Services Pvt Ltd. 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, @@ -75,7 +75,7 @@ public class TransactInvokerImpl implements TransactInvoker { sb.append("insert ["); if (row != null) { for (Object key : row.keySet()) { - sb.append(key + " : "+row.get(key)+" , "); + sb.append(key).append(" : ").append(row.get(key)).append(" , "); } } sb.append("] "); @@ -89,7 +89,7 @@ public class TransactInvokerImpl implements TransactInvoker { Map row = update.getRow(); if (row != null) { for (Object key : row.keySet()) { - sb.append(key + " : "+row.get(key)+" , "); + sb.append(key).append(" : ").append(row.get(key)).append(" , "); } } sb.append("]"); diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQosUpdateCommand.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQosUpdateCommand.java index 545464efc..916874f59 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQosUpdateCommand.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQosUpdateCommand.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Intel Communications Systems, Inc. and others. All rights reserved. + * Copyright © 2016, 2017 Intel Communications 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, @@ -104,7 +104,7 @@ public class OvsdbQosUpdateCommand extends AbstractTransactionCommand { qosEntryBuilder.setQosId(new Uri(getQosId(qos))); qosEntryBuilder.setQosUuid(new Uuid(entry.getKey().toString())); qosEntryBuilder.setQosType( - SouthboundMapper.createQosType(qos.getTypeColumn().getData().toString())); + SouthboundMapper.createQosType(qos.getTypeColumn().getData())); Qos oldQos = oldQosRows.get(entry.getKey()); setOtherConfig(transaction, qosEntryBuilder, oldQos, qos, nodeIId); setExternalIds(transaction, qosEntryBuilder, oldQos, qos, nodeIId); diff --git a/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManagerTest.java b/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManagerTest.java index fba509029..2f3519229 100644 --- a/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManagerTest.java +++ b/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManagerTest.java @@ -22,7 +22,7 @@ import static org.powermock.api.support.membermodification.MemberModifier.suppre import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; import java.net.InetAddress; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -92,7 +92,7 @@ public class OvsdbConnectionManagerTest { when(externalClient.getConnectionInfo().getRemotePort()).thenReturn(8080); when(externalClient.getConnectionInfo().getLocalAddress()).thenReturn(mock(InetAddress.class)); when(externalClient.getConnectionInfo().getLocalPort()).thenReturn(8080); - List databases = Arrays.asList("Open_vSwitch"); + List databases = Collections.singletonList("Open_vSwitch"); when(externalClient.getDatabases().get(1000, TimeUnit.MILLISECONDS)).thenReturn(databases); PowerMockito.mockStatic(SouthboundUtil.class); diff --git a/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/reconciliation/configuration/BridgeConfigReconciliationTaskTest.java b/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/reconciliation/configuration/BridgeConfigReconciliationTaskTest.java index 210dd203f..06725c0ca 100644 --- a/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/reconciliation/configuration/BridgeConfigReconciliationTaskTest.java +++ b/southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/reconciliation/configuration/BridgeConfigReconciliationTaskTest.java @@ -16,7 +16,7 @@ import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -128,12 +128,12 @@ public class BridgeConfigReconciliationTaskTest { Mockito.when(protocolEntry.getProtocol()).thenAnswer( (Answer>) invocation -> OvsdbBridgeProtocolOpenflow10.class); when(protocolEntry.getKey()).thenReturn(protocolEntryKey); - when(ovsdbBridgeAugmentation.getProtocolEntry()).thenReturn(Arrays.asList(protocolEntry)); + when(ovsdbBridgeAugmentation.getProtocolEntry()).thenReturn(Collections.singletonList(protocolEntry)); ControllerEntry controllerEntry = mock(ControllerEntry.class); ControllerEntryKey controllerEntryKey = mock(ControllerEntryKey.class); when(controllerEntry.getKey()).thenReturn(controllerEntryKey); - when(ovsdbBridgeAugmentation.getControllerEntry()).thenReturn(Arrays.asList(controllerEntry)); + when(ovsdbBridgeAugmentation.getControllerEntry()).thenReturn(Collections.singletonList(controllerEntry)); when(ovsdbBridgeAugmentation.getManagedBy()).thenReturn(ovsdbNodeRef); diff --git a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java b/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java index 1bd2f4834..b9a6fa3d9 100644 --- a/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java +++ b/southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java @@ -953,11 +953,11 @@ public class SouthboundIT extends AbstractMdsalTestBase { final boolean isOldSchema = schemaVersion.compareTo(AUTOATTACH_FROM_VERSION) < 0; ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber); - String testAutoattachId = new String("testAutoattachEntry"); - String testSystemName = new String("testSystemName"); - String testSystemDescription = new String("testSystemDescription"); - String testAutoattachExternalKey = new String("testAutoattachExternalKey"); - String testAutoattachExternalValue = new String("testAutoattachExternalValue"); + String testAutoattachId = "testAutoattachEntry"; + String testSystemName = "testSystemName"; + String testSystemDescription = "testSystemDescription"; + String testAutoattachExternalKey = "testAutoattachExternalKey"; + String testAutoattachExternalValue = "testAutoattachExternalValue"; try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME)) { OvsdbBridgeAugmentation bridge = getBridge(connectionInfo); @@ -1937,7 +1937,7 @@ public class SouthboundIT extends AbstractMdsalTestBase { @Test public void testCRUDTerminationPointQos() throws InterruptedException { ConnectionInfo connectionInfo = getConnectionInfo(addressStr, portNumber); - String testQosId = new String("testQosEntry"); + String testQosId = "testQosEntry"; // CREATE try (TestBridge testBridge = new TestBridge(connectionInfo, SouthboundITConstants.BRIDGE_NAME); diff --git a/utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalUtilsAsyncTest.java b/utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalUtilsAsyncTest.java index a3d30484e..1548b2f8b 100644 --- a/utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalUtilsAsyncTest.java +++ b/utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalUtilsAsyncTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Inocybe and others. All rights reserved. + * Copyright © 2016, 2017 Inocybe 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, @@ -17,6 +17,7 @@ import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import java.util.Arrays; +import java.util.Collections; import java.util.concurrent.ExecutionException; import org.junit.Before; import org.junit.Test; @@ -98,8 +99,8 @@ public class MdsalUtilsAsyncTest extends AbstractDataBrokerTest { final SupportingNode supportingNodeBuilder1 = new SupportingNodeBuilder().setKey(new SupportingNodeKey(new NodeId("id1"), TOPOLOGY_TEST)).build(); final SupportingNode supportingNodeBuilder2 = new SupportingNodeBuilder().setKey(new SupportingNodeKey(new NodeId("id2"), TOPOLOGY_TEST)).build(); - final Node data1 = new NodeBuilder(data).setSupportingNode(Arrays.asList(supportingNodeBuilder1)).build(); - final Node data2 = new NodeBuilder(data).setSupportingNode(Arrays.asList(supportingNodeBuilder2)).build(); + final Node data1 = new NodeBuilder(data).setSupportingNode(Collections.singletonList(supportingNodeBuilder1)).build(); + final Node data2 = new NodeBuilder(data).setSupportingNode(Collections.singletonList(supportingNodeBuilder2)).build(); mdsalUtilsAsync.put(LogicalDatastoreType.CONFIGURATION, TEST_IID, data1, operationDesc); assertEquals(data1, readDS()); @@ -125,8 +126,8 @@ public class MdsalUtilsAsyncTest extends AbstractDataBrokerTest { final SupportingNode supportingNodeBuilder1 = new SupportingNodeBuilder().setKey(new SupportingNodeKey(new NodeId("id1"), TOPOLOGY_TEST)).build(); final SupportingNode supportingNodeBuilder2 = new SupportingNodeBuilder().setKey(new SupportingNodeKey(new NodeId("id2"), TOPOLOGY_TEST)).build(); - final Node data1 = new NodeBuilder(data).setSupportingNode(Arrays.asList(supportingNodeBuilder1)).build(); - final Node data2 = new NodeBuilder(data).setSupportingNode(Arrays.asList(supportingNodeBuilder2)).build(); + final Node data1 = new NodeBuilder(data).setSupportingNode(Collections.singletonList(supportingNodeBuilder1)).build(); + final Node data2 = new NodeBuilder(data).setSupportingNode(Collections.singletonList(supportingNodeBuilder2)).build(); mdsalUtilsAsync.merge(LogicalDatastoreType.CONFIGURATION, TEST_IID, data1, operationDesc, true); assertEquals(data1, readDS()); -- 2.36.6