Skip to content

Apache Lucene open-source search software

tests: add core reload stress test

Yonik Seeley66898c265922
diff --git a/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java b/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java
index 653340b3be9..7b75e6f6bd4 100644
--- a/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java
+++ b/solr/core/src/test/org/apache/solr/search/TestRealTimeGet.java
@@ -111,6 +111,60 @@ public class TestRealTimeGet extends TestRTGBase {
}
+ @Test
+ public void testGetRealtimeReload() throws Exception {
+ clearIndex();
+ assertU(commit());
+ long version = addAndGetVersion(sdoc("id","1") , null);
+
+ // h.getCoreContainer().reload(h.getCore().getName());
+
+ assertU(commit("openSearcher","false")); // should cause a RTG searcher to be opened
+
+ // should also use the RTG searcher (commit should have cleared the translog cache)
+ assertJQ(req("qt","/get","id","1")
+ ,"=={'doc':{'id':'1','_version_':" + version + "}}"
+ );
+
+ assertU(commit("softCommit","true")); // open a normal (caching) NRT searcher
+
+ h.getCoreContainer().reload(h.getCore().getName());
+
+ Random rand = random();
+ for (int i=0; i<10; i++) {
+ if (rand.nextBoolean()) {
+ version = addAndGetVersion(sdoc("id","1") , null);
+ }
+
+ if (rand.nextBoolean()) {
+ if (rand.nextBoolean()) {
+ assertU(commit("openSearcher","false")); // should cause a RTG searcher to be opened as well
+ } else {
+ assertU(commit("softCommit", ""+rand.nextBoolean()));
+ }
+ }
+
+ if (rand.nextBoolean()) {
+ // RTG should always be able to see the last version
+ assertJQ(req("qt","/get","id","1")
+ ,"=={'doc':{'id':'1','_version_':" + version + "}}"
+ );
+ }
+
+ if (rand.nextBoolean()) {
+ // a normal search should always find 1 doc
+ assertJQ(req("q","id:1")
+ ,"/response/numFound==1"
+ );
+ }
+ }
+
+
+
+ // test framework should ensure that all searchers opened have been closed.
+ }
+
+
@Test
public void testVersions() throws Exception {
clearIndex();
diff --git a/solr/core/src/test/org/apache/solr/search/TestReload.java b/solr/core/src/test/org/apache/solr/search/TestReload.java
new file mode 100644
index 00000000000..e468e9c180a
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/search/TestReload.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.search;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.Ignore;
+
+import java.util.Random;
+
+@Ignore
+public class TestReload extends TestRTGBase {
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ useFactory(null); // force FS directory
+ initCore("solrconfig-tlog.xml","schema15.xml");
+ }
+
+ @Test
+ public void testGetRealtimeReload() throws Exception {
+ clearIndex();
+ assertU(commit());
+ long version = addAndGetVersion(sdoc("id","1") , null);
+
+ // h.getCoreContainer().reload(h.getCore().getName());
+
+ assertU(commit("openSearcher","false")); // should cause a RTG searcher to be opened
+
+ // should also use the RTG searcher (commit should have cleared the translog cache)
+ assertJQ(req("qt","/get","id","1")
+ ,"=={'doc':{'id':'1','_version_':" + version + "}}"
+ );
+
+ assertU(commit("softCommit","true")); // open a normal (caching) NRT searcher
+
+ h.getCoreContainer().reload(h.getCore().getName());
+
+ Random rand = random();
+ int iter = atLeast(20);
+ for (int i=0; i<iter; i++) {
+ if (rand.nextBoolean()) {
+ version = addAndGetVersion(sdoc("id","1") , null);
+ }
+
+ if (rand.nextBoolean()) {
+ if (rand.nextBoolean()) {
+ assertU(commit("openSearcher","false")); // should cause a RTG searcher to be opened as well
+ } else {
+ assertU(commit("softCommit", ""+rand.nextBoolean()));
+ }
+ }
+
+ if (rand.nextBoolean()) {
+ // RTG should always be able to see the last version
+ assertJQ(req("qt","/get","id","1")
+ ,"=={'doc':{'id':'1','_version_':" + version + "}}"
+ );
+ }
+
+ if (rand.nextBoolean()) {
+ // a normal search should always find 1 doc
+ assertJQ(req("q","id:1")
+ ,"/response/numFound==1"
+ );
+ }
+
+ // TODO: randomly do a reload
+ // but the test currently fails without this!
+ }
+
+ // test framework should ensure that all searchers opened have been closed.
+ }
+
+}
\ No newline at end of file
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index ab1df11dce2..8cb2728284a 100755
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -82,7 +82,6 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
endTrackingSearchers();
endTrackingZkClients();
resetFactory();
- resetFactory();
}
private static boolean changedFactory = false;