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 [28/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/UnloadDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/UnloadDistributedZkTest.java Sun Feb 8 23:53:14 2015
@@ -29,10 +29,10 @@ import org.apache.solr.common.SolrInputD
import org.apache.solr.common.cloud.ZkCoreNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.common.params.SolrParams;
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.File;
import java.io.IOException;
@@ -48,17 +48,6 @@ import java.util.concurrent.TimeUnit;
@Slow
@SuppressSSL(bugUrl = "https://issues.apache.org/jira/browse/SOLR-5776")
public class UnloadDistributedZkTest extends BasicDistributedZkTest {
-
- @BeforeClass
- public static void beforeThisClass3() throws Exception {
-
- }
-
- @Before
- @Override
- public void setUp() throws Exception {
- super.setUp();
- }
protected String getSolrXml() {
return "solr-no-core.xml";
@@ -68,9 +57,9 @@ public class UnloadDistributedZkTest ext
super();
checkCreatedVsState = false;
}
-
- @Override
- public void doTest() throws Exception {
+
+ @Test
+ public void test() throws Exception {
testCoreUnloadAndLeaders(); // long
testUnloadLotsOfCores(); // long
@@ -94,51 +83,51 @@ public class UnloadDistributedZkTest ext
SolrClient client = clients.get(0);
String url1 = getBaseUrl(client);
- HttpSolrClient adminClient = new HttpSolrClient(url1);
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(60000);
- adminClient.request(createCmd);
-
- createCmd = new Create();
- createCmd.setCoreName("test_unload_shard_and_collection_2");
- collection = "test_unload_shard_and_collection";
- createCmd.setCollection(collection);
- coreDataDir = createTempDir().toFile().getAbsolutePath();
- createCmd.setDataDir(getDataDir(coreDataDir));
-
- adminClient.request(createCmd);
-
- // does not mean they are active and up yet :*
- waitForRecoveriesToFinish(collection, false);
- // now unload one of the two
- Unload unloadCmd = new Unload(false);
- unloadCmd.setCoreName("test_unload_shard_and_collection_2");
- adminClient.request(unloadCmd);
-
- // there should be only one shard
- int slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collection).size();
- long timeoutAt = System.currentTimeMillis() + 45000;
- while (slices != 1) {
- if (System.currentTimeMillis() > timeoutAt) {
- printLayout();
- fail("Expected to find only one slice in " + collection);
+ try (HttpSolrClient adminClient = new HttpSolrClient(url1)) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(60000);
+ adminClient.request(createCmd);
+
+ createCmd = new Create();
+ createCmd.setCoreName("test_unload_shard_and_collection_2");
+ collection = "test_unload_shard_and_collection";
+ createCmd.setCollection(collection);
+ coreDataDir = createTempDir().toFile().getAbsolutePath();
+ createCmd.setDataDir(getDataDir(coreDataDir));
+
+ adminClient.request(createCmd);
+
+ // does not mean they are active and up yet :*
+ waitForRecoveriesToFinish(collection, false);
+
+ // now unload one of the two
+ Unload unloadCmd = new Unload(false);
+ unloadCmd.setCoreName("test_unload_shard_and_collection_2");
+ adminClient.request(unloadCmd);
+
+ // there should be only one shard
+ int slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collection).size();
+ long timeoutAt = System.currentTimeMillis() + 45000;
+ while (slices != 1) {
+ if (System.currentTimeMillis() > timeoutAt) {
+ printLayout();
+ fail("Expected to find only one slice in " + collection);
+ }
+
+ Thread.sleep(1000);
+ slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collection).size();
}
-
- Thread.sleep(1000);
- slices = getCommonCloudSolrClient().getZkStateReader().getClusterState().getSlices(collection).size();
+
+ // now unload one of the other
+ unloadCmd = new Unload(false);
+ unloadCmd.setCoreName("test_unload_shard_and_collection_1");
+ adminClient.request(unloadCmd);
}
-
- // now unload one of the other
- unloadCmd = new Unload(false);
- unloadCmd.setCoreName("test_unload_shard_and_collection_1");
- adminClient.request(unloadCmd);
- adminClient.shutdown();
- adminClient = null;
-
+
//printLayout();
// the collection should be gone
- timeoutAt = System.currentTimeMillis() + 30000;
+ long timeoutAt = System.currentTimeMillis() + 30000;
while (getCommonCloudSolrClient().getZkStateReader().getClusterState().hasCollection(collection)) {
if (System.currentTimeMillis() > timeoutAt) {
printLayout();
@@ -155,24 +144,23 @@ public class UnloadDistributedZkTest ext
*/
private void testCoreUnloadAndLeaders() throws Exception {
File tmpDir = createTempDir().toFile();
-
+
+ String core1DataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection1" + "_1n";
+
// create a new collection collection
SolrClient client = clients.get(0);
String url1 = getBaseUrl(client);
- HttpSolrClient adminClient = new HttpSolrClient(url1);
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(60000);
-
- Create createCmd = new Create();
- createCmd.setCoreName("unloadcollection1");
- createCmd.setCollection("unloadcollection");
- createCmd.setNumShards(1);
- String core1DataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection1" + "_1n";
- createCmd.setDataDir(getDataDir(core1DataDir));
- adminClient.request(createCmd);
- adminClient.shutdown();
- adminClient = null;
-
+ try (HttpSolrClient adminClient = new HttpSolrClient(url1)) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(60000);
+
+ Create createCmd = new Create();
+ createCmd.setCoreName("unloadcollection1");
+ createCmd.setCollection("unloadcollection");
+ createCmd.setNumShards(1);
+ createCmd.setDataDir(getDataDir(core1DataDir));
+ adminClient.request(createCmd);
+ }
ZkStateReader zkStateReader = getCommonCloudSolrClient().getZkStateReader();
zkStateReader.updateClusterState(true);
@@ -182,17 +170,15 @@ public class UnloadDistributedZkTest ext
client = clients.get(1);
String url2 = getBaseUrl(client);
- adminClient = new HttpSolrClient(url2);
-
- createCmd = new Create();
- createCmd.setCoreName("unloadcollection2");
- createCmd.setCollection("unloadcollection");
- String core2dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection1" + "_2n";
- createCmd.setDataDir(getDataDir(core2dataDir));
- adminClient.request(createCmd);
- adminClient.shutdown();
- adminClient = null;
-
+ try (HttpSolrClient adminClient = new HttpSolrClient(url2)) {
+
+ Create createCmd = new Create();
+ createCmd.setCoreName("unloadcollection2");
+ createCmd.setCollection("unloadcollection");
+ String core2dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection1" + "_2n";
+ createCmd.setDataDir(getDataDir(core2dataDir));
+ adminClient.request(createCmd);
+ }
zkStateReader.updateClusterState(true);
slices = zkStateReader.getClusterState().getCollection("unloadcollection").getSlices().size();
assertEquals(1, slices);
@@ -202,73 +188,64 @@ public class UnloadDistributedZkTest ext
ZkCoreNodeProps leaderProps = getLeaderUrlFromZk("unloadcollection", "shard1");
Random random = random();
- HttpSolrClient collectionClient;
if (random.nextBoolean()) {
- collectionClient = new HttpSolrClient(leaderProps.getCoreUrl());
- // lets try and use the solrj client to index and retrieve 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();
- collectionClient.shutdown();
- collectionClient = null;
+ try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getCoreUrl())) {
+ // lets try and use the solrj client to index and retrieve 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();
+ }
}
// create another replica for our collection
client = clients.get(2);
String url3 = getBaseUrl(client);
- adminClient = new HttpSolrClient(url3);
-
- createCmd = new Create();
- createCmd.setCoreName("unloadcollection3");
- createCmd.setCollection("unloadcollection");
- String core3dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection" + "_3n";
- createCmd.setDataDir(getDataDir(core3dataDir));
- adminClient.request(createCmd);
- adminClient.shutdown();
- adminClient = null;
-
+ try (HttpSolrClient adminClient = new HttpSolrClient(url3)) {
+ Create createCmd = new Create();
+ createCmd.setCoreName("unloadcollection3");
+ createCmd.setCollection("unloadcollection");
+ String core3dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection" + "_3n";
+ createCmd.setDataDir(getDataDir(core3dataDir));
+ adminClient.request(createCmd);
+ }
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
// so that we start with some versions when we reload...
DirectUpdateHandler2.commitOnClose = false;
- HttpSolrClient addClient = new HttpSolrClient(url3 + "/unloadcollection3");
- addClient.setConnectionTimeout(30000);
+ try (HttpSolrClient addClient = new HttpSolrClient(url3 + "/unloadcollection3")) {
+ addClient.setConnectionTimeout(30000);
- // add a few docs
- for (int x = 20; x < 100; x++) {
- SolrInputDocument doc1 = getDoc(id, x, i1, -600, tlong, 600, t1,
- "humpty dumpy sat on a wall");
- addClient.add(doc1);
+ // add a few docs
+ for (int x = 20; x < 100; x++) {
+ SolrInputDocument doc1 = getDoc(id, x, i1, -600, tlong, 600, t1,
+ "humpty dumpy sat on a wall");
+ addClient.add(doc1);
+ }
}
- addClient.shutdown();
- addClient = null;
-
// don't commit so they remain in the tran log
//collectionClient.commit();
// unload the leader
- collectionClient = new HttpSolrClient(leaderProps.getBaseUrl());
- collectionClient.setConnectionTimeout(15000);
- collectionClient.setSoTimeout(30000);
-
- Unload unloadCmd = new Unload(false);
- unloadCmd.setCoreName(leaderProps.getCoreName());
- ModifiableSolrParams p = (ModifiableSolrParams) unloadCmd.getParams();
-
- collectionClient.request(unloadCmd);
- collectionClient.shutdown();
- collectionClient = null;
+ try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getBaseUrl())) {
+ collectionClient.setConnectionTimeout(15000);
+ collectionClient.setSoTimeout(30000);
+
+ Unload unloadCmd = new Unload(false);
+ unloadCmd.setCoreName(leaderProps.getCoreName());
+ ModifiableSolrParams p = (ModifiableSolrParams) unloadCmd.getParams();
+ collectionClient.request(unloadCmd);
+ }
// Thread.currentThread().sleep(500);
// printLayout();
@@ -283,51 +260,45 @@ public class UnloadDistributedZkTest ext
// ensure there is a leader
zkStateReader.getLeaderRetry("unloadcollection", "shard1", 15000);
- addClient = new HttpSolrClient(url2 + "/unloadcollection2");
- addClient.setConnectionTimeout(30000);
- addClient.setSoTimeout(90000);
-
- // add a few docs while the leader is down
- for (int x = 101; x < 200; x++) {
- SolrInputDocument doc1 = getDoc(id, x, i1, -600, tlong, 600, t1,
- "humpty dumpy sat on a wall");
- addClient.add(doc1);
+ try (HttpSolrClient addClient = new HttpSolrClient(url2 + "/unloadcollection2")) {
+ addClient.setConnectionTimeout(30000);
+ addClient.setSoTimeout(90000);
+
+ // add a few docs while the leader is down
+ for (int x = 101; x < 200; x++) {
+ SolrInputDocument doc1 = getDoc(id, x, i1, -600, tlong, 600, t1,
+ "humpty dumpy sat on a wall");
+ addClient.add(doc1);
+ }
}
- addClient.shutdown();
- addClient = null;
-
// create another replica for our collection
client = clients.get(3);
String url4 = getBaseUrl(client);
- adminClient = new HttpSolrClient(url4);
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(30000);
-
- createCmd = new Create();
- createCmd.setCoreName("unloadcollection4");
- createCmd.setCollection("unloadcollection");
- String core4dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection" + "_4n";
- createCmd.setDataDir(getDataDir(core4dataDir));
- adminClient.request(createCmd);
- adminClient.shutdown();
- adminClient = null;
-
+ try (HttpSolrClient adminClient = new HttpSolrClient(url4)) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(30000);
+
+ Create createCmd = new Create();
+ createCmd.setCoreName("unloadcollection4");
+ createCmd.setCollection("unloadcollection");
+ String core4dataDir = tmpDir.getAbsolutePath() + File.separator + System.currentTimeMillis() + "unloadcollection" + "_4n";
+ createCmd.setDataDir(getDataDir(core4dataDir));
+ adminClient.request(createCmd);
+ }
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
// unload the leader again
leaderProps = getLeaderUrlFromZk("unloadcollection", "shard1");
- collectionClient = new HttpSolrClient(leaderProps.getBaseUrl());
- collectionClient.setConnectionTimeout(15000);
- collectionClient.setSoTimeout(30000);
-
- unloadCmd = new Unload(false);
- unloadCmd.setCoreName(leaderProps.getCoreName());
- p = (ModifiableSolrParams) unloadCmd.getParams();
- collectionClient.request(unloadCmd);
- collectionClient.shutdown();
- collectionClient = null;
-
+ try (HttpSolrClient collectionClient = new HttpSolrClient(leaderProps.getBaseUrl())) {
+ collectionClient.setConnectionTimeout(15000);
+ collectionClient.setSoTimeout(30000);
+
+ Unload unloadCmd = new Unload(false);
+ unloadCmd.setCoreName(leaderProps.getCoreName());
+ SolrParams p = (ModifiableSolrParams) unloadCmd.getParams();
+ collectionClient.request(unloadCmd);
+ }
tries = 50;
while (leaderProps.getCoreUrl().equals(zkStateReader.getLeaderUrl("unloadcollection", "shard1", 15000))) {
Thread.sleep(100);
@@ -343,99 +314,90 @@ public class UnloadDistributedZkTest ext
DirectUpdateHandler2.commitOnClose = true;
// bring the downed leader back as replica
- adminClient = new HttpSolrClient(leaderProps.getBaseUrl());
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(30000);
-
- createCmd = new Create();
- createCmd.setCoreName(leaderProps.getCoreName());
- createCmd.setCollection("unloadcollection");
- createCmd.setDataDir(getDataDir(core1DataDir));
- adminClient.request(createCmd);
- adminClient.shutdown();
- adminClient = null;
-
+ try (HttpSolrClient adminClient = new HttpSolrClient(leaderProps.getBaseUrl())) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(30000);
+
+ Create createCmd = new Create();
+ createCmd.setCoreName(leaderProps.getCoreName());
+ createCmd.setCollection("unloadcollection");
+ createCmd.setDataDir(getDataDir(core1DataDir));
+ adminClient.request(createCmd);
+ }
waitForRecoveriesToFinish("unloadcollection", zkStateReader, false);
+
+ long found1, found3;
- adminClient = new HttpSolrClient(url2 + "/unloadcollection");
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(30000);
- adminClient.commit();
- SolrQuery q = new SolrQuery("*:*");
- q.set("distrib", false);
- long found1 = adminClient.query(q).getResults().getNumFound();
- adminClient.shutdown();
- adminClient = new HttpSolrClient(url3 + "/unloadcollection");
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(30000);
- adminClient.commit();
- q = new SolrQuery("*:*");
- q.set("distrib", false);
- long found3 = adminClient.query(q).getResults().getNumFound();
- adminClient.shutdown();
- adminClient = new HttpSolrClient(url4 + "/unloadcollection");
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(30000);
- adminClient.commit();
- q = new SolrQuery("*:*");
- q.set("distrib", false);
- long found4 = adminClient.query(q).getResults().getNumFound();
-
- // all 3 shards should now have the same number of docs
- assertEquals(found1, found3);
- assertEquals(found3, found4);
- adminClient.shutdown();
+ try (HttpSolrClient adminClient = new HttpSolrClient(url2 + "/unloadcollection")) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(30000);
+ adminClient.commit();
+ SolrQuery q = new SolrQuery("*:*");
+ q.set("distrib", false);
+ found1 = adminClient.query(q).getResults().getNumFound();
+ }
+ try (HttpSolrClient adminClient = new HttpSolrClient(url3 + "/unloadcollection")) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(30000);
+ adminClient.commit();
+ SolrQuery q = new SolrQuery("*:*");
+ q.set("distrib", false);
+ found3 = adminClient.query(q).getResults().getNumFound();
+ }
+
+ try (HttpSolrClient adminClient = new HttpSolrClient(url4 + "/unloadcollection")) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(30000);
+ adminClient.commit();
+ SolrQuery q = new SolrQuery("*:*");
+ q.set("distrib", false);
+ long found4 = adminClient.query(q).getResults().getNumFound();
+
+ // all 3 shards should now have the same number of docs
+ assertEquals(found1, found3);
+ assertEquals(found3, found4);
+ }
}
private void testUnloadLotsOfCores() throws Exception {
SolrClient client = clients.get(2);
String url3 = getBaseUrl(client);
- final HttpSolrClient adminClient = new HttpSolrClient(url3);
- adminClient.setConnectionTimeout(15000);
- adminClient.setSoTimeout(60000);
- ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
- 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
- new DefaultSolrThreadFactory("testExecutor"));
- int cnt = atLeast(3);
-
- // create the cores
- createCores(adminClient, executor, "multiunload", 2, cnt);
-
- executor.shutdown();
- executor.awaitTermination(120, TimeUnit.SECONDS);
- executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5,
- TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
- new DefaultSolrThreadFactory("testExecutor"));
- for (int j = 0; j < cnt; j++) {
- final int freezeJ = j;
- executor.execute(new Runnable() {
- @Override
- public void run() {
- Unload unloadCmd = new Unload(true);
- unloadCmd.setCoreName("multiunload" + freezeJ);
- try {
- adminClient.request(unloadCmd);
- } catch (SolrServerException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
+ try (final HttpSolrClient adminClient = new HttpSolrClient(url3)) {
+ adminClient.setConnectionTimeout(15000);
+ adminClient.setSoTimeout(60000);
+ ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
+ 5, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
+ new DefaultSolrThreadFactory("testExecutor"));
+ int cnt = atLeast(3);
+
+ // create the cores
+ createCores(adminClient, executor, "multiunload", 2, cnt);
+
+ executor.shutdown();
+ executor.awaitTermination(120, TimeUnit.SECONDS);
+ executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5,
+ TimeUnit.SECONDS, new SynchronousQueue<Runnable>(),
+ new DefaultSolrThreadFactory("testExecutor"));
+ for (int j = 0; j < cnt; j++) {
+ final int freezeJ = j;
+ executor.execute(new Runnable() {
+ @Override
+ public void run() {
+ Unload unloadCmd = new Unload(true);
+ unloadCmd.setCoreName("multiunload" + freezeJ);
+ try {
+ adminClient.request(unloadCmd);
+ } catch (SolrServerException | IOException e) {
+ throw new RuntimeException(e);
+ }
}
- }
- });
- Thread.sleep(random().nextInt(50));
+ });
+ Thread.sleep(random().nextInt(50));
+ }
+ executor.shutdown();
+ executor.awaitTermination(120, TimeUnit.SECONDS);
}
- executor.shutdown();
- executor.awaitTermination(120, TimeUnit.SECONDS);
- adminClient.shutdown();
}
-
-
-
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
- }
}
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkCLITest.java Sun Feb 8 23:53:14 2015
@@ -17,14 +17,6 @@ package org.apache.solr.cloud;
* limitations under the License.
*/
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Collection;
-import java.util.List;
-
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.RegexFileFilter;
@@ -44,6 +36,14 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.List;
+
// TODO: This test would be a lot faster if it used a solrhome with fewer config
// files - there are a lot of them to upload
public class ZkCLITest extends SolrTestCaseJ4 {
@@ -78,19 +78,10 @@ public class ZkCLITest extends SolrTestC
log.info("####SETUP_START " + getTestName());
String exampleHome = SolrJettyTestBase.legacyExampleCollection1SolrHome();
-
- boolean useNewSolrXml = random().nextBoolean();
+
File tmpDir = createTempDir().toFile();
- if (useNewSolrXml) {
- solrHome = exampleHome;
- } else {
- File tmpSolrHome = new File(tmpDir, "tmp-solr-home");
- FileUtils.copyDirectory(new File(exampleHome), tmpSolrHome);
- FileUtils.copyFile(getFile("old-solr-example/solr.xml"), new File(tmpSolrHome, "solr.xml"));
- solrHome = tmpSolrHome.getAbsolutePath();
- }
-
-
+ solrHome = exampleHome;
+
zkDir = tmpDir.getAbsolutePath() + File.separator
+ "zookeeper/server1/data";
log.info("ZooKeeper dataDir:" + zkDir);
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkControllerTest.java Sun Feb 8 23:53:14 2015
@@ -17,12 +17,6 @@ package org.apache.solr.cloud;
* the License.
*/
-import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.SolrTestCaseJ4;
@@ -33,16 +27,21 @@ import org.apache.solr.core.ConfigSolr;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.CoresLocator;
+import org.apache.solr.core.PluginInfo;
import org.apache.solr.handler.admin.CoreAdminHandler;
import org.apache.solr.handler.component.HttpShardHandlerFactory;
-import org.apache.solr.handler.component.ShardHandlerFactory;
import org.apache.solr.update.UpdateShardHandler;
-import org.apache.solr.util.ExternalPaths;
import org.apache.zookeeper.CreateMode;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
@Slow
public class ZkControllerTest extends SolrTestCaseJ4 {
@@ -323,7 +322,7 @@ public class ZkControllerTest extends So
@Override
public ConfigSolr getConfig() {
- return new ConfigSolr() {
+ return new ConfigSolr(null, null) {
@Override
public CoresLocator getCoresLocator() {
@@ -331,25 +330,22 @@ public class ZkControllerTest extends So
}
@Override
- protected String getShardHandlerFactoryConfigPath() {
- throw new UnsupportedOperationException();
+ public PluginInfo getShardHandlerFactoryPluginInfo() {
+ return null;
}
@Override
- public boolean isPersistent() {
- throw new UnsupportedOperationException();
- }};
+ protected String getProperty(CfgProp key) {
+ return null;
+ }
+
+ };
}
@Override
public UpdateShardHandler getUpdateShardHandler() {
return new UpdateShardHandler(null);
}
-
- @Override
- public String getAdminPath() {
- return "/admin/cores";
- }
}
}
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/ZkSolrClientTest.java Sun Feb 8 23:53:14 2015
@@ -176,9 +176,7 @@ public class ZkSolrClientTest extends Ab
try {
zkClient.makePath("collections/collection4", true);
break;
- } catch (KeeperException.SessionExpiredException e) {
-
- } catch (KeeperException.ConnectionLossException e) {
+ } catch (KeeperException.SessionExpiredException | KeeperException.ConnectionLossException e) {
}
Thread.sleep(1000 * i);
@@ -289,9 +287,7 @@ public class ZkSolrClientTest extends Ab
try {
zkClient.getChildren("/collections", this, true);
latch.countDown();
- } catch (KeeperException e) {
- throw new RuntimeException(e);
- } catch (InterruptedException e) {
+ } catch (KeeperException | InterruptedException e) {
throw new RuntimeException(e);
}
}
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsChaosMonkeySafeLeaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsChaosMonkeySafeLeaderTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsChaosMonkeySafeLeaderTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsChaosMonkeySafeLeaderTest.java Sun Feb 8 23:53:14 2015
@@ -23,7 +23,6 @@ import org.apache.hadoop.hdfs.MiniDFSClu
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.cloud.ChaosMonkeySafeLeaderTest;
import org.junit.AfterClass;
-import org.junit.Before;
import org.junit.BeforeClass;
import com.carrotsearch.randomizedtesting.annotations.Nightly;
@@ -47,10 +46,9 @@ public class HdfsChaosMonkeySafeLeaderTe
dfsCluster = null;
}
- @Before
@Override
- public void setUp() throws Exception {
- super.setUp();
+ public void distribSetUp() throws Exception {
+ super.distribSetUp();
// super class may hard code directory
useFactory("org.apache.solr.core.HdfsDirectoryFactory");
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsCollectionsAPIDistributedZkTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsCollectionsAPIDistributedZkTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsCollectionsAPIDistributedZkTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsCollectionsAPIDistributedZkTest.java Sun Feb 8 23:53:14 2015
@@ -22,6 +22,7 @@ import java.io.IOException;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.cloud.CollectionsAPIDistributedZkTest;
+import org.apache.solr.update.HdfsUpdateLog;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -46,6 +47,7 @@ public class HdfsCollectionsAPIDistribut
@AfterClass
public static void teardownClass() throws Exception {
+ assertEquals(0, HdfsUpdateLog.INIT_FAILED_LOGS_COUNT.get());
HdfsTestUtil.teardownClass(dfsCluster);
System.clearProperty("solr.hdfs.home");
System.clearProperty("solr.hdfs.blockcache.enabled");
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsSyncSliceTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsSyncSliceTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsSyncSliceTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsSyncSliceTest.java Sun Feb 8 23:53:14 2015
@@ -23,7 +23,6 @@ import org.apache.hadoop.hdfs.MiniDFSClu
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.cloud.SyncSliceTest;
import org.junit.AfterClass;
-import org.junit.Before;
import org.junit.BeforeClass;
import com.carrotsearch.randomizedtesting.annotations.Nightly;
@@ -46,14 +45,7 @@ public class HdfsSyncSliceTest extends S
HdfsTestUtil.teardownClass(dfsCluster);
dfsCluster = null;
}
-
- @Before
- @Override
- public void setUp() throws Exception {
- super.setUp();
- }
-
@Override
protected String getDataDir(String dataDir) throws IOException {
return HdfsTestUtil.getDataDir(dfsCluster, dataDir);
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsTestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsTestUtil.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsTestUtil.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsTestUtil.java Sun Feb 8 23:53:14 2015
@@ -10,10 +10,14 @@ import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.util.IOUtils;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -38,7 +42,13 @@ public class HdfsTestUtil {
private static Map<MiniDFSCluster,Timer> timers = new ConcurrentHashMap<>();
+ private static FSDataOutputStream badTlogOutStream;
+
public static MiniDFSCluster setupClass(String dir) throws Exception {
+ return setupClass(dir, true);
+ }
+
+ public static MiniDFSCluster setupClass(String dir, boolean safeModeTesting) throws Exception {
LuceneTestCase.assumeFalse("HDFS tests were disabled by -Dtests.disableHdfs",
Boolean.parseBoolean(System.getProperty("tests.disableHdfs", "false")));
@@ -65,23 +75,32 @@ public class HdfsTestUtil {
final MiniDFSCluster dfsCluster = new MiniDFSCluster(conf, dataNodes, true, null);
dfsCluster.waitActive();
-
- System.setProperty("solr.hdfs.home", getDataDir(dfsCluster, "solr_hdfs_home"));
-
- NameNodeAdapter.enterSafeMode(dfsCluster.getNameNode(), false);
+ System.setProperty("solr.hdfs.home", getDataDir(dfsCluster, "solr_hdfs_home"));
- int rnd = LuceneTestCase.random().nextInt(10000);
- Timer timer = new Timer();
- timer.schedule(new TimerTask() {
+ int rndMode = LuceneTestCase.random().nextInt(10);
+ if (safeModeTesting && rndMode > 4) {
+ NameNodeAdapter.enterSafeMode(dfsCluster.getNameNode(), false);
- @Override
- public void run() {
- NameNodeAdapter.leaveSafeMode(dfsCluster.getNameNode());
- }
- }, rnd);
-
- timers.put(dfsCluster, timer);
+ int rnd = LuceneTestCase.random().nextInt(10000);
+ Timer timer = new Timer();
+ timer.schedule(new TimerTask() {
+
+ @Override
+ public void run() {
+ NameNodeAdapter.leaveSafeMode(dfsCluster.getNameNode());
+ }
+ }, rnd);
+
+ timers.put(dfsCluster, timer);
+ } else {
+ // force a lease recovery by creating a tlog file and not closing it
+ URI uri = dfsCluster.getURI();
+ Path hdfsDirPath = new Path(uri.toString() + "/solr/collection1/core_node1/data/tlog/tlog.0000000000000000000");
+ // tran log already being created testing
+ FileSystem fs = FileSystem.newInstance(hdfsDirPath.toUri(), conf);
+ badTlogOutStream = fs.create(hdfsDirPath);
+ }
SolrTestCaseJ4.useFactory("org.apache.solr.core.HdfsDirectoryFactory");
@@ -100,6 +119,10 @@ public class HdfsTestUtil {
dfsCluster.shutdown();
}
+ if (badTlogOutStream != null) {
+ IOUtils.closeQuietly(badTlogOutStream);
+ }
+
// TODO: we HACK around HADOOP-9643
if (savedLocale != null) {
Locale.setDefault(savedLocale);
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/HdfsWriteToMultipleCollectionsTest.java Sun Feb 8 23:53:14 2015
@@ -22,6 +22,7 @@ import com.carrotsearch.randomizedtestin
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.NRTCachingDirectory;
+import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase.Nightly;
import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.solr.client.solrj.SolrQuery;
@@ -40,6 +41,7 @@ import org.apache.solr.store.blockcache.
import org.apache.solr.util.RefCounted;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
@@ -77,15 +79,15 @@ public class HdfsWriteToMultipleCollecti
public HdfsWriteToMultipleCollectionsTest() {
super();
sliceCount = 1;
- shardCount = 3;
+ fixShardCount(3);
}
protected String getSolrXml() {
return "solr-no-core.xml";
}
-
- @Override
- public void doTest() throws Exception {
+
+ @Test
+ public void test() throws Exception {
int docCount = random().nextInt(1313) + 1;
int cnt = random().nextInt(4) + 1;
for (int i = 0; i < cnt; i++) {
@@ -116,10 +118,8 @@ public class HdfsWriteToMultipleCollecti
client.commit();
collectionsCount += client.query(new SolrQuery("*:*")).getResults().getNumFound();
}
-
- for (CloudSolrClient client : cloudClients) {
- client.shutdown();
- }
+
+ IOUtils.close(cloudClients);
assertEquals(addCnt, collectionsCount);
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/hdfs/StressHdfsTest.java Sun Feb 8 23:53:14 2015
@@ -17,14 +17,8 @@
package org.apache.solr.cloud.hdfs;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
-
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
@@ -32,8 +26,8 @@ import org.apache.hadoop.hdfs.MiniDFSClu
import org.apache.hadoop.hdfs.server.namenode.NameNodeAdapter;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.Slow;
-import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrClient;
+import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.QueryRequest;
@@ -45,9 +39,15 @@ import org.apache.solr.common.util.Named
import org.apache.zookeeper.KeeperException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.Test;
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
@Slow
@ThreadLeakScope(Scope.NONE) // hdfs client currently leaks thread(s)
@@ -80,16 +80,16 @@ public class StressHdfsTest extends Basi
public StressHdfsTest() {
super();
sliceCount = 1;
- shardCount = TEST_NIGHTLY ? 7 : random().nextInt(2) + 1;
+ fixShardCount(TEST_NIGHTLY ? 7 : random().nextInt(2) + 1);
testRestartIntoSafeMode = random().nextBoolean();
}
protected String getSolrXml() {
return "solr-no-core.xml";
}
-
- @Override
- public void doTest() throws Exception {
+
+ @Test
+ public void test() throws Exception {
randomlyEnableAutoSoftCommit();
int cnt = random().nextInt(2) + 1;
@@ -138,11 +138,11 @@ public class StressHdfsTest extends Basi
int nShards;
int maxReplicasPerNode;
if (overshard) {
- nShards = shardCount * 2;
+ nShards = getShardCount() * 2;
maxReplicasPerNode = 8;
rep = 1;
} else {
- nShards = shardCount / 2;
+ nShards = getShardCount() / 2;
maxReplicasPerNode = 1;
rep = 2;
if (nShards == 0) nShards = 1;
@@ -163,8 +163,7 @@ public class StressHdfsTest extends Basi
int i = 0;
for (SolrClient client : clients) {
- HttpSolrClient c = new HttpSolrClient(getBaseUrl(client) + "/" + DELETE_DATA_DIR_COLLECTION);
- try {
+ try (HttpSolrClient c = new HttpSolrClient(getBaseUrl(client) + "/" + DELETE_DATA_DIR_COLLECTION)) {
int docCnt = random().nextInt(1000) + 1;
for (int j = 0; j < docCnt; j++) {
c.add(getDoc("id", i++, "txt_t", "just some random text for a doc"));
@@ -182,8 +181,6 @@ public class StressHdfsTest extends Basi
NamedList<Object> coreInfo = (NamedList<Object>) response.get("core");
String dataDir = (String) ((NamedList<Object>) coreInfo.get("directory")).get("data");
dataDirs.add(dataDir);
- } finally {
- c.shutdown();
}
}
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/cloud/overseer/ZkStateWriterTest.java Sun Feb 8 23:53:14 2015
@@ -18,6 +18,7 @@ package org.apache.solr.cloud.overseer;
*/
import java.util.HashMap;
+import java.util.Map;
import org.apache.lucene.util.IOUtils;
import org.apache.solr.SolrTestCaseJ4;
@@ -28,6 +29,7 @@ import org.apache.solr.cloud.ZkTestServe
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.DocRouter;
+import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.ZkStateReader;
@@ -116,4 +118,47 @@ public class ZkStateWriterTest extends S
}
}
+ public void testSingleExternalCollection() throws Exception{
+ String zkDir = createTempDir("testSingleExternalCollection").toFile().getAbsolutePath();
+
+ ZkTestServer server = new ZkTestServer(zkDir);
+
+ SolrZkClient zkClient = null;
+
+ try {
+ server.run();
+ AbstractZkTestCase.tryCleanSolrZkNode(server.getZkHost());
+ AbstractZkTestCase.makeSolrZkNode(server.getZkHost());
+
+ zkClient = new SolrZkClient(server.getZkAddress(), OverseerTest.DEFAULT_CONNECTION_TIMEOUT);
+ zkClient.makePath(ZkStateReader.LIVE_NODES_ZKNODE, true);
+
+ ZkStateReader reader = new ZkStateReader(zkClient);
+ reader.createClusterStateWatchersAndUpdate();
+
+ ZkStateWriter writer = new ZkStateWriter(reader, new Overseer.Stats());
+
+ zkClient.makePath(ZkStateReader.COLLECTIONS_ZKNODE + "/c1", true);
+
+ // create new collection with stateFormat = 2
+ ZkWriteCommand c1 = new ZkWriteCommand("c1",
+ new DocCollection("c1", new HashMap<String, Slice>(), new HashMap<String, Object>(), DocRouter.DEFAULT, 0, ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json"));
+
+ ClusterState clusterState = writer.enqueueUpdate(reader.getClusterState(), c1, null);
+ writer.writePendingUpdates();
+
+ Map map = (Map) ZkStateReader.fromJSON(zkClient.getData("/clusterstate.json", null, null, true));
+ assertNull(map.get("c1"));
+ map = (Map) ZkStateReader.fromJSON(zkClient.getData(ZkStateReader.COLLECTIONS_ZKNODE + "/c1/state.json", null, null, true));
+ assertNotNull(map.get("c1"));
+
+ } finally {
+ IOUtils.close(zkClient);
+ server.shutdown();
+
+ }
+
+
+ }
+
}
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/OpenCloseCoreStressTest.java Sun Feb 8 23:53:14 2015
@@ -18,8 +18,8 @@
package org.apache.solr.core;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.IOUtils;
import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.UpdateRequest;
@@ -93,59 +93,49 @@ public class OpenCloseCoreStressTest ext
@After
public void tearDownServer() throws Exception {
if (jetty != null) jetty.stop();
- for(SolrClient client: indexingClients) {
- client.shutdown();
- }
- for(SolrClient client: queryingClients) {
- client.shutdown();
- }
+ IOUtils.close(indexingClients);
+ IOUtils.close(queryingClients);
indexingClients.clear();
queryingClients.clear();
}
@Test
public void test5Seconds() throws Exception {
- doStress(5, random().nextBoolean());
+ doStress(5);
}
@Test
@Nightly
public void test15SecondsOld() throws Exception {
- doStress(15, true);
+ doStress(15);
}
@Test
@Nightly
public void test15SecondsNew() throws Exception {
- doStress(15, false);
+ doStress(15);
}
@Test
@Nightly
public void test10MinutesOld() throws Exception {
- doStress(300, true);
+ doStress(300);
}
@Test
@Nightly
public void test10MinutesNew() throws Exception {
- doStress(300, false);
- }
-
- @Test
- @Weekly
- public void test1HourOld() throws Exception {
- doStress(1800, true);
+ doStress(300);
}
@Test
@Weekly
- public void test1HourNew() throws Exception {
- doStress(1800, false);
+ public void test1Hour() throws Exception {
+ doStress(1800);
}
-
-
+
private void buildClients() throws Exception {
+
jetty.start();
url = buildUrl(jetty.getLocalPort(), "/solr/");
@@ -169,8 +159,8 @@ public class OpenCloseCoreStressTest ext
}
// Unless things go _really_ well, stop after you have the directories set up.
- private void doStress(int secondsToRun, boolean oldStyle) throws Exception {
- makeCores(solrHomeDirectory, oldStyle);
+ private void doStress(int secondsToRun) throws Exception {
+ makeCores(solrHomeDirectory);
//MUST start the server after the cores are made.
buildClients();
@@ -213,25 +203,22 @@ public class OpenCloseCoreStressTest ext
}
}
- private void makeCores(File home, boolean oldStyle) throws Exception {
+ private void makeCores(File home) throws Exception {
File testSrcRoot = new File(SolrTestCaseJ4.TEST_HOME());
String srcSolrXml = "solr-stress-new.xml";
- if (oldStyle) {
- srcSolrXml = "solr-stress-old.xml";
- }
FileUtils.copyFile(new File(testSrcRoot, srcSolrXml), new File(home, "solr.xml"));
// create directories in groups of 100 until you have enough.
for (int idx = 0; idx < numCores; ++idx) {
String coreName = String.format(Locale.ROOT, "%05d_core", idx);
- makeCore(new File(home, coreName), testSrcRoot, oldStyle);
+ makeCore(new File(home, coreName), testSrcRoot);
coreCounts.put(coreName, 0L);
coreNames.add(coreName);
}
}
- private void makeCore(File coreDir, File testSrcRoot, boolean oldStyle) throws IOException {
+ private void makeCore(File coreDir, File testSrcRoot) throws IOException {
File conf = new File(coreDir, "conf");
if (!conf.mkdirs()) log.warn("mkdirs returned false in makeCore... ignoring");
@@ -244,9 +231,7 @@ public class OpenCloseCoreStressTest ext
FileUtils.copyFile(new File(testConf, "solrconfig.snippet.randomindexconfig.xml"),
new File(conf, "solrconfig.snippet.randomindexconfig.xml"));
- if (!oldStyle) {
- FileUtils.copyFile(new File(testSrcRoot, "conf/core.properties"), new File(coreDir, "core.properties"));
- }
+ FileUtils.copyFile(new File(testSrcRoot, "conf/core.properties"), new File(coreDir, "core.properties"));
}
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/SolrCoreTest.java Sun Feb 8 23:53:14 2015
@@ -51,35 +51,6 @@ public class SolrCoreTest extends SolrTe
deleteCore();
super.tearDown();
}
-
- @Test
- public void testRemoveThenAddDefaultCore() throws Exception {
- final CoreContainer cores = h.getCoreContainer();
- SolrCore core = cores.getCore("");
-
- assertEquals(COLLECTION1, cores.getDefaultCoreName());
-
- cores.unload("");
- core.close();
-
- CoreDescriptor cd = new CoreDescriptor(cores, COLLECTION1, "collection1",
- CoreDescriptor.CORE_DATADIR, createTempDir("dataDir2").toFile().getAbsolutePath());
-
- cores.create(cd);
-
- assertEquals(COLLECTION1, cores.getDefaultCoreName());
-
- // so we should be able to get a core with collection1
- core = cores.getCore(COLLECTION1);
- assertNotNull(core);
- core.close();
-
- // and with ""
- core = cores.getCore("");
- assertNotNull(core);
-
- core.close();
- }
@Test
public void testRequestHandlerRegistry() {
@@ -100,7 +71,7 @@ public class SolrCoreTest extends SolrTe
@Test
public void testClose() throws Exception {
final CoreContainer cores = h.getCoreContainer();
- SolrCore core = cores.getCore("");
+ SolrCore core = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
ClosingRequestHandler handler1 = new ClosingRequestHandler();
handler1.inform( core );
@@ -120,7 +91,7 @@ public class SolrCoreTest extends SolrTe
assertTrue("Refcount != 1", core.getOpenCount() == 1);
final CoreContainer cores = h.getCoreContainer();
- SolrCore c1 = cores.getCore("");
+ SolrCore c1 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
assertTrue("Refcount != 2", core.getOpenCount() == 2);
ClosingRequestHandler handler1 = new ClosingRequestHandler();
@@ -131,12 +102,12 @@ public class SolrCoreTest extends SolrTe
assertNull( old ); // should not be anything...
assertEquals( core.getRequestHandlers().get( path ), handler1 );
- SolrCore c2 = cores.getCore("");
+ SolrCore c2 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
c1.close();
assertTrue("Refcount < 1", core.getOpenCount() >= 1);
assertTrue("Handler is closed", handler1.closed == false);
- c1 = cores.getCore("");
+ c1 = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
assertTrue("Refcount < 2", core.getOpenCount() >= 2);
assertTrue("Handler is closed", handler1.closed == false);
@@ -184,7 +155,7 @@ public class SolrCoreTest extends SolrTe
try {
for (int l = 0; l < LOOP; ++l) {
r += 1;
- core = cores.getCore("");
+ core = cores.getCore(SolrTestCaseJ4.DEFAULT_TEST_CORENAME);
// sprinkle concurrency hinting...
yield(l);
assertTrue("Refcount < 1", core.getOpenCount() >= 1);
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestArbitraryIndexDir.java Sun Feb 8 23:53:14 2015
@@ -54,14 +54,12 @@ public class TestArbitraryIndexDir exten
@BeforeClass
public static void beforeClass() {
// this test wants to start solr, and then open a separate indexwriter of its own on the same dir.
- System.setProperty("solr.tests.nrtMode", "false");
System.setProperty("enable.update.log", "false"); // schema12 doesn't support _version_
savedFactory = System.getProperty("solr.DirectoryFactory");
System.setProperty("solr.directoryFactory", "org.apache.solr.core.MockFSDirectoryFactory");
}
@AfterClass
public static void afterClass() {
- System.clearProperty("solr.tests.nrtMode");
if (savedFactory == null) {
System.clearProperty("solr.directoryFactory");
} else {
@@ -125,7 +123,7 @@ public class TestArbitraryIndexDir exten
iw.close();
//commit will cause searcher to open with the new index dir
- assertU(commit());
+ assertU(commit());h.getCoreContainer().reload(h.getCore().getName());
//new index dir contains just 1 doc.
assertQ("return doc with id 2",
req("id:2"),
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestBadConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestBadConfig.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestBadConfig.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestBadConfig.java Sun Feb 8 23:53:14 2015
@@ -27,10 +27,10 @@ public class TestBadConfig extends Abstr
assertConfigs("bad_solrconfig.xml","schema.xml","unset.sys.property");
}
- public void testSegmentMergerWithoutReopen() throws Exception {
- assertConfigs("bad-solrconfig-warmer-no-reopen.xml", "schema12.xml",
- "mergedSegmentWarmer");
+ public void testNRTModeProperty() throws Exception {
+ assertConfigs("bad-solrconfig-nrtmode.xml","schema.xml", "nrtMode");
}
+
public void testMultipleDirectoryFactories() throws Exception {
assertConfigs("bad-solrconfig-multiple-dirfactory.xml", "schema12.xml",
"directoryFactory");
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestConfig.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestConfig.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestConfig.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestConfig.java Sun Feb 8 23:53:14 2015
@@ -17,17 +17,14 @@
package org.apache.solr.core;
-import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.ConcurrentMergeScheduler;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.TieredMergePolicy;
-import org.apache.lucene.index.ConcurrentMergeScheduler;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.handler.admin.ShowFileRequestHandler;
-import org.apache.solr.update.DirectUpdateHandler2;
-import org.apache.solr.update.SolrIndexConfig;
-import org.apache.solr.util.RefCounted;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.IndexSchemaFactory;
+import org.apache.solr.update.SolrIndexConfig;
import org.junit.BeforeClass;
import org.junit.Test;
import org.w3c.dom.Node;
@@ -36,7 +33,6 @@ import org.w3c.dom.NodeList;
import javax.xml.xpath.XPathConstants;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Locale;
public class TestConfig extends SolrTestCaseJ4 {
@@ -117,10 +113,10 @@ public class TestConfig extends SolrTest
SolrIndexConfig sic = sc.indexConfig;
assertEquals("default ramBufferSizeMB", 100.0D, sic.ramBufferSizeMB, 0.0D);
assertEquals("default LockType", SolrIndexConfig.LOCK_TYPE_NATIVE, sic.lockType);
- assertEquals("default useCompoundFile", false, sic.useCompoundFile);
+ assertEquals("default useCompoundFile", false, sic.getUseCompoundFile());
IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig);
- IndexWriterConfig iwc = sic.toIndexWriterConfig(indexSchema);
+ IndexWriterConfig iwc = sic.toIndexWriterConfig(h.getCore());
assertNotNull("null mp", iwc.getMergePolicy());
assertTrue("mp is not TMP", iwc.getMergePolicy() instanceof TieredMergePolicy);
@@ -140,7 +136,7 @@ public class TestConfig extends SolrTest
Double.parseDouble(System.getProperty("solr.tests.ramBufferSizeMB")),
sic.ramBufferSizeMB, 0.0D);
assertEquals("useCompoundFile sysprop",
- Boolean.parseBoolean(System.getProperty("useCompoundFile")), sic.useCompoundFile);
+ Boolean.parseBoolean(System.getProperty("useCompoundFile")), sic.getUseCompoundFile());
}
}
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestConfigSets.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestConfigSets.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestConfigSets.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestConfigSets.java Sun Feb 8 23:53:14 2015
@@ -46,7 +46,7 @@ public class TestConfigSets extends Solr
System.setProperty("configsets", configSetsBaseDir);
SolrResourceLoader loader = new SolrResourceLoader(testDirectory.getAbsolutePath());
- CoreContainer container = new CoreContainer(loader, ConfigSolr.fromString(loader, solrxml));
+ CoreContainer container = new CoreContainer(ConfigSolr.fromString(loader, solrxml));
container.load();
return container;
@@ -115,12 +115,12 @@ public class TestConfigSets extends Solr
System.setProperty("configsets", csd);
SolrResourceLoader loader = new SolrResourceLoader(testDirectory.getAbsolutePath());
- CoreContainer container = new CoreContainer(loader, ConfigSolr.fromString(loader, solrxml));
+ CoreContainer container = new CoreContainer(ConfigSolr.fromString(loader, solrxml));
container.load();
// We initially don't have a /get handler defined
SolrCore core = container.create(new CoreDescriptor(container, "core1", testDirectory + "/core", "configSet", "configset-2"));
- assertThat("No /get handler should be defined in the initial configuration",
+ assertThat("No /dump handler should be defined in the initial configuration",
core.getRequestHandler("/dump"), is(nullValue()));
// Now copy in a config with a /get handler and reload
@@ -129,7 +129,7 @@ public class TestConfigSets extends Solr
container.reload("core1");
core = container.getCore("core1");
- assertThat("A /get handler should be defined in the reloaded configuration",
+ assertThat("A /dump handler should be defined in the reloaded configuration",
core.getRequestHandler("/dump"), is(notNullValue()));
core.close();
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestCoreContainer.java Sun Feb 8 23:53:14 2015
@@ -18,6 +18,7 @@
package org.apache.solr.core;
import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.IOUtils;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.handler.admin.CollectionsHandler;
@@ -26,19 +27,18 @@ import org.apache.solr.handler.admin.Inf
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
-import javax.xml.parsers.ParserConfigurationException;
-import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
+import java.util.regex.Pattern;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
@@ -55,7 +55,7 @@ public class TestCoreContainer extends S
@BeforeClass
public static void beforeClass() throws Exception {
oldSolrHome = System.getProperty(SOLR_HOME_PROP);
- initCore("solrconfig.xml", "schema.xml");
+ System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
}
@AfterClass
@@ -67,16 +67,14 @@ public class TestCoreContainer extends S
}
}
- private File solrHomeDirectory;
-
- private CoreContainer init(String dirName) throws Exception {
-
- solrHomeDirectory = createTempDir(dirName).toFile();
-
- FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME()), solrHomeDirectory);
- System.out.println("Using solrconfig from " + new File(SolrTestCaseJ4.TEST_HOME()).getAbsolutePath());
+ private CoreContainer init(String xml) throws Exception {
+ Path solrHomeDirectory = createTempDir();
+ return init(solrHomeDirectory, xml);
+ }
- CoreContainer ret = new CoreContainer(solrHomeDirectory.getAbsolutePath());
+ private CoreContainer init(Path homeDirectory, String xml) throws Exception {
+ SolrResourceLoader loader = new SolrResourceLoader(homeDirectory.toString());
+ CoreContainer ret = new CoreContainer(ConfigSolr.fromString(loader, xml));
ret.load();
return ret;
}
@@ -84,12 +82,14 @@ public class TestCoreContainer extends S
@Test
public void testShareSchema() throws Exception {
System.setProperty("shareSchema", "true");
- final CoreContainer cores = init("_shareSchema");
+
+ CoreContainer cores = init(CONFIGSETS_SOLR_XML);
+
try {
- CoreDescriptor descriptor1 = new CoreDescriptor(cores, "core1", "./collection1");
+ CoreDescriptor descriptor1 = new CoreDescriptor(cores, "core1", "./collection1", "configSet", "minimal");
SolrCore core1 = cores.create(descriptor1);
- CoreDescriptor descriptor2 = new CoreDescriptor(cores, "core2", "./collection1");
+ CoreDescriptor descriptor2 = new CoreDescriptor(cores, "core2", "./collection1", "configSet", "minimal");
SolrCore core2 = cores.create(descriptor2);
assertSame(core1.getLatestSchema(), core2.getLatestSchema());
@@ -102,12 +102,14 @@ public class TestCoreContainer extends S
@Test
public void testReloadSequential() throws Exception {
- final CoreContainer cc = init("_reloadSequential");
+ final CoreContainer cc = init(CONFIGSETS_SOLR_XML);
+ CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1", "configSet", "minimal");
+ cc.create(descriptor1);
try {
- cc.reload("collection1");
- cc.reload("collection1");
- cc.reload("collection1");
- cc.reload("collection1");
+ cc.reload("core1");
+ cc.reload("core1");
+ cc.reload("core1");
+ cc.reload("core1");
} finally {
cc.shutdown();
@@ -116,63 +118,52 @@ public class TestCoreContainer extends S
@Test
public void testReloadThreaded() throws Exception {
- final CoreContainer cc = init("_reloadThreaded");
-
- class TestThread extends Thread {
- @Override
- public void run() {
- cc.reload("collection1");
- }
+ final CoreContainer cc = init(CONFIGSETS_SOLR_XML);
+ CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1", "configSet", "minimal");
+ cc.create(descriptor1);
+
+ class TestThread extends Thread {
+ @Override
+ public void run() {
+ cc.reload("core1");
}
+ }
- List<Thread> threads = new ArrayList<>();
- int numThreads = 4;
- for (int i = 0; i < numThreads; i++) {
- threads.add(new TestThread());
- }
+ List<Thread> threads = new ArrayList<>();
+ int numThreads = 4;
+ for (int i = 0; i < numThreads; i++) {
+ threads.add(new TestThread());
+ }
- for (Thread thread : threads) {
- thread.start();
- }
+ for (Thread thread : threads) {
+ thread.start();
+ }
- for (Thread thread : threads) {
- thread.join();
+ for (Thread thread : threads) {
+ thread.join();
}
cc.shutdown();
}
+ @Test
+ public void testNoCores() throws Exception {
+ CoreContainer cores = init(CONFIGSETS_SOLR_XML);
- @Test
- public void testNoCores() throws IOException, ParserConfigurationException, SAXException {
- //create solrHome
- File solrHomeDirectory = createTempDir().toFile();
-
- boolean oldSolrXml = random().nextBoolean();
-
- SetUpHome(solrHomeDirectory, oldSolrXml ? EMPTY_SOLR_XML : EMPTY_SOLR_XML2);
- CoreContainer cores = new CoreContainer(solrHomeDirectory.getAbsolutePath());
- cores.load();
try {
//assert zero cores
assertEquals("There should not be cores", 0, cores.getCores().size());
- FileUtils.copyDirectory(new File(SolrTestCaseJ4.TEST_HOME(), "collection1"), solrHomeDirectory);
//add a new core
- CoreDescriptor coreDescriptor = new CoreDescriptor(cores, "core1", solrHomeDirectory.getAbsolutePath());
+ CoreDescriptor coreDescriptor = new CoreDescriptor(cores, "core1", "collection1", CoreDescriptor.CORE_CONFIGSET, "minimal");
SolrCore newCore = cores.create(coreDescriptor);
//assert one registered core
assertEquals("There core registered", 1, cores.getCores().size());
- if (oldSolrXml) {
- assertXmlFile(new File(solrHomeDirectory, "solr.xml"),
- "/solr/cores[@transientCacheSize='32']");
- }
-
cores.unload("core1");
//assert cero cores
assertEquals("There should not be cores", 0, cores.getCores().size());
@@ -193,27 +184,14 @@ public class TestCoreContainer extends S
}
@Test
- public void testLogWatcherEnabledByDefault() {
- assertNotNull(h.getCoreContainer().getLogging());
- }
-
- private void SetUpHome(File solrHomeDirectory, String xmlFile) throws IOException {
- if (solrHomeDirectory.exists()) {
- FileUtils.deleteDirectory(solrHomeDirectory);
- }
- assertTrue("Failed to mkdirs workDir", solrHomeDirectory.mkdirs());
- try {
- File solrXmlFile = new File(solrHomeDirectory, "solr.xml");
- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(solrXmlFile), StandardCharsets.UTF_8));
- out.write(xmlFile);
- out.close();
- } catch (IOException e) {
- FileUtils.deleteDirectory(solrHomeDirectory);
- throw e;
+ public void testLogWatcherEnabledByDefault() throws Exception {
+ CoreContainer cc = init("<solr></solr>");
+ try {
+ assertNotNull(cc.getLogging());
+ }
+ finally {
+ cc.shutdown();
}
-
- //init
- System.setProperty(SOLR_HOME_PROP, solrHomeDirectory.getAbsolutePath());
}
@Test
@@ -221,13 +199,12 @@ public class TestCoreContainer extends S
MockCoresLocator cl = new MockCoresLocator();
- solrHomeDirectory = createTempDir("_deleteBadCores").toFile();
- SolrResourceLoader resourceLoader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
- File instanceDir = new File(solrHomeDirectory, "_deleteBadCores");
+ SolrResourceLoader resourceLoader = new SolrResourceLoader(createTempDir().toString());
+
System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
- final CoreContainer cc = new CoreContainer(resourceLoader, ConfigSolr.fromString(resourceLoader, EMPTY_SOLR_XML2), cl);
- CoreDescriptor badcore = new CoreDescriptor(cc, "badcore", instanceDir.getAbsolutePath(), "configSet", "nosuchconfigset");
+ final CoreContainer cc = new CoreContainer(ConfigSolr.fromString(resourceLoader, CONFIGSETS_SOLR_XML), cl);
+ CoreDescriptor badcore = new CoreDescriptor(cc, "badcore", "badcore", "configSet", "nosuchconfigset");
cl.add(badcore);
try {
@@ -238,7 +215,7 @@ public class TestCoreContainer extends S
assertThat(cc.getCoreInitFailures().size(), is(0));
// can we create the core now with a good config?
- SolrCore core = cc.create(new CoreDescriptor(cc, "badcore", instanceDir.getAbsolutePath(), "configSet", "minimal"));
+ SolrCore core = cc.create(new CoreDescriptor(cc, "badcore", "badcore", "configSet", "minimal"));
assertThat(core, not(nullValue()));
}
@@ -249,13 +226,13 @@ public class TestCoreContainer extends S
@Test
public void testClassLoaderHierarchy() throws Exception {
- final CoreContainer cc = init("_classLoaderHierarchy");
+ final CoreContainer cc = init(CONFIGSETS_SOLR_XML);
try {
ClassLoader sharedLoader = cc.loader.getClassLoader();
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
assertSame(contextLoader, sharedLoader.getParent());
- CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1");
+ CoreDescriptor descriptor1 = new CoreDescriptor(cc, "core1", "./collection1", "configSet", "minimal");
SolrCore core1 = cc.create(descriptor1);
ClassLoader coreLoader = core1.getResourceLoader().getClassLoader();
assertSame(sharedLoader, coreLoader.getParent());
@@ -267,9 +244,9 @@ public class TestCoreContainer extends S
@Test
public void testSharedLib() throws Exception {
- File tmpRoot = createTempDir("testSharedLib").toFile();
+ Path tmpRoot = createTempDir("testSharedLib");
- File lib = new File(tmpRoot, "lib");
+ File lib = new File(tmpRoot.toFile(), "lib");
lib.mkdirs();
JarOutputStream jar1 = new JarOutputStream(new FileOutputStream(new File(lib, "jar1.jar")));
@@ -277,7 +254,7 @@ public class TestCoreContainer extends S
jar1.closeEntry();
jar1.close();
- File customLib = new File(tmpRoot, "customLib");
+ File customLib = new File(tmpRoot.toFile(), "customLib");
customLib.mkdirs();
JarOutputStream jar2 = new JarOutputStream(new FileOutputStream(new File(customLib, "jar2.jar")));
@@ -285,41 +262,32 @@ public class TestCoreContainer extends S
jar2.closeEntry();
jar2.close();
- FileUtils.writeStringToFile(new File(tmpRoot, "default-lib-solr.xml"), "<solr><cores/></solr>", "UTF-8");
- FileUtils.writeStringToFile(new File(tmpRoot, "explicit-lib-solr.xml"), "<solr sharedLib=\"lib\"><cores/></solr>", "UTF-8");
- FileUtils.writeStringToFile(new File(tmpRoot, "custom-lib-solr.xml"), "<solr sharedLib=\"customLib\"><cores/></solr>", "UTF-8");
-
- final CoreContainer cc1 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "default-lib-solr.xml"));
+ final CoreContainer cc1 = init(tmpRoot, "<solr></solr>");
try {
cc1.loader.openResource("defaultSharedLibFile").close();
} finally {
cc1.shutdown();
}
- final CoreContainer cc2 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "explicit-lib-solr.xml"));
+ final CoreContainer cc2 = init(tmpRoot, "<solr><str name=\"sharedLib\">lib</str></solr>");
try {
cc2.loader.openResource("defaultSharedLibFile").close();
} finally {
cc2.shutdown();
}
- final CoreContainer cc3 = CoreContainer.createAndLoad(tmpRoot.getAbsolutePath(), new File(tmpRoot, "custom-lib-solr.xml"));
+ final CoreContainer cc3 = init(tmpRoot, "<solr><str name=\"sharedLib\">customLib</str></solr>");
try {
cc3.loader.openResource("customSharedLibFile").close();
} finally {
cc3.shutdown();
}
}
-
- private static final String EMPTY_SOLR_XML ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
- "<solr persistent=\"false\">\n" +
- " <cores adminPath=\"/admin/cores\" transientCacheSize=\"32\" >\n" +
- " </cores>\n" +
- "</solr>";
-
- private static final String EMPTY_SOLR_XML2 ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
+
+ private static final String CONFIGSETS_SOLR_XML ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
"<solr>\n" +
- "<str name=\"configSetBaseDir\">${configsets:configsets}</str>" +
+ "<str name=\"configSetBaseDir\">${configsets:configsets}</str>\n" +
+ "<str name=\"shareSchema\">${shareSchema:false}</str>\n" +
"</solr>";
private static final String CUSTOM_HANDLERS_SOLR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
@@ -350,12 +318,7 @@ public class TestCoreContainer extends S
@Test
public void testCustomHandlers() throws Exception {
- solrHomeDirectory = createTempDir("_customHandlers").toFile();
- SolrResourceLoader loader = new SolrResourceLoader(solrHomeDirectory.getAbsolutePath());
-
- ConfigSolr config = ConfigSolr.fromString(loader, CUSTOM_HANDLERS_SOLR_XML);
-
- CoreContainer cc = new CoreContainer(loader, config);
+ CoreContainer cc = init(CUSTOM_HANDLERS_SOLR_XML);
try {
cc.load();
assertThat(cc.getCollectionsHandler(), is(instanceOf(CustomCollectionsHandler.class)));
@@ -406,4 +369,262 @@ public class TestCoreContainer extends S
return cores;
}
}
+
+ @Test
+ public void testCoreInitFailuresFromEmptyContainer() throws Exception {
+ // reused state
+ Map<String,CoreContainer.CoreLoadFailure> failures = null;
+ Collection<String> cores = null;
+ Exception fail = null;
+
+ // ----
+ // init the CoreContainer
+ CoreContainer cc = init(CONFIGSETS_SOLR_XML);
+
+ // check that we have the cores we expect
+ cores = cc.getCoreNames();
+ assertNotNull("core names is null", cores);
+ assertEquals("wrong number of cores", 0, cores.size());
+
+ // check that we have the failures we expect
+ failures = cc.getCoreInitFailures();
+ assertNotNull("core failures is a null map", failures);
+ assertEquals("wrong number of core failures", 0, failures.size());
+
+ // -----
+ // try to add a collection with a path that doesn't exist
+ final CoreDescriptor bogus = new CoreDescriptor(cc, "bogus", "bogus_path");
+ try {
+ ignoreException(Pattern.quote("bogus_path"));
+ cc.create(bogus);
+ fail("bogus inst dir failed to trigger exception from create");
+ } catch (SolrException e) {
+ assertTrue("init exception doesn't mention bogus dir: " + e.getCause().getCause().getMessage(),
+ 0 < e.getCause().getCause().getMessage().indexOf("bogus_path"));
+
+ }
+
+ // check that we have the cores we expect
+ cores = cc.getCoreNames();
+ assertNotNull("core names is null", cores);
+ assertEquals("wrong number of cores", 0, cores.size());
+
+ // check that we have the failures we expect
+ failures = cc.getCoreInitFailures();
+ assertNotNull("core failures is a null map", failures);
+ assertEquals("wrong number of core failures", 1, failures.size());
+ fail = failures.get("bogus").exception;
+ assertNotNull("null failure for test core", fail);
+ assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),
+ 0 < fail.getCause().getMessage().indexOf("bogus_path"));
+
+ // check that we get null accessing a non-existent core
+ assertNull(cc.getCore("does_not_exist"));
+ // check that we get a 500 accessing the core with an init failure
+ try {
+ SolrCore c = cc.getCore("bogus");
+ fail("Failed to get Exception on accessing core with init failure");
+ } catch (SolrException ex) {
+ assertEquals(500, ex.code());
+ // double wrapped
+ String cause = ex.getCause().getCause().getMessage();
+ assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
+ 0 < cause.indexOf("bogus_path"));
+
+ }
+
+ cc.shutdown();
+ }
+
+ @Test
+ public void testCoreInitFailuresOnReload() throws Exception {
+
+ // reused state
+ Map<String,CoreContainer.CoreLoadFailure> failures = null;
+ Collection<String> cores = null;
+ Exception fail = null;
+
+ // -----
+ // init the CoreContainer with the mix of ok/bad cores
+ MockCoresLocator cl = new MockCoresLocator();
+
+ SolrResourceLoader resourceLoader = new SolrResourceLoader(createTempDir().toString());
+
+ System.setProperty("configsets", getFile("solr/configsets").getAbsolutePath());
+
+ final CoreContainer cc = new CoreContainer(ConfigSolr.fromString(resourceLoader, CONFIGSETS_SOLR_XML), cl);
+ cl.add(new CoreDescriptor(cc, "col_ok", "col_ok", "configSet", "minimal"));
+ cl.add(new CoreDescriptor(cc, "col_bad", "col_bad", "configSet", "bad-mergepolicy"));
+ cc.load();
+
+ // check that we have the cores we expect
+ cores = cc.getCoreNames();
+ assertNotNull("core names is null", cores);
+ assertEquals("wrong number of cores", 1, cores.size());
+ assertTrue("col_ok not found", cores.contains("col_ok"));
+
+ // check that we have the failures we expect
+ failures = cc.getCoreInitFailures();
+ assertNotNull("core failures is a null map", failures);
+ assertEquals("wrong number of core failures", 1, failures.size());
+ fail = failures.get("col_bad").exception;
+ assertNotNull("null failure for test core", fail);
+ assertTrue("init failure doesn't mention problem: " + fail.getMessage(),
+ 0 < fail.getMessage().indexOf("DummyMergePolicy"));
+
+ // check that we get null accessing a non-existent core
+ assertNull(cc.getCore("does_not_exist"));
+ // check that we get a 500 accessing the core with an init failure
+ try {
+ SolrCore c = cc.getCore("col_bad");
+ fail("Failed to get Exception on accessing core with init failure");
+ } catch (SolrException ex) {
+ assertEquals(500, ex.code());
+ // double wrapped
+ String cause = ex.getCause().getCause().getMessage();
+ assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
+ 0 < cause.indexOf("DummyMergePolicy"));
+ }
+
+ // -----
+ // "fix" the bad collection
+ FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),
+ FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "solrconfig.xml"));
+ FileUtils.copyFile(getFile("solr/collection1/conf/schema-minimal.xml"),
+ FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "schema.xml"));
+ final CoreDescriptor fixed = new CoreDescriptor(cc, "col_bad", "col_bad");
+ cc.create(fixed);
+
+ // check that we have the cores we expect
+ cores = cc.getCoreNames();
+ assertNotNull("core names is null", cores);
+ assertEquals("wrong number of cores", 2, cores.size());
+ assertTrue("col_ok not found", cores.contains("col_ok"));
+ assertTrue("col_bad not found", cores.contains("col_bad"));
+
+ // check that we have the failures we expect
+ failures = cc.getCoreInitFailures();
+ assertNotNull("core failures is a null map", failures);
+ assertEquals("wrong number of core failures", 0, failures.size());
+
+
+ // -----
+ // try to add a collection with a path that doesn't exist
+ final CoreDescriptor bogus = new CoreDescriptor(cc, "bogus", "bogus_path");
+ try {
+ ignoreException(Pattern.quote("bogus_path"));
+ cc.create(bogus);
+ fail("bogus inst dir failed to trigger exception from create");
+ } catch (SolrException e) {
+ assertTrue("init exception doesn't mention bogus dir: " + e.getCause().getCause().getMessage(),
+ 0 < e.getCause().getCause().getMessage().indexOf("bogus_path"));
+
+ }
+
+ // check that we have the cores we expect
+ cores = cc.getCoreNames();
+ assertNotNull("core names is null", cores);
+ assertEquals("wrong number of cores", 2, cores.size());
+ assertTrue("col_ok not found", cores.contains("col_ok"));
+ assertTrue("col_bad not found", cores.contains("col_bad"));
+
+ // check that we have the failures we expect
+ failures = cc.getCoreInitFailures();
+ assertNotNull("core failures is a null map", failures);
+ assertEquals("wrong number of core failures", 1, failures.size());
+ fail = failures.get("bogus").exception;
+ assertNotNull("null failure for test core", fail);
+ assertTrue("init failure doesn't mention problem: " + fail.getCause().getMessage(),
+ 0 < fail.getCause().getMessage().indexOf("bogus_path"));
+
+ // check that we get null accessing a non-existent core
+ assertNull(cc.getCore("does_not_exist"));
+ // check that we get a 500 accessing the core with an init failure
+ try {
+ SolrCore c = cc.getCore("bogus");
+ fail("Failed to get Exception on accessing core with init failure");
+ } catch (SolrException ex) {
+ assertEquals(500, ex.code());
+ // double wrapped
+ String cause = ex.getCause().getCause().getMessage();
+ assertTrue("getCore() ex cause doesn't mention init fail: " + cause,
+ 0 < cause.indexOf("bogus_path"));
+ }
+
+ // -----
+ // break col_bad's config and try to RELOAD to add failure
+
+ final long col_bad_old_start = getCoreStartTime(cc, "col_bad");
+
+ FileUtils.write
+ (FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "solrconfig.xml"),
+ "This is giberish, not valid XML <",
+ IOUtils.UTF_8);
+
+ try {
+ ignoreException(Pattern.quote("SAX"));
+ cc.reload("col_bad");
+ fail("corrupt solrconfig.xml failed to trigger exception from reload");
+ } catch (SolrException e) {
+ Throwable rootException = getWrappedException(e);
+ assertTrue("We're supposed to have a wrapped SAXParserException here, but we don't",
+ rootException instanceof SAXParseException);
+ SAXParseException se = (SAXParseException) rootException;
+ assertTrue("reload exception doesn't refer to slrconfig.xml " + se.getSystemId(),
+ 0 < se.getSystemId().indexOf("solrconfig.xml"));
+
+ }
+
+ assertEquals("Failed core reload should not have changed start time",
+ col_bad_old_start, getCoreStartTime(cc, "col_bad"));
+
+ // check that we have the cores we expect
+ cores = cc.getCoreNames();
+ assertNotNull("core names is null", cores);
+ assertEquals("wrong number of cores", 2, cores.size());
+ assertTrue("col_ok not found", cores.contains("col_ok"));
+ assertTrue("col_bad not found", cores.contains("col_bad"));
+
+ // check that we have the failures we expect
+ failures = cc.getCoreInitFailures();
+ assertNotNull("core failures is a null map", failures);
+ assertEquals("wrong number of core failures", 2, failures.size());
+ Throwable ex = getWrappedException(failures.get("col_bad").exception);
+ assertNotNull("null failure for test core", ex);
+ assertTrue("init failure isn't SAXParseException",
+ ex instanceof SAXParseException);
+ SAXParseException saxEx = (SAXParseException) ex;
+ assertTrue("init failure doesn't mention problem: " + saxEx.toString(), saxEx.getSystemId().contains("solrconfig.xml"));
+
+ // ----
+ // fix col_bad's config (again) and RELOAD to fix failure
+ FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-defaults.xml"),
+ FileUtils.getFile(cc.getSolrHome(), "col_bad", "conf", "solrconfig.xml"));
+ cc.reload("col_bad");
+
+ assertTrue("Core reload should have changed start time",
+ col_bad_old_start < getCoreStartTime(cc, "col_bad"));
+
+
+ // check that we have the cores we expect
+ cores = cc.getCoreNames();
+ assertNotNull("core names is null", cores);
+ assertEquals("wrong number of cores", 2, cores.size());
+ assertTrue("col_ok not found", cores.contains("col_ok"));
+ assertTrue("col_bad not found", cores.contains("col_bad"));
+
+ // check that we have the failures we expect
+ failures = cc.getCoreInitFailures();
+ assertNotNull("core failures is a null map", failures);
+ assertEquals("wrong number of core failures", 1, failures.size());
+
+ cc.shutdown();
+
+ }
+
+ private long getCoreStartTime(final CoreContainer cc, final String name) {
+ try (SolrCore tmp = cc.getCore(name)) {
+ return tmp.getStartTime();
+ }
+ }
}
Modified: lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java?rev=1658277&r1=1658276&r2=1658277&view=diff
==============================================================================
--- lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java (original)
+++ lucene/dev/branches/lucene6005/solr/core/src/test/org/apache/solr/core/TestCoreDiscovery.java Sun Feb 8 23:53:14 2015
@@ -110,7 +110,12 @@ public class TestCoreDiscovery extends S
private CoreContainer init() throws Exception {
final CoreContainer cores = new CoreContainer();
- cores.load();
+ try {
+ cores.load();
+ } catch (Exception e) {
+ cores.shutdown();
+ throw e;
+ }
return cores;
}
@@ -135,8 +140,6 @@ public class TestCoreDiscovery extends S
CoreContainer cc = init();
try {
- assertEquals(ConfigSolrXmlOld.DEFAULT_DEFAULT_CORE_NAME,
- cc.getDefaultCoreName());
TestLazyCores.checkInCores(cc, "core1");
TestLazyCores.checkNotInCores(cc, "lazy1", "core2", "collection1");