lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r1210711 - /lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java
Date Mon, 05 Dec 2011 23:35:19 GMT
Author: markrmiller
Date: Mon Dec  5 23:35:19 2011
New Revision: 1210711

URL: http://svn.apache.org/viewvc?rev=1210711&view=rev
Log:
attempt to fix test failure where seq would sometimes be -1 instead of 0

Modified:
    lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java

Modified: lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java?rev=1210711&r1=1210710&r2=1210711&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java
(original)
+++ lucene/dev/branches/solrcloud/solr/core/src/test/org/apache/solr/cloud/LeaderElectionTest.java
Mon Dec  5 23:35:19 2011
@@ -72,6 +72,7 @@ public class LeaderElectionTest extends 
     SolrZkClient zkClient;
     private int nodeNumber;
     private int seq = -1;
+    private volatile boolean stop;
     
     public ClientThread(int nodeNumber) throws Exception {
       super("Thread-" + nodeNumber);
@@ -81,26 +82,36 @@ public class LeaderElectionTest extends 
     
     @Override
     public void run() {
-      try {
+      
         LeaderElector elector = new LeaderElector(zkClient);
         
-        ElectionContext context = new ShardLeaderElectionContext("shard1", "collection1",
Integer.toString(nodeNumber), null);
+        ElectionContext context = new ShardLeaderElectionContext("shard1",
+            "collection1", Integer.toString(nodeNumber), null);
         
-        elector.setup(context);
-        seq = elector.joinElection(context);
-        seqToThread.put(seq, this);
-        // run forever - we will be explicitly killed
-        Thread.sleep(Integer.MAX_VALUE);
-      } catch (Throwable e) {
-
+        try {
+          elector.setup(context);
+          
+          seq = elector.joinElection(context);
+          seqToThread.put(seq, this);
+        } catch (Exception e) {
+          e.printStackTrace();
+        }
+        
+      while (!stop) {
+        try {
+          Thread.sleep(100);
+        } catch (InterruptedException e) {
+          e.printStackTrace();
+        }
       }
+      
     }
     
     public void close() throws InterruptedException {
       if (!zkClient.isClosed()) {
         zkClient.close();
       }
-      this.stop();
+      this.stop = true;
     }
   }
   
@@ -151,7 +162,6 @@ public class LeaderElectionTest extends 
     int leaderThread = Integer.parseInt(getLeader());
     
     // whoever the leader is, should be the n_0 seq
-    // TODO: seen this fail by seq being -1
     assertEquals(0, threads.get(leaderThread).seq);
     
     // kill n_0, 1, 3 and 4



Mime
View raw message