Bug 8055: various performance issues 56/53156/6
authorStephen Kitt <skitt@redhat.com>
Fri, 10 Mar 2017 15:59:15 +0000 (16:59 +0100)
committerStephen Kitt <skitt@redhat.com>
Thu, 23 Mar 2017 14:21:09 +0000 (15:21 +0100)
* 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 <skitt@redhat.com>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/PhysicalPortUpdateCommand.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/TransactInvokerImpl.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbQosUpdateCommand.java
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManagerTest.java
southbound/southbound-impl/src/test/java/org/opendaylight/ovsdb/southbound/reconciliation/configuration/BridgeConfigReconciliationTaskTest.java
southbound/southbound-it/src/test/java/org/opendaylight/ovsdb/southbound/it/SouthboundIT.java
utils/mdsal-utils/src/test/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalUtilsAsyncTest.java

index f029d18b4713c7eddc02eebec6e663a85d8999a6..1e4637d697296f5efa94307b6819d77442ab91ee 100644 (file)
@@ -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());
         }
     }
 
index ec2fb75f22323aef3059540663105e00250b512a..30d74d129bb68b94e46ec0e1b22de68ce8d3cd3f 100644 (file)
@@ -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("]");
index 545464efcd45a21bce3b5edd9636d84e568b75f4..916874f59af6f0a2e7e9130051d67e132a03c217 100644 (file)
@@ -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);
index fba5090293612b4d35dd363d2885f218865699a9..2f3519229b7176b75046b5475e17a86351b4a5f8 100644 (file)
@@ -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<String> databases = Arrays.asList("Open_vSwitch");
+        List<String> databases = Collections.singletonList("Open_vSwitch");
         when(externalClient.getDatabases().get(1000, TimeUnit.MILLISECONDS)).thenReturn(databases);
 
         PowerMockito.mockStatic(SouthboundUtil.class);
index 210dd203f0388c918f1e85914570607e79aed6cb..06725c0ca280045e33a9f2d56dff5eb5d815b8c4 100644 (file)
@@ -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<Class<? extends OvsdbBridgeProtocolBase>>) 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);
 
index 1bd2f48344d50d8aa6513b05af7b5270333fb3a3..b9a6fa3d93411ac934c515adce93f24ae5f40560 100644 (file)
@@ -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);
index a3d30484e6b95ef3374ec54368835bb7506561d0..1548b2f8b237ac00a06dd88297b6aa7ca70f8615 100644 (file)
@@ -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());