accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [3/6] git commit: ACCUMULO-2948 Use an AtomicInteger to any worry from multiple threads access pdCount concurrently.
Date Tue, 24 Jun 2014 18:39:50 GMT
ACCUMULO-2948 Use an AtomicInteger to any worry from multiple threads access pdCount concurrently.


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

Branch: refs/heads/master
Commit: 886cd19813052a64c190f80d92e52787c5ffc813
Parents: c3de15b
Author: Josh Elser <elserj@apache.org>
Authored: Tue Jun 24 14:07:04 2014 -0400
Committer: Josh Elser <elserj@apache.org>
Committed: Tue Jun 24 14:08:57 2014 -0400

----------------------------------------------------------------------
 .../accumulo/fate/zookeeper/ZooLockTest.java    | 31 ++++++++++----------
 1 file changed, 16 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/886cd198/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java b/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
index 717bf0a..40454f6 100644
--- a/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
+++ b/test/src/test/java/org/apache/accumulo/fate/zookeeper/ZooLockTest.java
@@ -19,6 +19,7 @@ package org.apache.accumulo.fate.zookeeper;
 import java.lang.reflect.Field;
 import java.util.Collections;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.accumulo.fate.zookeeper.ZooLock.AsyncLockWatcher;
 import org.apache.accumulo.fate.zookeeper.ZooLock.LockLossReason;
@@ -116,13 +117,13 @@ public class ZooLockTest {
     accumulo.start();
     
   }
-  
-  private static int pdCount = 0;
-  
+
+  private static final AtomicInteger pdCount = new AtomicInteger(0);
+
   @Test(timeout = 10000)
   public void testDeleteParent() throws Exception {
-    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-    
+    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount.incrementAndGet();
+
     ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(),
parent);
     
     Assert.assertFalse(zl.isLocked());
@@ -152,8 +153,8 @@ public class ZooLockTest {
   
   @Test(timeout = 10000)
   public void testNoParent() throws Exception {
-    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-    
+    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount.incrementAndGet();
+ 
     ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 30000, "digest", "secret".getBytes(),
parent);
     
     Assert.assertFalse(zl.isLocked());
@@ -172,8 +173,8 @@ public class ZooLockTest {
   
   @Test(timeout = 10000)
   public void testDeleteLock() throws Exception {
-    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-    
+    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount.incrementAndGet();
+ 
     ZooReaderWriter zk = ZooReaderWriter.getInstance(accumulo.getZooKeepers(), 30000, "digest",
"secret".getBytes());
     zk.mkdirs(parent);
     
@@ -203,8 +204,8 @@ public class ZooLockTest {
   
   @Test(timeout = 10000)
   public void testDeleteWaiting() throws Exception {
-    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-    
+    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount.incrementAndGet();
+ 
     ZooReaderWriter zk = ZooReaderWriter.getInstance(accumulo.getZooKeepers(), 30000, "digest",
"secret".getBytes());
     zk.mkdirs(parent);
     
@@ -269,7 +270,7 @@ public class ZooLockTest {
   
   @Test(timeout = 10000)
   public void testUnexpectedEvent() throws Exception {
-    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
+    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount.incrementAndGet();
 
     ConnectedWatcher watcher = new ConnectedWatcher();
     ZooKeeper zk = new ZooKeeper(accumulo.getZooKeepers(), 30000, watcher);
@@ -313,8 +314,8 @@ public class ZooLockTest {
   
   @Test(timeout = 10000)
   public void testTryLock() throws Exception {
-    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
-    
+    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount.incrementAndGet();
+
     ZooLock zl = new ZooLock(accumulo.getZooKeepers(), 1000, "digest", "secret".getBytes(),
parent);
     
     ConnectedWatcher watcher = new ConnectedWatcher();
@@ -350,7 +351,7 @@ public class ZooLockTest {
   
   @Test(timeout = 10000)
   public void testChangeData() throws Exception {
-    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount++;
+    String parent = "/zltest-" + this.hashCode() + "-l" + pdCount.incrementAndGet();
     ConnectedWatcher watcher = new ConnectedWatcher();
     ZooKeeper zk = new ZooKeeper(accumulo.getZooKeepers(), 1000, watcher);
     zk.addAuthInfo("digest", "secret".getBytes());


Mime
View raw message