This is an automated email from the ASF dual-hosted git repository.
dsmiley 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 c36283c753e SOLR-17776: Fix test
c36283c753e is described below
commit c36283c753e56c635a271497412f81056cbd70e2
Author: David Smiley <[email protected]>
AuthorDate: Fri Jun 27 01:54:13 2025 -0400
SOLR-17776: Fix test
Also improved testRequestTimeoutWithHttpClient to be structured like the
idle timeout test.
---
.../client/solrj/impl/Http2SolrClientTest.java | 39 ++++++++++++----------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
index 484bb38e207..dec74f23a62 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java
@@ -18,13 +18,13 @@
package org.apache.solr.client.solrj.impl;
import static org.apache.solr.handler.admin.api.ReplicationAPIBase.FILE_STREAM;
+import static org.hamcrest.core.StringContains.containsStringIgnoringCase;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Collections;
-import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.solr.client.api.util.SolrVersion;
import org.apache.solr.client.solrj.ResponseParser;
@@ -74,7 +74,7 @@ public class Http2SolrClientTest extends
HttpSolrClientTestBase {
client.query(q, SolrRequest.METHOD.GET);
fail("No exception thrown.");
} catch (SolrServerException e) {
- assertTrue(isTimeout(e));
+ assertIsTimeout(e);
}
}
@@ -105,7 +105,7 @@ public class Http2SolrClientTest extends
HttpSolrClientTestBase {
client.query(q, SolrRequest.METHOD.GET);
fail("No exception thrown.");
} catch (SolrServerException e) {
- assertTrue(isTimeout(e));
+ assertIsTimeout(e);
}
}
@@ -673,10 +673,9 @@ public class Http2SolrClientTest extends
HttpSolrClientTestBase {
// too little time to succeed
QueryRequest req = new QueryRequest();
req.setResponseParser(new InputStreamResponseParser(FILE_STREAM));
- assertExceptionThrownWithMessageContaining(
- SolrServerException.class, List.of("Timeout"), () ->
oldClient.request(req));
+ assertIsTimeout(expectThrows(SolrServerException.class, () ->
oldClient.request(req)));
- int newIdleTimeoutMs = 5 * 1000; // enough time to succeed
+ int newIdleTimeoutMs = 10 * 1000; // enough time to succeed
try (Http2SolrClient idleTimeoutChangedClient =
new Http2SolrClient.Builder(url)
.withHttpClient(oldClient)
@@ -697,12 +696,22 @@ public class Http2SolrClientTest extends
HttpSolrClientTestBase {
String url = getBaseUrl() + SLOW_STREAM_SERVLET_PATH;
try (Http2SolrClient oldClient =
new Http2SolrClient.Builder(url)
- .withIdleTimeout(1000, TimeUnit.MILLISECONDS)
- .withRequestTimeout(10, TimeUnit.SECONDS)
+ .withIdleTimeout(Long.MAX_VALUE, TimeUnit.MILLISECONDS)
+ .withRequestTimeout(100, TimeUnit.MILLISECONDS)
.build()) {
+
+ try (Http2SolrClient onlyBaseUrlChangedClient =
+ new Http2SolrClient.Builder(url).withHttpClient(oldClient).build()) {
+ // Client created with the same HTTP client should have the same
behavior
+ assertEquals(oldClient.getHttpClient(),
onlyBaseUrlChangedClient.getHttpClient());
+ }
+
+ // too little time to succeed
QueryRequest req = new QueryRequest();
req.setResponseParser(new InputStreamResponseParser(FILE_STREAM));
- int newRequestTimeoutMs = 2000;
+ assertIsTimeout(expectThrows(SolrServerException.class, () ->
oldClient.request(req)));
+
+ int newRequestTimeoutMs = 10 * 1000; // enough time to succeed
try (Http2SolrClient requestTimeoutChangedClient =
new Http2SolrClient.Builder(url)
.withHttpClient(oldClient)
@@ -710,19 +719,15 @@ public class Http2SolrClientTest extends
HttpSolrClientTestBase {
.build()) {
NamedList<Object> response = requestTimeoutChangedClient.request(req);
try (InputStream is = (InputStream) response.get("stream")) {
- assertExceptionThrownWithMessageContaining(
- IOException.class, List.of("Total timeout"), is::readAllBytes);
+ assertEquals("0123456789", new String(is.readAllBytes(),
StandardCharsets.UTF_8));
}
}
- NamedList<Object> response = oldClient.request(req);
- try (InputStream is = (InputStream) response.get("stream")) {
- assertEquals("0123456789", new String(is.readAllBytes(),
StandardCharsets.UTF_8));
- }
}
}
- private static boolean isTimeout(SolrServerException e) {
- return e.getMessage().contains("timeout") ||
e.getMessage().contains("Timeout");
+ private static void assertIsTimeout(Throwable t) {
+ assertThat(t.getMessage(), containsStringIgnoringCase("Timeout"));
}
+
/* Missed tests : - set cookies via interceptor - invariant params -
compression */
}