You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2015/02/09 00:53:25 UTC
svn commit: r1658277 [25/38] - in /lucene/dev/branches/lucene6005: ./
dev-tools/ dev-tools/idea/solr/contrib/dataimporthandler/
dev-tools/idea/solr/contrib/velocity/ dev-tools/maven/lucene/replicator/
dev-tools/maven/solr/ dev-tools/maven/solr/contrib/...
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/AliasIntegrationTest.java Sun Feb 8 23:53:14 2015
@@ -33,10 +33,11 @@ import org.apache.solr.common.SolrExcept
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.CollectionParams.CollectionAction;
import org.apache.solr.common.params.ModifiableSolrParams;
-import org.junit.After;
import org.junit.AfterClass;
-import org.junit.Before;
import org.junit.BeforeClass;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
@@ -48,6 +49,8 @@ import java.util.List;
*/
@Slow
public class AliasIntegrationTest extends AbstractFullDistribZkTestBase {
+
+ private static final Logger logger = LoggerFactory.getLogger(AliasIntegrationTest.class);
@BeforeClass
public static void beforeSuperClass() throws Exception {
@@ -58,34 +61,28 @@ public class AliasIntegrationTest extend
}
- @Before
@Override
- public void setUp() throws Exception {
- super.setUp();
+ public void distribSetUp() throws Exception {
+ super.distribSetUp();
System.setProperty("numShards", Integer.toString(sliceCount));
}
-
- @Override
- @After
- public void tearDown() throws Exception {
- super.tearDown();
- resetExceptionIgnores();
- }
-
+
public AliasIntegrationTest() {
super();
sliceCount = 1;
- shardCount = random().nextBoolean() ? 3 : 4;
+ fixShardCount(random().nextBoolean() ? 3 : 4);
}
- @Override
- public void doTest() throws Exception {
-
+ @Test
+ public void test() throws Exception {
+
handle.clear();
handle.put("timestamp", SKIPVAL);
-
+
waitForThingsToLevelOut(30);
+ logger.info("### STARTING ACTUAL TEST");
+
del("*:*");
createCollection("collection2", 2, 1, 10);
@@ -137,60 +134,55 @@ public class AliasIntegrationTest extend
query.set("collection", "testalias");
JettySolrRunner jetty = jettys.get(random().nextInt(jettys.size()));
int port = jetty.getLocalPort();
- HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias");
- res = client.query(query);
- assertEquals(3, res.getResults().getNumFound());
- client.shutdown();
- client = null;
-
+ try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
+ res = client.query(query);
+ assertEquals(3, res.getResults().getNumFound());
+ }
+
// now without collections param
query = new SolrQuery("*:*");
jetty = jettys.get(random().nextInt(jettys.size()));
port = jetty.getLocalPort();
- client = new HttpSolrClient(buildUrl(port) + "/testalias");
- res = client.query(query);
- assertEquals(3, res.getResults().getNumFound());
- client.shutdown();
- client = null;
-
+ try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
+ res = client.query(query);
+ assertEquals(3, res.getResults().getNumFound());
+ }
// create alias, collection2 first because it's not on every node
createAlias("testalias", "collection2,collection1");
// search with new cloud client
- CloudSolrClient cloudSolrClient = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean());
- cloudSolrClient.setParallelUpdates(random().nextBoolean());
- query = new SolrQuery("*:*");
- query.set("collection", "testalias");
- res = cloudSolrClient.query(query);
- assertEquals(5, res.getResults().getNumFound());
-
- // Try with setDefaultCollection
- query = new SolrQuery("*:*");
- cloudSolrClient.setDefaultCollection("testalias");
- res = cloudSolrClient.query(query);
- cloudSolrClient.shutdown();
- assertEquals(5, res.getResults().getNumFound());
-
+ try (CloudSolrClient cloudSolrClient = new CloudSolrClient(zkServer.getZkAddress(), random().nextBoolean())) {
+ cloudSolrClient.setParallelUpdates(random().nextBoolean());
+ query = new SolrQuery("*:*");
+ query.set("collection", "testalias");
+ res = cloudSolrClient.query(query);
+ assertEquals(5, res.getResults().getNumFound());
+
+ // Try with setDefaultCollection
+ query = new SolrQuery("*:*");
+ cloudSolrClient.setDefaultCollection("testalias");
+ res = cloudSolrClient.query(query);
+ assertEquals(5, res.getResults().getNumFound());
+ }
+
// search for alias with random non cloud client
query = new SolrQuery("*:*");
query.set("collection", "testalias");
jetty = jettys.get(random().nextInt(jettys.size()));
port = jetty.getLocalPort();
- client = new HttpSolrClient(buildUrl(port) + "/testalias");
- res = client.query(query);
- assertEquals(5, res.getResults().getNumFound());
-
-
+ try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
+ res = client.query(query);
+ assertEquals(5, res.getResults().getNumFound());
+ }
// now without collections param
query = new SolrQuery("*:*");
jetty = jettys.get(random().nextInt(jettys.size()));
port = jetty.getLocalPort();
- client = new HttpSolrClient(buildUrl(port) + "/testalias");
- res = client.query(query);
- assertEquals(5, res.getResults().getNumFound());
- client.shutdown();
- client = null;
-
+ try (HttpSolrClient client = new HttpSolrClient(buildUrl(port) + "/testalias")) {
+ res = client.query(query);
+ assertEquals(5, res.getResults().getNumFound());
+ }
+
// update alias
createAlias("testalias", "collection2");
//checkForAlias("testalias", "collection2");
@@ -213,26 +205,24 @@ public class AliasIntegrationTest extend
// try a std client
// search 1 and 2, but have no collections param
query = new SolrQuery("*:*");
- HttpSolrClient httpclient = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias");
- res = httpclient.query(query);
- assertEquals(5, res.getResults().getNumFound());
- httpclient.shutdown();
- httpclient = null;
-
+ try (HttpSolrClient client = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) {
+ res = client.query(query);
+ assertEquals(5, res.getResults().getNumFound());
+ }
+
createAlias("testalias", "collection2");
// a second alias
createAlias("testalias2", "collection2");
-
- httpclient = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias");
- SolrInputDocument doc8 = getDoc(id, 11, i1, -600, tlong, 600, t1,
- "humpty dumpy4 sat on a walls");
- httpclient.add(doc8);
- httpclient.commit();
- res = httpclient.query(query);
- assertEquals(3, res.getResults().getNumFound());
- httpclient.shutdown();
- httpclient = null;
+
+ try (HttpSolrClient client = new HttpSolrClient(getBaseUrl((HttpSolrClient) clients.get(0)) + "/testalias")) {
+ SolrInputDocument doc8 = getDoc(id, 11, i1, -600, tlong, 600, t1,
+ "humpty dumpy4 sat on a walls");
+ client.add(doc8);
+ client.commit();
+ res = client.query(query);
+ assertEquals(3, res.getResults().getNumFound());
+ }
createAlias("testalias", "collection2,collection1");
@@ -251,46 +241,47 @@ public class AliasIntegrationTest extend
sawException = true;
}
assertTrue(sawException);
+
+ logger.info("### FINISHED ACTUAL TEST");
}
private void createAlias(String alias, String collections)
throws SolrServerException, IOException {
- SolrClient client = createNewSolrClient("",
- getBaseUrl((HttpSolrClient) clients.get(0)));
- if (random().nextBoolean()) {
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.set("collections", collections);
- params.set("name", alias);
- params.set("action", CollectionAction.CREATEALIAS.toString());
- QueryRequest request = new QueryRequest(params);
- request.setPath("/admin/collections");
- client.request(request);
- } else {
- CreateAlias request = new CreateAlias();
- request.setAliasName(alias);
- request.setAliasedCollections(collections);
- request.process(client);
+
+ try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
+ if (random().nextBoolean()) {
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.set("collections", collections);
+ params.set("name", alias);
+ params.set("action", CollectionAction.CREATEALIAS.toString());
+ QueryRequest request = new QueryRequest(params);
+ request.setPath("/admin/collections");
+ client.request(request);
+ } else {
+ CreateAlias request = new CreateAlias();
+ request.setAliasName(alias);
+ request.setAliasedCollections(collections);
+ request.process(client);
+ }
}
- client.shutdown();
}
private void deleteAlias(String alias) throws SolrServerException,
IOException {
- SolrClient client = createNewSolrClient("",
- getBaseUrl((HttpSolrClient) clients.get(0)));
- if (random().nextBoolean()) {
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.set("name", alias);
- params.set("action", CollectionAction.DELETEALIAS.toString());
- QueryRequest request = new QueryRequest(params);
- request.setPath("/admin/collections");
- client.request(request);
- } else {
- DeleteAlias request = new DeleteAlias();
- request.setAliasName(alias);
- request.process(client);
+ try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
+ if (random().nextBoolean()) {
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.set("name", alias);
+ params.set("action", CollectionAction.DELETEALIAS.toString());
+ QueryRequest request = new QueryRequest(params);
+ request.setPath("/admin/collections");
+ client.request(request);
+ } else {
+ DeleteAlias request = new DeleteAlias();
+ request.setAliasName(alias);
+ request.process(client);
+ }
}
- client.shutdown();
}
protected void indexDoc(List<CloudJettyRunner> skipServers, Object... fields) throws IOException,
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/AsyncMigrateRouteKeyTest.java Sun Feb 8 23:53:14 2015
@@ -24,7 +24,7 @@ import org.apache.solr.client.solrj.requ
import org.apache.solr.common.params.CollectionParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
-import org.junit.Before;
+import org.junit.Test;
import java.io.IOException;
@@ -36,13 +36,8 @@ public class AsyncMigrateRouteKeyTest ex
private static final int MAX_WAIT_SECONDS = 2 * 60;
- @Override
- @Before
- public void setUp() throws Exception {
- super.setUp();
- }
-
- public void doTest() throws Exception {
+ @Test
+ public void test() throws Exception {
waitForThingsToLevelOut(15);
multipleShardMigrateTest();
@@ -117,14 +112,9 @@ public class AsyncMigrateRouteKeyTest ex
.getBaseURL();
baseUrl = baseUrl.substring(0, baseUrl.length() - "collection1".length());
- HttpSolrClient baseServer = null;
-
- try {
- baseServer = new HttpSolrClient(baseUrl);
+ try (HttpSolrClient baseServer = new HttpSolrClient(baseUrl)) {
baseServer.setConnectionTimeout(15000);
return baseServer.request(request);
- } finally {
- baseServer.shutdown();
}
}
}
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZk2Test.java Sun Feb 8 23:53:14 2015
@@ -38,6 +38,7 @@ import org.apache.solr.common.params.Com
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.handler.ReplicationHandler;
+import org.junit.Test;
import java.io.File;
import java.io.FilenameFilter;
@@ -58,21 +59,12 @@ public class BasicDistributedZk2Test ext
public BasicDistributedZk2Test() {
super();
- fixShardCount = true;
-
sliceCount = 2;
- shardCount = 4;
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.solr.BaseDistributedSearchTestCase#doTest()
- *
- * Create 3 shards, each with one replica
- */
- @Override
- public void doTest() throws Exception {
+ @Test
+ @ShardsFixed(num = 4)
+ public void test() throws Exception {
boolean testFinished = false;
try {
handle.clear();
@@ -156,11 +148,9 @@ public class BasicDistributedZk2Test ext
}
- private void testNodeWithoutCollectionForwarding() throws Exception,
- SolrServerException, IOException {
- try {
- final String baseUrl = getBaseUrl((HttpSolrClient) clients.get(0));
- HttpSolrClient client = new HttpSolrClient(baseUrl);
+ private void testNodeWithoutCollectionForwarding() throws Exception {
+ final String baseUrl = getBaseUrl((HttpSolrClient) clients.get(0));
+ try (HttpSolrClient client = new HttpSolrClient(baseUrl)) {
client.setConnectionTimeout(30000);
Create createCmd = new Create();
createCmd.setRoles("none");
@@ -169,7 +159,6 @@ public class BasicDistributedZk2Test ext
createCmd.setNumShards(1);
createCmd.setDataDir(getDataDir(createTempDir(ONE_NODE_COLLECTION).toFile().getAbsolutePath()));
client.request(createCmd);
- client.shutdown();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
@@ -182,8 +171,8 @@ public class BasicDistributedZk2Test ext
int docs = 2;
for (SolrClient client : clients) {
- final String baseUrl = getBaseUrl((HttpSolrClient) client);
- addAndQueryDocs(baseUrl, docs);
+ final String clientUrl = getBaseUrl((HttpSolrClient) client);
+ addAndQueryDocs(clientUrl, docs);
docs += 2;
}
}
@@ -191,36 +180,39 @@ public class BasicDistributedZk2Test ext
// 2 docs added every call
private void addAndQueryDocs(final String baseUrl, int docs)
throws Exception {
- HttpSolrClient qclient = new HttpSolrClient(baseUrl + "/onenodecollection" + "core");
-
- // it might take a moment for the proxy node to see us in their cloud state
- waitForNon403or404or503(qclient);
-
- // add a doc
- SolrInputDocument doc = new SolrInputDocument();
- doc.addField("id", docs);
- qclient.add(doc);
- qclient.commit();
-
+
SolrQuery query = new SolrQuery("*:*");
- QueryResponse results = qclient.query(query);
- assertEquals(docs - 1, results.getResults().getNumFound());
- qclient.shutdown();
-
- qclient = new HttpSolrClient(baseUrl + "/onenodecollection");
- results = qclient.query(query);
- assertEquals(docs - 1, results.getResults().getNumFound());
-
- doc = new SolrInputDocument();
- doc.addField("id", docs + 1);
- qclient.add(doc);
- qclient.commit();
-
- query = new SolrQuery("*:*");
- query.set("rows", 0);
- results = qclient.query(query);
- assertEquals(docs, results.getResults().getNumFound());
- qclient.shutdown();
+
+ try (HttpSolrClient qclient = new HttpSolrClient(baseUrl + "/onenodecollection" + "core")) {
+
+ // it might take a moment for the proxy node to see us in their cloud state
+ waitForNon403or404or503(qclient);
+
+ // add a doc
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.addField("id", docs);
+ qclient.add(doc);
+ qclient.commit();
+
+
+ QueryResponse results = qclient.query(query);
+ assertEquals(docs - 1, results.getResults().getNumFound());
+ }
+
+ try (HttpSolrClient qclient = new HttpSolrClient(baseUrl + "/onenodecollection")) {
+ QueryResponse results = qclient.query(query);
+ assertEquals(docs - 1, results.getResults().getNumFound());
+
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.addField("id", docs + 1);
+ qclient.add(doc);
+ qclient.commit();
+
+ query = new SolrQuery("*:*");
+ query.set("rows", 0);
+ results = qclient.query(query);
+ assertEquals(docs, results.getResults().getNumFound());
+ }
}
private long testUpdateAndDelete() throws Exception {
@@ -400,7 +392,7 @@ public class BasicDistributedZk2Test ext
// make sure we have published we are recovering
Thread.sleep(1500);
- waitForThingsToLevelOut(45);
+ waitForThingsToLevelOut(60);
Thread.sleep(500);
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/BasicDistributedZkTest.java Sun Feb 8 23:53:14 2015
@@ -18,6 +18,7 @@ package org.apache.solr.cloud;
*/
import org.apache.commons.lang.StringUtils;
+import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.JSONTestUtil;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
@@ -50,8 +51,8 @@ import org.apache.solr.common.params.Upd
import org.apache.solr.common.util.NamedList;
import org.apache.solr.update.DirectUpdateHandler2;
import org.apache.solr.util.DefaultSolrThreadFactory;
-import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
@@ -106,20 +107,16 @@ public class BasicDistributedZkTest exte
public static void beforeThisClass2() throws Exception {
}
- @Before
@Override
- public void setUp() throws Exception {
- super.setUp();
+ public void distribSetUp() throws Exception {
+ super.distribSetUp();
System.setProperty("numShards", Integer.toString(sliceCount));
System.setProperty("solr.xml.persist", "true");
}
public BasicDistributedZkTest() {
- fixShardCount = true;
-
sliceCount = 2;
- shardCount = 4;
completionService = new ExecutorCompletionService<>(executor);
pending = new HashSet<>();
@@ -133,7 +130,7 @@ public class BasicDistributedZkTest exte
} else {
// use shard ids rather than physical locations
StringBuilder sb = new StringBuilder();
- for (int i = 0; i < shardCount; i++) {
+ for (int i = 0; i < getShardCount(); i++) {
if (i > 0)
sb.append(',');
sb.append("shard" + (i + 3));
@@ -141,9 +138,10 @@ public class BasicDistributedZkTest exte
params.set("shards", sb.toString());
}
}
-
- @Override
- public void doTest() throws Exception {
+
+ @Test
+ @ShardsFixed(num = 4)
+ public void test() throws Exception {
// setLoggingLevel(null);
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
@@ -333,7 +331,7 @@ public class BasicDistributedZkTest exte
params.set("commitWithin", 10);
add(cloudClient, params , getDoc("id", 300));
- long timeout = System.currentTimeMillis() + 30000;
+ long timeout = System.currentTimeMillis() + 45000;
while (cloudClient.query(new SolrQuery("*:*")).getResults().getNumFound() != before + 1) {
if (timeout <= System.currentTimeMillis()) {
fail("commitWithin did not work");
@@ -381,14 +379,11 @@ public class BasicDistributedZkTest exte
createCmd.setSchemaName("nonexistent_schema.xml");
String url = getBaseUrl(clients.get(0));
- final HttpSolrClient client = new HttpSolrClient(url);
- try {
+ try (final HttpSolrClient client = new HttpSolrClient(url)) {
client.request(createCmd);
fail("Expected SolrCore create to fail");
} catch (Exception e) {
- } finally {
- client.shutdown();
}
long timeout = System.currentTimeMillis() + 15000;
@@ -509,20 +504,20 @@ public class BasicDistributedZkTest exte
private void testStopAndStartCoresInOneInstance() throws Exception {
SolrClient client = clients.get(0);
String url3 = getBaseUrl(client);
- final HttpSolrClient httpSolrClient = new HttpSolrClient(url3);
- httpSolrClient.setConnectionTimeout(15000);
- httpSolrClient.setSoTimeout(60000);
- ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
- 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
- new DefaultSolrThreadFactory("testExecutor"));
- int cnt = 3;
-
- // create the cores
- createCores(httpSolrClient, executor, "multiunload2", 1, cnt);
-
- executor.shutdown();
- executor.awaitTermination(120, TimeUnit.SECONDS);
- httpSolrClient.shutdown();
+ try (final HttpSolrClient httpSolrClient = new HttpSolrClient(url3)) {
+ httpSolrClient.setConnectionTimeout(15000);
+ httpSolrClient.setSoTimeout(60000);
+ ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
+ 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
+ new DefaultSolrThreadFactory("testExecutor"));
+ int cnt = 3;
+
+ // create the cores
+ createCores(httpSolrClient, executor, "multiunload2", 1, cnt);
+
+ executor.shutdown();
+ executor.awaitTermination(120, TimeUnit.SECONDS);
+ }
ChaosMonkey.stop(cloudJettys.get(0).jetty);
printLayout();
@@ -559,9 +554,7 @@ public class BasicDistributedZkTest exte
createCmd.setDataDir(getDataDir(core3dataDir));
client.request(createCmd);
- } catch (SolrServerException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
+ } catch (SolrServerException | IOException e) {
throw new RuntimeException(e);
}
}
@@ -608,9 +601,9 @@ public class BasicDistributedZkTest exte
((HttpSolrClient) clients.get(clientIndex)).getBaseURL().length()
- DEFAULT_COLLECTION.length() - 1);
- SolrClient aClient = createNewSolrClient("", baseUrl);
- res.setResponse(aClient.request(request));
- aClient.shutdown();
+ try (SolrClient aClient = createNewSolrClient("", baseUrl)) {
+ res.setResponse(aClient.request(request));
+ }
} else {
res.setResponse(client.request(request));
}
@@ -733,21 +726,20 @@ public class BasicDistributedZkTest exte
private Long getNumCommits(HttpSolrClient sourceClient) throws
SolrServerException, IOException {
- HttpSolrClient client = new HttpSolrClient(sourceClient.getBaseURL());
- client.setConnectionTimeout(15000);
- client.setSoTimeout(60000);
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.set("qt", "/admin/mbeans?key=updateHandler&stats=true");
- // use generic request to avoid extra processing of queries
- QueryRequest req = new QueryRequest(params);
- NamedList<Object> resp = client.request(req);
- NamedList mbeans = (NamedList) resp.get("solr-mbeans");
- NamedList uhandlerCat = (NamedList) mbeans.get("UPDATEHANDLER");
- NamedList uhandler = (NamedList) uhandlerCat.get("updateHandler");
- NamedList stats = (NamedList) uhandler.get("stats");
- Long commits = (Long) stats.get("commits");
- client.shutdown();
- return commits;
+ try (HttpSolrClient client = new HttpSolrClient(sourceClient.getBaseURL())) {
+ client.setConnectionTimeout(15000);
+ client.setSoTimeout(60000);
+ ModifiableSolrParams params = new ModifiableSolrParams();
+ params.set("qt", "/admin/mbeans?key=updateHandler&stats=true");
+ // use generic request to avoid extra processing of queries
+ QueryRequest req = new QueryRequest(params);
+ NamedList<Object> resp = client.request(req);
+ NamedList mbeans = (NamedList) resp.get("solr-mbeans");
+ NamedList uhandlerCat = (NamedList) mbeans.get("UPDATEHANDLER");
+ NamedList uhandler = (NamedList) uhandlerCat.get("updateHandler");
+ NamedList stats = (NamedList) uhandler.get("stats");
+ return (Long) stats.get("commits");
+ }
}
private void testANewCollectionInOneInstanceWithManualShardAssignement() throws Exception {
@@ -825,32 +817,30 @@ public class BasicDistributedZkTest exte
ZkCoreNodeProps props = new ZkCoreNodeProps(getCommonCloudSolrClient().getZkStateReader().getClusterState().getLeader(oneInstanceCollection2, "slice1"));
// now test that unloading a core gets us a new leader
- HttpSolrClient unloadClient = new HttpSolrClient(baseUrl);
- unloadClient.setConnectionTimeout(15000);
- unloadClient.setSoTimeout(60000);
- Unload unloadCmd = new Unload(true);
- unloadCmd.setCoreName(props.getCoreName());
-
- String leader = props.getCoreUrl();
-
- unloadClient.request(unloadCmd);
- unloadClient.shutdown();
-
- int tries = 50;
- while (leader.equals(zkStateReader.getLeaderUrl(oneInstanceCollection2, "slice1", 10000))) {
- Thread.sleep(100);
- if (tries-- == 0) {
- fail("Leader never changed");
+ try (HttpSolrClient unloadClient = new HttpSolrClient(baseUrl)) {
+ unloadClient.setConnectionTimeout(15000);
+ unloadClient.setSoTimeout(60000);
+ Unload unloadCmd = new Unload(true);
+ unloadCmd.setCoreName(props.getCoreName());
+
+ String leader = props.getCoreUrl();
+
+ unloadClient.request(unloadCmd);
+
+ int tries = 50;
+ while (leader.equals(zkStateReader.getLeaderUrl(oneInstanceCollection2, "slice1", 10000))) {
+ Thread.sleep(100);
+ if (tries-- == 0) {
+ fail("Leader never changed");
+ }
}
}
- for (SolrClient aClient : collectionClients) {
- aClient.shutdown();
- }
+ IOUtils.close(collectionClients);
}
- private void testSearchByCollectionName() throws SolrServerException {
+ private void testSearchByCollectionName() throws SolrServerException, IOException {
log.info("### STARTING testSearchByCollectionName");
SolrClient client = clients.get(0);
final String baseUrl = ((HttpSolrClient) client).getBaseURL().substring(
@@ -860,11 +850,11 @@ public class BasicDistributedZkTest exte
// the cores each have different names, but if we add the collection name to the url
// we should get mapped to the right core
- SolrClient client1 = createNewSolrClient(oneInstanceCollection, baseUrl);
- SolrQuery query = new SolrQuery("*:*");
- long oneDocs = client1.query(query).getResults().getNumFound();
- assertEquals(3, oneDocs);
- client1.shutdown();
+ try (SolrClient client1 = createNewSolrClient(oneInstanceCollection, baseUrl)) {
+ SolrQuery query = new SolrQuery("*:*");
+ long oneDocs = client1.query(query).getResults().getNumFound();
+ assertEquals(3, oneDocs);
+ }
}
private void testUpdateByCollectionName() throws SolrServerException, IOException {
@@ -878,9 +868,9 @@ public class BasicDistributedZkTest exte
// the cores each have different names, but if we add the collection name to the url
// we should get mapped to the right core
// test hitting an update url
- SolrClient client1 = createNewSolrClient(oneInstanceCollection, baseUrl);
- client1.commit();
- client1.shutdown();
+ try (SolrClient client1 = createNewSolrClient(oneInstanceCollection, baseUrl)) {
+ client1.commit();
+ }
}
private void testANewCollectionInOneInstance() throws Exception {
@@ -934,9 +924,8 @@ public class BasicDistributedZkTest exte
// System.out.println("All Docs:" + allDocs);
assertEquals(3, allDocs);
- for(SolrClient newCollectionClient:collectionClients) {
- newCollectionClient.shutdown();
- }
+ IOUtils.close(collectionClients);
+
}
private void createCollection(String collection,
@@ -950,9 +939,7 @@ public class BasicDistributedZkTest exte
Callable call = new Callable() {
@Override
public Object call() {
- HttpSolrClient client = null;
- try {
- client = new HttpSolrClient(baseUrl);
+ try (HttpSolrClient client = new HttpSolrClient(baseUrl)) {
client.setConnectionTimeout(15000);
Create createCmd = new Create();
createCmd.setRoles("none");
@@ -975,10 +962,6 @@ public class BasicDistributedZkTest exte
} catch (Exception e) {
e.printStackTrace();
//fail
- } finally {
- if (client != null) {
- client.shutdown();
- }
}
return null;
}
@@ -1087,9 +1070,8 @@ public class BasicDistributedZkTest exte
Callable call = new Callable() {
@Override
public Object call() {
- HttpSolrClient client = null;
- try {
- client = new HttpSolrClient(baseUrl);
+
+ try (HttpSolrClient client = new HttpSolrClient(baseUrl)) {
client.setConnectionTimeout(15000);
client.setSoTimeout(60000);
Create createCmd = new Create();
@@ -1099,10 +1081,6 @@ public class BasicDistributedZkTest exte
} catch (Exception e) {
e.printStackTrace();
//fails
- } finally {
- if (client != null) {
- client.shutdown();
- }
}
return null;
}
@@ -1162,24 +1140,21 @@ public class BasicDistributedZkTest exte
}
@Override
- public void tearDown() throws Exception {
- super.tearDown();
+ public void distribTearDown() throws Exception {
+ super.distribTearDown();
if (commondCloudSolrClient != null) {
- commondCloudSolrClient.shutdown();
+ commondCloudSolrClient.close();
}
if (otherCollectionClients != null) {
for (List<SolrClient> clientList : otherCollectionClients.values()) {
- for (SolrClient client : clientList) {
- client.shutdown();
- }
+ IOUtils.close(clientList);
}
}
otherCollectionClients = null;
List<Runnable> tasks = executor.shutdownNow();
assertTrue(tasks.isEmpty());
-
+
System.clearProperty("numShards");
- System.clearProperty("zkHost");
System.clearProperty("solr.xml.persist");
// insurance
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyNothingIsSafeTest.java Sun Feb 8 23:53:14 2015
@@ -18,7 +18,7 @@ package org.apache.solr.cloud;
*/
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
-import org.apache.http.client.HttpClient;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrClient;
@@ -29,12 +29,12 @@ import org.apache.solr.client.solrj.impl
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.util.IOUtils;
import org.apache.solr.core.Diagnostics;
import org.apache.solr.update.SolrCmdDistributor;
-import org.junit.After;
import org.junit.AfterClass;
-import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,7 +46,7 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
@Slow
-@SuppressSSL
+@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
@ThreadLeakLingering(linger = 60000)
public class ChaosMonkeyNothingIsSafeTest extends AbstractFullDistribZkTestBase {
private static final int FAIL_TOLERANCE = 20;
@@ -86,10 +86,9 @@ public class ChaosMonkeyNothingIsSafeTes
return randVals;
}
- @Before
@Override
- public void setUp() throws Exception {
- super.setUp();
+ public void distribSetUp() throws Exception {
+ super.distribSetUp();
// can help to hide this when testing and looking at logs
//ignoreException("shard update error");
System.setProperty("numShards", Integer.toString(sliceCount));
@@ -97,28 +96,27 @@ public class ChaosMonkeyNothingIsSafeTes
}
@Override
- @After
- public void tearDown() throws Exception {
+ public void distribTearDown() throws Exception {
System.clearProperty("numShards");
- super.tearDown();
- resetExceptionIgnores();
+ super.distribTearDown();
}
public ChaosMonkeyNothingIsSafeTest() {
super();
sliceCount = Integer.parseInt(System.getProperty("solr.tests.cloud.cm.slicecount", "-1"));
- shardCount = Integer.parseInt(System.getProperty("solr.tests.cloud.cm.shardcount", "-1"));
-
if (sliceCount == -1) {
sliceCount = random().nextInt(TEST_NIGHTLY ? 5 : 3) + 1;
}
- if (shardCount == -1) {
- shardCount = sliceCount + random().nextInt(TEST_NIGHTLY ? 12 : 2);
+
+ int numShards = Integer.parseInt(System.getProperty("solr.tests.cloud.cm.shardcount", "-1"));
+ if (numShards == -1) {
+ numShards = sliceCount + random().nextInt(TEST_NIGHTLY ? 12 : 2);
}
+ fixShardCount(numShards);
}
-
- @Override
- public void doTest() throws Exception {
+
+ @Test
+ public void test() throws Exception {
boolean testsSuccesful = false;
try {
handle.clear();
@@ -252,13 +250,11 @@ public class ChaosMonkeyNothingIsSafeTes
zkServer.run();
}
- CloudSolrClient client = createCloudClient("collection1");
- try {
+
+ try (CloudSolrClient client = createCloudClient("collection1")) {
createCollection(null, "testcollection",
1, 1, 1, client, null, "conf1");
- } finally {
- client.shutdown();
}
List<Integer> numShardsNumReplicas = new ArrayList<>(2);
numShardsNumReplicas.add(1);
@@ -290,7 +286,7 @@ public class ChaosMonkeyNothingIsSafeTes
}
class FullThrottleStopableIndexingThread extends StopableIndexingThread {
- private HttpClient httpClient = HttpClientUtil.createClient(null);
+ private CloseableHttpClient httpClient = HttpClientUtil.createClient(null);
private volatile boolean stop = false;
int clientIndex = 0;
private ConcurrentUpdateSolrClient cusc;
@@ -389,7 +385,7 @@ public class ChaosMonkeyNothingIsSafeTes
stop = true;
cusc.blockUntilFinished();
cusc.shutdownNow();
- httpClient.getConnectionManager().shutdown();
+ IOUtils.closeQuietly(httpClient);
}
@Override
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeySafeLeaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeySafeLeaderTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeySafeLeaderTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeySafeLeaderTest.java Sun Feb 8 23:53:14 2015
@@ -17,10 +17,6 @@ package org.apache.solr.cloud;
* limitations under the License.
*/
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.TimeUnit;
-
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
@@ -28,10 +24,13 @@ import org.apache.solr.client.solrj.impl
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.Diagnostics;
import org.apache.solr.update.SolrCmdDistributor;
-import org.junit.After;
import org.junit.AfterClass;
-import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
@Slow
public class ChaosMonkeySafeLeaderTest extends AbstractFullDistribZkTestBase {
@@ -69,39 +68,37 @@ public class ChaosMonkeySafeLeaderTest e
return randVals;
}
- @Before
@Override
- public void setUp() throws Exception {
+ public void distribSetUp() throws Exception {
useFactory("solr.StandardDirectoryFactory");
- super.setUp();
+ super.distribSetUp();
System.setProperty("numShards", Integer.toString(sliceCount));
}
@Override
- @After
- public void tearDown() throws Exception {
+ public void distribTearDown() throws Exception {
System.clearProperty("numShards");
- super.tearDown();
- resetExceptionIgnores();
+ super.distribTearDown();
}
public ChaosMonkeySafeLeaderTest() {
super();
sliceCount = Integer.parseInt(System.getProperty("solr.tests.cloud.cm.slicecount", "-1"));
- shardCount = Integer.parseInt(System.getProperty("solr.tests.cloud.cm.shardcount", "-1"));
-
if (sliceCount == -1) {
sliceCount = random().nextInt(TEST_NIGHTLY ? 5 : 3) + 1;
}
- if (shardCount == -1) {
- shardCount = sliceCount + random().nextInt(TEST_NIGHTLY ? 12 : 2);
+
+ int numShards = Integer.parseInt(System.getProperty("solr.tests.cloud.cm.shardcount", "-1"));
+ if (numShards == -1) {
+ numShards = sliceCount + random().nextInt(TEST_NIGHTLY ? 12 : 2);
}
+ fixShardCount(numShards);
}
-
- @Override
- public void doTest() throws Exception {
+
+ @Test
+ public void test() throws Exception {
handle.clear();
handle.put("timestamp", SKIPVAL);
@@ -171,14 +168,10 @@ public class ChaosMonkeySafeLeaderTest e
zkServer = new ZkTestServer(zkServer.getZkDir(), zkServer.getPort());
zkServer.run();
}
-
- CloudSolrClient client = createCloudClient("collection1");
- try {
- createCollection(null, "testcollection",
- 1, 1, 1, client, null, "conf1");
- } finally {
- client.shutdown();
+ try (CloudSolrClient client = createCloudClient("collection1")) {
+ createCollection(null, "testcollection", 1, 1, 1, client, null, "conf1");
+
}
List<Integer> numShardsNumReplicas = new ArrayList<>(2);
numShardsNumReplicas.add(1);
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ChaosMonkeyShardSplitTest.java Sun Feb 8 23:53:14 2015
@@ -31,9 +31,8 @@ import org.apache.solr.handler.component
import org.apache.solr.update.UpdateShardHandler;
import org.apache.solr.util.MockConfigSolr;
import org.apache.zookeeper.KeeperException;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Ignore;
+import org.junit.Test;
import java.io.IOException;
import java.util.Collection;
@@ -50,20 +49,8 @@ public class ChaosMonkeyShardSplitTest e
static final int TIMEOUT = 10000;
private AtomicInteger killCounter = new AtomicInteger();
- @Before
- @Override
- public void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- @After
- public void tearDown() throws Exception {
- super.tearDown();
- }
-
- @Override
- public void doTest() throws Exception {
+ @Test
+ public void test() throws Exception {
waitForThingsToLevelOut(15);
ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CloudExitableDirectoryReaderTest.java Sun Feb 8 23:53:14 2015
@@ -22,6 +22,7 @@ import org.apache.lucene.util.LuceneTest
import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,8 +44,8 @@ public class CloudExitableDirectoryReade
return configString;
}
- @Override
- public void doTest() throws Exception {
+ @Test
+ public void test() throws Exception {
handle.clear();
handle.put("timestamp", SKIPVAL);
waitForRecoveriesToFinish(false);
@@ -77,17 +78,18 @@ public class CloudExitableDirectoryReade
time than this. Keeping it at 5 because the delaying search component delays all requests
by at 1 second.
*/
- long fiveSeconds = 5000L;
+ int fiveSeconds = 5000;
- Long timeAllowed = TestUtil.nextLong(random(), fiveSeconds, Long.MAX_VALUE);
+ Integer timeAllowed = TestUtil.nextInt(random(), fiveSeconds, Integer.MAX_VALUE);
assertSuccess(params("q", "name:a*", "timeAllowed",timeAllowed.toString()));
assertPartialResults(params("q", "name:a*", "timeAllowed", "1"));
- timeAllowed = TestUtil.nextLong(random(), fiveSeconds, Long.MAX_VALUE);
+ timeAllowed = TestUtil.nextInt(random(), fiveSeconds, Integer.MAX_VALUE);
assertSuccess(params("q", "name:b*", "timeAllowed",timeAllowed.toString()));
- timeAllowed = TestUtil.nextLong(random(), Long.MIN_VALUE, -1L); // negative timeAllowed should disable timeouts
+ // negative timeAllowed should disable timeouts
+ timeAllowed = TestUtil.nextInt(random(), Integer.MIN_VALUE, -1);
assertSuccess(params("q", "name:b*", "timeAllowed",timeAllowed.toString()));
assertSuccess(params("q","name:b*")); // no time limitation
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIAsyncDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIAsyncDistributedZkTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIAsyncDistributedZkTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIAsyncDistributedZkTest.java Sun Feb 8 23:53:14 2015
@@ -28,7 +28,7 @@ import org.apache.solr.client.solrj.requ
import org.apache.solr.client.solrj.response.CollectionAdminResponse;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.update.DirectUpdateHandler2;
-import org.junit.Before;
+import org.junit.Test;
import java.io.IOException;
@@ -40,10 +40,9 @@ public class CollectionsAPIAsyncDistribu
private static final int MAX_TIMEOUT_SECONDS = 60;
private static final boolean DEBUG = false;
- @Before
@Override
- public void setUp() throws Exception {
- super.setUp();
+ public void distribSetUp() throws Exception {
+ super.distribSetUp();
useJettyDataDir = false;
@@ -52,68 +51,61 @@ public class CollectionsAPIAsyncDistribu
}
public CollectionsAPIAsyncDistributedZkTest() {
- fixShardCount = true;
-
sliceCount = 1;
- shardCount = 1;
}
- @Override
- public void doTest() throws Exception {
-
- testSolrJAPICalls();
+ @Test
+ @ShardsFixed(num = 1)
+ public void testSolrJAPICalls() throws Exception {
+ try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
+ Create createCollectionRequest = new Create();
+ createCollectionRequest.setCollectionName("testasynccollectioncreation");
+ createCollectionRequest.setNumShards(1);
+ createCollectionRequest.setConfigName("conf1");
+ createCollectionRequest.setAsyncId("1001");
+ createCollectionRequest.process(client);
+
+ String state = getRequestStateAfterCompletion("1001", MAX_TIMEOUT_SECONDS, client);
+
+ assertEquals("CreateCollection task did not complete!", "completed", state);
+
+
+ createCollectionRequest = new Create();
+ createCollectionRequest.setCollectionName("testasynccollectioncreation");
+ createCollectionRequest.setNumShards(1);
+ createCollectionRequest.setConfigName("conf1");
+ createCollectionRequest.setAsyncId("1002");
+ createCollectionRequest.process(client);
+
+ state = getRequestStateAfterCompletion("1002", MAX_TIMEOUT_SECONDS, client);
+
+ assertEquals("Recreating a collection with the same name didn't fail, should have.", "failed", state);
+
+ CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica();
+ addReplica.setCollectionName("testasynccollectioncreation");
+ addReplica.setShardName("shard1");
+ addReplica.setAsyncId("1003");
+ client.request(addReplica);
+ state = getRequestStateAfterCompletion("1003", MAX_TIMEOUT_SECONDS, client);
+ assertEquals("Add replica did not complete", "completed", state);
+
+
+ SplitShard splitShardRequest = new SplitShard();
+ splitShardRequest.setCollectionName("testasynccollectioncreation");
+ splitShardRequest.setShardName("shard1");
+ splitShardRequest.setAsyncId("1004");
+ splitShardRequest.process(client);
+
+ state = getRequestStateAfterCompletion("1004", MAX_TIMEOUT_SECONDS * 2, client);
+
+ assertEquals("Shard split did not complete. Last recorded state: " + state, "completed", state);
+ }
if (DEBUG) {
- super.printLayout();
+ printLayout();
}
}
- private void testSolrJAPICalls() throws Exception {
- SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)));
-
- Create createCollectionRequest = new Create();
- createCollectionRequest.setCollectionName("testasynccollectioncreation");
- createCollectionRequest.setNumShards(1);
- createCollectionRequest.setConfigName("conf1");
- createCollectionRequest.setAsyncId("1001");
- createCollectionRequest.process(client);
-
- String state = getRequestStateAfterCompletion("1001", MAX_TIMEOUT_SECONDS, client);
-
- assertEquals("CreateCollection task did not complete!", "completed", state);
-
-
- createCollectionRequest = new Create();
- createCollectionRequest.setCollectionName("testasynccollectioncreation");
- createCollectionRequest.setNumShards(1);
- createCollectionRequest.setConfigName("conf1");
- createCollectionRequest.setAsyncId("1002");
- createCollectionRequest.process(client);
-
- state = getRequestStateAfterCompletion("1002", MAX_TIMEOUT_SECONDS, client);
-
- assertEquals("Recreating a collection with the same name didn't fail, should have.", "failed", state);
-
- CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica();
- addReplica.setCollectionName("testasynccollectioncreation");
- addReplica.setShardName("shard1");
- addReplica.setAsyncId("1003");
- client.request(addReplica);
- state = getRequestStateAfterCompletion("1003", MAX_TIMEOUT_SECONDS, client);
- assertEquals("Add replica did not complete", "completed", state);
-
-
- SplitShard splitShardRequest = new SplitShard();
- splitShardRequest.setCollectionName("testasynccollectioncreation");
- splitShardRequest.setShardName("shard1");
- splitShardRequest.setAsyncId("1004");
- splitShardRequest.process(client);
-
- state = getRequestStateAfterCompletion("1004", MAX_TIMEOUT_SECONDS * 2, client);
-
- assertEquals("Shard split did not complete. Last recorded state: " + state, "completed", state);
- }
-
private String getRequestStateAfterCompletion(String requestId, int waitForSeconds, SolrClient client)
throws IOException, SolrServerException {
String state = null;
@@ -138,10 +130,9 @@ public class CollectionsAPIAsyncDistribu
}
@Override
- public void tearDown() throws Exception {
- super.tearDown();
+ public void distribTearDown() throws Exception {
+ super.distribTearDown();
System.clearProperty("numShards");
- System.clearProperty("zkHost");
System.clearProperty("solr.xml.persist");
// insurance
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPIDistributedZkTest.java Sun Feb 8 23:53:14 2015
@@ -19,6 +19,7 @@ package org.apache.solr.cloud;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util.TestUtil;
+import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
@@ -53,12 +54,11 @@ import org.apache.solr.common.util.StrUt
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrInfoMBean.Category;
-import org.apache.solr.core.SolrResourceLoader;
import org.apache.solr.servlet.SolrDispatchFilter;
import org.apache.solr.update.DirectUpdateHandler2;
import org.apache.solr.util.DefaultSolrThreadFactory;
-import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Test;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
@@ -66,6 +66,9 @@ import javax.management.ObjectName;
import java.io.File;
import java.io.IOException;
import java.lang.management.ManagementFactory;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -108,26 +111,18 @@ public class CollectionsAPIDistributedZk
// we randomly use a second config set rather than just one
private boolean secondConfigSet = random().nextBoolean();
- private boolean oldStyleSolrXml = false;
@BeforeClass
public static void beforeThisClass2() throws Exception {
}
- @Before
@Override
- public void setUp() throws Exception {
- super.setUp();
+ public void distribSetUp() throws Exception {
+ super.distribSetUp();
useJettyDataDir = false;
-
- oldStyleSolrXml = random().nextBoolean();
- if (oldStyleSolrXml) {
- System.err.println("Using old style solr.xml");
- } else {
- System.err.println("Using new style solr.xml");
- }
+
if (secondConfigSet ) {
String zkHost = zkServer.getZkHost();
String zkAddress = zkServer.getZkAddress();
@@ -156,20 +151,16 @@ public class CollectionsAPIDistributedZk
}
System.setProperty("numShards", Integer.toString(sliceCount));
- System.setProperty("solr.xml.persist", "true");
+
}
protected String getSolrXml() {
- // test old style and new style solr.xml
- return oldStyleSolrXml ? "solr-no-core-old-style.xml" : "solr-no-core.xml";
+ return "solr-no-core.xml";
}
public CollectionsAPIDistributedZkTest() {
- fixShardCount = true;
-
sliceCount = 2;
- shardCount = 4;
completionService = new ExecutorCompletionService<>(executor);
pending = new HashSet<>();
checkCreatedVsState = false;
@@ -184,7 +175,7 @@ public class CollectionsAPIDistributedZk
} else {
// use shard ids rather than physical locations
StringBuilder sb = new StringBuilder();
- for (int i = 0; i < shardCount; i++) {
+ for (int i = 0; i < getShardCount(); i++) {
if (i > 0)
sb.append(',');
sb.append("shard" + (i + 3));
@@ -192,9 +183,10 @@ public class CollectionsAPIDistributedZk
params.set("shards", sb.toString());
}
}
-
- @Override
- public void doTest() throws Exception {
+
+ @Test
+ @ShardsFixed(num = 4)
+ public void test() throws Exception {
testNodesUsedByCreate();
testCollectionsAPI();
testCollectionsAPIAddRemoveStress();
@@ -231,8 +223,7 @@ public class CollectionsAPIDistributedZk
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
try {
- NamedList<Object> resp = createNewSolrClient("", baseUrl)
- .request(request);
+ makeRequest(baseUrl, request);
fail("Expected to fail, because collection is not in clusterstate");
} catch (RemoteSolrException e) {
@@ -256,7 +247,8 @@ public class CollectionsAPIDistributedZk
if (secondConfigSet) {
createCmd.setCollectionConfigName("conf1");
}
- createNewSolrClient("", baseUrl).request(createCmd);
+
+ makeRequest(baseUrl, createCmd);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionAction.DELETE.toString());
@@ -264,7 +256,7 @@ public class CollectionsAPIDistributedZk
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
- NamedList<Object> resp = createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
checkForMissingCollection(collectionName);
@@ -278,7 +270,7 @@ public class CollectionsAPIDistributedZk
if (secondConfigSet) {
params.set("collection.configName", "conf1");
}
- resp = createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
}
@@ -286,11 +278,13 @@ public class CollectionsAPIDistributedZk
String baseUrl = getBaseUrl((HttpSolrClient) clients.get(0));
// now try to remove a collection when a couple of its nodes are down
if (secondConfigSet) {
- createCollection(null, "halfdeletedcollection2", 3, 3, 6,
- createNewSolrClient("", baseUrl), null, "conf2");
+ try (SolrClient client = createNewSolrClient("", baseUrl)) {
+ createCollection(null, "halfdeletedcollection2", 3, 3, 6, client, null, "conf2");
+ }
} else {
- createCollection(null, "halfdeletedcollection2", 3, 3, 6,
- createNewSolrClient("", baseUrl), null);
+ try (SolrClient client = createNewSolrClient("", baseUrl)) {
+ createCollection(null, "halfdeletedcollection2", 3, 3, 6, client, null);
+ }
}
waitForRecoveriesToFinish("halfdeletedcollection2", false);
@@ -313,7 +307,7 @@ public class CollectionsAPIDistributedZk
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
- createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
long timeout = System.currentTimeMillis() + 10000;
while (cloudClient.getZkStateReader().getClusterState().hasCollection("halfdeletedcollection2")) {
@@ -329,6 +323,13 @@ public class CollectionsAPIDistributedZk
}
+ private NamedList<Object> makeRequest(String baseUrl, SolrRequest request)
+ throws SolrServerException, IOException {
+ try (SolrClient client = createNewSolrClient("", baseUrl)) {
+ return client.request(request);
+ }
+ }
+
private void testErrorHandling() throws Exception {
final String baseUrl = getBaseUrl((HttpSolrClient) clients.get(0));
@@ -342,9 +343,8 @@ public class CollectionsAPIDistributedZk
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
boolean gotExp = false;
- NamedList<Object> resp = null;
try {
- resp = createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
} catch (SolrException e) {
gotExp = true;
}
@@ -364,9 +364,8 @@ public class CollectionsAPIDistributedZk
request = new QueryRequest(params);
request.setPath("/admin/collections");
gotExp = false;
- resp = null;
try {
- resp = createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
} catch (SolrException e) {
gotExp = true;
}
@@ -386,7 +385,7 @@ public class CollectionsAPIDistributedZk
request.setPath("/admin/collections");
gotExp = false;
try {
- resp = createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
} catch (SolrException e) {
gotExp = true;
}
@@ -404,9 +403,8 @@ public class CollectionsAPIDistributedZk
request = new QueryRequest(params);
request.setPath("/admin/collections");
gotExp = false;
- resp = null;
try {
- resp = createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
} catch (SolrException e) {
gotExp = true;
}
@@ -425,9 +423,8 @@ public class CollectionsAPIDistributedZk
request = new QueryRequest(params);
request.setPath("/admin/collections");
gotExp = false;
- resp = null;
try {
- resp = createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
} catch (SolrException e) {
gotExp = true;
}
@@ -446,7 +443,7 @@ public class CollectionsAPIDistributedZk
if (secondConfigSet) {
createCmd.setCollectionConfigName("conf1");
}
- createNewSolrClient("", baseUrl).request(createCmd);
+ makeRequest(baseUrl, createCmd);
createCmd = new Create();
createCmd.setCoreName("halfcollection_shard1_replica1");
@@ -457,7 +454,7 @@ public class CollectionsAPIDistributedZk
if (secondConfigSet) {
createCmd.setCollectionConfigName("conf1");
}
- createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(1))).request(createCmd);
+ makeRequest(getBaseUrl((HttpSolrClient) clients.get(1)), createCmd);
params = new ModifiableSolrParams();
params.set("action", CollectionAction.CREATE.toString());
@@ -477,7 +474,7 @@ public class CollectionsAPIDistributedZk
request = new QueryRequest(params);
request.setPath("/admin/collections");
gotExp = false;
- resp = createNewSolrClient("", baseUrl).request(request);
+ NamedList<Object> resp = makeRequest(baseUrl, request);;
SimpleOrderedMap success = (SimpleOrderedMap) resp.get("success");
SimpleOrderedMap failure = (SimpleOrderedMap) resp.get("failure");
@@ -507,15 +504,13 @@ public class CollectionsAPIDistributedZk
createCmd.setCollectionConfigName("conf1");
}
- createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(1)))
- .request(createCmd);
+ makeRequest(getBaseUrl((HttpSolrClient) clients.get(1)), createCmd);
// try and create a SolrCore with no collection name
createCmd.setCollection(null);
createCmd.setCoreName("corewithnocollection2");
- createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(1)))
- .request(createCmd);
+ makeRequest(getBaseUrl((HttpSolrClient) clients.get(1)), createCmd);
// in both cases, the collection should have default to the core name
cloudClient.getZkStateReader().updateClusterState(true);
@@ -542,7 +537,7 @@ public class CollectionsAPIDistributedZk
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
- createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
List<Integer> numShardsNumReplicaList = new ArrayList<>();
numShardsNumReplicaList.add(2);
@@ -591,7 +586,7 @@ public class CollectionsAPIDistributedZk
int cnt = random().nextInt(TEST_NIGHTLY ? 6 : 1) + 1;
for (int i = 0; i < cnt; i++) {
- int numShards = TestUtil.nextInt(random(), 0, shardCount) + 1;
+ int numShards = TestUtil.nextInt(random(), 0, getShardCount()) + 1;
int replicationFactor = TestUtil.nextInt(random(), 0, 3) + 1;
int maxShardsPerNode = (((numShards * replicationFactor) / getCommonCloudSolrClient()
.getZkStateReader().getClusterState().getLiveNodes().size())) + 1;
@@ -626,7 +621,7 @@ public class CollectionsAPIDistributedZk
numShards, replicationFactor, maxShardsPerNode, client, null);
}
} finally {
- if (client != null) client.shutdown();
+ if (client != null) client.close();
}
}
@@ -638,11 +633,10 @@ public class CollectionsAPIDistributedZk
String url = getUrlFromZk(collection);
- HttpSolrClient collectionClient = new HttpSolrClient(url);
-
- // poll for a second - it can take a moment before we are ready to serve
- waitForNon403or404or503(collectionClient);
- collectionClient.shutdown();
+ try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
+ // poll for a second - it can take a moment before we are ready to serve
+ waitForNon403or404or503(collectionClient);
+ }
}
// sometimes we restart one of the jetty nodes
@@ -658,11 +652,10 @@ public class CollectionsAPIDistributedZk
String url = getUrlFromZk(collection);
- HttpSolrClient collectionClient = new HttpSolrClient(url);
-
- // poll for a second - it can take a moment before we are ready to serve
- waitForNon403or404or503(collectionClient);
- collectionClient.shutdown();
+ try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
+ // poll for a second - it can take a moment before we are ready to serve
+ waitForNon403or404or503(collectionClient);
+ }
}
}
@@ -705,29 +698,27 @@ public class CollectionsAPIDistributedZk
String url = getUrlFromZk(collectionName);
- HttpSolrClient collectionClient = new HttpSolrClient(url);
-
-
- // lets try and use the solrj client to index a couple documents
- SolrInputDocument doc1 = getDoc(id, 6, i1, -600, tlong, 600, t1,
- "humpty dumpy sat on a wall");
- SolrInputDocument doc2 = getDoc(id, 7, i1, -600, tlong, 600, t1,
- "humpty dumpy3 sat on a walls");
- SolrInputDocument doc3 = getDoc(id, 8, i1, -600, tlong, 600, t1,
- "humpty dumpy2 sat on a walled");
+ try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
- collectionClient.add(doc1);
-
- collectionClient.add(doc2);
+ // lets try and use the solrj client to index a couple documents
+ SolrInputDocument doc1 = getDoc(id, 6, i1, -600, tlong, 600, t1,
+ "humpty dumpy sat on a wall");
+ SolrInputDocument doc2 = getDoc(id, 7, i1, -600, tlong, 600, t1,
+ "humpty dumpy3 sat on a walls");
+ SolrInputDocument doc3 = getDoc(id, 8, i1, -600, tlong, 600, t1,
+ "humpty dumpy2 sat on a walled");
+
+ collectionClient.add(doc1);
+
+ collectionClient.add(doc2);
+
+ collectionClient.add(doc3);
+
+ collectionClient.commit();
+
+ assertEquals(3, collectionClient.query(new SolrQuery("*:*")).getResults().getNumFound());
+ }
- collectionClient.add(doc3);
-
- collectionClient.commit();
-
- assertEquals(3, collectionClient.query(new SolrQuery("*:*")).getResults().getNumFound());
- collectionClient.shutdown();
- collectionClient = null;
-
// lets try a collection reload
// get core open times
@@ -743,7 +734,7 @@ public class CollectionsAPIDistributedZk
// we can use this client because we just want base url
final String baseUrl = getBaseUrl((HttpSolrClient) clients.get(0));
- createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
// reloads make take a short while
boolean allTimesAreCorrect = waitForReloads(collectionName, urlToTimeBefore);
@@ -759,7 +750,7 @@ public class CollectionsAPIDistributedZk
request = new QueryRequest(params);
request.setPath("/admin/collections");
- createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
// ensure its out of the state
checkForMissingCollection(collectionName);
@@ -775,7 +766,7 @@ public class CollectionsAPIDistributedZk
boolean exp = false;
try {
- createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
} catch (SolrException e) {
exp = true;
}
@@ -795,7 +786,7 @@ public class CollectionsAPIDistributedZk
}
request = new QueryRequest(params);
request.setPath("/admin/collections");
- createNewSolrClient("", baseUrl).request(request);
+ makeRequest(baseUrl, request);
List<Integer> list = new ArrayList<>(2);
list.add(1);
@@ -804,13 +795,11 @@ public class CollectionsAPIDistributedZk
url = getUrlFromZk(collectionName);
- collectionClient = new HttpSolrClient(url);
-
- // poll for a second - it can take a moment before we are ready to serve
- waitForNon403or404or503(collectionClient);
- collectionClient.shutdown();
- collectionClient = null;
-
+ try (HttpSolrClient collectionClient = new HttpSolrClient(url)) {
+ // poll for a second - it can take a moment before we are ready to serve
+ waitForNon403or404or503(collectionClient);
+ }
+
for (int j = 0; j < cnt; j++) {
waitForRecoveriesToFinish(collectionName, zkStateReader, false);
}
@@ -821,8 +810,7 @@ public class CollectionsAPIDistributedZk
int replicationFactor = 2;
int maxShardsPerNode = 1;
collectionInfos = new HashMap<>();
- CloudSolrClient client = createCloudClient("awholynewcollection_" + cnt);
- try {
+ try (CloudSolrClient client = createCloudClient("awholynewcollection_" + cnt)) {
exp = false;
try {
createCollection(collectionInfos, "awholynewcollection_" + cnt,
@@ -831,8 +819,6 @@ public class CollectionsAPIDistributedZk
exp = true;
}
assertTrue("expected exception", exp);
- } finally {
- client.shutdown();
}
@@ -854,19 +840,17 @@ public class CollectionsAPIDistributedZk
numShards = createNodeList.size() * maxShardsPerNode;
replicationFactor = 1;
collectionInfos = new HashMap<>();
- client = createCloudClient("awholynewcollection_" + (cnt+1));
- try {
+
+ try (SolrClient client = createCloudClient("awholynewcollection_" + (cnt+1))) {
CollectionAdminResponse res = createCollection(collectionInfos, "awholynewcollection_" + (cnt+1), numShards, replicationFactor, maxShardsPerNode, client, StrUtils.join(createNodeList, ','), "conf1");
assertTrue(res.isSuccess());
- } finally {
- client.shutdown();
}
checkForCollection(collectionInfos.keySet().iterator().next(), collectionInfos.entrySet().iterator().next().getValue(), createNodeList);
checkNoTwoShardsUseTheSameIndexDir();
if(disableLegacy) {
setClusterProp(client1, ZkStateReader.LEGACY_CLOUD, null);
- client1.shutdown();
+ client1.close();
}
}
@@ -874,10 +858,8 @@ public class CollectionsAPIDistributedZk
class CollectionThread extends Thread {
- private String name;
-
public CollectionThread(String name) {
- this.name = name;
+ super(name);
}
public void run() {
@@ -886,22 +868,14 @@ public class CollectionsAPIDistributedZk
int cnt = random().nextInt(TEST_NIGHTLY ? 13 : 1) + 1;
for (int i = 0; i < cnt; i++) {
- String collectionName = "awholynewstresscollection_" + name + "_" + i;
- int numShards = TestUtil.nextInt(random(), 0, shardCount * 2) + 1;
+ String collectionName = "awholynewstresscollection_" + getName() + "_" + i;
+ int numShards = TestUtil.nextInt(random(), 0, getShardCount() * 2) + 1;
int replicationFactor = TestUtil.nextInt(random(), 0, 3) + 1;
int maxShardsPerNode = (((numShards * 2 * replicationFactor) / getCommonCloudSolrClient()
.getZkStateReader().getClusterState().getLiveNodes().size())) + 1;
-
- CloudSolrClient client = null;
- try {
- if (i == 0) {
- client = createCloudClient(null);
- } else if (i == 1) {
- client = createCloudClient(collectionName);
- } else {
- client = createCloudClient(null);
- }
-
+
+ try (CloudSolrClient client = createCloudClient(i == 1 ? collectionName : null)) {
+
createCollection(collectionInfos, collectionName,
numShards, replicationFactor, maxShardsPerNode, client, null,
"conf1");
@@ -910,14 +884,9 @@ public class CollectionsAPIDistributedZk
CollectionAdminRequest.Delete delete = new CollectionAdminRequest.Delete();
delete.setCollectionName(collectionName);
client.request(delete);
- } catch (SolrServerException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (IOException e) {
+ } catch (SolrServerException | IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
- } finally {
- if (client != null) client.shutdown();
}
}
}
@@ -937,28 +906,22 @@ public class CollectionsAPIDistributedZk
}
}
- private void checkInstanceDirs(JettySolrRunner jetty) {
+ private void checkInstanceDirs(JettySolrRunner jetty) throws IOException {
CoreContainer cores = ((SolrDispatchFilter) jetty.getDispatchFilter()
.getFilter()).getCores();
Collection<SolrCore> theCores = cores.getCores();
for (SolrCore core : theCores) {
- if (!oldStyleSolrXml) {
- // look for core props file
- assertTrue("Could not find expected core.properties file",
- new File((String) core.getStatistics().get("instanceDir"),
- "core.properties").exists());
- }
- try {
- assertEquals(
- new File(SolrResourceLoader.normalizeDir(jetty.getSolrHome() + File.separator
- + core.getName())).getCanonicalPath(),
- new File(SolrResourceLoader.normalizeDir((String) core.getStatistics().get(
- "instanceDir"))).getCanonicalPath());
- } catch (IOException e) {
- log.error("Failed to get canonical path", e);
- fail("Failed to get canonical path");
- }
+ // look for core props file
+ assertTrue("Could not find expected core.properties file",
+ new File((String) core.getStatistics().get("instanceDir"),
+ "core.properties").exists());
+
+ Path expected = Paths.get(jetty.getSolrHome()).toAbsolutePath().resolve("cores").resolve(core.getName());
+ Path reported = Paths.get((String) core.getStatistics().get("instanceDir"));
+
+ assertTrue("Expected: " + expected + "\nFrom core stats: " + reported, Files.isSameFile(expected, reported));
+
}
}
@@ -1009,12 +972,9 @@ public class CollectionsAPIDistributedZk
while (shardIt.hasNext()) {
Entry<String,Replica> shardEntry = shardIt.next();
ZkCoreNodeProps coreProps = new ZkCoreNodeProps(shardEntry.getValue());
- HttpSolrClient server = new HttpSolrClient(coreProps.getBaseUrl());
CoreAdminResponse mcr;
- try {
+ try (HttpSolrClient server = new HttpSolrClient(coreProps.getBaseUrl())) {
mcr = CoreAdminRequest.getStatus(coreProps.getCoreName(), server);
- } finally {
- server.shutdown();
}
long before = mcr.getStartTime(coreProps.getCoreName()).getTime();
urlToTime.put(coreProps.getCoreUrl(), before);
@@ -1125,8 +1085,7 @@ public class CollectionsAPIDistributedZk
private void addReplicaTest() throws Exception {
String collectionName = "addReplicaColl";
- CloudSolrClient client = createCloudClient(null);
- try {
+ try (CloudSolrClient client = createCloudClient(null)) {
createCollection(collectionName, client, 2, 2);
String newReplicaName = Assign.assignNode(collectionName, client.getZkStateReader().getClusterState());
ArrayList<String> nodeList = new ArrayList<>(client.getZkStateReader().getClusterState().getLiveNodes());
@@ -1168,9 +1127,6 @@ public class CollectionsAPIDistributedZk
assertNotNull(newReplica);
-
- } finally {
- client.shutdown();
}
}
@@ -1202,10 +1158,9 @@ public class CollectionsAPIDistributedZk
}
@Override
- public void tearDown() throws Exception {
- super.tearDown();
+ public void distribTearDown() throws Exception {
+ super.distribTearDown();
System.clearProperty("numShards");
- System.clearProperty("zkHost");
System.clearProperty("solr.xml.persist");
// insurance
@@ -1213,12 +1168,10 @@ public class CollectionsAPIDistributedZk
}
private void clusterPropTest() throws Exception {
- CloudSolrClient client = createCloudClient(null);
-
- assertTrue("cluster property not set", setClusterProp(client, ZkStateReader.LEGACY_CLOUD, "false"));
- assertTrue("cluster property not unset ", setClusterProp(client, ZkStateReader.LEGACY_CLOUD, null));
-
- client.shutdown();
+ try (CloudSolrClient client = createCloudClient(null)) {
+ assertTrue("cluster property not set", setClusterProp(client, ZkStateReader.LEGACY_CLOUD, "false"));
+ assertTrue("cluster property not unset ", setClusterProp(client, ZkStateReader.LEGACY_CLOUD, null));
+ }
}
public static boolean setClusterProp(CloudSolrClient client, String name , String val) throws SolrServerException, IOException, InterruptedException {
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java Sun Feb 8 23:53:14 2015
@@ -34,6 +34,7 @@ import org.apache.solr.common.cloud.ZkSt
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.util.NamedList;
import org.apache.zookeeper.KeeperException;
+import org.junit.Test;
import java.io.File;
import java.io.IOException;
@@ -49,9 +50,9 @@ import static org.apache.solr.cloud.Repl
@LuceneTestCase.Slow
public class CollectionsAPISolrJTests extends AbstractFullDistribZkTestBase {
-
- @Override
- public void doTest() throws Exception {
+
+ @Test
+ public void test() throws Exception {
testCreateAndDeleteCollection();
testCreateAndDeleteShard();
testReloadCollection();
@@ -67,19 +68,6 @@ public class CollectionsAPISolrJTests ex
testBalanceShardUnique();
}
- public void tearDown() throws Exception {
- if (controlClient != null) {
- controlClient.shutdown();
- }
- if (cloudClient != null) {
- cloudClient.shutdown();
- }
- if (controlClientCloud != null) {
- controlClientCloud.shutdown();
- }
- super.tearDown();
- }
-
protected void testCreateAndDeleteCollection() throws Exception {
String collectionName = "solrj_test";
CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create();
@@ -269,9 +257,8 @@ public class CollectionsAPISolrJTests ex
Replica replica1 = testCollection.getReplica("core_node1");
- HttpSolrClient solrServer = new HttpSolrClient(replica1.getStr("base_url"));
- try {
- CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), solrServer);
+ try (HttpSolrClient client = new HttpSolrClient(replica1.getStr("base_url"))) {
+ CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), client);
NamedList<Object> coreStatus = status.getCoreStatus(replica1.getStr("core"));
String dataDirStr = (String) coreStatus.get("dataDir");
String instanceDirStr = (String) coreStatus.get("instanceDir");
@@ -279,9 +266,6 @@ public class CollectionsAPISolrJTests ex
new File(instanceDirStr).getAbsolutePath(), instanceDir.getAbsolutePath());
assertEquals("Data dir does not match param given in property.dataDir syntax",
new File(dataDirStr).getAbsolutePath(), dataDir.getAbsolutePath());
-
- } finally {
- solrServer.shutdown();
}
CollectionAdminRequest.Delete deleteCollectionRequest = new CollectionAdminRequest.Delete();