You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2026/03/06 21:32:15 UTC
(tika) branch maybe-fix-new-flaky-solr-integration-tests created (now 3a87a13170)
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a change to branch maybe-fix-new-flaky-solr-integration-tests
in repository https://gitbox.apache.org/repos/asf/tika.git
at 3a87a13170 maybe fix flaky solr tests
This branch includes the following new commits:
new 3a87a13170 maybe fix flaky solr tests
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(tika) 01/01: maybe fix flaky solr tests
Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tallison pushed a commit to branch maybe-fix-new-flaky-solr-integration-tests
in repository https://gitbox.apache.org/repos/asf/tika.git
commit 3a87a131700b6ea597f3c4421640156cbe90b7ca
Author: tallison <ta...@apache.org>
AuthorDate: Fri Mar 6 16:32:03 2026 -0500
maybe fix flaky solr tests
---
.../pipes/solr/tests/TikaPipesSolrTestBase.java | 53 ++++++++++++++++++++--
1 file changed, 50 insertions(+), 3 deletions(-)
diff --git a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolrTestBase.java b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolrTestBase.java
index 0fea4b0cd0..75f92c2732 100644
--- a/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolrTestBase.java
+++ b/tika-integration-tests/tika-pipes-solr-integration-tests/src/test/java/org/apache/tika/pipes/solr/tests/TikaPipesSolrTestBase.java
@@ -20,6 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -41,6 +43,8 @@ import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.testcontainers.containers.FixedHostPortGenericContainer;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
@@ -55,6 +59,10 @@ import org.apache.tika.utils.SystemUtils;
public abstract class TikaPipesSolrTestBase {
+ private static final Logger LOG = LoggerFactory.getLogger(TikaPipesSolrTestBase.class);
+ private static final int SOLR_READY_TIMEOUT_MS = 30_000;
+ private static final int SOLR_READY_POLL_MS = 500;
+
private final String collection = "testcol";
private final int numDocs = 42;
private Path testFileFolder;
@@ -95,9 +103,40 @@ public abstract class TikaPipesSolrTestBase {
.withCommand("-DzkRun");
}
solr.start();
+ waitForSolrReady();
+ }
- // Ideally wanted to use TestContainers WaitStrategy but they were inconsistent
- Thread.sleep(2000);
+ private void waitForSolrReady() {
+ String host = solr.getHost();
+ int port = solr.getMappedPort(8983);
+ String adminUrl = "http://" + host + ":" + port + "/solr/admin/info/system";
+ long deadline = System.currentTimeMillis() + SOLR_READY_TIMEOUT_MS;
+ LOG.info("Waiting for Solr to be ready at {}...", adminUrl);
+ while (System.currentTimeMillis() < deadline) {
+ try {
+ HttpURLConnection conn = (HttpURLConnection) new URL(adminUrl).openConnection();
+ conn.setConnectTimeout(1000);
+ conn.setReadTimeout(1000);
+ int code = conn.getResponseCode();
+ conn.disconnect();
+ if (code == 200) {
+ LOG.info("Solr is ready (responded 200 in {} ms)",
+ SOLR_READY_TIMEOUT_MS - (deadline - System.currentTimeMillis()));
+ return;
+ }
+ LOG.debug("Solr returned status {}, retrying...", code);
+ } catch (Exception e) {
+ LOG.debug("Solr not ready yet: {}", e.getMessage());
+ }
+ try {
+ Thread.sleep(SOLR_READY_POLL_MS);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new RuntimeException("Interrupted waiting for Solr", e);
+ }
+ }
+ LOG.error("Solr did not become ready within {} ms at {}", SOLR_READY_TIMEOUT_MS, adminUrl);
+ throw new RuntimeException("Solr did not become ready within " + SOLR_READY_TIMEOUT_MS + " ms");
}
@AfterEach
@@ -140,7 +179,15 @@ public abstract class TikaPipesSolrTestBase {
zkPort = solr.getMappedPort(9983);
solrEndpoint = "http://" + solrHost + ":" + solrPort + "/solr";
- solr.execInContainer("/opt/solr/bin/solr", "create_collection", "-c", collection);
+ org.testcontainers.containers.Container.ExecResult createResult =
+ solr.execInContainer("/opt/solr/bin/solr", "create_collection", "-c", collection);
+ if (createResult.getExitCode() != 0) {
+ LOG.error("Failed to create Solr collection '{}'. Exit code: {}, stdout: {}, stderr: {}",
+ collection, createResult.getExitCode(),
+ createResult.getStdout(), createResult.getStderr());
+ throw new RuntimeException("Failed to create Solr collection: " + createResult.getStderr());
+ }
+ LOG.info("Created Solr collection '{}': {}", collection, createResult.getStdout().trim());
try (SolrClient solrClient = new Http2SolrClient.Builder(solrEndpoint).build()) {