-
Notifications
You must be signed in to change notification settings - Fork 791
Migrate Solr tests from SolrJettyTestBase to using SolrJettyTestRule #3947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ede5683
bba2ab0
fbfadce
652dc89
f2efcef
f3d688e
21f2949
c44be5d
614c5f7
1177167
835d926
33c61ce
bf278de
cab85b2
df7ba8d
e2270f6
5de956c
dff81d7
793d987
df01f34
331b419
29398cc
abaeda2
13c4ee1
0577c46
afdf1c1
8ef50c4
19f746d
758d698
0905bb0
9be336b
e246dab
2e624aa
978e884
633c342
f71725b
f0ea4c8
a8c6187
9dbe91a
3a2c223
66524de
382e8fe
e575210
36dc9d1
7ab56ca
a8e563a
e1f9c1b
12aa2da
0c1a6e4
583db85
cd8c40f
3344164
e258844
796bac2
1851cd5
a2a66d9
d24a74c
d610b04
2b9010f
4a46298
e37bbb4
6b590b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,6 @@ | |||||||||||||||||||||
| import java.nio.file.Files; | ||||||||||||||||||||||
| import java.nio.file.Path; | ||||||||||||||||||||||
| import java.nio.file.StandardCopyOption; | ||||||||||||||||||||||
| import org.apache.commons.io.FileUtils; | ||||||||||||||||||||||
| import org.apache.solr.client.solrj.SolrClient; | ||||||||||||||||||||||
| import org.apache.solr.client.solrj.SolrServerException; | ||||||||||||||||||||||
| import org.apache.solr.client.solrj.request.CoreAdminRequest; | ||||||||||||||||||||||
|
|
@@ -34,49 +33,62 @@ | |||||||||||||||||||||
| import org.apache.solr.request.SolrQueryRequest; | ||||||||||||||||||||||
| import org.apache.solr.response.JavaBinResponseWriter; | ||||||||||||||||||||||
| import org.apache.solr.response.SolrQueryResponse; | ||||||||||||||||||||||
| import org.apache.solr.util.SolrJettyTestRule; | ||||||||||||||||||||||
| import org.junit.AfterClass; | ||||||||||||||||||||||
| import org.junit.BeforeClass; | ||||||||||||||||||||||
| import org.junit.ClassRule; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public class TestTolerantSearch extends SolrJettyTestBase { | ||||||||||||||||||||||
| public class TestTolerantSearch extends SolrTestCaseJ4 { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private static SolrClient collection1; | ||||||||||||||||||||||
| private static SolrClient collection2; | ||||||||||||||||||||||
| private static String shard1; | ||||||||||||||||||||||
| private static String shard2; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private static Path createSolrHome() throws Exception { | ||||||||||||||||||||||
| Path workDir = createTempDir(); | ||||||||||||||||||||||
| setupJettyTestHome(workDir, "collection1"); | ||||||||||||||||||||||
| Path workDir = createTempDir().toRealPath(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Copy solr.xml | ||||||||||||||||||||||
| Files.copy( | ||||||||||||||||||||||
| Path.of(SolrTestCaseJ4.TEST_HOME() + "/collection1/conf/solrconfig-tolerant-search.xml"), | ||||||||||||||||||||||
| workDir.resolve("collection1").resolve("conf").resolve("solrconfig.xml"), | ||||||||||||||||||||||
| SolrTestCaseJ4.TEST_PATH().resolve("solr.xml"), | ||||||||||||||||||||||
| workDir.resolve("solr.xml"), | ||||||||||||||||||||||
| StandardCopyOption.REPLACE_EXISTING); | ||||||||||||||||||||||
| FileUtils.copyDirectory( | ||||||||||||||||||||||
| workDir.resolve("collection1").toFile(), workDir.resolve("collection2").toFile()); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Set up collection1 with minimal config + tolerant search solrconfig | ||||||||||||||||||||||
| Path collection1Dir = workDir.resolve("collection1"); | ||||||||||||||||||||||
| copyMinConf(collection1Dir, "name=collection1\n", "solrconfig-tolerant-search.xml"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Set up configset for CoreAdminRequest.Create (reuse the same config) | ||||||||||||||||||||||
| Path configSetDir = workDir.resolve("configsets").resolve("collection1"); | ||||||||||||||||||||||
| copyMinConf(configSetDir, null, "solrconfig-tolerant-search.xml"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return workDir; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| @BeforeClass | ||||||||||||||||||||||
| public static void createThings() throws Exception { | ||||||||||||||||||||||
| systemSetPropertyEnableUrlAllowList(false); | ||||||||||||||||||||||
| Path solrHome = createSolrHome(); | ||||||||||||||||||||||
| createAndStartJetty(solrHome); | ||||||||||||||||||||||
| String url = getBaseUrl(); | ||||||||||||||||||||||
| collection1 = getHttpSolrClient(url, "collection1"); | ||||||||||||||||||||||
| collection2 = getHttpSolrClient(url, "collection2"); | ||||||||||||||||||||||
| solrTestRule.startSolr(solrHome); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| String urlCollection1 = getBaseUrl() + "/" + "collection1"; | ||||||||||||||||||||||
| String urlCollection2 = getBaseUrl() + "/" + "collection2"; | ||||||||||||||||||||||
| collection1 = solrTestRule.getSolrClient("collection1"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| String urlCollection1 = solrTestRule.getBaseUrl() + "/" + "collection1"; | ||||||||||||||||||||||
| String urlCollection2 = solrTestRule.getBaseUrl() + "/" + "collection2"; | ||||||||||||||||||||||
| shard1 = urlCollection1.replaceAll("https?://", ""); | ||||||||||||||||||||||
| shard2 = urlCollection2.replaceAll("https?://", ""); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // create second core | ||||||||||||||||||||||
| try (SolrClient nodeClient = getHttpSolrClient(url)) { | ||||||||||||||||||||||
| CoreAdminRequest.Create req = new CoreAdminRequest.Create(); | ||||||||||||||||||||||
| req.setCoreName("collection2"); | ||||||||||||||||||||||
| req.setConfigSet("collection1"); | ||||||||||||||||||||||
| nodeClient.request(req); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| SolrClient nodeClient = solrTestRule.getSolrClient(); | ||||||||||||||||||||||
| CoreAdminRequest.Create req = new CoreAdminRequest.Create(); | ||||||||||||||||||||||
| req.setCoreName("collection2"); | ||||||||||||||||||||||
| req.setConfigSet("collection1"); | ||||||||||||||||||||||
| nodeClient.request(req); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Now get the client for collection2 after it's been created | ||||||||||||||||||||||
| collection2 = solrTestRule.getSolrClient("collection2"); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| SolrInputDocument doc = new SolrInputDocument(); | ||||||||||||||||||||||
| doc.setField("id", "1"); | ||||||||||||||||||||||
|
|
@@ -100,14 +112,8 @@ public static void createThings() throws Exception { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| @AfterClass | ||||||||||||||||||||||
| public static void destroyThings() throws Exception { | ||||||||||||||||||||||
| if (null != collection1) { | ||||||||||||||||||||||
| collection1.close(); | ||||||||||||||||||||||
| collection1 = null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| if (null != collection2) { | ||||||||||||||||||||||
| collection2.close(); | ||||||||||||||||||||||
| collection2 = null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| collection1 = null; | ||||||||||||||||||||||
| collection2 = null; | ||||||||||||||||||||||
|
Comment on lines
+115
to
+116
|
||||||||||||||||||||||
| collection1 = null; | |
| collection2 = null; | |
| if (collection1 != null) { | |
| collection1.close(); | |
| collection1 = null; | |
| } | |
| if (collection2 != null) { | |
| collection2.close(); | |
| collection2 = null; | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,8 +52,7 @@ public void beforeTest() throws Exception { | |
| backupPath = createTempDir(getTestClass().getSimpleName() + "_backups"); | ||
| System.setProperty("solr.security.allow.paths", backupPath.toString()); | ||
|
|
||
| // NOTE: we don't actually care about using SolrCloud, but we want to use SolrClient and I can't | ||
| // bring myself to deal with the nonsense that is SolrJettyTestBase. | ||
| // NOTE: we don't actually care about using SolrCloud, but we want to use SolrClient. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOL. Maybe this becomes a TODO now that we have a nice rule encapsulating Solr lifecycle for Jetty |
||
|
|
||
| // We do however explicitly want a fresh "cluster" every time a test is run | ||
| configureCluster(1).addConfig("conf1", configset("cloud-minimal")).configure(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.