BUG-8607: Fix issues in checkstyle enforcement for module bulk-o-matic 30/57730/8
authorDavid Suarez <david.suarez.fuentes@ericsson.com>
Tue, 23 May 2017 22:27:36 +0000 (00:27 +0200)
committerDavid Suarez <david.suarez.fuentes@ericsson.com>
Mon, 26 Jun 2017 14:40:19 +0000 (16:40 +0200)
- Copyright section
- Change variables and methods names
- Remove redundant modifiers
- Order imports
- Line lengths
- Declare some static constants properly
- Enforcement in pom.xml

Change-Id: I288ef46a01e5795081d28466ab7a4b9d896a4aa5
Signed-off-by: David Suarez <david.suarez.fuentes@ericsson.com>
18 files changed:
applications/bulk-o-matic/pom.xml
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/BulkOMaticUtils.java
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowCounter.java
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowCounterMBean.java
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowReader.java
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowWriterConcurrent.java
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowWriterDirectOFRpc.java
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowWriterSequential.java
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowWriterTxChain.java
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/SalBulkFlowServiceImpl.java
applications/bulk-o-matic/src/main/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/TableWriter.java
applications/bulk-o-matic/src/test/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowReaderTest.java
applications/bulk-o-matic/src/test/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowWriterConcurrentTest.java
applications/bulk-o-matic/src/test/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowWriterDirectOFRpcTest.java
applications/bulk-o-matic/src/test/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowWriterSequentialTest.java
applications/bulk-o-matic/src/test/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/FlowWriterTxChainTest.java
applications/bulk-o-matic/src/test/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/SalBulkFlowServiceImplTest.java
applications/bulk-o-matic/src/test/java/org/opendaylight/openflowplugin/applications/bulk/o/matic/TableWriterTest.java

index 6f4feaf5f6b7ee103500dfa84130d6d6893b5077..88891f30e74cc4e6b8dae1af7603d90bfa7ef9d8 100644 (file)
@@ -1,61 +1,68 @@
 <?xml version="1.0"?>
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
-         xmlns="http://maven.apache.org/POM/4.0.0"
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-    <modelVersion>4.0.0</modelVersion>
-    <parent>
-        <groupId>org.opendaylight.openflowplugin</groupId>
-        <artifactId>applications</artifactId>
-        <version>0.5.0-SNAPSHOT</version>
-    </parent>
-    <groupId>org.opendaylight.openflowplugin.applications</groupId>
-    <artifactId>bulk-o-matic</artifactId>
-    <packaging>bundle</packaging>
-    <dependencies>
-        <dependency>
-            <groupId>org.opendaylight.openflowplugin</groupId>
-            <artifactId>openflowplugin-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-binding-api</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-binding-config</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller</groupId>
-            <artifactId>sal-binding-broker-impl</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.controller.model</groupId>
-            <artifactId>model-inventory</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.opendaylight.openflowplugin.model</groupId>
-            <artifactId>model-flow-base</artifactId>
-        </dependency>
+<project
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+  xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.openflowplugin</groupId>
+    <artifactId>applications</artifactId>
+    <version>0.5.0-SNAPSHOT</version>
+  </parent>
+  <groupId>org.opendaylight.openflowplugin.applications</groupId>
+  <artifactId>bulk-o-matic</artifactId>
+  <packaging>bundle</packaging>
+  <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.openflowplugin</groupId>
+      <artifactId>openflowplugin-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-binding-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-binding-config</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal-binding-broker-impl</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller.model</groupId>
+      <artifactId>model-inventory</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.openflowplugin.model</groupId>
+      <artifactId>model-flow-base</artifactId>
+    </dependency>
 
         <!-- Test dependencies -->
-        <dependency>
-            <groupId>org.mockito</groupId>
-            <artifactId>mockito-core</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
 
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.opendaylight.yangtools</groupId>
-                <artifactId>yang-maven-plugin</artifactId>
-            </plugin>
-        </plugins>
-    </build>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.opendaylight.yangtools</groupId>
+        <artifactId>yang-maven-plugin</artifactId>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <configuration>
+          <propertyExpansion>checkstyle.violationSeverity=warning</propertyExpansion>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
 </project>
index 8a750d56e397007ad085a199084f7d2f28d29302..2b0352181c11585b902cf46e9b43563193db0592 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson 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,
@@ -40,16 +40,15 @@ public final class BulkOMaticUtils {
     private BulkOMaticUtils() {
     }
 
-    public static String ipIntToStr (int k) {
-        return new StringBuilder().append(k >> 24 & 0xFF).append(".")
-                .append(k >> 16 & 0xFF).append(".")
-                .append(k >> 8 & 0xFF).append(".")
-                .append(k & 0xFF).append("/32").toString();
+    public static String ipIntToStr(int number) {
+        return new StringBuilder().append(number >> 24 & 0xFF).append(".")
+                .append(number >> 16 & 0xFF).append(".")
+                .append(number >> 8 & 0xFF).append(".")
+                .append(number & 0xFF).append("/32").toString();
     }
 
-    public static Match getMatch(final Integer sourceIp){
-        Ipv4Match ipv4Match = new Ipv4MatchBuilder().setIpv4Source(
-                new Ipv4Prefix(ipIntToStr(sourceIp))).build();
+    public static Match getMatch(final Integer sourceIp) {
+        Ipv4Match ipv4Match = new Ipv4MatchBuilder().setIpv4Source(new Ipv4Prefix(ipIntToStr(sourceIp))).build();
         MatchBuilder matchBuilder = new MatchBuilder();
         matchBuilder.setLayer3Match(ipv4Match);
         EthernetTypeBuilder ethTypeBuilder = new EthernetTypeBuilder();
@@ -60,7 +59,7 @@ public final class BulkOMaticUtils {
         return matchBuilder.build();
     }
 
-    public static Flow buildFlow(Short tableId, String flowId, Match match){
+    public static Flow buildFlow(Short tableId, String flowId, Match match) {
         FlowBuilder flowBuilder = new FlowBuilder();
         flowBuilder.setKey(new FlowKey(new FlowId(flowId)));
         flowBuilder.setTableId(tableId);
@@ -69,26 +68,19 @@ public final class BulkOMaticUtils {
     }
 
     public static InstanceIdentifier<Flow> getFlowInstanceIdentifier(Short tableId, String flowId, String dpId) {
-        return InstanceIdentifier.create(Nodes.class).child(Node.class,
-                new NodeKey(new NodeId(dpId)))
-                .augmentation(FlowCapableNode.class)
-                .child(Table.class, new TableKey(tableId))
+        return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(dpId)))
+                .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId))
                 .child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow.class,
                         new FlowKey(new FlowId(flowId)));
     }
 
-    public static InstanceIdentifier<Node> getFlowCapableNodeId(String dpId){
-        return InstanceIdentifier.builder(Nodes.class)
-                .child(Node.class, new NodeKey(new NodeId(dpId)))
-                .build();
+    public static InstanceIdentifier<Node> getFlowCapableNodeId(String dpId) {
+        return InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId(dpId))).build();
     }
 
     public static InstanceIdentifier<Table> getTableId(Short tableId, String dpId) {
-        return InstanceIdentifier.builder(Nodes.class)
-                .child(Node.class, new NodeKey(new NodeId(dpId)))
-                .augmentation(FlowCapableNode.class)
-                .child(Table.class, new TableKey(tableId))
-                .build();
+        return InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId(dpId)))
+                .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).build();
     }
 
     public static InstanceIdentifier<Flow> getFlowId(final InstanceIdentifier<Table> tablePath, final String flowId) {
index 32716eaaada2ede3559c3c51450055852f8ac796..e1188cb7f4a096551ce0a8217010fbac5ad291c0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson 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,
@@ -12,10 +12,7 @@ public class FlowCounter implements FlowCounterMBean {
     private FlowCounterMBean writer;
 
     public enum OperationStatus {
-        INIT (0),
-        SUCCESS (2),
-        FAILURE (-1),
-        IN_PROGRESS (1);
+        INIT(0), SUCCESS(2), FAILURE(-1), IN_PROGRESS(1);
 
         private final int status;
 
@@ -38,7 +35,7 @@ public class FlowCounter implements FlowCounterMBean {
 
     @Override
     public long getFlowCount() {
-        if(reader != null) {
+        if (reader != null) {
             return reader.getFlowCount();
         }
         return BulkOMaticUtils.DEFAULT_FLOW_COUNT;
@@ -46,7 +43,7 @@ public class FlowCounter implements FlowCounterMBean {
 
     @Override
     public int getReadOpStatus() {
-        if(reader != null) {
+        if (reader != null) {
             return reader.getReadOpStatus();
         }
         return OperationStatus.INIT.status();
@@ -54,7 +51,7 @@ public class FlowCounter implements FlowCounterMBean {
 
     @Override
     public int getWriteOpStatus() {
-        if(writer != null) {
+        if (writer != null) {
             return writer.getWriteOpStatus();
         }
         return OperationStatus.INIT.status();
@@ -62,7 +59,7 @@ public class FlowCounter implements FlowCounterMBean {
 
     @Override
     public long getTaskCompletionTime() {
-        if(writer != null) {
+        if (writer != null) {
             return writer.getTaskCompletionTime();
         }
         return BulkOMaticUtils.DEFAULT_COMPLETION_TIME;
index b1ddb4a6fceb46bcd6109f6bf4643e2421b4d935..0cfcbd7326c966cae2969fe96c876947c7ca5e1a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson 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,
@@ -9,27 +9,27 @@ package org.opendaylight.openflowplugin.applications.bulk.o.matic;
 
 public interface FlowCounterMBean {
 
-    default public long getFlowCount() {
+    default long getFlowCount() {
         return BulkOMaticUtils.DEFAULT_FLOW_COUNT;
     }
 
-    default public int getReadOpStatus() {
+    default int getReadOpStatus() {
         return BulkOMaticUtils.DEFUALT_STATUS;
     }
 
-    default public int getWriteOpStatus() {
+    default int getWriteOpStatus() {
         return BulkOMaticUtils.DEFUALT_STATUS;
     }
 
-    default public long getTaskCompletionTime() {
+    default long getTaskCompletionTime() {
         return BulkOMaticUtils.DEFAULT_COMPLETION_TIME;
     }
 
-    default public String getUnits() {
+    default String getUnits() {
         return BulkOMaticUtils.DEFAULT_UNITS;
     }
 
-    default public long getTableCount() {
+    default long getTableCount() {
         return BulkOMaticUtils.DEFAULT_TABLE_COUNT;
     }
 }
index 70c3bbbeb58b877832daa0162ebcf5d9be4e344d..9fa1aa5e4953f50eecd465b5f51429564166a748 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson 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,
@@ -37,16 +37,11 @@ public class FlowReader implements Runnable, FlowCounterMBean {
     private final short startTableId;
     private final short endTableId;
     private final boolean isConfigDs;
-    private AtomicLong flowCount = new AtomicLong();
-    private AtomicInteger readOpStatus = new AtomicInteger(FlowCounter.OperationStatus.INIT.status());
+    private final AtomicLong flowCount = new AtomicLong();
+    private final AtomicInteger readOpStatus = new AtomicInteger(FlowCounter.OperationStatus.INIT.status());
 
-    private FlowReader(final DataBroker dataBroker,
-                      final Integer dpnCount,
-                      final int flowsPerDpn,
-                      final boolean verbose,
-                      final boolean isConfigDs,
-                      final short startTableId,
-                      final short endTableId) {
+    private FlowReader(final DataBroker dataBroker, final Integer dpnCount, final int flowsPerDpn,
+            final boolean verbose, final boolean isConfigDs, final short startTableId, final short endTableId) {
         this.dataBroker = dataBroker;
         this.dpnCount = dpnCount;
         this.verbose = verbose;
@@ -57,14 +52,13 @@ public class FlowReader implements Runnable, FlowCounterMBean {
     }
 
     public static FlowReader getNewInstance(final DataBroker dataBroker,
-                                      final Integer dpnCount,
-                                      final int flowsPerDpn,
-                                      final boolean verbose,
-                                      final boolean isConfigDs,
-                                      final short startTableId,
-                                      final short endTableId) {
-        return new FlowReader(dataBroker, dpnCount, flowsPerDpn, verbose,
-                isConfigDs, startTableId, endTableId);
+            final Integer dpnCount, final int flowsPerDpn,
+            final boolean verbose, final boolean isConfigDs,
+            final short startTableId, final short endTableId) {
+        return new FlowReader(dataBroker, dpnCount,
+                flowsPerDpn, verbose,
+                isConfigDs, startTableId,
+                endTableId);
     }
 
     @Override
@@ -77,8 +71,8 @@ public class FlowReader implements Runnable, FlowCounterMBean {
         for (int i = 1; i <= dpnCount; i++) {
             String dpId = BulkOMaticUtils.DEVICE_TYPE_PREFIX + i;
             for (int j = 0; j < flowsPerDPN; j++) {
-                short tableRollover = (short)(endTableId - startTableId + 1);
-                short tableId = (short) (((j) % tableRollover) + startTableId);
+                short tableRollover = (short) (endTableId - startTableId + 1);
+                short tableId = (short) (j % tableRollover + startTableId);
 
                 Integer sourceIp = j + 1;
 
@@ -88,8 +82,9 @@ public class FlowReader implements Runnable, FlowCounterMBean {
                 ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
                 try {
                     Optional<Flow> flowOptional;
-                    if(isConfigDs) {
-                        flowOptional = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, flowIid).checkedGet();
+                    if (isConfigDs) {
+                        flowOptional = readOnlyTransaction.read(LogicalDatastoreType.CONFIGURATION, flowIid)
+                                .checkedGet();
                     } else {
                         flowOptional = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, flowIid).checkedGet();
                     }
@@ -110,18 +105,16 @@ public class FlowReader implements Runnable, FlowCounterMBean {
                 }
             }
         }
-        if(readOpStatus.get() != FlowCounter.OperationStatus.FAILURE.status()) {
+        if (readOpStatus.get() != FlowCounter.OperationStatus.FAILURE.status()) {
             readOpStatus.set(FlowCounter.OperationStatus.SUCCESS.status());
         }
         LOG.info("Total Flows read: {}", flowCount);
     }
 
-    private InstanceIdentifier<Flow> getFlowInstanceIdentifier(String dpId, Short tableId, String flowId){
+    private InstanceIdentifier<Flow> getFlowInstanceIdentifier(String dpId, Short tableId, String flowId) {
         return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(dpId)))
-                .augmentation(FlowCapableNode.class)
-                .child(Table.class, new TableKey(tableId))
-                .child(Flow.class,
-                        new FlowKey(new FlowId(flowId)));
+                .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId))
+                .child(Flow.class, new FlowKey(new FlowId(flowId)));
     }
 
     @Override
@@ -133,4 +126,4 @@ public class FlowReader implements Runnable, FlowCounterMBean {
     public int getReadOpStatus() {
         return readOpStatus.get();
     }
-}
\ No newline at end of file
+}
index 65c014db380be0dd9ed17ddcde271a7a512186ae..f644849aee25c13d3aba4e8aed64ab5446717a4e 100644 (file)
@@ -23,13 +23,14 @@ import org.slf4j.LoggerFactory;
 
 public class FlowWriterConcurrent implements FlowCounterMBean {
     private static final Logger LOG = LoggerFactory.getLogger(FlowWriterConcurrent.class);
-    public static final String USING_CONCURRENT_IMPLEMENTATION_OF_FLOW_WRITER = "Using Concurrent implementation of Flow Writer.";
+    public static final String USING_CONCURRENT_IMPLEMENTATION_OF_FLOW_WRITER =
+            "Using Concurrent implementation of Flow Writer.";
     private final DataBroker dataBroker;
     private final ExecutorService flowPusher;
     private long startTime;
-    private AtomicInteger writeOpStatus = new AtomicInteger(FlowCounter.OperationStatus.INIT.status());
-    private AtomicInteger countDpnWriteCompletion = new AtomicInteger();
-    private AtomicLong taskCompletionTime = new AtomicLong();
+    private final AtomicInteger writeOpStatus = new AtomicInteger(FlowCounter.OperationStatus.INIT.status());
+    private final AtomicInteger countDpnWriteCompletion = new AtomicInteger();
+    private final AtomicLong taskCompletionTime = new AtomicLong();
 
     public FlowWriterConcurrent(final DataBroker dataBroker, ExecutorService flowPusher) {
         this.dataBroker = dataBroker;
@@ -37,26 +38,25 @@ public class FlowWriterConcurrent implements FlowCounterMBean {
         LOG.info(USING_CONCURRENT_IMPLEMENTATION_OF_FLOW_WRITER);
     }
 
-    public void addFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize,
-                         int sleepMillis, int sleepAfter, short startTableId, short endTableId,
-                         boolean isCreateParents) {
+    public void addFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize, int sleepMillis, int sleepAfter,
+            short startTableId, short endTableId, boolean isCreateParents) {
         LOG.info(USING_CONCURRENT_IMPLEMENTATION_OF_FLOW_WRITER);
         countDpnWriteCompletion.set(dpnCount);
         startTime = System.nanoTime();
         for (int i = 1; i <= dpnCount; i++) {
-            FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i),
-                    flowsPerDPN, true, batchSize, sleepMillis, sleepAfter, startTableId, endTableId, isCreateParents);
+            FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i), flowsPerDPN, true, batchSize, sleepMillis,
+                    sleepAfter, startTableId, endTableId, isCreateParents);
             flowPusher.execute(task);
         }
     }
 
-    public void deleteFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize,
-                            short startTableId, short endTableId) {
+    public void deleteFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize, short startTableId,
+            short endTableId) {
         LOG.info(USING_CONCURRENT_IMPLEMENTATION_OF_FLOW_WRITER);
         countDpnWriteCompletion.set(dpnCount);
         for (int i = 1; i <= dpnCount; i++) {
-            FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i), flowsPerDPN, false, batchSize,
-                    0, 1, startTableId, endTableId, false);
+            FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i), flowsPerDPN, false, batchSize, 0, 1,
+                    startTableId, endTableId, false);
             flowPusher.execute(task);
         }
     }
@@ -80,18 +80,14 @@ public class FlowWriterConcurrent implements FlowCounterMBean {
         private final int sleepMillis;
         private final short startTableId;
         private final short endTableId;
-        private AtomicInteger remainingTxReturn = new AtomicInteger(0);
+        private final AtomicInteger remainingTxReturn = new AtomicInteger(0);
         private final boolean isCreateParents;
 
-        public FlowHandlerTask(final String dpId,
-                               final int flowsPerDpn,
-                               final boolean add,
-                               final int batchSize,
-                               final int sleepMillis,
-                               final int sleepAfter,
-                               final short startTableId,
-                               final short endTableId,
-                               final boolean isCreateParents){
+        FlowHandlerTask(final String dpId, final int flowsPerDpn,
+                final boolean add, final int batchSize,
+                final int sleepMillis, final int sleepAfter,
+                final short startTableId, final short endTableId,
+                final boolean isCreateParents) {
             this.dpId = BulkOMaticUtils.DEVICE_TYPE_PREFIX + dpId;
             this.add = add;
             this.flowsPerDpn = flowsPerDpn;
@@ -101,43 +97,46 @@ public class FlowWriterConcurrent implements FlowCounterMBean {
             this.startTableId = startTableId;
             this.endTableId = endTableId;
             this.isCreateParents = isCreateParents;
-            remainingTxReturn.set(flowsPerDpn/batchSize);
+            remainingTxReturn.set(flowsPerDpn / batchSize);
         }
 
         @Override
         public void run() {
-            LOG.info("Starting flow writer task for dpid: {}. Number of transactions: {}", dpId, flowsPerDpn/batchSize);
+            LOG.info("Starting flow writer task for dpid: {}. Number of transactions: {}", dpId,
+                    flowsPerDpn / batchSize);
             writeOpStatus.set(FlowCounter.OperationStatus.IN_PROGRESS.status());
             short tableId = startTableId;
-            int numSubmits = flowsPerDpn/batchSize;
+            int numSubmits = flowsPerDpn / batchSize;
             int sourceIp = 1;
             int newBatchSize = batchSize;
 
             for (int i = 1; i <= numSubmits; i++) {
                 WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
-                short k = tableId;
+                short calculatedTableId = tableId;
                 for (; sourceIp <= newBatchSize; sourceIp++) {
-                    String flowId = "Flow-" + dpId + "." + k + "." + sourceIp;
+                    String flowId = "Flow-" + dpId + "." + calculatedTableId + "." + sourceIp;
                     Flow flow = null;
                     if (add) {
                         Match match = BulkOMaticUtils.getMatch(sourceIp);
-                        flow = BulkOMaticUtils.buildFlow(k, flowId, match);
+                        flow = BulkOMaticUtils.buildFlow(calculatedTableId, flowId, match);
                     }
 
                     addFlowToTx(writeTransaction, flowId,
-                            BulkOMaticUtils.getFlowInstanceIdentifier(k, flowId, dpId), flow, sourceIp, k);
+                            BulkOMaticUtils.getFlowInstanceIdentifier(calculatedTableId, flowId, dpId), flow, sourceIp,
+                            calculatedTableId);
 
                     if (sourceIp < newBatchSize) {
-                        short a = 1;
-                        short b = (short)(endTableId - startTableId + 1);
-                        k = (short) (((k + a) % b) + startTableId);
+                        short numberA = 1;
+                        short numberB = (short) (endTableId - startTableId + 1);
+                        calculatedTableId = (short) ((calculatedTableId + numberA) % numberB + startTableId);
                     }
                 }
-                Futures.addCallback(writeTransaction.submit(), new DsCallBack(dpId, tableId, k, sourceIp));
+                Futures.addCallback(writeTransaction.submit(),
+                        new DsCallBack(dpId, tableId, calculatedTableId, sourceIp));
                 // Wrap around
-                tableId = (short)(((k + 1)%((short)(endTableId - startTableId + 1))) + startTableId);
+                tableId = (short) ((calculatedTableId + 1) % (short) (endTableId - startTableId + 1) + startTableId);
                 newBatchSize += batchSize;
-                if (((i%sleepAfter) == 0) && (sleepMillis > 0)) {
+                if (i % sleepAfter == 0 && sleepMillis > 0) {
                     try {
                         Thread.sleep(sleepMillis);
                     } catch (InterruptedException e) {
@@ -147,7 +146,8 @@ public class FlowWriterConcurrent implements FlowCounterMBean {
             }
         }
 
-        private void addFlowToTx(WriteTransaction writeTransaction, String flowId, InstanceIdentifier<Flow> flowIid, Flow flow, Integer sourceIp, Short tableId){
+        private void addFlowToTx(WriteTransaction writeTransaction, String flowId, InstanceIdentifier<Flow> flowIid,
+                Flow flow, Integer sourceIp, Short tableId) {
             if (add) {
                 LOG.trace("Adding flow for flowId: {}, flowIid: {}", flowId, flowIid);
                 writeTransaction.put(LogicalDatastoreType.CONFIGURATION, flowIid, flow, isCreateParents);
@@ -158,12 +158,12 @@ public class FlowWriterConcurrent implements FlowCounterMBean {
         }
 
         private class DsCallBack implements FutureCallback {
-            private String dpId;
-            private int sourceIp;
-            private short endTableId;
-            private short beginTableId;
+            private final String dpId;
+            private final int sourceIp;
+            private final short endTableId;
+            private final short beginTableId;
 
-            public DsCallBack(String dpId, Short beginTableId, Short endTableId, Integer sourceIp) {
+            DsCallBack(String dpId, Short beginTableId, Short endTableId, Integer sourceIp) {
                 this.dpId = dpId;
                 this.sourceIp = sourceIp;
                 this.endTableId = endTableId;
@@ -171,29 +171,28 @@ public class FlowWriterConcurrent implements FlowCounterMBean {
             }
 
             @Override
-            public void onSuccess(Object o) {
+            public void onSuccess(Object object) {
                 if (remainingTxReturn.decrementAndGet() <= 0) {
                     long dur = System.nanoTime() - startTime;
-                    LOG.info("Completed all flows installation for: dpid: {} in {}ns", dpId,
-                            dur);
-                    if(0 == countDpnWriteCompletion.decrementAndGet() &&
-                            writeOpStatus.get() != FlowCounter.OperationStatus.FAILURE.status()) {
+                    LOG.info("Completed all flows installation for: dpid: {} in {}ns", dpId, dur);
+                    if (0 == countDpnWriteCompletion.decrementAndGet()
+                            && writeOpStatus.get() != FlowCounter.OperationStatus.FAILURE.status()) {
                         writeOpStatus.set(FlowCounter.OperationStatus.SUCCESS.status());
                         taskCompletionTime.set(dur);
                     }
                 }
             }
 
+            @Override
             public void onFailure(Throwable error) {
                 if (remainingTxReturn.decrementAndGet() <= 0) {
                     long dur = System.nanoTime() - startTime;
-                    LOG.info("Completed all flows installation for: dpid: {} in {}ns", dpId,
-                            dur);
+                    LOG.info("Completed all flows installation for: dpid: {} in {}ns", dpId, dur);
                 }
-                LOG.error("Error: {} in Datastore write operation: dpid: {}, begin tableId: {}, " +
-                        "end tableId: {}, sourceIp: {} ", error, dpId, beginTableId, endTableId, sourceIp);
+                LOG.error("Error: {} in Datastore write operation: dpid: {}, begin tableId: {}, "
+                        "end tableId: {}, sourceIp: {} ", error, dpId, beginTableId, endTableId, sourceIp);
                 writeOpStatus.set(FlowCounter.OperationStatus.FAILURE.status());
             }
         }
     }
-}
\ No newline at end of file
+}
index 59d8409e56de777777b31604f05a7997502d3241..3a743fcfcc12681bfc5c2b06d59cb27d75b4af04 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson 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,
@@ -41,29 +41,26 @@ public class FlowWriterDirectOFRpc {
     private final ExecutorService flowPusher;
     private static final long PAUSE_BETWEEN_BATCH_MILLIS = 40;
 
-    public FlowWriterDirectOFRpc(final DataBroker dataBroker,
-                                 final SalFlowService salFlowService,
-                                 final ExecutorService flowPusher) {
+    public FlowWriterDirectOFRpc(final DataBroker dataBroker, final SalFlowService salFlowService,
+            final ExecutorService flowPusher) {
         this.dataBroker = dataBroker;
         this.flowService = salFlowService;
         this.flowPusher = flowPusher;
     }
 
-
-    public void rpcFlowAdd(String dpId, int flowsPerDpn, int batchSize){
+    public void rpcFlowAdd(String dpId, int flowsPerDpn, int batchSize) {
         if (!getAllNodes().isEmpty() && getAllNodes().contains(dpId)) {
             FlowRPCHandlerTask addFlowRpcTask = new FlowRPCHandlerTask(dpId, flowsPerDpn, batchSize);
             flowPusher.execute(addFlowRpcTask);
         }
     }
 
-    public void rpcFlowAddAll(int flowsPerDpn, int batchSize){
+    public void rpcFlowAddAll(int flowsPerDpn, int batchSize) {
         Set<String> nodeIdSet = getAllNodes();
-        if (nodeIdSet.isEmpty()){
+        if (nodeIdSet.isEmpty()) {
             LOG.warn("No nodes seen on OPERATIONAL DS. Aborting !!!!");
-        }
-        else{
-            for (String dpId : nodeIdSet){
+        } else {
+            for (String dpId : nodeIdSet) {
                 LOG.info("Starting FlowRPCTaskHandler for switch id {}", dpId);
                 FlowRPCHandlerTask addFlowRpcTask = new FlowRPCHandlerTask(dpId, flowsPerDpn, batchSize);
                 flowPusher.execute(addFlowRpcTask);
@@ -71,31 +68,29 @@ public class FlowWriterDirectOFRpc {
         }
     }
 
-    private Set<String> getAllNodes(){
+    private Set<String> getAllNodes() {
 
         Set<String> nodeIds = new HashSet<>();
         InstanceIdentifier<Nodes> nodes = InstanceIdentifier.create(Nodes.class);
-        ReadOnlyTransaction rTx = dataBroker.newReadOnlyTransaction();
+        ReadOnlyTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
 
         try {
-            Optional<Nodes> nodesDataNode = rTx.read(LogicalDatastoreType.OPERATIONAL, nodes).checkedGet();
-            if (nodesDataNode.isPresent()){
+            Optional<Nodes> nodesDataNode = readOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, nodes)
+                    .checkedGet();
+            if (nodesDataNode.isPresent()) {
                 List<Node> nodesCollection = nodesDataNode.get().getNode();
                 if (nodesCollection != null && !nodesCollection.isEmpty()) {
                     for (Node node : nodesCollection) {
                         LOG.info("Switch with ID {} discovered !!", node.getId().getValue());
                         nodeIds.add(node.getId().getValue());
                     }
-                }
-                else{
+                } else {
                     return Collections.emptySet();
                 }
-            }
-            else{
+            } else {
                 return Collections.emptySet();
             }
-        }
-        catch(ReadFailedException rdFailedException){
+        } catch (ReadFailedException rdFailedException) {
             LOG.error("Failed to read connected nodes {}", rdFailedException);
         }
         return nodeIds;
@@ -106,9 +101,7 @@ public class FlowWriterDirectOFRpc {
         private final int flowsPerDpn;
         private final int batchSize;
 
-        public FlowRPCHandlerTask(final String dpId,
-                                  final int flowsPerDpn,
-                                  final int batchSize){
+        public FlowRPCHandlerTask(final String dpId, final int flowsPerDpn, final int batchSize) {
             this.dpId = dpId;
             this.flowsPerDpn = flowsPerDpn;
             this.batchSize = batchSize;
@@ -117,10 +110,10 @@ public class FlowWriterDirectOFRpc {
         @Override
         public void run() {
 
-            short tableId = (short)1;
+            short tableId = (short) 1;
             int initFlowId = 500;
 
-            for (int i=1; i<= flowsPerDpn; i++){
+            for (int i = 1; i <= flowsPerDpn; i++) {
 
                 String flowId = Integer.toString(initFlowId + i);
 
@@ -140,8 +133,7 @@ public class FlowWriterDirectOFRpc {
 
                 AddFlowInput addFlowInput = builder.build();
 
-                LOG.debug("RPC invocation for adding flow-id {} with input {}", flowId,
-                        addFlowInput.toString());
+                LOG.debug("RPC invocation for adding flow-id {} with input {}", flowId, addFlowInput.toString());
                 flowService.addFlow(addFlowInput);
 
                 if (i % batchSize == 0) {
index c6c6b841a8762a785e87aed7708d0b30de32532c..2fc3a2802b636db6f783347a77b3ab93e53e7593 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson 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,
@@ -27,9 +27,9 @@ public class FlowWriterSequential implements FlowCounterMBean {
     private final ExecutorService flowPusher;
     protected int dpnCount;
     private long startTime;
-    private AtomicInteger writeOpStatus = new AtomicInteger(FlowCounter.OperationStatus.INIT.status());
-    private AtomicInteger countDpnWriteCompletion = new AtomicInteger();
-    private AtomicLong taskCompletionTime = new AtomicLong();
+    private final AtomicInteger writeOpStatus = new AtomicInteger(FlowCounter.OperationStatus.INIT.status());
+    private final AtomicInteger countDpnWriteCompletion = new AtomicInteger();
+    private final AtomicLong taskCompletionTime = new AtomicLong();
 
     public FlowWriterSequential(final DataBroker dataBroker, ExecutorService flowPusher) {
         this.dataBroker = dataBroker;
@@ -37,21 +37,21 @@ public class FlowWriterSequential implements FlowCounterMBean {
         LOG.info("Using Sequential implementation of Flow Writer.");
     }
 
-    public void addFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize, int sleepMillis,
-                         short startTableId, short endTableId, boolean isCreateParents) {
+    public void addFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize, int sleepMillis, short startTableId,
+            short endTableId, boolean isCreateParents) {
         LOG.info("Using Sequential implementation of Flow Writer.");
         this.dpnCount = dpnCount;
         countDpnWriteCompletion.set(dpnCount);
         startTime = System.nanoTime();
         for (int i = 1; i <= dpnCount; i++) {
-            FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i), flowsPerDPN, true, batchSize,
-                    sleepMillis, startTableId, endTableId, isCreateParents);
+            FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i), flowsPerDPN, true, batchSize, sleepMillis,
+                    startTableId, endTableId, isCreateParents);
             flowPusher.execute(task);
         }
     }
 
     public void deleteFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize, short startTableId,
-                            short endTableId) {
+            short endTableId) {
         LOG.info("Using Sequential implementation of Flow Writer.");
         countDpnWriteCompletion.set(dpnCount);
         for (int i = 1; i <= dpnCount; i++) {
@@ -81,14 +81,14 @@ public class FlowWriterSequential implements FlowCounterMBean {
         private final short endTableId;
         private final boolean isCreateParents;
 
-        public FlowHandlerTask(final String dpId,
-                               final int flowsPerDpn,
-                               final boolean add,
-                               final int batchSize,
-                               int sleepMillis,
-                               final short startTableId,
-                               final short endTableId,
-                               final boolean isCreateParents){
+        FlowHandlerTask(final String dpId,
+                        final int flowsPerDpn,
+                        final boolean add,
+                        final int batchSize,
+                        int sleepMillis,
+                        final short startTableId,
+                        final short endTableId,
+                        final boolean isCreateParents) {
             this.dpId = BulkOMaticUtils.DEVICE_TYPE_PREFIX + dpId;
             this.add = add;
             this.flowsPerDpn = flowsPerDpn;
@@ -101,40 +101,42 @@ public class FlowWriterSequential implements FlowCounterMBean {
 
         @Override
         public void run() {
-            LOG.info("Starting flow writer task for dpid: {}. Number of transactions: {}", dpId, flowsPerDpn/batchSize);
+            LOG.info("Starting flow writer task for dpid: {}. Number of transactions: {}", dpId,
+                    flowsPerDpn / batchSize);
             writeOpStatus.set(FlowCounter.OperationStatus.IN_PROGRESS.status());
 
             Short tableId = startTableId;
             Integer sourceIp = 1;
 
             WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
-            short k = tableId;
+            short calculatedTableId = tableId;
 
             for (; sourceIp <= batchSize; sourceIp++) {
-                String flowId = "Flow-" + dpId + "." + k + "." + sourceIp;
+                String flowId = "Flow-" + dpId + "." + calculatedTableId + "." + sourceIp;
                 LOG.debug("Adding flow with id: {}", flowId);
                 Flow flow = null;
                 if (add) {
                     Match match = BulkOMaticUtils.getMatch(sourceIp);
-                    flow = BulkOMaticUtils.buildFlow(k, flowId, match);
+                    flow = BulkOMaticUtils.buildFlow(calculatedTableId, flowId, match);
                 }
                 addFlowToTx(writeTransaction, flowId,
-                        BulkOMaticUtils.getFlowInstanceIdentifier(k, flowId, dpId), flow);
+                        BulkOMaticUtils.getFlowInstanceIdentifier(calculatedTableId, flowId, dpId), flow);
 
                 if (sourceIp < batchSize) {
-                    short a = 1;
-                    short b = (short)(endTableId - startTableId + 1);
-                    k = (short) (((k + a) % b) + startTableId);
+                    short numberA = 1;
+                    short numberB = (short) (endTableId - startTableId + 1);
+                    calculatedTableId = (short) ((calculatedTableId + numberA) % numberB + startTableId);
                 }
             }
 
-            LOG.debug("Submitting Txn for dpId: {}, begin tableId: {}, end tableId: {}, sourceIp: {}", dpId, tableId, k, sourceIp);
+            LOG.debug("Submitting Txn for dpId: {}, begin tableId: {}, end tableId: {}, sourceIp: {}", dpId, tableId,
+                    calculatedTableId, sourceIp);
 
-            Futures.addCallback(writeTransaction.submit(), new DsCallBack(dpId, sourceIp, k));
+            Futures.addCallback(writeTransaction.submit(), new DsCallBack(dpId, sourceIp, calculatedTableId));
         }
 
         private void addFlowToTx(WriteTransaction writeTransaction, String flowId, InstanceIdentifier<Flow> flowIid,
-                                 Flow flow) {
+                Flow flow) {
             if (add) {
                 LOG.trace("Adding flow for flowId: {}, flowIid: {}", flowId, flowIid);
                 writeTransaction.put(LogicalDatastoreType.CONFIGURATION, flowIid, flow, isCreateParents);
@@ -145,26 +147,26 @@ public class FlowWriterSequential implements FlowCounterMBean {
         }
 
         private class DsCallBack implements FutureCallback {
-            private String dpId;
+            private final String dpId;
             private Integer sourceIp;
-            private Short tableId;
+            private final Short tableId;
 
-            public DsCallBack(String dpId, Integer sourceIp, Short tableId) {
+            DsCallBack(String dpId, Integer sourceIp, Short tableId) {
                 this.dpId = dpId;
                 this.sourceIp = sourceIp;
-                short a = 1;
-                short b = (short)(endTableId - startTableId + 1);
-                this.tableId = (short) (((tableId + a) % b) + startTableId);
+                short numberA = 1;
+                short numberB = (short) (endTableId - startTableId + 1);
+                this.tableId = (short) ((tableId + numberA) % numberB + startTableId);
             }
 
             @Override
-            public void onSuccess(Object o) {
+            public void onSuccess(Object object) {
                 if (sourceIp > flowsPerDpn) {
                     long dur = System.nanoTime() - startTime;
                     LOG.info("Completed all flows installation for: dpid: {}, tableId: {}, sourceIp: {} in {}ns", dpId,
                             tableId, sourceIp, dur);
-                    if(0 == countDpnWriteCompletion.decrementAndGet() &&
-                            writeOpStatus.get() != FlowCounter.OperationStatus.FAILURE.status()) {
+                    if (0 == countDpnWriteCompletion.decrementAndGet()
+                            && writeOpStatus.get() != FlowCounter.OperationStatus.FAILURE.status()) {
                         writeOpStatus.set(FlowCounter.OperationStatus.SUCCESS.status());
                         taskCompletionTime.set(dur);
                     }
@@ -180,34 +182,36 @@ public class FlowWriterSequential implements FlowCounterMBean {
 
                 WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
                 int newBatchSize = sourceIp + batchSize - 1;
-                short k = tableId;
+                short calculatedTableId = tableId;
                 for (; sourceIp <= newBatchSize; sourceIp++) {
-                    String flowId = "Flow-" + dpId + "." + k + "." + sourceIp;
+                    String flowId = "Flow-" + dpId + "." + calculatedTableId + "." + sourceIp;
                     Flow flow = null;
                     if (add) {
                         Match match = BulkOMaticUtils.getMatch(sourceIp);
-                        flow = BulkOMaticUtils.buildFlow(k, flowId, match);
+                        flow = BulkOMaticUtils.buildFlow(calculatedTableId, flowId, match);
                     }
                     LOG.debug("Adding flow with id: {}", flowId);
                     addFlowToTx(writeTransaction, flowId,
-                            BulkOMaticUtils.getFlowInstanceIdentifier(k, flowId, dpId), flow);
+                            BulkOMaticUtils.getFlowInstanceIdentifier(calculatedTableId, flowId, dpId),
+                            flow);
 
                     if (sourceIp < newBatchSize) {
-                        short a = 1;
-                        short b = (short)(endTableId - startTableId + 1);
-                        k = (short) (((k + a) % b) + startTableId);
+                        short numberA = 1;
+                        short numberB = (short) (endTableId - startTableId + 1);
+                        calculatedTableId = (short) ((calculatedTableId + numberA) % numberB + startTableId);
                     }
                 }
                 LOG.debug("OnSuccess: Submitting Txn for dpId: {}, begin tableId: {}, end tableId: {}, sourceIp: {}",
-                        dpId, tableId, k, sourceIp);
-                Futures.addCallback(writeTransaction.submit(), new DsCallBack(dpId, sourceIp, k));
+                        dpId, tableId, calculatedTableId, sourceIp);
+                Futures.addCallback(writeTransaction.submit(), new DsCallBack(dpId, sourceIp, calculatedTableId));
             }
 
+            @Override
             public void onFailure(Throwable error) {
-                LOG.error("Error: {} in Datastore write operation: dpid: {}, tableId: {}, sourceIp: {}",
-                        error, dpId, tableId, sourceIp);
+                LOG.error("Error: {} in Datastore write operation: dpid: {}, tableId: {}, sourceIp: {}", error, dpId,
+                        tableId, sourceIp);
                 writeOpStatus.set(FlowCounter.OperationStatus.FAILURE.status());
             }
         }
     }
-}
\ No newline at end of file
+}
index 660b8d0797c9a7a1f2b27bb22d02c10557d9f225..f45202f4b3a0a93f709a07b672629831a32f5527 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson 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,
@@ -30,36 +30,35 @@ public class FlowWriterTxChain implements FlowCounterMBean {
     private final DataBroker dataBroker;
     private final ExecutorService flowPusher;
     private long startTime;
-    private AtomicInteger writeOpStatus = new AtomicInteger(FlowCounter.OperationStatus.INIT.status());
-    private AtomicInteger countDpnWriteCompletion = new AtomicInteger();
-    private AtomicLong taskCompletionTime = new AtomicLong();
+    private final AtomicInteger writeOpStatus = new AtomicInteger(FlowCounter.OperationStatus.INIT.status());
+    private final AtomicInteger countDpnWriteCompletion = new AtomicInteger();
+    private final AtomicLong taskCompletionTime = new AtomicLong();
 
-    public FlowWriterTxChain(final DataBroker dataBroker, ExecutorService flowPusher){
+    public FlowWriterTxChain(final DataBroker dataBroker, ExecutorService flowPusher) {
         this.dataBroker = dataBroker;
         this.flowPusher = flowPusher;
         LOG.info("Using Ping Pong Flow Tester Impl");
     }
 
-    public void addFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize,
-                         int sleepMillis, int sleepAfter, short startTableId, short endTableId,
-                         boolean isCreateParents) {
+    public void addFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize, int sleepMillis, int sleepAfter,
+            short startTableId, short endTableId, boolean isCreateParents) {
         LOG.info("Using Transaction Chain Flow Writer Impl");
         countDpnWriteCompletion.set(dpnCount);
         startTime = System.nanoTime();
         for (int i = 1; i <= dpnCount; i++) {
-            FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i),
-                    flowsPerDPN, true, batchSize, sleepMillis, sleepAfter, startTableId, endTableId, isCreateParents);
+            FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i), flowsPerDPN, true, batchSize, sleepMillis,
+                    sleepAfter, startTableId, endTableId, isCreateParents);
             flowPusher.execute(task);
         }
     }
 
-    public void deleteFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize,
-                            short startTableId, short endTableId) {
+    public void deleteFlows(Integer dpnCount, Integer flowsPerDPN, int batchSize, short startTableId,
+            short endTableId) {
         LOG.info("Using Transaction Chain Flow Writer Impl");
         countDpnWriteCompletion.set(dpnCount);
         for (int i = 1; i <= dpnCount; i++) {
-            FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i), flowsPerDPN, false, batchSize,
-                    0, 1, startTableId, endTableId, false);
+            FlowHandlerTask task = new FlowHandlerTask(Integer.toString(i), flowsPerDPN, false, batchSize, 0, 1,
+                    startTableId, endTableId, false);
             flowPusher.execute(task);
         }
     }
@@ -84,19 +83,19 @@ public class FlowWriterTxChain implements FlowCounterMBean {
         private final short startTableId;
         private final short endTableId;
         private final boolean isCreateParents;
-        private AtomicInteger remainingTxReturn = new AtomicInteger(0);
+        private final AtomicInteger remainingTxReturn = new AtomicInteger(0);
 
         BindingTransactionChain txChain;
 
-        public FlowHandlerTask(final String dpId,
-                               final int flowsPerDpn,
-                               final boolean add,
-                               final int batchSize,
-                               final int sleepMillis,
-                               final int sleepAfter,
-                               final short startTableId,
-                               final short endTableId,
-                               final boolean isCreateParents){
+        FlowHandlerTask(final String dpId,
+                        final int flowsPerDpn,
+                        final boolean add,
+                        final int batchSize,
+                        final int sleepMillis,
+                        final int sleepAfter,
+                        final short startTableId,
+                        final short endTableId,
+                        final boolean isCreateParents) {
             this.dpId = BulkOMaticUtils.DEVICE_TYPE_PREFIX + dpId;
             this.add = add;
             this.flowsPerDpn = flowsPerDpn;
@@ -106,14 +105,14 @@ public class FlowWriterTxChain implements FlowCounterMBean {
             this.startTableId = startTableId;
             this.endTableId = endTableId;
             this.isCreateParents = isCreateParents;
-            remainingTxReturn.set(flowsPerDpn/batchSize);
+            remainingTxReturn.set(flowsPerDpn / batchSize);
         }
 
         @Override
         public void run() {
             writeOpStatus.set(FlowCounter.OperationStatus.IN_PROGRESS.status());
             short tableId = startTableId;
-            int numSubmits = flowsPerDpn/batchSize;
+            int numSubmits = flowsPerDpn / batchSize;
             int sourceIp = 1;
             int newBatchSize = batchSize;
             LOG.info("Number of Txn for dpId: {} is: {}", dpId, numSubmits);
@@ -122,37 +121,34 @@ public class FlowWriterTxChain implements FlowCounterMBean {
             LOG.info("Creating new txChain: {} for dpid: {}", txChain, dpId);
 
             for (int i = 1; i <= numSubmits; i++) {
-                WriteTransaction writeTransaction;
-                try {
-                    writeTransaction = txChain.newWriteOnlyTransaction();
-                } catch (Exception e) {
-                    LOG.error("Transaction creation failed in txChain: {}, due to: {}", txChain, e);
-                    break;
-                }
-                short k = tableId;
+                WriteTransaction writeTransaction = txChain.newWriteOnlyTransaction();
+                short calculatedTableId = tableId;
                 for (; sourceIp <= newBatchSize; sourceIp++) {
-                    String flowId = "Flow-" + dpId + "." + k + "." + sourceIp;
+                    String flowId = "Flow-" + dpId + "." + calculatedTableId + "." + sourceIp;
                     Flow flow = null;
                     if (add) {
                         Match match = BulkOMaticUtils.getMatch(sourceIp);
-                        flow = BulkOMaticUtils.buildFlow(k, flowId, match);
+                        flow = BulkOMaticUtils.buildFlow(calculatedTableId, flowId, match);
                     }
 
                     writeTxToDs(writeTransaction, flowId,
-                            BulkOMaticUtils.getFlowInstanceIdentifier(k, flowId, dpId), flow, sourceIp, k);
+                            BulkOMaticUtils.getFlowInstanceIdentifier(calculatedTableId, flowId, dpId),
+                            flow, sourceIp, calculatedTableId);
 
                     if (sourceIp < newBatchSize) {
-                        short a = 1;
-                        short b = (short) (endTableId - startTableId + 1);
-                        k = (short) (((k + a) % b) + startTableId);
+                        short numberA = 1;
+                        short numberB = (short) (endTableId - startTableId + 1);
+                        calculatedTableId = (short) ((calculatedTableId + numberA) % numberB + startTableId);
                     }
                 }
-                LOG.debug("Submitting Txn for dpId: {}, begin tableId: {}, end tableId: {}, sourceIp: {}", dpId, tableId, k, sourceIp - 1);
-                Futures.addCallback(writeTransaction.submit(), new DsCallBack(dpId, tableId, k, sourceIp));
+                LOG.debug("Submitting Txn for dpId: {}, begin tableId: {}, end tableId: {}, sourceIp: {}", dpId,
+                        tableId, calculatedTableId, sourceIp - 1);
+                Futures.addCallback(writeTransaction.submit(),
+                        new DsCallBack(dpId, tableId, calculatedTableId, sourceIp));
                 // Wrap around
-                tableId = (short) (((k + 1) % ((short) (endTableId - startTableId + 1))) + startTableId);
+                tableId = (short) ((calculatedTableId + 1) % (short) (endTableId - startTableId + 1) + startTableId);
                 newBatchSize += batchSize;
-                if (((i % sleepAfter) == 0) && (sleepMillis > 0)) {
+                if (i % sleepAfter == 0 && sleepMillis > 0) {
                     try {
                         Thread.sleep(sleepMillis);
                     } catch (InterruptedException e) {
@@ -164,7 +160,8 @@ public class FlowWriterTxChain implements FlowCounterMBean {
         }
 
         @Override
-        public void onTransactionChainFailed(TransactionChain<?, ?> transactionChain, AsyncTransaction<?, ?> asyncTransaction, Throwable throwable) {
+        public void onTransactionChainFailed(TransactionChain<?, ?> transactionChain,
+                AsyncTransaction<?, ?> asyncTransaction, Throwable throwable) {
             LOG.error("Transaction chain: {} FAILED at asyncTransaction: {} due to: {}", transactionChain,
                     asyncTransaction.getIdentifier(), throwable);
             transactionChain.close();
@@ -175,7 +172,8 @@ public class FlowWriterTxChain implements FlowCounterMBean {
             LOG.info("Transaction chain: {} closed successfully.", transactionChain);
         }
 
-        private void writeTxToDs(WriteTransaction writeTransaction, String flowId, InstanceIdentifier<Flow> flowIid, Flow flow, Integer sourceIp, Short tableId){
+        private void writeTxToDs(WriteTransaction writeTransaction, String flowId, InstanceIdentifier<Flow> flowIid,
+                Flow flow, Integer sourceIp, Short tableId) {
             if (add) {
                 LOG.trace("Adding flow for flowId: {}, flowIid: {}", flowId, flowIid);
                 writeTransaction.put(LogicalDatastoreType.CONFIGURATION, flowIid, flow, isCreateParents);
@@ -186,12 +184,12 @@ public class FlowWriterTxChain implements FlowCounterMBean {
         }
 
         private class DsCallBack implements FutureCallback {
-            private String dpId;
-            private int sourceIp;
-            private short endTableId;
-            private short beginTableId;
+            private final String dpId;
+            private final int sourceIp;
+            private final short endTableId;
+            private final short beginTableId;
 
-            public DsCallBack(String dpId, Short beginTableId, Short endTableId, Integer sourceIp) {
+            DsCallBack(String dpId, Short beginTableId, Short endTableId, Integer sourceIp) {
                 this.dpId = dpId;
                 this.sourceIp = sourceIp;
                 this.endTableId = endTableId;
@@ -199,13 +197,12 @@ public class FlowWriterTxChain implements FlowCounterMBean {
             }
 
             @Override
-            public void onSuccess(Object o) {
+            public void onSuccess(Object object) {
                 if (remainingTxReturn.decrementAndGet() <= 0) {
                     long dur = System.nanoTime() - startTime;
-                    LOG.info("Completed all flows installation for: dpid: {} in {}ns", dpId,
-                            dur);
-                    if(0 == countDpnWriteCompletion.decrementAndGet() &&
-                            writeOpStatus.get() != FlowCounter.OperationStatus.FAILURE.status()) {
+                    LOG.info("Completed all flows installation for: dpid: {} in {}ns", dpId, dur);
+                    if (0 == countDpnWriteCompletion.decrementAndGet()
+                            && writeOpStatus.get() != FlowCounter.OperationStatus.FAILURE.status()) {
                         writeOpStatus.set(FlowCounter.OperationStatus.SUCCESS.status());
                         taskCompletionTime.set(dur);
                     }
@@ -213,16 +210,16 @@ public class FlowWriterTxChain implements FlowCounterMBean {
                 }
             }
 
+            @Override
             public void onFailure(Throwable error) {
                 if (remainingTxReturn.decrementAndGet() <= 0) {
                     long dur = System.nanoTime() - startTime;
-                    LOG.info("Completed all flows installation for: dpid: {} in {}ns", dpId,
-                            dur);
+                    LOG.info("Completed all flows installation for: dpid: {} in {}ns", dpId, dur);
                 }
-                LOG.error("Error: {} in Datastore write operation: dpid: {}, begin tableId: {}, " +
-                        "end tableId: {}, sourceIp: {} ", error, dpId, beginTableId, endTableId, sourceIp);
+                LOG.error("Error: {} in Datastore write operation: dpid: {}, begin tableId: {}, "
+                        "end tableId: {}, sourceIp: {} ", error, dpId, beginTableId, endTableId, sourceIp);
                 writeOpStatus.set(FlowCounter.OperationStatus.FAILURE.status());
             }
         }
     }
-}
\ No newline at end of file
+}
index 1a4dc4369ae6d6ab8c270d797455e09c35ae0d6f..94eca21e5c15788c807376350134df00b770fa42 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2015, 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,
@@ -44,7 +44,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.RemoveFlowsRpcInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.SalBulkFlowService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.TableTestInput;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.TableTestInput.Operation;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.bulk.flow.service.rev150608.bulk.flow.ds.list.grouping.BulkFlowDsItem;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
@@ -78,6 +77,7 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
     private final DataBroker dataBroker;
     private final FlowCounter flowCounterBeanImpl = new FlowCounter();
     private final ExecutorService fjService = new ForkJoinPool();
+
     public SalBulkFlowServiceImpl(SalFlowService flowService, DataBroker dataBroker) {
         this.flowService = Preconditions.checkNotNull(flowService);
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
@@ -103,11 +103,9 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
 
     private InstanceIdentifier<Flow> getFlowInstanceIdentifier(BulkFlowDsItem bulkFlow) {
         final NodeRef nodeRef = bulkFlow.getNode();
-        return ((InstanceIdentifier<Node>) nodeRef.getValue())
-                .augmentation(FlowCapableNode.class)
+        return ((InstanceIdentifier<Node>) nodeRef.getValue()).augmentation(FlowCapableNode.class)
                 .child(Table.class, new TableKey(bulkFlow.getTableId()))
-                .child(Flow.class,
-                        new FlowKey(new FlowId(bulkFlow.getFlowId())));
+                .child(Flow.class, new FlowKey(new FlowId(bulkFlow.getFlowId())));
     }
 
     @Override
@@ -120,8 +118,8 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
         return handleResultFuture(submitFuture);
     }
 
-    private ListenableFuture<RpcResult<Void>> handleResultFuture(CheckedFuture<Void,
-            TransactionCommitFailedException> submitFuture) {
+    private ListenableFuture<RpcResult<Void>> handleResultFuture(
+            CheckedFuture<Void, TransactionCommitFailedException> submitFuture) {
         final SettableFuture<RpcResult<Void>> rpcResult = SettableFuture.create();
         Futures.addCallback(submitFuture, new FutureCallback<Void>() {
             @Override
@@ -130,11 +128,10 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
             }
 
             @Override
-            public void onFailure(Throwable t) {
+            public void onFailure(Throwable throwable) {
                 RpcResultBuilder<Void> rpcResultBld = RpcResultBuilder.<Void>failed()
-                        .withRpcErrors(Collections.singleton(
-                                RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, null, t.getMessage())
-                        ));
+                        .withRpcErrors(Collections.singleton(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION,
+                                null, throwable.getMessage())));
                 rpcResult.set(rpcResultBld.build());
             }
         });
@@ -150,11 +147,10 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
             }
 
             @Override
-            public void onFailure(Throwable t) {
+            public void onFailure(Throwable throwable) {
                 RpcResultBuilder<Void> rpcResultBld = RpcResultBuilder.<Void>failed()
-                        .withRpcErrors(Collections.singleton(
-                                RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, null, t.getMessage())
-                        ));
+                        .withRpcErrors(Collections.singleton(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION,
+                                null, throwable.getMessage())));
                 rpcResult.set(rpcResultBld.build());
             }
         });
@@ -166,7 +162,8 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
         List<ListenableFuture<RpcResult<AddFlowOutput>>> bulkResults = new ArrayList<>();
 
         for (BulkFlowBaseContentGrouping bulkFlow : input.getBulkFlowItem()) {
-            AddFlowInputBuilder flowInputBuilder = new AddFlowInputBuilder((org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) bulkFlow);
+            AddFlowInputBuilder flowInputBuilder = new AddFlowInputBuilder(
+                    (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) bulkFlow);
             final NodeRef nodeRef = bulkFlow.getNode();
             flowInputBuilder.setNode(nodeRef);
             flowInputBuilder.setTableId(bulkFlow.getTableId());
@@ -178,11 +175,9 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
 
     @Override
     public Future<RpcResult<Void>> readFlowTest(ReadFlowTestInput input) {
-        FlowReader flowReader = FlowReader.getNewInstance(dataBroker,
-                input.getDpnCount().intValue(),
-                input.getFlowsPerDpn().intValue(), input.isVerbose(),
-                input.isIsConfigDs(),input.getStartTableId().shortValue(),
-                input.getEndTableId().shortValue());
+        FlowReader flowReader = FlowReader.getNewInstance(dataBroker, input.getDpnCount().intValue(),
+                input.getFlowsPerDpn().intValue(), input.isVerbose(), input.isIsConfigDs(),
+                input.getStartTableId().shortValue(), input.getEndTableId().shortValue());
         flowCounterBeanImpl.setReader(flowReader);
         fjService.execute(flowReader);
         RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.success();
@@ -192,12 +187,9 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
     @Override
     public Future<RpcResult<Void>> flowRpcAddTest(FlowRpcAddTestInput input) {
         FlowWriterDirectOFRpc flowAddRpcTestImpl = new FlowWriterDirectOFRpc(dataBroker, flowService, fjService);
-        flowAddRpcTestImpl.rpcFlowAdd(
-                input.getDpnId(),
-                input.getFlowCount().intValue(),
+        flowAddRpcTestImpl.rpcFlowAdd(input.getDpnId(), input.getFlowCount().intValue(),
                 input.getRpcBatchSize().intValue());
 
-
         RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.success();
         return Futures.immediateFuture(rpcResultBuilder.build());
     }
@@ -206,16 +198,13 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
     public Future<RpcResult<Void>> register() {
         RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.success();
         try {
-        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
-        String pathToMBean = String.format("%s:type=%s",
-                FlowCounter.class.getPackage().getName(),
-                FlowCounter.class.getSimpleName());
-        ObjectName name = null;
-
-            name = new ObjectName(pathToMBean);
+            MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+            String pathToMBean = String.format("%s:type=%s", FlowCounter.class.getPackage().getName(),
+                    FlowCounter.class.getSimpleName());
+            ObjectName name = new ObjectName(pathToMBean);
             mbs.registerMBean(flowCounterBeanImpl, name);
-        } catch (MalformedObjectNameException | InstanceAlreadyExistsException
-                | MBeanRegistrationException | NotCompliantMBeanException e) {
+        } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException
+                | NotCompliantMBeanException e) {
             rpcResultBuilder = RpcResultBuilder.failed();
             LOG.warn("Exception occurred: {} ", e.getMessage(), e);
         }
@@ -227,7 +216,8 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
         List<ListenableFuture<RpcResult<RemoveFlowOutput>>> bulkResults = new ArrayList<>();
 
         for (BulkFlowBaseContentGrouping bulkFlow : input.getBulkFlowItem()) {
-            RemoveFlowInputBuilder flowInputBuilder = new RemoveFlowInputBuilder((org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) bulkFlow);
+            RemoveFlowInputBuilder flowInputBuilder = new RemoveFlowInputBuilder(
+                    (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) bulkFlow);
             final NodeRef nodeRef = bulkFlow.getNode();
             flowInputBuilder.setNode(nodeRef);
             flowInputBuilder.setTableId(bulkFlow.getTableId());
@@ -242,7 +232,7 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
         if (input.isTxChain()) {
             FlowWriterTxChain flowTester = new FlowWriterTxChain(dataBroker, fjService);
             flowCounterBeanImpl.setWriter(flowTester);
-            if (input.isIsAdd()){
+            if (input.isIsAdd()) {
                 flowTester.addFlows(input.getDpnCount().intValue(), input.getFlowsPerDpn().intValue(),
                         input.getBatchSize().intValue(), input.getSleepFor().intValue(),
                         input.getSleepAfter().intValue(), input.getStartTableId().shortValue(),
@@ -258,7 +248,7 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
         if (input.isSeq()) {
             FlowWriterSequential flowTester = new FlowWriterSequential(dataBroker, fjService);
             flowCounterBeanImpl.setWriter(flowTester);
-            if (input.isIsAdd()){
+            if (input.isIsAdd()) {
                 flowTester.addFlows(input.getDpnCount().intValue(), input.getFlowsPerDpn().intValue(),
                         input.getBatchSize().intValue(), input.getSleepFor().intValue(),
                         input.getStartTableId().shortValue(), input.getEndTableId().shortValue(),
@@ -271,7 +261,7 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
         } else {
             FlowWriterConcurrent flowTester = new FlowWriterConcurrent(dataBroker, fjService);
             flowCounterBeanImpl.setWriter(flowTester);
-            if (input.isIsAdd()){
+            if (input.isIsAdd()) {
                 flowTester.addFlows(input.getDpnCount().intValue(), input.getFlowsPerDpn().intValue(),
                         input.getBatchSize().intValue(), input.getSleepFor().intValue(),
                         input.getSleepAfter().intValue(), input.getStartTableId().shortValue(),
@@ -292,12 +282,12 @@ public class SalBulkFlowServiceImpl implements SalBulkFlowService {
         flowCounterBeanImpl.setWriter(writer);
         switch (input.getOperation()) {
             case Add:
-                writer.addTables(input.getDpnCount().intValue(),
-                    input.getStartTableId().shortValue(), input.getEndTableId().shortValue());
+                writer.addTables(input.getDpnCount().intValue(), input.getStartTableId().shortValue(),
+                        input.getEndTableId().shortValue());
                 break;
             case Delete:
-                writer.deleteTables(input.getDpnCount().intValue(),
-                    input.getStartTableId().shortValue(), input.getEndTableId().shortValue());
+                writer.deleteTables(input.getDpnCount().intValue(), input.getStartTableId().shortValue(),
+                        input.getEndTableId().shortValue());
                 break;
             default:
                 RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.failed();
index 5bf57166a69c55b131c687fdefa87f636a753b8e..ed0be50bb56a2a407f8bd7a65803ae3e685b25b2 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.util.concurrent.Futures;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
-import javax.annotation.Nullable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -26,7 +25,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class TableWriter implements FlowCounterMBean {
-    private final Logger LOG = LoggerFactory.getLogger(TableWriter.class);
+    private static final Logger LOG = LoggerFactory.getLogger(TableWriter.class);
 
     private final AtomicInteger writeOpStatus = new AtomicInteger(FlowCounter.OperationStatus.INIT.status());
     private final AtomicLong taskCompletionTime = new AtomicLong(BulkOMaticUtils.DEFAULT_COMPLETION_TIME);
@@ -69,12 +68,12 @@ public class TableWriter implements FlowCounterMBean {
 
     private class TableHandlerTask implements Runnable {
 
-        private short startTableId;
-        private short endTableId;
-        private int dpnCount;
-        private boolean isAdd;
+        private final short startTableId;
+        private final short endTableId;
+        private final int dpnCount;
+        private final boolean isAdd;
 
-        public TableHandlerTask(int dpnCount, short startTableId, short endTableId, boolean isAdd) {
+        TableHandlerTask(int dpnCount, short startTableId, short endTableId, boolean isAdd) {
             this.dpnCount = dpnCount;
             this.startTableId = startTableId;
             this.endTableId = endTableId;
@@ -90,9 +89,7 @@ public class TableWriter implements FlowCounterMBean {
                 String dpId = BulkOMaticUtils.DEVICE_TYPE_PREFIX + String.valueOf(dpn);
                 for (short tableId = startTableId; tableId <= endTableId; tableId++) {
                     WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
-                    Table table = new TableBuilder().setKey(new TableKey(tableId))
-                            .setId(tableId)
-                            .build();
+                    Table table = new TableBuilder().setKey(new TableKey(tableId)).setId(tableId).build();
                     InstanceIdentifier<Table> tableIId = BulkOMaticUtils.getTableId(tableId, dpId);
 
                     if (isAdd) {
@@ -105,7 +102,7 @@ public class TableWriter implements FlowCounterMBean {
 
                     Futures.addCallback(future, new FutureCallback<Void>() {
                         @Override
-                        public void onSuccess(@Nullable Void v) {
+                        public void onSuccess(Void voidParameter) {
                             if (successfulWrites.incrementAndGet() == totalTables) {
                                 if (failedWrites.get() > 0) {
                                     writeOpStatus.set(FlowCounter.OperationStatus.FAILURE.status());
index a2c46adf02b35c37502754cd2ea31ef6f2ac5db7..174fadbee2d2b6efd62e4a3b334e8a42c1f79478 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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,
@@ -34,7 +34,7 @@ public class FlowReaderTest {
     @Mock
     private DataBroker mockDataBroker;
     @Mock
-    private ReadOnlyTransaction rTx;
+    private ReadOnlyTransaction readOnlyTransaction;
     @Mock
     private Node node;
 
@@ -42,10 +42,10 @@ public class FlowReaderTest {
 
     @Before
     public void setUp() throws Exception {
-        when(rTx.read(Mockito.any(LogicalDatastoreType.class), Mockito.<InstanceIdentifier<Node>>any()))
+        when(readOnlyTransaction.read(Mockito.any(LogicalDatastoreType.class), Mockito.<InstanceIdentifier<Node>>any()))
                 .thenReturn(Futures.immediateCheckedFuture(Optional.of(node)));
-        when(mockDataBroker.newReadOnlyTransaction()).thenReturn(rTx);
-        flowReader = FlowReader.getNewInstance(mockDataBroker, 2, 5, true, false, (short)1, (short)2 );
+        when(mockDataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
+        flowReader = FlowReader.getNewInstance(mockDataBroker, 2, 5, true, false, (short) 1, (short) 2);
     }
 
     @Test
@@ -54,4 +54,4 @@ public class FlowReaderTest {
         Assert.assertEquals(10, flowReader.getFlowCount());
         Assert.assertEquals(FlowCounter.OperationStatus.SUCCESS.status(), flowReader.getReadOpStatus());
     }
-}
\ No newline at end of file
+}
index 769f70d9fda38e47dd04f7ae5cf35781c4be0b18..b1370385f2ffb441477f9027cb0a7c3e3003b3fe 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * 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,
@@ -18,9 +18,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -44,7 +42,7 @@ public class FlowWriterConcurrentTest {
     @Mock
     private ExecutorService mockFlowPusher;
     @Mock
-    private WriteTransaction wTx;
+    private WriteTransaction writeTransaction;
     @Mock
     private Nodes mockNodes;
 
@@ -53,29 +51,28 @@ public class FlowWriterConcurrentTest {
     @Before
     public void setUp() throws Exception {
 
-        doReturn(wTx).when(mockDataBroker).newWriteOnlyTransaction();
-        Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+        doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
+        Mockito.when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
 
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(InvocationOnMock invocation) throws Throwable {
-                ((Runnable)invocation.getArguments()[0]).run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            ((Runnable) invocation.getArguments()[0]).run();
+            return null;
         }).when(mockFlowPusher).execute(Matchers.<Runnable>any());
 
         flowWriterConcurrent = new FlowWriterConcurrent(mockDataBroker, mockFlowPusher);
     }
+
     @Test
     public void testAddFlows() throws Exception {
-        flowWriterConcurrent.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short)0, (short)1, true);
-        Mockito.verify(wTx, Mockito.times(FLOWS_PER_DPN)).put(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
+        flowWriterConcurrent.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short) 0, (short) 1, true);
+        Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(Matchers.<LogicalDatastoreType>any(),
+                Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
     }
 
     @Test
     public void testDeleteFlows() throws Exception {
-        flowWriterConcurrent.deleteFlows(1, FLOWS_PER_DPN, 10, (short)0, (short)1);
-        Mockito.verify(wTx, Mockito.times(FLOWS_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any());
+        flowWriterConcurrent.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
+        Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(),
+                Matchers.<InstanceIdentifier<DataObject>>any());
     }
-
-}
\ No newline at end of file
+}
index b45da843c9da6adfde558bd1422c270a6cd88a14..a3ae13e875d00e9db4baaa98f17c9a9780129344 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * 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,
@@ -21,9 +21,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -53,7 +51,7 @@ public class FlowWriterDirectOFRpcTest {
     @Mock
     private ExecutorService mockFlowPusher;
     @Mock
-    private ReadOnlyTransaction rTx;
+    private ReadOnlyTransaction readOnlyTransaction;
     @Mock
     private Nodes mockNodes;
 
@@ -61,7 +59,7 @@ public class FlowWriterDirectOFRpcTest {
 
     @Before
     public void setUp() throws Exception {
-        when(mockDataBroker.newReadOnlyTransaction()).thenReturn(rTx);
+        when(mockDataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
         NodeBuilder nodeBuilder = new NodeBuilder()
                 .setId(new NodeId("1"));
 
@@ -71,15 +69,13 @@ public class FlowWriterDirectOFRpcTest {
 
         when(mockNodes.getNode()).thenReturn(nodes);
 
-        when(rTx.read(Mockito.any(LogicalDatastoreType.class), Mockito.<InstanceIdentifier<Nodes>>any()))
-                .thenReturn(Futures.immediateCheckedFuture(Optional.of(mockNodes)));
+        when(readOnlyTransaction.read(Mockito.any(LogicalDatastoreType.class),
+                Mockito.<InstanceIdentifier<Nodes>>any()))
+                        .thenReturn(Futures.immediateCheckedFuture(Optional.of(mockNodes)));
 
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(InvocationOnMock invocation) throws Throwable {
-                ((Runnable)invocation.getArguments()[0]).run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            ((Runnable)invocation.getArguments()[0]).run();
+            return null;
         }).when(mockFlowPusher).execute(Matchers.<Runnable>any());
 
         flowWriterDirectOFRpc = new FlowWriterDirectOFRpc(mockDataBroker, mockSalFlowService, mockFlowPusher);
@@ -96,5 +92,4 @@ public class FlowWriterDirectOFRpcTest {
         flowWriterDirectOFRpc.rpcFlowAddAll(FLOWS_PER_DPN, 10);
         Mockito.verify(mockSalFlowService, Mockito.times(FLOWS_PER_DPN)).addFlow(Mockito.<AddFlowInput>any());
     }
-
-}
\ No newline at end of file
+}
index 0aa5cee7966124ae41666b6333016cf13c372ee8..8fa73e936586375e89de58146aa7e237cf8b3470 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * 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,
@@ -18,9 +18,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -43,36 +41,35 @@ public class FlowWriterSequentialTest {
     @Mock
     private ExecutorService mockFlowPusher;
     @Mock
-    private WriteTransaction wTx;
+    private WriteTransaction writeTransaction;
 
     private FlowWriterSequential flowWriterSequential;
 
     @Before
     public void setUp() throws Exception {
 
-        doReturn(wTx).when(mockDataBroker).newWriteOnlyTransaction();
-        Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+        doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
+        Mockito.when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
 
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(InvocationOnMock invocation) throws Throwable {
-                ((Runnable)invocation.getArguments()[0]).run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            ((Runnable) invocation.getArguments()[0]).run();
+            return null;
         }).when(mockFlowPusher).execute(Matchers.<Runnable>any());
 
         flowWriterSequential = new FlowWriterSequential(mockDataBroker, mockFlowPusher);
     }
+
     @Test
     public void testAddFlows() throws Exception {
-        flowWriterSequential.addFlows(1, FLOWS_PER_DPN, 10, 10, (short)0, (short)1, true);
-        Mockito.verify(wTx, Mockito.times(FLOWS_PER_DPN)).put(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
+        flowWriterSequential.addFlows(1, FLOWS_PER_DPN, 10, 10, (short) 0, (short) 1, true);
+        Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(Matchers.<LogicalDatastoreType>any(),
+                Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
     }
 
     @Test
     public void testDeleteFlows() throws Exception {
-        flowWriterSequential.deleteFlows(1, FLOWS_PER_DPN, 10, (short)0, (short)1);
-        Mockito.verify(wTx, Mockito.times(FLOWS_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any());
+        flowWriterSequential.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
+        Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(),
+                Matchers.<InstanceIdentifier<DataObject>>any());
     }
-
-}
\ No newline at end of file
+}
index e5b003b757bca04dd25974a660cf8528d4f20632..0bda86c799d9ec935fa5288ba96f9c176a6310fc 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * 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,
@@ -20,9 +20,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
@@ -47,39 +45,38 @@ public class FlowWriterTxChainTest {
     @Mock
     private ExecutorService mockFlowPusher;
     @Mock
-    private WriteTransaction wTx;
+    private WriteTransaction writeTransaction;
 
     private FlowWriterTxChain flowWriterTxChain;
 
     @Before
     public void setUp() throws Exception {
 
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(InvocationOnMock invocation) throws Throwable {
-                ((Runnable)invocation.getArguments()[0]).run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            ((Runnable) invocation.getArguments()[0]).run();
+            return null;
         }).when(mockFlowPusher).execute(Matchers.<Runnable>any());
 
         final BindingTransactionChain mockedTxChain = mock(BindingTransactionChain.class);
-        when(mockedTxChain.newWriteOnlyTransaction()).thenReturn(wTx);
+        when(mockedTxChain.newWriteOnlyTransaction()).thenReturn(writeTransaction);
         doReturn(mockedTxChain).when(mockDataBroker).createTransactionChain(Matchers.<TransactionChainListener>any());
 
-        when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+        when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
 
         flowWriterTxChain = new FlowWriterTxChain(mockDataBroker, mockFlowPusher);
     }
+
     @Test
     public void testAddFlows() throws Exception {
-        flowWriterTxChain.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short)0, (short)1, true);
-        Mockito.verify(wTx, Mockito.times(FLOWS_PER_DPN)).put(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
+        flowWriterTxChain.addFlows(1, FLOWS_PER_DPN, 10, 10, 10, (short) 0, (short) 1, true);
+        Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).put(Matchers.<LogicalDatastoreType>any(),
+                Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
     }
 
     @Test
     public void testDeleteFlows() throws Exception {
-        flowWriterTxChain.deleteFlows(1, FLOWS_PER_DPN, 10, (short)0, (short)1);
-        Mockito.verify(wTx, Mockito.times(FLOWS_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any());
+        flowWriterTxChain.deleteFlows(1, FLOWS_PER_DPN, 10, (short) 0, (short) 1);
+        Mockito.verify(writeTransaction, Mockito.times(FLOWS_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(),
+                Matchers.<InstanceIdentifier<DataObject>>any());
     }
-
-}
\ No newline at end of file
+}
index f8c564d1775a07656a036cfee0ce5e9f1606c574..116df5f200d363cb7bf197cdff776dca866991d7 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * 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,
@@ -83,9 +83,9 @@ public class SalBulkFlowServiceImplTest {
     @Mock
     private SalFlowService mockSalFlowService;
     @Mock
-    private WriteTransaction wTx;
+    private WriteTransaction writeTransaction;
     @Mock
-    private ReadOnlyTransaction rTx;
+    private ReadOnlyTransaction readOnlyTransaction;
     @Mock
     private Nodes mockNodes;
     @Mock
@@ -97,20 +97,19 @@ public class SalBulkFlowServiceImplTest {
 
     @Before
     public void setUp() throws Exception {
-        when(mockDataBroker.newWriteOnlyTransaction()).thenReturn(wTx);
-        when(mockDataBroker.newReadOnlyTransaction()).thenReturn(rTx);
-        when(rTx.read(Mockito.any(LogicalDatastoreType.class), Mockito.<InstanceIdentifier<Node>>any()))
+        when(mockDataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
+        when(mockDataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
+        when(readOnlyTransaction.read(Mockito.any(LogicalDatastoreType.class), Mockito.<InstanceIdentifier<Node>>any()))
                 .thenReturn(Futures.immediateCheckedFuture(Optional.of(mockNode)));
         salBulkFlowService = new SalBulkFlowServiceImpl(mockSalFlowService, mockDataBroker);
     }
 
     @Test
     public void testAddRemoveFlowsDs() throws Exception {
-        Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+        Mockito.when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
 
-        final BulkFlowDsItemBuilder bulkFlowDsItemBuilder = new BulkFlowDsItemBuilder()
-            .setFlowId(new FlowId("1"))
-            .setTableId((short)2);
+        final BulkFlowDsItemBuilder bulkFlowDsItemBuilder = new BulkFlowDsItemBuilder().setFlowId(new FlowId("1"))
+                .setTableId((short) 2);
 
         final InstanceIdentifier<Node> nodeId = BulkOMaticUtils.getFlowCapableNodeId("1");
         bulkFlowDsItemBuilder.setNode(new NodeRef(nodeId));
@@ -125,8 +124,9 @@ public class SalBulkFlowServiceImplTest {
         final AddFlowsDsInput addFlowsDsInput = addFlowsDsInputBuilder.build();
         salBulkFlowService.addFlowsDs(addFlowsDsInput);
 
-        verify(wTx).submit();
-        verify(wTx).put(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<Flow>>any(), flowArgumentCaptor.capture(), Mockito.anyBoolean());
+        verify(writeTransaction).submit();
+        verify(writeTransaction).put(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<Flow>>any(),
+                flowArgumentCaptor.capture(), Mockito.anyBoolean());
 
         Flow flow = flowArgumentCaptor.getValue();
         Assert.assertEquals("1", flow.getId().getValue());
@@ -138,8 +138,8 @@ public class SalBulkFlowServiceImplTest {
         final RemoveFlowsDsInput removeFlowsDsInput = removeFlowsDsInputBuilder.build();
 
         salBulkFlowService.removeFlowsDs(removeFlowsDsInput);
-        verify(wTx).delete(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<Flow>>any());
-        verify(wTx,times(2)).submit();
+        verify(writeTransaction).delete(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<Flow>>any());
+        verify(writeTransaction, times(2)).submit();
     }
 
     @Test
@@ -177,13 +177,8 @@ public class SalBulkFlowServiceImplTest {
 
     @Test
     public void testReadFlowTest() throws Exception {
-        final ReadFlowTestInputBuilder readFlowTestInputBuilder = new ReadFlowTestInputBuilder()
-            .setDpnCount(1L)
-            .setStartTableId(1L)
-            .setEndTableId(2L)
-            .setIsConfigDs(false)
-            .setFlowsPerDpn(1L)
-            .setVerbose(true);
+        final ReadFlowTestInputBuilder readFlowTestInputBuilder = new ReadFlowTestInputBuilder().setDpnCount(1L)
+                .setStartTableId(1L).setEndTableId(2L).setIsConfigDs(false).setFlowsPerDpn(1L).setVerbose(true);
 
         final ReadFlowTestInput readFlowTestInput = readFlowTestInputBuilder.build();
         final Future<RpcResult<Void>> resultFuture = salBulkFlowService.readFlowTest(readFlowTestInput);
@@ -193,13 +188,12 @@ public class SalBulkFlowServiceImplTest {
 
     @Test
     public void testFlowRpcAddTest() throws Exception {
-        when(rTx.read(Mockito.any(LogicalDatastoreType.class), Mockito.<InstanceIdentifier<Nodes>>any()))
-                .thenReturn(Futures.immediateCheckedFuture(Optional.of(mockNodes)));
+        when(readOnlyTransaction.read(Mockito.any(LogicalDatastoreType.class),
+                Mockito.<InstanceIdentifier<Nodes>>any()))
+                        .thenReturn(Futures.immediateCheckedFuture(Optional.of(mockNodes)));
 
-        final FlowRpcAddTestInputBuilder flowRpcAddTestInputBuilder = new FlowRpcAddTestInputBuilder()
-                .setFlowCount(1L)
-                .setDpnId("1")
-                .setRpcBatchSize(1L);
+        final FlowRpcAddTestInputBuilder flowRpcAddTestInputBuilder = new FlowRpcAddTestInputBuilder().setFlowCount(1L)
+                .setDpnId("1").setRpcBatchSize(1L);
 
         final FlowRpcAddTestInput flowRpcAddTestInput = flowRpcAddTestInputBuilder.build();
         final Future<RpcResult<Void>> resultFuture = salBulkFlowService.flowRpcAddTest(flowRpcAddTestInput);
@@ -209,18 +203,9 @@ public class SalBulkFlowServiceImplTest {
 
     @Test
     public void testFlowTest() throws Exception {
-        final FlowTestInputBuilder flowTestInputBuilder = new FlowTestInputBuilder()
-                .setBatchSize(1L)
-                .setDpnCount(1L)
-                .setEndTableId(2L)
-                .setFlowsPerDpn(1L)
-                .setIsAdd(true)
-                .setSeq(true)
-                .setSleepAfter(20L)
-                .setSleepFor(1L)
-                .setStartTableId(1L)
-                .setTxChain(true)
-                .setCreateParents(true);
+        final FlowTestInputBuilder flowTestInputBuilder = new FlowTestInputBuilder().setBatchSize(1L).setDpnCount(1L)
+                .setEndTableId(2L).setFlowsPerDpn(1L).setIsAdd(true).setSeq(true).setSleepAfter(20L).setSleepFor(1L)
+                .setStartTableId(1L).setTxChain(true).setCreateParents(true);
 
         FlowTestInput flowTestInput = flowTestInputBuilder.build();
 
@@ -254,12 +239,12 @@ public class SalBulkFlowServiceImplTest {
 
     @Test
     public void testFlowRpcAddMultiple() throws Exception {
-        when(rTx.read(Mockito.any(LogicalDatastoreType.class), Mockito.<InstanceIdentifier<Nodes>>any()))
-                .thenReturn(Futures.immediateCheckedFuture(Optional.of(mockNodes)));
+        when(readOnlyTransaction.read(Mockito.any(LogicalDatastoreType.class),
+                Mockito.<InstanceIdentifier<Nodes>>any()))
+                        .thenReturn(Futures.immediateCheckedFuture(Optional.of(mockNodes)));
 
         final FlowRpcAddMultipleInputBuilder flowRpcAddMultipleInputBuilder = new FlowRpcAddMultipleInputBuilder()
-                .setFlowCount(1L)
-                .setRpcBatchSize(1L);
+                .setFlowCount(1L).setRpcBatchSize(1L);
 
         final FlowRpcAddMultipleInput flowRpcAddMultipleInput = flowRpcAddMultipleInputBuilder.build();
 
@@ -268,11 +253,8 @@ public class SalBulkFlowServiceImplTest {
 
     @Test
     public void testTableTest() throws Exception {
-        final TableTestInputBuilder tableTestInputBuilder = new TableTestInputBuilder()
-                .setStartTableId(0L)
-                .setEndTableId(99L)
-                .setDpnCount(1L)
-                .setOperation(Operation.Add);
+        final TableTestInputBuilder tableTestInputBuilder = new TableTestInputBuilder().setStartTableId(0L)
+                .setEndTableId(99L).setDpnCount(1L).setOperation(Operation.Add);
 
         TableTestInput tableTestInput = tableTestInputBuilder.build();
 
@@ -283,4 +265,4 @@ public class SalBulkFlowServiceImplTest {
 
         Assert.assertTrue(salBulkFlowService.tableTest(tableTestInput).get().isSuccessful());
     }
-}
\ No newline at end of file
+}
index 775ecd08b47c8659f239218c58f46ee8efca6c30..2192ba4ba6ca574c02272e33d0a014d3a012dbd0 100644 (file)
@@ -18,9 +18,7 @@ import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mock;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.mockito.stubbing.Answer;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -46,35 +44,35 @@ public class TableWriterTest {
     @Mock
     private ExecutorService mockTablePusher;
     @Mock
-    private WriteTransaction wTx;
+    private WriteTransaction writeTransaction;
 
     private TableWriter tableWriter;
 
     @Before
     public void setUp() throws Exception {
 
-        doReturn(wTx).when(mockDataBroker).newWriteOnlyTransaction();
-        Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+        doReturn(writeTransaction).when(mockDataBroker).newWriteOnlyTransaction();
+        Mockito.when(writeTransaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
 
-        Mockito.doAnswer(new Answer<Void>() {
-            @Override
-            public Void answer(InvocationOnMock invocation) throws Throwable {
-                ((Runnable)invocation.getArguments()[0]).run();
-                return null;
-            }
+        Mockito.doAnswer(invocation -> {
+            ((Runnable) invocation.getArguments()[0]).run();
+            return null;
         }).when(mockTablePusher).execute(Matchers.<Runnable>any());
 
         tableWriter = new TableWriter(mockDataBroker, mockTablePusher);
     }
+
     @Test
     public void testAddTables() throws Exception {
         tableWriter.addTables(DPN_COUNT, START_TABLE_ID, END_TABLE_ID);
-        Mockito.verify(wTx, Mockito.times(TABLES_PER_DPN)).put(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
+        Mockito.verify(writeTransaction, Mockito.times(TABLES_PER_DPN)).put(Matchers.<LogicalDatastoreType>any(),
+                Matchers.<InstanceIdentifier<DataObject>>any(), Matchers.<DataObject>any(), Matchers.anyBoolean());
     }
 
     @Test
     public void testDeleteTables() throws Exception {
         tableWriter.deleteTables(DPN_COUNT, START_TABLE_ID, END_TABLE_ID);
-        Mockito.verify(wTx, Mockito.times(TABLES_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(), Matchers.<InstanceIdentifier<DataObject>>any());
+        Mockito.verify(writeTransaction, Mockito.times(TABLES_PER_DPN)).delete(Matchers.<LogicalDatastoreType>any(),
+                Matchers.<InstanceIdentifier<DataObject>>any());
     }
-}
\ No newline at end of file
+}