This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new 813f6a134e0 SOLR-17933: Remove DirectSolrConnection from test (#3708)
813f6a134e0 is described below
commit 813f6a134e01a33033fc976c3f2fe17a424c6f0a
Author: Eric Pugh <[email protected]>
AuthorDate: Fri Dec 19 12:37:39 2025 -0500
SOLR-17933: Remove DirectSolrConnection from test (#3708)
Remove DirectSolrConnection from code base
Update the tests to use sdoc() helpers instead of xml based string
generating helpers doc()
Some refactoring of TestHarness, remove some code paths that are not
exercised.
One global refactoring sneaking in of using List.of for ContentStream
collection.
---
.../SOLR-17933-remove-directsolrconnection.yml | 8 ++
.../apache/solr/servlet/DirectSolrConnection.java | 133 ---------------------
.../test/org/apache/solr/TestCrossCoreJoin.java | 96 ++++++---------
.../solr/handler/MoreLikeThisHandlerTest.java | 12 +-
.../TestSubQueryTransformerCrossCore.java | 102 +++++++---------
.../org/apache/solr/search/TestIndexSearcher.java | 25 ++--
.../solr/servlet/DirectSolrConnectionTest.java | 70 -----------
.../processor/TolerantUpdateProcessorTest.java | 31 +++--
.../UniqFieldsUpdateProcessorFactoryTest.java | 5 +-
.../xslt/XSLTUpdateRequestHandlerTest.java | 5 +-
.../apache/solr/client/solrj/util/ClientUtils.java | 5 +-
.../src/java/org/apache/solr/SolrTestCaseHS.java | 15 ++-
.../src/java/org/apache/solr/SolrTestCaseJ4.java | 29 +++--
.../src/java/org/apache/solr/util/TestHarness.java | 35 +++---
14 files changed, 179 insertions(+), 392 deletions(-)
diff --git a/changelog/unreleased/SOLR-17933-remove-directsolrconnection.yml
b/changelog/unreleased/SOLR-17933-remove-directsolrconnection.yml
new file mode 100644
index 00000000000..a6e663c8a41
--- /dev/null
+++ b/changelog/unreleased/SOLR-17933-remove-directsolrconnection.yml
@@ -0,0 +1,8 @@
+# See https://github.com/apache/solr/blob/main/dev-docs/changelog.adoc
+title: Remove deprecated DirectSolrConnection use
+type: removed # added, changed, fixed, deprecated, removed, dependency_update,
security, other
+authors:
+ - name: Eric Pugh
+links:
+ - name: SOLR-17933
+ url: https://issues.apache.org/jira/browse/SOLR-17933
diff --git
a/solr/core/src/java/org/apache/solr/servlet/DirectSolrConnection.java
b/solr/core/src/java/org/apache/solr/servlet/DirectSolrConnection.java
deleted file mode 100644
index 244cf8b4128..00000000000
--- a/solr/core/src/java/org/apache/solr/servlet/DirectSolrConnection.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * 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.servlet;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.params.CommonParams;
-import org.apache.solr.common.params.SolrParams;
-import org.apache.solr.common.util.ContentStream;
-import org.apache.solr.common.util.ContentStreamBase;
-import org.apache.solr.core.SolrCore;
-import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestHandler;
-import org.apache.solr.request.SolrRequestInfo;
-import org.apache.solr.response.SolrQueryResponse;
-
-/**
- * DirectSolrConnection provides an interface to Solr that is similar to the
HTTP interface, but
- * does not require an HTTP connection.
- *
- * <p>This class is designed to be as simple as possible and allow for more
flexibility in how you
- * interface to Solr.
- *
- * @since solr 1.2
- * @deprecated see {@link
org.apache.solr.client.solrj.embedded.EmbeddedSolrServer}
- */
-@Deprecated
-public class DirectSolrConnection {
- protected final SolrCore core;
- protected final SolrRequestParsers parser;
-
- /** Initialize using an explicit SolrCore */
- public DirectSolrConnection(SolrCore c) {
- core = c;
- parser = new SolrRequestParsers(c.getSolrConfig());
- }
-
- /**
- * For example:
- *
- * <p>String json = solr.request( "/select?qt=dismax&wt=json&q=...",
null ); String xml =
- * solr.request( "/select?qt=dismax&wt=xml&q=...", null ); String
xml = solr.request(
- * "/update", "<add><doc><field ..." );
- */
- public String request(String pathAndParams, String body) throws Exception {
- String path = null;
- SolrParams params = null;
- int idx = pathAndParams.indexOf('?');
- if (idx > 0) {
- path = pathAndParams.substring(0, idx);
- params = SolrRequestParsers.parseQueryString(pathAndParams.substring(idx
+ 1));
- } else {
- path = pathAndParams;
- params = SolrParams.of();
- }
-
- return request(path, params, body);
- }
-
- public String request(String path, SolrParams params, String body) throws
Exception {
- // Extract the handler from the path or params
- SolrRequestHandler handler = core.getRequestHandler(path);
- if (handler == null) {
- if ("/select".equals(path) || "/select/".equalsIgnoreCase(path)) {
- if (params == null) params = SolrParams.of();
- String qt = params.get(CommonParams.QT);
- handler = core.getRequestHandler(qt);
- if (handler == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"unknown handler: " + qt);
- }
- }
- }
- if (handler == null) {
- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "unknown
handler: " + path);
- }
-
- return request(handler, params, body);
- }
-
- public String request(SolrRequestHandler handler, SolrParams params, String
body)
- throws Exception {
- if (params == null) params = SolrParams.of();
-
- // Make a stream for the 'body' content
- List<ContentStream> streams = new ArrayList<>(1);
- if (body != null && body.length() > 0) {
- streams.add(new ContentStreamBase.StringStream(body));
- }
-
- SolrQueryRequest req = null;
- try {
- req = parser.buildRequestFrom(core, params, streams);
- SolrQueryResponse rsp = new SolrQueryResponse();
- SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
- core.execute(handler, req, rsp);
- if (rsp.getException() != null) {
- throw rsp.getException();
- }
-
- // Now write it out
- return req.getResponseWriter().writeToString(req, rsp);
- } finally {
- if (req != null) {
- req.close();
- SolrRequestInfo.clearRequestInfo();
- }
- }
- }
-
- /**
- * Use this method to close the underlying SolrCore.
- *
- * @since solr 1.3
- */
- public void close() {
- core.close();
- }
-}
diff --git a/solr/core/src/test/org/apache/solr/TestCrossCoreJoin.java
b/solr/core/src/test/org/apache/solr/TestCrossCoreJoin.java
index a4ba1f26e68..228cbaa304e 100644
--- a/solr/core/src/test/org/apache/solr/TestCrossCoreJoin.java
+++ b/solr/core/src/test/org/apache/solr/TestCrossCoreJoin.java
@@ -17,18 +17,19 @@
package org.apache.solr;
import java.util.Collections;
+import java.util.List;
import java.util.Map;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.common.SolrException.ErrorCode;
+import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.search.join.TestScoreJoinQPNoScore;
-import org.apache.solr.servlet.DirectSolrConnection;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -36,21 +37,21 @@ import org.junit.Test;
public class TestCrossCoreJoin extends SolrTestCaseJ4 {
private static SolrCore fromCore;
+ private static EmbeddedSolrServer fromServer;
@BeforeClass
public static void beforeTests() throws Exception {
System.setProperty(
"solr.index.updatelog.enabled", "false"); // schema12 doesn't support
_version_
System.setProperty("solr.filterCache.async", "true");
- // initCore("solrconfig.xml","schema12.xml");
- // File testHome = createTempDir().toFile();
- // FileUtils.copyDirectory(getFile("solrj/solr"), testHome);
initCore("solrconfig.xml", "schema12.xml", TEST_HOME(), "collection1");
final CoreContainer coreContainer = h.getCoreContainer();
fromCore = coreContainer.create("fromCore", Map.of("configSet",
"minimal"));
+ fromServer = new EmbeddedSolrServer(fromCore.getCoreContainer(),
fromCore.getName());
+ // Add documents to the main core
assertU(
add(
doc(
@@ -98,63 +99,34 @@ public class TestCrossCoreJoin extends SolrTestCaseJ4 {
"Engineering")));
assertU(commit());
- update(
- fromCore,
- add(
- doc(
- "id",
- "10",
- "id_s_dv",
- "10",
- "dept_id_s",
- "Engineering",
- "text",
- "These guys develop stuff",
- "cat",
- "dev")));
- update(
- fromCore,
- add(
- doc(
- "id",
- "11",
- "id_s_dv",
- "11",
- "dept_id_s",
- "Marketing",
- "text",
- "These guys make you look good")));
- update(
- fromCore,
- add(
- doc(
- "id",
- "12",
- "id_s_dv",
- "12",
- "dept_id_s",
- "Sales",
- "text",
- "These guys sell stuff")));
- update(
- fromCore,
- add(
- doc(
- "id",
- "13",
- "id_s_dv",
- "13",
- "dept_id_s",
- "Support",
- "text",
- "These guys help customers")));
- update(fromCore, commit());
- }
-
- public static String update(SolrCore core, String xml) throws Exception {
- DirectSolrConnection connection = new DirectSolrConnection(core);
- SolrRequestHandler handler = core.getRequestHandler("/update");
- return connection.request(handler, null, xml);
+ // Add documents to the fromCore
+ List<SolrInputDocument> docs =
+ sdocs(
+ sdoc(
+ "id", "10",
+ "id_s_dv", "10",
+ "dept_id_s", "Engineering",
+ "text", "These guys develop stuff",
+ "cat", "dev"),
+ sdoc(
+ "id", "11",
+ "id_s_dv", "11",
+ "dept_id_s", "Marketing",
+ "text", "These guys make you look good"),
+ sdoc(
+ "id", "12",
+ "id_s_dv", "12",
+ "dept_id_s", "Sales",
+ "text", "These guys sell stuff"),
+ sdoc(
+ "id", "13",
+ "id_s_dv", "13",
+ "dept_id_s", "Support",
+ "text", "These guys help customers"));
+
+ // Add all documents to fromCore
+ fromServer.add(docs);
+ fromServer.commit();
}
@Test
diff --git
a/solr/core/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java
b/solr/core/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java
index df7ec8ecb38..63908f192a6 100644
--- a/solr/core/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/MoreLikeThisHandlerTest.java
@@ -17,6 +17,7 @@
package org.apache.solr.handler;
import java.util.ArrayList;
+import java.util.List;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
@@ -157,10 +158,9 @@ public class MoreLikeThisHandlerTest extends
SolrTestCaseJ4 {
() -> {
try (MoreLikeThisHandler mlt = new MoreLikeThisHandler();
SolrQueryRequestBase req = new SolrQueryRequestBase(core,
params) {}) {
- ArrayList<ContentStream> streams = new ArrayList<>(2);
- streams.add(new ContentStreamBase.StringStream("hello"));
- streams.add(new ContentStreamBase.StringStream("there"));
- req.setContentStreams(streams);
+ req.setContentStreams(List.of(
+ new ContentStreamBase.StringStream("hello"),
+ new ContentStreamBase.StringStream("there")));
mlt.handleRequestBody(req, new SolrQueryResponse());
}
});
@@ -277,9 +277,7 @@ public class MoreLikeThisHandlerTest extends SolrTestCaseJ4
{
params.set("indent", "true");
try (SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {})
{
- ArrayList<ContentStream> streams = new ArrayList<>(2);
- streams.add(new ContentStreamBase.StringStream("bbb", "zzz"));
- req.setContentStreams(streams);
+ req.setContentStreams(List.of(new ContentStreamBase.StringStream("bbb",
"zzz")));
// Make sure we have terms from both fields in the interestingTerms
array and all documents
// have been retrieved as matching.
diff --git
a/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerCrossCore.java
b/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerCrossCore.java
index b40d752f72f..67af41cfcdd 100644
---
a/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerCrossCore.java
+++
b/solr/core/src/test/org/apache/solr/response/transform/TestSubQueryTransformerCrossCore.java
@@ -16,13 +16,14 @@
*/
package org.apache.solr.response.transform;
+import java.util.List;
import java.util.Map;
import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrCore;
-import org.apache.solr.request.SolrRequestHandler;
-import org.apache.solr.servlet.DirectSolrConnection;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -30,6 +31,7 @@ import org.junit.Test;
public class TestSubQueryTransformerCrossCore extends SolrTestCaseJ4 {
private static SolrCore fromCore;
+ private static EmbeddedSolrServer fromServer;
@BeforeClass
public static void beforeTests() throws Exception {
@@ -38,11 +40,10 @@ public class TestSubQueryTransformerCrossCore extends
SolrTestCaseJ4 {
initCore("solrconfig-basic.xml", "schema-docValuesJoin.xml");
final CoreContainer coreContainer = h.getCoreContainer();
- fromCore =
- coreContainer.create(
- "fromCore", // FileSystems.getDefault().getPath( TEST_HOME()),
- //
ImmutableMap.of("config","solrconfig-basic.xml","schema","schema-docValuesJoin.xml"
- Map.of("configSet", "minimal"));
+ fromCore = coreContainer.create("fromCore", Map.of("configSet",
"minimal"));
+ fromServer = new EmbeddedSolrServer(fromCore.getCoreContainer(),
fromCore.getName());
+
+ // Add documents to the main core
assertU(
add(
doc(
@@ -112,61 +113,32 @@ public class TestSubQueryTransformerCrossCore extends
SolrTestCaseJ4 {
"These guys develop stuff")));
assertU(commit());
- update(
- fromCore,
- add(
- doc(
- "id",
- "10",
- "dept_id_s",
- "Engineering",
- "text_t",
- "These guys develop stuff",
- "salary_i_dv",
- "1000")));
- update(
- fromCore,
- add(
- doc(
- "id",
- "11",
- "dept_id_s",
- "Marketing",
- "text_t",
- "These guys make you look good",
- "salary_i_dv",
- "1500")));
- update(
- fromCore,
- add(
- doc(
- "id",
- "12",
- "dept_id_s",
- "Sales",
- "text_t",
- "These guys sell stuff",
- "salary_i_dv",
- "1600")));
- update(
- fromCore,
- add(
- doc(
- "id",
- "13",
- "dept_id_s",
- "Support",
- "text_t",
- "These guys help customers",
- "salary_i_dv",
- "800")));
- update(fromCore, commit());
- }
+ // Add documents to the fromCore
+ List<SolrInputDocument> docs =
+ sdocs(
+ sdoc(
+ "id", "10",
+ "dept_id_s", "Engineering",
+ "text_t", "These guys develop stuff",
+ "salary_i_dv", 1000),
+ sdoc(
+ "id", "11",
+ "dept_id_s", "Marketing",
+ "text_t", "These guys make you look good",
+ "salary_i_dv", 1500),
+ sdoc(
+ "id", "12",
+ "dept_id_s", "Sales",
+ "text_t", "These guys sell stuff",
+ "salary_i_dv", 1600),
+ sdoc(
+ "id", "13",
+ "dept_id_s", "Support",
+ "text_t", "These guys help customers",
+ "salary_i_dv", 800));
- public static String update(SolrCore core, String xml) throws Exception {
- DirectSolrConnection connection = new DirectSolrConnection(core);
- SolrRequestHandler handler = core.getRequestHandler("/update");
- return connection.request(handler, null, xml);
+ fromServer.add(docs);
+ fromServer.commit();
}
@Test
@@ -245,6 +217,14 @@ public class TestSubQueryTransformerCrossCore extends
SolrTestCaseJ4 {
@AfterClass
public static void nukeAll() {
+ if (fromServer != null) {
+ try {
+ fromServer.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
fromCore = null;
+ fromServer = null;
}
}
diff --git a/solr/core/src/test/org/apache/solr/search/TestIndexSearcher.java
b/solr/core/src/test/org/apache/solr/search/TestIndexSearcher.java
index 4f7e0eb0809..857aac9800f 100644
--- a/solr/core/src/test/org/apache/solr/search/TestIndexSearcher.java
+++ b/solr/core/src/test/org/apache/solr/search/TestIndexSearcher.java
@@ -32,7 +32,11 @@ import org.apache.lucene.index.ReaderUtil;
import org.apache.lucene.queries.function.FunctionValues;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.common.params.ModifiableSolrParams;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.request.SolrQuery;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.response.UpdateResponse;
+import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.CoreDescriptor;
import org.apache.solr.core.SolrCore;
@@ -41,9 +45,7 @@ import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.index.LogDocMergePolicyFactory;
import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.schema.SchemaField;
-import org.apache.solr.servlet.DirectSolrConnection;
import org.apache.solr.util.plugin.SolrCoreAware;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -265,11 +267,10 @@ public class TestIndexSearcher extends SolrTestCaseJ4 {
}
private void doQuery(SolrCore core) throws Exception {
- DirectSolrConnection connection = new DirectSolrConnection(core);
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.add("q", "*:*");
- assertTrue(
- connection.request("/select", params, null).contains("<int
name=\"status\">0</int>"));
+ EmbeddedSolrServer server = new EmbeddedSolrServer(core);
+ SolrQuery query = new SolrQuery("*:*");
+ QueryResponse response = server.query(query);
+ assertEquals(0, response.getStatus());
}
public void testDontUseColdSearcher() throws Exception {
@@ -410,9 +411,11 @@ public class TestIndexSearcher extends SolrTestCaseJ4 {
}
private void addDummyDoc(SolrCore core) throws Exception {
- DirectSolrConnection connection = new DirectSolrConnection(core);
- SolrRequestHandler handler = core.getRequestHandler("/update");
- connection.request(handler, null, adoc("id", "1"));
+ EmbeddedSolrServer server = new EmbeddedSolrServer(core);
+
+ SolrInputDocument doc = sdoc("id", "1");
+ UpdateResponse response = server.add(doc);
+ assertEquals(0, response.getStatus());
}
public static class MockSearchComponent extends SearchComponent implements
SolrCoreAware {
diff --git
a/solr/core/src/test/org/apache/solr/servlet/DirectSolrConnectionTest.java
b/solr/core/src/test/org/apache/solr/servlet/DirectSolrConnectionTest.java
deleted file mode 100644
index 9d6c5c8f916..00000000000
--- a/solr/core/src/test/org/apache/solr/servlet/DirectSolrConnectionTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.servlet;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.junit.BeforeClass;
-
-@Deprecated
-public class DirectSolrConnectionTest extends SolrTestCaseJ4 {
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- initCore("solr/crazy-path-to-config.xml", "solr/crazy-path-to-schema.xml");
- }
-
- DirectSolrConnection direct;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- direct = new DirectSolrConnection(h.getCore());
- }
-
- // Check that a request gets back the echoParams call
- public void testSimpleRequest() throws Exception {
- String pathAndParams = "/select?wt=xml&echoParams=explicit&q=*:*";
-
- String got = direct.request(pathAndParams, null);
-
- assertTrue(got.indexOf("<str name=\"echoParams\">explicit</str>") > 5);
-
- // It should throw an exception for unknown handler
- expectThrows(Exception.class, () -> direct.request("/path to nonexistent
thingy!!", null));
- }
-
- // Check that a request gets back the echoParams call
- public void testInsertThenSelect() throws Exception {
- String value = "Kittens!!! \u20AC";
- String[] cmds =
- new String[] {
- "<delete><id>42</id></delete>",
- "<add><doc><field name=\"id\">42</field><field name=\"subject\">"
- + value
- + "</field></doc></add>",
- "<commit/>"
- };
- String getIt = "/select?wt=xml&q=id:42";
-
- // Test using by posting in the body
- for (String cmd : cmds) {
- direct.request("/update", cmd);
- }
- String got = direct.request(getIt, null);
- assertTrue(got.indexOf(value) > 0);
- }
-}
diff --git
a/solr/core/src/test/org/apache/solr/update/processor/TolerantUpdateProcessorTest.java
b/solr/core/src/test/org/apache/solr/update/processor/TolerantUpdateProcessorTest.java
index 7eaec9480e7..c057e101373 100644
---
a/solr/core/src/test/org/apache/solr/update/processor/TolerantUpdateProcessorTest.java
+++
b/solr/core/src/test/org/apache/solr/update/processor/TolerantUpdateProcessorTest.java
@@ -26,19 +26,22 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.xml.xpath.XPathExpressionException;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
+import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
+import org.apache.solr.client.solrj.response.InputStreamResponseParser;
import org.apache.solr.client.solrj.util.ClientUtils;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.common.util.IOUtils;
+import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.response.SolrQueryResponse;
-import org.apache.solr.servlet.DirectSolrConnection;
import org.apache.solr.update.AddUpdateCommand;
import org.apache.solr.util.BaseTestHarness;
import org.junit.AfterClass;
@@ -48,6 +51,8 @@ import org.xml.sax.SAXException;
public class TolerantUpdateProcessorTest extends UpdateProcessorTestBase {
+ private static EmbeddedSolrServer server;
+
/** List of valid + invalid documents */
private static List<SolrInputDocument> docs = null;
@@ -57,10 +62,11 @@ public class TolerantUpdateProcessorTest extends
UpdateProcessorTestBase {
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig-update-processor-chains.xml", "schema12.xml");
+ server = new EmbeddedSolrServer(h.getCoreContainer(),
h.getCore().getName());
}
@AfterClass
- public static void tearDownClass() {
+ public static void afterClass() {
docs = null;
badIds = null;
}
@@ -379,12 +385,21 @@ public class TolerantUpdateProcessorTest extends
UpdateProcessorTestBase {
}
public String update(String chain, String xml) {
- DirectSolrConnection connection = new DirectSolrConnection(h.getCore());
- SolrRequestHandler handler = h.getCore().getRequestHandler("/update");
- ModifiableSolrParams params = new ModifiableSolrParams();
- params.add("update.chain", chain);
try {
- return connection.request(handler, params, xml);
+ // Use ContentStreamUpdateRequest to send raw XML through
EmbeddedSolrServer
+ ContentStreamUpdateRequest xmlRequest = new
ContentStreamUpdateRequest("/update");
+ xmlRequest.addContentStream(new ContentStreamBase.StringStream(xml,
"text/xml"));
+
+ // Set the update chain parameter and request XML response
+ xmlRequest.getParams().add("update.chain", chain);
+ xmlRequest.getParams().add("wt", "xml");
+
+ // Use InputStreamResponseParser to get the raw XML response directly
+ xmlRequest.setResponseParser(new InputStreamResponseParser("xml"));
+ NamedList<Object> response = server.request(xmlRequest);
+
+ // Extract the XML string from the response
+ return InputStreamResponseParser.consumeResponseToString(response);
} catch (SolrException e) {
throw e;
} catch (Exception e) {
diff --git
a/solr/core/src/test/org/apache/solr/update/processor/UniqFieldsUpdateProcessorFactoryTest.java
b/solr/core/src/test/org/apache/solr/update/processor/UniqFieldsUpdateProcessorFactoryTest.java
index dce2f9e9ffd..2735130d72e 100644
---
a/solr/core/src/test/org/apache/solr/update/processor/UniqFieldsUpdateProcessorFactoryTest.java
+++
b/solr/core/src/test/org/apache/solr/update/processor/UniqFieldsUpdateProcessorFactoryTest.java
@@ -18,6 +18,7 @@ package org.apache.solr.update.processor;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.MultiMapSolrParams;
@@ -122,9 +123,7 @@ public class UniqFieldsUpdateProcessorFactoryTest extends
SolrTestCaseJ4 {
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(null);
- ArrayList<ContentStream> streams = new ArrayList<>(2);
- streams.add(new ContentStreamBase.StringStream(doc));
- req.setContentStreams(streams);
+ req.setContentStreams(List.of(new ContentStreamBase.StringStream(doc)));
handler.handleRequestBody(req, new SolrQueryResponse());
req.close();
}
diff --git
a/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTUpdateRequestHandlerTest.java
b/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTUpdateRequestHandlerTest.java
index 4e3eff4b6a5..22d23b90603 100644
---
a/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTUpdateRequestHandlerTest.java
+++
b/solr/modules/scripting/src/test/org/apache/solr/scripting/xslt/XSLTUpdateRequestHandlerTest.java
@@ -18,6 +18,7 @@ package org.apache.solr.scripting.xslt;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.MapSolrParams;
@@ -69,9 +70,7 @@ public class XSLTUpdateRequestHandlerTest extends
SolrTestCaseJ4 {
SolrCore core = h.getCore();
LocalSolrQueryRequest req = new LocalSolrQueryRequest(core, new
MapSolrParams(args));
- ArrayList<ContentStream> streams = new ArrayList<>();
- streams.add(new ContentStreamBase.StringStream(xml));
- req.setContentStreams(streams);
+ req.setContentStreams(List.of(new ContentStreamBase.StringStream(xml)));
SolrQueryResponse rsp = new SolrQueryResponse();
// try (UpdateRequestHandler handler = new UpdateRequestHandler()) {
try (XSLTUpdateRequestHandler handler = new XSLTUpdateRequestHandler()) {
diff --git
a/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
index 9cb62fe2578..cc4aef43ddf 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.Base64;
import java.util.Collection;
import java.util.Date;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.solr.client.solrj.SolrRequest;
@@ -51,11 +52,9 @@ public class ClientUtils {
final String str, final String contentType) {
if (str == null) return null;
- ArrayList<ContentStream> streams = new ArrayList<>(1);
ContentStreamBase ccc = new ContentStreamBase.StringStream(str);
ccc.setContentType(contentType);
- streams.add(ccc);
- return streams;
+ return List.of(ccc);
}
/**
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java
b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java
index 421e3e0fa87..e27708c5381 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseHS.java
@@ -34,6 +34,7 @@ import javax.xml.xpath.XPathExpressionException;
import org.apache.lucene.util.IOUtils;
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.client.solrj.request.QueryRequest;
import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.InputStreamResponseParser;
@@ -51,7 +52,6 @@ import org.apache.solr.embedded.JettySolrRunner;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.security.AllowListUrlChecker;
-import org.apache.solr.servlet.DirectSolrConnection;
import org.apache.solr.util.TestHarness;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -186,13 +186,16 @@ public class SolrTestCaseHS extends SolrTestCaseJ4 {
public static String getQueryResponse(String wt, SolrParams params) throws
Exception {
ModifiableSolrParams p = new ModifiableSolrParams(params);
p.set("wt", wt);
- String path = p.get("qt");
- p.remove("qt");
p.set("indent", "true");
- DirectSolrConnection connection = new DirectSolrConnection(h.getCore());
- String raw = connection.request(path, p, null);
- return raw;
+ try (EmbeddedSolrServer server =
+ new EmbeddedSolrServer(h.getCoreContainer(), h.getCore().getName())) {
+ QueryRequest query = new QueryRequest(p);
+
+ query.setResponseParser(new InputStreamResponseParser(wt));
+ NamedList<Object> rsp = server.request(query);
+ return InputStreamResponseParser.consumeResponseToString(rsp);
+ }
}
public static String getJSON(SolrClient client, SolrParams params) throws
Exception {
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 b216fd980e6..bee5d1e4614 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -121,12 +121,12 @@ import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryRequestBase;
import org.apache.solr.request.SolrRequestHandler;
+import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.security.AllowListUrlChecker;
-import org.apache.solr.servlet.DirectSolrConnection;
import org.apache.solr.update.processor.DistributedUpdateProcessor;
import
org.apache.solr.update.processor.DistributedUpdateProcessor.DistribPhase;
import org.apache.solr.update.processor.DistributedZkUpdateProcessor;
@@ -1188,9 +1188,7 @@ public abstract class SolrTestCaseJ4 extends SolrTestCase
{
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(null);
- ArrayList<ContentStream> streams = new ArrayList<>(2);
- streams.add(new ContentStreamBase.StringStream(doc));
- req.setContentStreams(streams);
+ req.setContentStreams(List.of(new ContentStreamBase.StringStream(doc)));
handler.handleRequestBody(req, new SolrQueryResponse());
req.close();
}
@@ -1362,13 +1360,26 @@ public abstract class SolrTestCaseJ4 extends
SolrTestCase {
if (newArgs.get("indent") == null) newArgs.set("indent", "true");
args = newArgs;
}
- DirectSolrConnection connection = new DirectSolrConnection(core);
+
+ LocalSolrQueryRequest req = new LocalSolrQueryRequest(core, args);
+ if (json != null && !json.isEmpty()) {
+ req.setContentStreams(List.of(new ContentStreamBase.StringStream(json)));
+ }
+
+ SolrQueryResponse rsp = new SolrQueryResponse();
SolrRequestHandler handler = core.getRequestHandler("/update/json");
- if (handler == null) {
- handler = new UpdateRequestHandler();
- handler.init(null);
+
+ try {
+ SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
+ handler.handleRequest(req, rsp);
+ if (rsp.getException() != null) {
+ throw rsp.getException();
+ }
+ return req.getResponseWriter().writeToString(req, rsp);
+ } finally {
+ req.close();
+ SolrRequestInfo.clearRequestInfo();
}
- return connection.request(handler, args, json);
}
public static SolrInputDocument sdoc(Object... fieldsAndValues) {
diff --git a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
index b05da370d4d..c363a1e635d 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/TestHarness.java
@@ -22,9 +22,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.client.solrj.impl.SolrZkClientTimeout;
+import org.apache.solr.client.solrj.request.ContentStreamUpdateRequest;
+import org.apache.solr.client.solrj.response.InputStreamResponseParser;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.NamedList.NamedListEntry;
import org.apache.solr.core.CloudConfig;
@@ -37,16 +41,13 @@ import org.apache.solr.core.NodeConfig;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrXmlConfig;
-import org.apache.solr.handler.UpdateRequestHandler;
import org.apache.solr.logging.MDCSnapshot;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
-import org.apache.solr.request.SolrRequestHandler;
import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.IndexSchemaFactory;
-import org.apache.solr.servlet.DirectSolrConnection;
import org.apache.solr.update.UpdateShardHandlerConfig;
/**
@@ -59,7 +60,6 @@ import org.apache.solr.update.UpdateShardHandlerConfig;
public class TestHarness extends BaseTestHarness {
public String coreName;
protected volatile CoreContainer container;
- public UpdateRequestHandler updater;
/**
* Creates a SolrConfig object for the specified coreName assuming it
follows the basic
@@ -171,8 +171,6 @@ public class TestHarness extends BaseTestHarness {
public TestHarness(NodeConfig config, CoresLocator coresLocator) {
container = new CoreContainer(config, coresLocator);
container.load();
- updater = new UpdateRequestHandler();
- updater.init(null);
}
public static NodeConfig buildTestNodeConfig(Path solrHome) {
@@ -263,17 +261,22 @@ public class TestHarness extends BaseTestHarness {
*/
@Override
public String update(String xml) {
- try (var mdcSnap = MDCSnapshot.create();
- SolrCore core = getCoreInc()) {
+ try (var mdcSnap = MDCSnapshot.create()) {
assert null != mdcSnap; // prevent compiler warning of unused var
- DirectSolrConnection connection = new DirectSolrConnection(core);
- SolrRequestHandler handler = core.getRequestHandler("/update");
- // prefer the handler mapped to /update, but use our generic backup
handler
- // if that lookup fails
- if (handler == null) {
- handler = updater;
- }
- return connection.request(handler, null, xml);
+
+ EmbeddedSolrServer server = new EmbeddedSolrServer(getCoreContainer(),
getCore().getName());
+ ContentStreamUpdateRequest xmlRequest = new
ContentStreamUpdateRequest("/update");
+ xmlRequest.addContentStream(new ContentStreamBase.StringStream(xml,
"text/xml"));
+
+ // Request XML response format and use InputStreamResponseParser
+ xmlRequest.getParams().add("wt", "xml");
+ xmlRequest.setResponseParser(new InputStreamResponseParser("xml"));
+ NamedList<Object> response = server.request(xmlRequest);
+ server.close();
+
+ // Extract the XML string from the response
+ return InputStreamResponseParser.consumeResponseToString(response);
+
} catch (SolrException e) {
throw e;
} catch (Exception e) {