Skip to content

Commit

Permalink
improve logging and error handling in TikaServerIntegrationTest
Browse files Browse the repository at this point in the history
  • Loading branch information
tballison committed Dec 3, 2019
1 parent 42676a6 commit 5920689
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.time.Instant;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;

import static java.nio.charset.StandardCharsets.UTF_8;
Expand All @@ -61,6 +62,8 @@ public class TikaServerIntegrationTest extends TikaTest {
private static final String TEST_STATIC_STDOUT_STDERR = "mock/testStaticStdOutErr.xml";
private static final String META_PATH = "/rmeta";

private static final long MAX_WAIT_MS = 60000;

//running into conflicts on 9998 with the CXFTestBase tests
//TODO: figure out why?!
private static final String INTEGRATION_TEST_PORT = "9999";
Expand Down Expand Up @@ -423,20 +426,17 @@ public void run() {
}

private void awaitServerStartup() throws Exception {
long maxWaitMs = 30000;
Instant started = Instant.now();
long elapsed = Duration.between(started, Instant.now()).toMillis();
WebClient client = WebClient.create(endPoint+"/tika").accept("text/plain");
while (elapsed < maxWaitMs) {
while (elapsed < MAX_WAIT_MS) {
try {
Response response = client.get();
if (response.getStatus() == 200) {
Thread.sleep(100);
response = client.get();
if (response.getStatus() == 200) {
LOG.info("client observes that server successfully started");
return;
}
elapsed = Duration.between(started, Instant.now()).toMillis();
LOG.info("client observes server successfully started after " +
elapsed+ " ms");
return;
}
LOG.debug("tika test client failed to connect to server with status: {}", response.getStatus());

Expand All @@ -447,8 +447,8 @@ private void awaitServerStartup() throws Exception {
Thread.sleep(100);
elapsed = Duration.between(started, Instant.now()).toMillis();
}
throw new IllegalStateException("couldn't connect to server after " +
maxWaitMs + " ms");
throw new TimeoutException("couldn't connect to server after " +
elapsed + " ms");
}

@Test
Expand Down

0 comments on commit 5920689

Please sign in to comment.