You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2013/12/29 00:44:11 UTC
svn commit: r1553976 - in
/lucene/dev/branches/lucene_solr_4_6/solr/core/src/test/org/apache/solr/cloud:
DeleteInactiveReplicaTest.java DeleteReplicaTest.java
Author: markrmiller
Date: Sat Dec 28 23:44:11 2013
New Revision: 1553976
URL: http://svn.apache.org/r1553976
Log:
merge back latest delete replica tests
Modified:
lucene/dev/branches/lucene_solr_4_6/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java
lucene/dev/branches/lucene_solr_4_6/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java
Modified: lucene/dev/branches/lucene_solr_4_6/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_6/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java?rev=1553976&r1=1553975&r2=1553976&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_6/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java (original)
+++ lucene/dev/branches/lucene_solr_4_6/solr/core/src/test/org/apache/solr/cloud/DeleteInactiveReplicaTest.java Sat Dec 28 23:44:11 2013
@@ -17,6 +17,11 @@ package org.apache.solr.cloud;
* limitations under the License.
*/
+import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
+
+import java.net.URL;
+import java.util.Map;
+
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
@@ -27,34 +32,46 @@ import org.apache.solr.common.cloud.Slic
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.MapSolrParams;
import org.apache.solr.common.util.NamedList;
-
-import java.net.URL;
-import java.util.Map;
-import java.util.Random;
-import java.util.concurrent.Future;
-
-import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
+import org.junit.After;
+import org.junit.Before;
public class DeleteInactiveReplicaTest extends DeleteReplicaTest{
+ private CloudSolrServer client;
+
@Override
public void doTest() throws Exception {
deleteInactiveReplicaTest();
}
- private void deleteInactiveReplicaTest() throws Exception{
- String COLL_NAME = "delDeadColl";
- CloudSolrServer client = createCloudClient(null);
- createCloudClient(null);
- createColl(COLL_NAME, client);
-
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ client = createCloudClient(null);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+ client.shutdown();
+ }
+
+ private void deleteInactiveReplicaTest() throws Exception {
+ String collectionName = "delDeadColl";
+
+ createCollection(collectionName, client);
+
+ waitForRecoveriesToFinish(collectionName, false);
+
boolean stopped = false;
JettySolrRunner stoppedJetty = null;
StringBuilder sb = new StringBuilder();
- Replica replica1=null;
+ Replica replica1 = null;
Slice shard1 = null;
- DocCollection testcoll = getCommonCloudSolrServer().getZkStateReader().getClusterState().getCollection(COLL_NAME);
- for (JettySolrRunner jetty : jettys) sb.append(jetty.getBaseUrl()).append(",");
-
+ DocCollection testcoll = getCommonCloudSolrServer().getZkStateReader()
+ .getClusterState().getCollection(collectionName);
+ for (JettySolrRunner jetty : jettys)
+ sb.append(jetty.getBaseUrl()).append(",");
+
for (Slice slice : testcoll.getActiveSlices()) {
for (Replica replica : slice.getReplicas())
for (JettySolrRunner jetty : jettys) {
@@ -64,7 +81,8 @@ public class DeleteInactiveReplicaTest e
} catch (Exception e) {
continue;
}
- if (baseUrl.toString().startsWith(replica.getStr(ZkStateReader.BASE_URL_PROP))) {
+ if (baseUrl.toString().startsWith(
+ replica.getStr(ZkStateReader.BASE_URL_PROP))) {
stoppedJetty = jetty;
ChaosMonkey.stop(jetty);
replica1 = replica;
@@ -74,48 +92,48 @@ public class DeleteInactiveReplicaTest e
}
}
}
-
- /*final Slice shard1 = testcoll.getSlices().iterator().next();
- if(!shard1.getState().equals(Slice.ACTIVE)) fail("shard is not active");
- Replica replica1 = shard1.getReplicas().iterator().next();
- JettySolrRunner stoppedJetty = null;
- StringBuilder sb = new StringBuilder();
- for (JettySolrRunner jetty : jettys) {
- sb.append(jetty.getBaseUrl()).append(",");
- if( jetty.getBaseUrl().toString().startsWith(replica1.getStr(ZkStateReader.BASE_URL_PROP)) ) {
- stoppedJetty = jetty;
- ChaosMonkey.stop(jetty);
- stopped = true;
- break;
- }
- }*/
- if(!stopped){
- fail("Could not find jetty to stop in collection "+ testcoll + " jettys: "+sb);
+
+ /*
+ * final Slice shard1 = testcoll.getSlices().iterator().next();
+ * if(!shard1.getState().equals(Slice.ACTIVE)) fail("shard is not active");
+ * Replica replica1 = shard1.getReplicas().iterator().next();
+ * JettySolrRunner stoppedJetty = null; StringBuilder sb = new
+ * StringBuilder(); for (JettySolrRunner jetty : jettys) {
+ * sb.append(jetty.getBaseUrl()).append(","); if(
+ * jetty.getBaseUrl().toString
+ * ().startsWith(replica1.getStr(ZkStateReader.BASE_URL_PROP)) ) {
+ * stoppedJetty = jetty; ChaosMonkey.stop(jetty); stopped = true; break; } }
+ */
+ if (!stopped) {
+ fail("Could not find jetty to stop in collection " + testcoll
+ + " jettys: " + sb);
}
-
- long endAt = System.currentTimeMillis()+3000;
+
+ long endAt = System.currentTimeMillis() + 3000;
boolean success = false;
- while(System.currentTimeMillis() < endAt){
- testcoll = getCommonCloudSolrServer().getZkStateReader().getClusterState().getCollection(COLL_NAME);
- if(!"active".equals(testcoll.getSlice(shard1.getName()).getReplica(replica1.getName()).getStr(Slice.STATE)) ){
- success=true;
+ while (System.currentTimeMillis() < endAt) {
+ testcoll = getCommonCloudSolrServer().getZkStateReader()
+ .getClusterState().getCollection(collectionName);
+ if (!"active".equals(testcoll.getSlice(shard1.getName())
+ .getReplica(replica1.getName()).getStr(Slice.STATE))) {
+ success = true;
}
- if(success) break;
+ if (success) break;
Thread.sleep(100);
}
- log.info("removed_replicas {}/{} ",shard1.getName(),replica1.getName());
- removeAndWaitForReplicaGone(COLL_NAME, client, replica1, shard1.getName());
- client.shutdown();
-
+ log.info("removed_replicas {}/{} ", shard1.getName(), replica1.getName());
+ removeAndWaitForReplicaGone(collectionName, client, replica1,
+ shard1.getName());
+
ChaosMonkey.start(stoppedJetty);
log.info("restarted jetty");
-
-
- Map m = makeMap("qt","/admin/cores",
- "action", "status");
-
- NamedList<Object> resp = new HttpSolrServer(replica1.getStr("base_url")).request(new QueryRequest(new MapSolrParams(m)));
- assertNull( "The core is up and running again" , ((NamedList)resp.get("status")).get(replica1.getStr("core")));
-
+
+ Map m = makeMap("qt", "/admin/cores", "action", "status");
+
+ NamedList<Object> resp = new HttpSolrServer(replica1.getStr("base_url"))
+ .request(new QueryRequest(new MapSolrParams(m)));
+ assertNull("The core is up and running again",
+ ((NamedList) resp.get("status")).get(replica1.getStr("core")));
+
}
}
Modified: lucene/dev/branches/lucene_solr_4_6/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_4_6/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java?rev=1553976&r1=1553975&r2=1553976&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_4_6/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java (original)
+++ lucene/dev/branches/lucene_solr_4_6/solr/core/src/test/org/apache/solr/cloud/DeleteReplicaTest.java Sat Dec 28 23:44:11 2013
@@ -17,55 +17,36 @@ package org.apache.solr.cloud;
* limitations under the License.
*/
-import org.apache.lucene.util.Constants;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.DELETEREPLICA;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.MAX_SHARDS_PER_NODE;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
+import static org.apache.solr.cloud.OverseerCollectionProcessor.REPLICATION_FACTOR;
+import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
-import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.request.QueryRequest;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.params.MapSolrParams;
-import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.update.SolrCmdDistributor;
-import org.apache.solr.util.DefaultSolrThreadFactory;
+import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CompletionService;
-import java.util.concurrent.ExecutorCompletionService;
-import java.util.concurrent.Future;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-import static org.apache.solr.cloud.OverseerCollectionProcessor.DELETEREPLICA;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.MAX_SHARDS_PER_NODE;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.NUM_SLICES;
-import static org.apache.solr.cloud.OverseerCollectionProcessor.REPLICATION_FACTOR;
-import static org.apache.solr.common.cloud.ZkNodeProps.makeMap;
-
public class DeleteReplicaTest extends AbstractFullDistribZkTestBase {
- private static final boolean DEBUG = false;
-
- ThreadPoolExecutor executor = new ThreadPoolExecutor(0,
- Integer.MAX_VALUE, 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
- new DefaultSolrThreadFactory("testExecutor"));
-
- CompletionService<Object> completionService;
- Set<Future<Object>> pending;
-
+ private CloudSolrServer client;
+
@BeforeClass
public static void beforeThisClass2() throws Exception {
- assumeFalse("FIXME: This test fails under Java 8 all the time, see SOLR-4711", Constants.JRE_IS_MINIMUM_JAVA8);
+
}
@Before
@@ -74,87 +55,85 @@ public class DeleteReplicaTest extends A
super.setUp();
System.setProperty("numShards", Integer.toString(sliceCount));
System.setProperty("solr.xml.persist", "true");
+ client = createCloudClient(null);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ super.tearDown();
+ client.shutdown();
}
protected String getSolrXml() {
return "solr-no-core.xml";
}
-
public DeleteReplicaTest() {
fixShardCount = true;
sliceCount = 2;
shardCount = 4;
- completionService = new ExecutorCompletionService<Object>(executor);
- pending = new HashSet<Future<Object>>();
- checkCreatedVsState = false;
+ checkCreatedVsState = false;
}
@Override
- protected void setDistributedParams(ModifiableSolrParams params) {
-
- if (r.nextBoolean()) {
- // don't set shards, let that be figured out from the cloud state
- } else {
- // use shard ids rather than physical locations
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < shardCount; i++) {
- if (i > 0)
- sb.append(',');
- sb.append("shard" + (i + 3));
- }
- params.set("shards", sb.toString());
- }
- }
-
-
- @Override
public void doTest() throws Exception {
deleteLiveReplicaTest();
-// deleteInactiveReplicaTest();
-// super.printLayout();
}
-
-
- private void deleteLiveReplicaTest() throws Exception{
- String COLL_NAME = "delLiveColl";
+ private void deleteLiveReplicaTest() throws Exception {
+ String collectionName = "delLiveColl";
CloudSolrServer client = createCloudClient(null);
- createColl(COLL_NAME, client);
- DocCollection testcoll = getCommonCloudSolrServer().getZkStateReader().getClusterState().getCollection(COLL_NAME);
- final Slice shard1 = testcoll.getSlices().iterator().next();
- if(!shard1.getState().equals(Slice.ACTIVE)) fail("shard is not active");
- boolean found = false;
- Replica replica1 = null;
- for (Replica replica : shard1.getReplicas()) if("active".equals(replica.getStr("state"))) replica1 =replica;
-
- if(replica1 == null) fail("no active relicas found");
-
- removeAndWaitForReplicaGone(COLL_NAME, client, replica1, shard1.getName());
- client.shutdown();
-
-
+ try {
+ createCollection(collectionName, client);
+
+ waitForRecoveriesToFinish(collectionName, false);
+
+ DocCollection testcoll = getCommonCloudSolrServer().getZkStateReader()
+ .getClusterState().getCollection(collectionName);
+
+ Slice shard1 = null;
+ Replica replica1 = null;
+ for (Slice slice : testcoll.getSlices()) {
+ if ("active".equals(slice.getStr("state"))) {
+ shard1 = slice;
+ for (Replica replica : shard1.getReplicas())
+ if ("active".equals(replica.getStr("state"))) replica1 = replica;
+ }
+ }
+ // final Slice shard1 = testcoll.getSlices().iterator().next();
+ // if(!shard1.getState().equals(Slice.ACTIVE))
+ // fail("shard is not active");
+ // for (Replica replica : shard1.getReplicas())
+ // if("active".equals(replica.getStr("state"))) replica1 =replica;
+ if (replica1 == null) fail("no active replicas found");
+ removeAndWaitForReplicaGone(collectionName, client, replica1,
+ shard1.getName());
+ } finally {
+ client.shutdown();
+ }
}
- protected void removeAndWaitForReplicaGone(String COLL_NAME, CloudSolrServer client, Replica replica, String shard) throws SolrServerException, IOException, InterruptedException {
- Map m = makeMap("collection", COLL_NAME,
- "action", DELETEREPLICA,
- "shard",shard,
- "replica",replica.getName());
- SolrParams params = new MapSolrParams( m);
+ protected void removeAndWaitForReplicaGone(String COLL_NAME,
+ CloudSolrServer client, Replica replica, String shard)
+ throws SolrServerException, IOException, InterruptedException {
+ Map m = makeMap("collection", COLL_NAME, "action", DELETEREPLICA, "shard",
+ shard, "replica", replica.getName());
+ SolrParams params = new MapSolrParams(m);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
client.request(request);
- long endAt = System.currentTimeMillis()+3000;
+ long endAt = System.currentTimeMillis() + 3000;
boolean success = false;
DocCollection testcoll = null;
- while(System.currentTimeMillis() < endAt){
- testcoll = getCommonCloudSolrServer().getZkStateReader().getClusterState().getCollection(COLL_NAME);
+ while (System.currentTimeMillis() < endAt) {
+ testcoll = getCommonCloudSolrServer().getZkStateReader()
+ .getClusterState().getCollection(COLL_NAME);
success = testcoll.getSlice(shard).getReplica(replica.getName()) == null;
- if(success) {
- log.info("replica cleaned up {}/{} core {}",shard+"/"+replica.getName(), replica.getStr("core"));
+ if (success) {
+ log.info("replica cleaned up {}/{} core {}",
+ shard + "/" + replica.getName(), replica.getStr("core"));
log.info("current state {}", testcoll);
break;
}
@@ -163,7 +142,7 @@ public class DeleteReplicaTest extends A
assertTrue("Replica not cleaned up", success);
}
- protected void createColl(String COLL_NAME, CloudSolrServer client) throws Exception {
+ protected void createCollection(String COLL_NAME, CloudSolrServer client) throws Exception {
int replicationFactor = 2;
int numShards = 2;
int maxShardsPerNode = ((((numShards+1) * replicationFactor) / getCommonCloudSolrServer()
@@ -175,15 +154,5 @@ public class DeleteReplicaTest extends A
NUM_SLICES, numShards);
Map<String,List<Integer>> collectionInfos = new HashMap<String,List<Integer>>();
createCollection(collectionInfos, COLL_NAME, props, client);
- Set<Map.Entry<String,List<Integer>>> collectionInfosEntrySet = collectionInfos.entrySet();
- for (Map.Entry<String,List<Integer>> entry : collectionInfosEntrySet) {
- String collection = entry.getKey();
- List<Integer> list = entry.getValue();
- checkForCollection(collection, list, null);
- String url = getUrlFromZk(getCommonCloudSolrServer().getZkStateReader().getClusterState(), collection);
- HttpSolrServer collectionClient = new HttpSolrServer(url);
- // poll for a second - it can take a moment before we are ready to serve
- waitForNon403or404or503(collectionClient);
- }
}
}