Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.core.SolrCore;
import org.apache.solr.index.NoMergePolicyFactory;
Expand Down Expand Up @@ -83,8 +82,7 @@ public void test() throws Exception {
Random r = random();
String[][] expectVals = indexDocs(client, r);

try (SolrCore core =
((EmbeddedSolrServer) client).getCoreContainer().getCore(DEFAULT_TEST_CORENAME)) {
try (SolrCore core = solrTestRule.getCoreContainer().getCore(DEFAULT_TEST_CORENAME)) {
RefCounted<SolrIndexSearcher> sref = core.getSearcher();
try (Closeable c = sref::decref) {
SolrIndexSearcher s = sref.get();
Expand Down
13 changes: 6 additions & 7 deletions solr/core/src/test/org/apache/solr/update/CustomTLogDirTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.util.EmbeddedSolrServerTestRule;
import org.apache.solr.util.SolrClientTestRule;
Expand All @@ -49,7 +48,7 @@ public void testExternal() throws Exception {
String collectionName = "coll" + collectionIdx.getAndIncrement();
SolrClient client = solrTestRule.getSolrClient(collectionName);

Path coreRootDir = ((EmbeddedSolrServer) client).getCoreContainer().getCoreRootDirectory();
Path coreRootDir = solrTestRule.getCoreContainer().getCoreRootDirectory();

Path instanceDir = FilterPath.unwrap(coreRootDir.resolve(collectionName));

Expand All @@ -65,7 +64,7 @@ public void testRelative() throws Exception {
String collectionName = "coll" + collectionIdx.getAndIncrement();
SolrClient client = solrTestRule.getSolrClient(collectionName);

Path coreRootDir = ((EmbeddedSolrServer) client).getCoreContainer().getCoreRootDirectory();
Path coreRootDir = solrTestRule.getCoreContainer().getCoreRootDirectory();

Path instanceDir = FilterPath.unwrap(coreRootDir.resolve(collectionName));

Expand Down Expand Up @@ -96,7 +95,7 @@ public void testAbsoluteSubdir() throws Exception {
String collectionName = "coll" + collectionIdx.getAndIncrement();
SolrClient client = solrTestRule.getSolrClient(collectionName);

Path coreRootDir = ((EmbeddedSolrServer) client).getCoreContainer().getCoreRootDirectory();
Path coreRootDir = solrTestRule.getCoreContainer().getCoreRootDirectory();

Path instanceDir = FilterPath.unwrap(coreRootDir.resolve(collectionName));

Expand All @@ -112,7 +111,7 @@ public void testDefault() throws Exception {
String collectionName = "coll" + collectionIdx.getAndIncrement();
SolrClient client = solrTestRule.getSolrClient(collectionName);

Path coreRootDir = ((EmbeddedSolrServer) client).getCoreContainer().getCoreRootDirectory();
Path coreRootDir = solrTestRule.getCoreContainer().getCoreRootDirectory();

Path instanceDir = FilterPath.unwrap(coreRootDir.resolve(collectionName));

Expand All @@ -126,7 +125,7 @@ public void testExplicitDefault() throws Exception {
String collectionName = "coll" + collectionIdx.getAndIncrement();
SolrClient client = solrTestRule.getSolrClient(collectionName);

Path coreRootDir = ((EmbeddedSolrServer) client).getCoreContainer().getCoreRootDirectory();
Path coreRootDir = solrTestRule.getCoreContainer().getCoreRootDirectory();

Path instanceDir = FilterPath.unwrap(coreRootDir.resolve(collectionName));

Expand Down Expand Up @@ -169,7 +168,7 @@ private static void validateTlogPath(
.toList();
assertNotNull(list);
assertEquals(1, list.size());
CoreContainer cc = ((EmbeddedSolrServer) client).getCoreContainer();
CoreContainer cc = solrTestRule.getCoreContainer();
cc.unload(collectionName, true, true, true);
assertFalse(Files.exists(resolvedTlogDir));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public EmbeddedSolrBackend(EmbeddedSolrServer solrServer) {
this.adminClient = solrServer;
}

/**
* @lucene.internal
*/
public EmbeddedSolrBackend(CoreContainer container) {
this.coreContainer = container;
this.adminClient = new EmbeddedSolrServer(container, null);
}

@Override
public CoreContainer getCoreContainer() {
return coreContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.concurrent.TimeoutException;
import org.apache.solr.SolrBackend;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.jetty.SSLConfig;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
Expand Down Expand Up @@ -832,7 +831,7 @@ private EmbeddedSolrBackend getEmbeddedSolrBackend() {
throw new IllegalStateException(
"Don't call SolrBackend methods in SolrCloud on JettySolrRunner");
}
return new EmbeddedSolrBackend(new EmbeddedSolrServer(container, null)); // cheap
return new EmbeddedSolrBackend(container); // cheap
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@
*/
package org.apache.solr.util;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
import java.util.Set;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrPaths;
import org.apache.solr.core.SolrXmlConfig;
import org.apache.solr.embedded.EmbeddedSolrBackend;
import org.apache.solr.update.UpdateShardHandlerConfig;

/**
Expand All @@ -35,16 +38,6 @@
public class EmbeddedSolrServerTestRule extends SolrClientTestRule {

private static final String CORE_DIR_PROP = "coreRootDirectory";
private EmbeddedSolrServer adminClient = null;

/**
* Shuts down the EmbeddedSolrServer instance and clears the coreRootDirectory system property if
* necessary
*/
@Override
protected void after() {
if (adminClient != null) adminClient.getCoreContainer().shutdown();
}

/**
* Starts the Solr server with the given solrHome. If solrHome contains a solr.xml file, it is
Expand Down Expand Up @@ -80,8 +73,8 @@ public void startSolr(Path solrHome) {
/** Starts Solr with custom NodeConfig */
public void startSolr(NodeConfig nodeConfig) {
var container = new CoreContainer(nodeConfig);
adminClient = new EmbeddedSolrServer(container, null);
container.load(); // do after setting adminClient so that after() can shutdown the container
backend = new EmbeddedSolrBackend(container);
container.load(); // do after setting this.backend so that after() can shutdown the container
}

/** Returns a NodeConfigBuilder with default settings for test configuration */
Expand All @@ -93,21 +86,13 @@ public NodeConfig.NodeConfigBuilder newNodeConfigBuilder(Path solrHome) {
.setCoreRootDirectory(LuceneTestCase.createTempDir("cores").toString());
}

/** Provides an EmbeddedSolrServer instance for administration actions */
@Override
public EmbeddedSolrServer getAdminClient() {
if (adminClient == null) {
throw new RuntimeException("Solr must be started first");
}
return adminClient;
}

@Override
public EmbeddedSolrServer getSolrClient(String collection) {
return new EmbeddedSolrServer(getCoreContainer(), collection);
}

public CoreContainer getCoreContainer() {
return getAdminClient().getCoreContainer();
@Override
protected void createColl(NewCollectionBuilder b) throws SolrServerException, IOException {
createCollStandalone(b);
}
}
Loading
Loading