cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [2/6] git commit: updated refs/heads/master to fac259f
Date Mon, 18 Jan 2016 15:00:53 GMT
Fix execution counter to support separate counts per thread


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c35c4164
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c35c4164
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c35c4164

Branch: refs/heads/master
Commit: c35c4164d94cd6c1878b841080e96ac073342ddd
Parents: 21d2423
Author: Miguel Ferreira <miguelferreira@me.com>
Authored: Thu Dec 17 19:47:08 2015 +0100
Committer: Miguel Ferreira <miguelferreira@me.com>
Committed: Mon Jan 18 09:24:32 2016 +0100

----------------------------------------------------------------------
 .../java/com/cloud/network/nicira/ExecutionCounter.java | 12 ++++++++----
 .../com/cloud/network/nicira/ExecutionCounterTest.java  |  2 ++
 2 files changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c35c4164/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ExecutionCounter.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ExecutionCounter.java
b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ExecutionCounter.java
index 1314498..7eedebb 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ExecutionCounter.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/ExecutionCounter.java
@@ -19,15 +19,19 @@
 
 package com.cloud.network.nicira;
 
-import java.util.concurrent.atomic.AtomicInteger;
-
 public class ExecutionCounter {
 
     private final int executionLimit;
-    private final AtomicInteger executionCount = new AtomicInteger(0);
+    private final ThreadLocal<Integer> executionCount;
 
     public ExecutionCounter(final int executionLimit) {
         this.executionLimit = executionLimit;
+        executionCount = new ThreadLocal<Integer>() {
+            @Override
+            protected Integer initialValue() {
+                return new Integer(0);
+            }
+        };
     }
 
     public ExecutionCounter resetExecutionCounter() {
@@ -40,7 +44,7 @@ public class ExecutionCounter {
     }
 
     public ExecutionCounter incrementExecutionCounter() {
-        executionCount.incrementAndGet();
+        executionCount.set(executionCount.get() + 1);
         return this;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c35c4164/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
index f063b75..b14694d 100644
--- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
+++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/nicira/ExecutionCounterTest.java
@@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.equalTo;
 
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.junit.Test;
@@ -92,6 +93,7 @@ public class ExecutionCounterTest {
         executorService.execute(task3);
 
         executorService.shutdown();
+        executorService.awaitTermination(5L, TimeUnit.SECONDS);
 
         assertThat(counterTask1.get(), equalTo(4));
         assertThat(counterTask2.get(), equalTo(2));


Mime
View raw message