Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
ede5683
First pass of a prompt for migrating to SolrJettyTestRule
epugh Dec 13, 2025
bba2ab0
First pass through using LLM to migrate from SolrJettyTestBase to Sol…
epugh Dec 13, 2025
fbfadce
for what ever reason these were considered more complex then the prev…
epugh Dec 13, 2025
652dc89
Additional migration of tests.
epugh Dec 13, 2025
f2efcef
add two more instructions based on review...
epugh Dec 14, 2025
f3d688e
Pretty straightforward migraiton..
epugh Dec 14, 2025
21f2949
These migrations appear more concerning, a lot of deprecated code and…
epugh Dec 14, 2025
c44be5d
Actually remove SolrJettyTestBase!
epugh Dec 14, 2025
614c5f7
tracking file updates
epugh Dec 14, 2025
1177167
Revert "Actually remove SolrJettyTestBase!"
epugh Dec 14, 2025
835d926
Revert "These migrations appear more concerning, a lot of deprecated …
epugh Dec 14, 2025
33c61ce
Merge remote-tracking branch 'upstream/main' into migrate_away_from_s…
epugh Dec 15, 2025
bf278de
remove files that dont have license for now
epugh Dec 15, 2025
cab85b2
remove files that dont have license for now
epugh Dec 15, 2025
df7ba8d
Revert "remove files that dont have license for now"
epugh Dec 15, 2025
e2270f6
Revert "remove files that dont have license for now"
epugh Dec 15, 2025
5de956c
add license header just to pass precommit, they are temp files however
epugh Dec 15, 2025
dff81d7
Merge remote-tracking branch 'upstream/main' into migrate_away_from_s…
epugh Dec 22, 2025
793d987
Update dependencies needed for tests.
epugh Dec 22, 2025
df01f34
reworking the setup steps
epugh Dec 22, 2025
331b419
Use copyMinConf to reduce amount of boilerplate copying
epugh Dec 22, 2025
29398cc
Local variable that isn't used.
epugh Dec 22, 2025
abaeda2
rework awkward comment.
epugh Dec 22, 2025
13c4ee1
lint
epugh Dec 22, 2025
0577c46
Using copyMinConf reduces boilerplate copying.
epugh Dec 22, 2025
afdf1c1
With the migration, some of the comments are out of date.
epugh Dec 22, 2025
8ef50c4
simplify client setup.
epugh Dec 22, 2025
19f746d
unneeded code
epugh Dec 22, 2025
758d698
Code review driven tweaks.
epugh Dec 22, 2025
0905bb0
unneeded property set/clear
epugh Dec 22, 2025
9be336b
Migrate SolrExampleTestsBase to using SolrJettyTestRule
epugh Dec 22, 2025
e246dab
move method to specific subclass that uses it.
epugh Dec 22, 2025
2e624aa
Remove unused code
epugh Dec 23, 2025
978e884
Various code clean ups from looking for issues.
epugh Dec 23, 2025
633c342
basic migation done
epugh Dec 23, 2025
f71725b
Update names and lint checking of java code
epugh Dec 23, 2025
f0ea4c8
Commit changes before merge
epugh Dec 23, 2025
a8c6187
respond to feedback.
epugh Dec 23, 2025
9dbe91a
Remove a method duplicated by the parent class.
epugh Dec 23, 2025
3a2c223
Wihtout this, it appeared not to work..
epugh Dec 23, 2025
66524de
Reworked CacheHeader tests
epugh Dec 25, 2025
382e8fe
lint
epugh Dec 25, 2025
e575210
Migrated to SolrTestCaseJ4 w solrClientTestRule
epugh Dec 25, 2025
36dc9d1
lint
epugh Dec 27, 2025
7ab56ca
Remove no longer used dependency.
epugh Dec 27, 2025
a8e563a
Finally remove SolrJettyTestBase
epugh Dec 27, 2025
e1f9c1b
Merge remote-tracking branch 'upstream/main' into migrate_away_from_s…
epugh Dec 27, 2025
12aa2da
remove in progress generated files
epugh Dec 28, 2025
0c1a6e4
Merge remote-tracking branch 'upstream/main' into migrate_away_from_s…
epugh Dec 28, 2025
583db85
Using the SolrClientTestRule.create for collections.
epugh Dec 28, 2025
cd8c40f
Use modern approach for creating the needed collection.
epugh Dec 28, 2025
3344164
Merge remote-tracking branch 'upstream/main' into migrate_away_from_s…
epugh Dec 29, 2025
e258844
Update solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolr…
epugh Dec 29, 2025
796bac2
Clean up that David spotted that applies in many places!
epugh Dec 29, 2025
1851cd5
Merge branch 'migrate_away_from_solrjettytestbase' of github.com:epug…
epugh Dec 29, 2025
a2a66d9
Inline deprecated method
epugh Dec 29, 2025
d24a74c
try with resoruces is som much shorter
epugh Dec 29, 2025
d610b04
lint
epugh Dec 29, 2025
2b9010f
Standardize on solrTestRule across the code base.
epugh Dec 29, 2025
4a46298
Except in four places, we always have a Path. So let's embrace the P…
epugh Dec 29, 2025
e37bbb4
Back out overly aggressive swap to path, and allow string configset
epugh Dec 30, 2025
6b590b1
two lints while checking for a potential method to remove
epugh Dec 30, 2025
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 @@ -36,7 +36,7 @@
*/
public class TestCustomCoreProperties extends SolrTestCaseJ4 {

@ClassRule public static SolrJettyTestRule solrClientTestRule = new SolrJettyTestRule();
@ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();

// TODO these properties files don't work with configsets

Expand All @@ -49,7 +49,6 @@ public static void beforeClass() throws Exception {

Files.createDirectories(confDir);

Files.copy(SolrTestCaseJ4.TEST_HOME().resolve("solr.xml"), homeDir.resolve("solr.xml"));
String src_dir = TEST_HOME() + "/collection1/conf";
Files.copy(Path.of(src_dir, "schema-tiny.xml"), confDir.resolve("schema.xml"));
Files.copy(
Expand Down Expand Up @@ -79,7 +78,7 @@ public static void beforeClass() throws Exception {
nodeProperties.setProperty("solr.data.dir", createTempDir().toRealPath().toString());
}

solrClientTestRule.startSolr(homeDir, nodeProperties, JettyConfig.builder().build());
solrTestRule.startSolr(homeDir, nodeProperties, JettyConfig.builder().build());
}

@Test
Expand All @@ -88,7 +87,7 @@ public void testSimple() throws Exception {
params(
"q", "*:*",
"echoParams", "all");
QueryResponse res = solrClientTestRule.getSolrClient("collection1").query(params);
QueryResponse res = solrTestRule.getSolrClient("collection1").query(params);
assertEquals(0, res.getResults().getNumFound());

NamedList<?> echoedParams = (NamedList<?>) res.getHeader().get("params");
Expand Down
62 changes: 34 additions & 28 deletions solr/core/src/test/org/apache/solr/TestTolerantSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clients collection1 and collection2 in TestTolerantSearch are set to null in AfterClass without being closed. This creates a potential resource leak. Either close these clients before nulling them, or verify that the SolrJettyTestRule handles cleanup of all client instances.

Suggested change
collection1 = null;
collection2 = null;
if (collection1 != null) {
collection1.close();
collection1 = null;
}
if (collection2 != null) {
collection2.close();
collection2 = null;
}

Copilot uses AI. Check for mistakes.
resetExceptionIgnores();
systemClearPropertySolrEnableUrlAllowList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void before() throws Exception {

@After
public void after() throws Exception {
solrClientTestRule.reset();
solrTestRule.reset();

if (restTestHarness != null) {
restTestHarness.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void before() throws Exception {

@After
public void after() throws Exception {
solrClientTestRule.reset();
solrTestRule.reset();

if (restTestHarness != null) {
restTestHarness.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.jetty.HttpJettySolrClient;
import org.apache.solr.client.solrj.request.SolrPing;
import org.apache.solr.common.util.ExecutorUtil;
Expand All @@ -35,16 +35,20 @@
import org.apache.solr.common.util.SuppressForbidden;
import org.apache.solr.util.LogLevel;
import org.apache.solr.util.LogListener;
import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.slf4j.MDC;

@LogLevel("org.apache.solr.client.solrj.jetty.HttpJettySolrClient=DEBUG")
public class TestHttpRequestId extends SolrJettyTestBase {
public class TestHttpRequestId extends SolrTestCaseJ4 {

@ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();

@BeforeClass
public static void beforeTest() throws Exception {
createAndStartJetty(legacyExampleCollection1SolrHome());
solrTestRule.startSolr(createTempDir());
}

@Test
Expand Down Expand Up @@ -95,7 +99,7 @@ private void setupClientAndRun(
false);
CompletableFuture<NamedList<Object>> cf;
try (var client =
new HttpJettySolrClient.Builder(getBaseUrl())
new HttpJettySolrClient.Builder(solrTestRule.getBaseUrl())
.withDefaultCollection(collection)
.withExecutor(commExecutor)
.build()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.lucene.store.NIOFSDirectory;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.apache.HttpSolrClient;
Expand All @@ -53,7 +52,7 @@
// Backups do checksum validation against a footer value not present in 'SimpleText'
@LuceneTestCase.SuppressCodecs({"SimpleText"})
@SolrTestCaseJ4.SuppressSSL // Currently, unknown why SSL does not work with this test
public class TestReplicationHandlerBackup extends SolrJettyTestBase {
public class TestReplicationHandlerBackup extends SolrTestCaseJ4 {

JettySolrRunner leaderJetty;
ReplicationTestHelper.SolrInstance leader = null;
Expand All @@ -78,9 +77,8 @@ private static JettySolrRunner createAndStartJetty(ReplicationTestHelper.SolrIns
return jetty;
}

private static SolrClient createNewSolrClient(int port) {
final String baseUrl = buildUrl(port);
return new HttpSolrClient.Builder(baseUrl)
private static SolrClient createNewSolrClient(JettySolrRunner jetty) {
return new HttpSolrClient.Builder(jetty.getBaseUrl().toString())
.withConnectionTimeout(15000, TimeUnit.MILLISECONDS)
.withSocketTimeout(60000, TimeUnit.MILLISECONDS)
.build();
Expand All @@ -102,7 +100,7 @@ public void setUp() throws Exception {
leader.copyConfigFile(CONF_DIR.resolve(configFile).toString(), "solrconfig.xml");

leaderJetty = createAndStartJetty(leader);
leaderClient = createNewSolrClient(leaderJetty.getLocalPort());
leaderClient = createNewSolrClient(leaderJetty);
docsSeed = random().nextLong();
}

Expand Down Expand Up @@ -247,7 +245,7 @@ private void testDeleteNamedBackup(String[] backupNames) throws Exception {
public static void runBackupCommand(JettySolrRunner leaderJetty, String cmd, String params)
throws IOException {
String leaderUrl =
buildUrl(leaderJetty.getLocalPort())
leaderJetty.getBaseUrl().toString()
+ "/"
+ DEFAULT_TEST_CORENAME
+ ReplicationHandler.PATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.tests.util.TestUtil;
import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.apache.HttpSolrClient;
Expand All @@ -41,7 +40,7 @@
@SolrTestCaseJ4.SuppressSSL // Currently, unknown why SSL does not work with this test
// Backups do checksum validation against a footer value not present in 'SimpleText'
@LuceneTestCase.SuppressCodecs("SimpleText")
public class TestRestoreCore extends SolrJettyTestBase {
public class TestRestoreCore extends SolrTestCaseJ4 {

JettySolrRunner leaderJetty;
ReplicationTestHelper.SolrInstance leader = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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
CC @gerlowskija


// We do however explicitly want a fresh "cluster" every time a test is run
configureCluster(1).addConfig("conf1", configset("cloud-minimal")).configure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public static void afterClass() {
public void beforeTest() throws Exception {
backupDir = createTempDir(getTestClass().getSimpleName() + "_backups");

// 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

// We do however explicitly want a fresh "cluster" every time a test is run
configureCluster(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.io.InputStream;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.solr.SolrJettyTestBase;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
Expand All @@ -38,18 +38,18 @@
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.util.SolrJettyTestRule;
import org.junit.BeforeClass;
import org.junit.ClassRule;

/**
* Extend SolrJettyTestBase because the SOLR-2535 bug only manifested itself when the {@link
* org.apache.solr.servlet.SolrDispatchFilter} is used, which isn't for embedded Solr use.
*/
public class ShowFileRequestHandlerTest extends SolrJettyTestBase {
public class ShowFileRequestHandlerTest extends SolrTestCaseJ4 {

@ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();

@BeforeClass
public static void beforeTest() throws Exception {
initCore("solrconfig.xml", "schema.xml");
createAndStartJetty(legacyExampleCollection1SolrHome());
solrTestRule.startSolr(legacyExampleCollection1SolrHome());
}

private GenericSolrRequest createShowFileRequest(SolrParams params) {
Expand All @@ -59,7 +59,7 @@ private GenericSolrRequest createShowFileRequest(SolrParams params) {
}

public void test404ViaHttp() {
SolrClient client = getSolrClient();
SolrClient client = solrTestRule.getSolrClient();
var request = createShowFileRequest(params("file", "does-not-exist-404.txt"));
SolrException e = expectThrows(SolrException.class, () -> request.process(client));
assertEquals(404, e.code());
Expand All @@ -82,18 +82,14 @@ public void test404Locally() {
}

public void testDirList() throws SolrServerException, IOException {
SolrClient client = getSolrClient();
// assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends
// SolrTestCaseJ4
SolrClient client = solrTestRule.getSolrClient();
var request = createShowFileRequest(new ModifiableSolrParams());
var resp = request.process(client);
assertTrue(((NamedList) resp.getResponse().get("files")).size() > 0); // some files
}

public void testGetRawFile() throws SolrServerException, IOException {
SolrClient client = getSolrClient();
// assertQ(req("qt", "/admin/file"));
// TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4
SolrClient client = solrTestRule.getSolrClient();
var request = createShowFileRequest(params("file", "managed-schema.xml"));
final AtomicBoolean readFile = new AtomicBoolean();
request.setResponseParser(
Expand Down Expand Up @@ -146,7 +142,7 @@ public void testContentTypeHtmlDefault() {
}

public void testIllegalContentType() throws SolrServerException, IOException {
SolrClient client = getSolrClient();
SolrClient client = solrTestRule.getSolrClient();
var request =
createShowFileRequest(params("file", "managed-schema", "contentType", "not/known"));
request.setResponseParser(new InputStreamResponseParser("xml"));
Expand All @@ -155,7 +151,7 @@ public void testIllegalContentType() throws SolrServerException, IOException {
}

public void testAbsoluteFilename() throws SolrServerException, IOException {
SolrClient client = getSolrClient();
SolrClient client = solrTestRule.getSolrClient();
final var request =
createShowFileRequest(
params("file", "/etc/passwd", "contentType", "text/plain; charset=utf-8"));
Expand All @@ -165,7 +161,7 @@ public void testAbsoluteFilename() throws SolrServerException, IOException {
}

public void testEscapeConfDir() throws SolrServerException, IOException {
SolrClient client = getSolrClient();
SolrClient client = solrTestRule.getSolrClient();
final var request =
createShowFileRequest(
params("file", "../../solr.xml", "contentType", "application/xml; charset=utf-8"));
Expand All @@ -175,7 +171,7 @@ public void testEscapeConfDir() throws SolrServerException, IOException {
}

public void testPathTraversalFilename() throws SolrServerException, IOException {
SolrClient client = getSolrClient();
SolrClient client = solrTestRule.getSolrClient();
final var request =
createShowFileRequest(
params(
Expand Down
Loading
Loading