Explorar o código

ZOOKEEPER-305. Replace timers with semaphores in FLENewEpochTest. (flavio via mahadev)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/zookeeper/trunk@761126 13f79535-47bb-0310-9956-ffa450edef68
Mahadev Konar %!s(int64=16) %!d(string=hai) anos
pai
achega
8aeade991c
Modificáronse 2 ficheiros con 16 adicións e 4 borrados
  1. 3 0
      CHANGES.txt
  2. 13 4
      src/java/test/org/apache/zookeeper/test/FLENewEpochTest.java

+ 3 - 0
CHANGES.txt

@@ -60,6 +60,9 @@ mahadev)
   ZOOKEEPER-349. to automate patch testing. (giridharan kesavan via mahadev)
   ZOOKEEPER-349. to automate patch testing. (giridharan kesavan via mahadev)
 
 
   ZOOKEEPER-288. Cleanup and fixes to BookKeeper (flavio via mahadev)
   ZOOKEEPER-288. Cleanup and fixes to BookKeeper (flavio via mahadev)
+ 
+  ZOOKEEPER-305.  Replace timers with semaphores in FLENewEpochTest.
+(flavio via mahadev)
 
 
 NEW FEATURES:
 NEW FEATURES:
 
 

+ 13 - 4
src/java/test/org/apache/zookeeper/test/FLENewEpochTest.java

@@ -22,6 +22,7 @@ import java.io.File;
 import java.net.InetSocketAddress;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashMap;
+import java.util.concurrent.Semaphore;
 
 
 import junit.framework.TestCase;
 import junit.framework.TestCase;
 
 
@@ -45,6 +46,9 @@ public class FLENewEpochTest extends TestCase {
     int port[];
     int port[];
     volatile int [] round;
     volatile int [] round;
     
     
+    Semaphore start0;
+    Semaphore finish3;
+    
     @Override
     @Override
     public void setUp() throws Exception {
     public void setUp() throws Exception {
         count = 3;
         count = 3;
@@ -60,6 +64,10 @@ public class FLENewEpochTest extends TestCase {
         round[0] = 0;
         round[0] = 0;
         round[1] = 0;
         round[1] = 0;
         round[2] = 0;
         round[2] = 0;
+        
+        start0 = new Semaphore(0);
+        finish3 = new Semaphore(0);
+        
         LOG.info("SetUp " + getName());
         LOG.info("SetUp " + getName());
     }
     }
 
 
@@ -115,9 +123,8 @@ public class FLENewEpochTest extends TestCase {
             			LOG.info("Second entering case");
             			LOG.info("Second entering case");
             			if(round[1] != 0) flag = false;
             			if(round[1] != 0) flag = false;
             			else{
             			else{
-            				while(round[2] == 0){
-            					Thread.sleep(200);
-            				}
+            				finish3.acquire();
+            				start0.release();
             			}
             			}
             			LOG.info("Second is going to start second round");
             			LOG.info("Second is going to start second round");
             			round[1]++;
             			round[1]++;
@@ -128,6 +135,7 @@ public class FLENewEpochTest extends TestCase {
             			peer.shutdown();
             			peer.shutdown();
             			flag = false;
             			flag = false;
             			round[2] = 1;
             			round[2] = 1;
+            			finish3.release();
             			LOG.info("Third leaving");
             			LOG.info("Third leaving");
             			break;
             			break;
             		}
             		}
@@ -159,7 +167,8 @@ public class FLENewEpochTest extends TestCase {
               thread.start();
               thread.start();
               threads.add(thread);
               threads.add(thread);
           }
           }
-          Thread.sleep(2000);
+          start0.acquire();
+
           QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 2, 2, 2);
           QuorumPeer peer = new QuorumPeer(peers, tmpdir[0], tmpdir[0], port[0], 3, 0, 2, 2, 2);
           peer.startLeaderElection();
           peer.startLeaderElection();
           LEThread thread = new LEThread(peer, 0);
           LEThread thread = new LEThread(peer, 0);