Search in sources :

Example 1 with TimeoutException

use of com.microsoft.applicationinsights.smoketest.exceptions.TimeoutException in project ApplicationInsights-Java by microsoft.

the class AiSmokeTest method waitForHealthCheckTelemetryIfNeeded.

private static void waitForHealthCheckTelemetryIfNeeded(String contextRootUrl) throws InterruptedException, ExecutionException {
    if (!requestCaptureEnabled) {
        return;
    }
    Stopwatch receivedTelemetryTimer = Stopwatch.createStarted();
    int requestTelemetryFromHealthCheckTimeout;
    if (currentImageName.startsWith("javase_")) {
        requestTelemetryFromHealthCheckTimeout = APPLICATION_READY_TIMEOUT_SECONDS;
    } else {
        requestTelemetryFromHealthCheckTimeout = TELEMETRY_RECEIVE_TIMEOUT_SECONDS;
    }
    try {
        mockedIngestion.waitForItem(new Predicate<Envelope>() {

            @Override
            public boolean test(Envelope input) {
                if (!"RequestData".equals(input.getData().getBaseType())) {
                    return false;
                }
                RequestData data = (RequestData) ((Data<?>) input.getData()).getBaseData();
                return contextRootUrl.equals(data.getUrl()) && "200".equals(data.getResponseCode());
            }
        }, requestTelemetryFromHealthCheckTimeout, TimeUnit.SECONDS);
        System.out.printf("Received request telemetry after %.3f seconds...%n", receivedTelemetryTimer.elapsed(TimeUnit.MILLISECONDS) / 1000.0);
        System.out.println("Clearing any RequestData from health check.");
    } catch (java.util.concurrent.TimeoutException e) {
        throw new TimeoutException("request telemetry from application health check", requestTelemetryFromHealthCheckTimeout, TimeUnit.SECONDS, e);
    }
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) Stopwatch(com.google.common.base.Stopwatch) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) RemoteDependencyData(com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) TimeoutException(com.microsoft.applicationinsights.smoketest.exceptions.TimeoutException)

Example 2 with TimeoutException

use of com.microsoft.applicationinsights.smoketest.exceptions.TimeoutException in project ApplicationInsights-Java by microsoft.

the class AiSmokeTest method configureEnvironment.

@BeforeWithParams
public static void configureEnvironment(String appServer, String os, String jreVersion) throws Exception {
    System.out.println("Preparing environment...");
    try {
        ContainerInfo containerInfo = currentContainerInfo.get();
        if (containerInfo != null) {
            // test cleanup didn't take...try to clean up
            if (docker.isContainerRunning(containerInfo.getContainerId())) {
                System.err.println("From last test run, container is still running: " + containerInfo);
                try {
                    docker.stopContainer(containerInfo.getContainerId());
                } catch (Exception e) {
                    System.err.println("Couldn't clean up environment. Must be done manually.");
                    throw e;
                }
            } else {
                // container must have stopped after timeout reached.
                currentContainerInfo.set(null);
            }
        }
        checkParams(appServer, os, jreVersion);
        setupProperties(appServer, os, jreVersion);
        startMockedIngestion();
        createDockerNetwork();
        startAllContainers();
        waitForApplicationToStart();
        System.out.println("Environment preparation complete.");
    } catch (Exception e) {
        String additionalMessage;
        if (e instanceof TimeoutException) {
            additionalMessage = e.getLocalizedMessage();
        } else {
            additionalMessage = ExceptionUtils.getStackTrace(e);
        }
        System.err.printf("Could not configure environment: %s%n", additionalMessage);
        throw e;
    }
}
Also used : ContainerInfo(com.microsoft.applicationinsights.smoketest.docker.ContainerInfo) TimeoutException(com.microsoft.applicationinsights.smoketest.exceptions.TimeoutException) SmokeTestException(com.microsoft.applicationinsights.smoketest.exceptions.SmokeTestException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(com.microsoft.applicationinsights.smoketest.exceptions.TimeoutException) BeforeWithParams(com.microsoft.applicationinsights.smoketest.fixtures.BeforeWithParams)

Example 3 with TimeoutException

use of com.microsoft.applicationinsights.smoketest.exceptions.TimeoutException in project ApplicationInsights-Java by microsoft.

the class AiSmokeTest method waitForUrl.

protected static void waitForUrl(String url, long timeout, TimeUnit timeoutUnit, String appName) throws InterruptedException {
    int rval = 404;
    Stopwatch watch = Stopwatch.createStarted();
    do {
        if (watch.elapsed(timeoutUnit) > timeout) {
            throw new TimeoutException(appName, timeout, timeoutUnit);
        }
        try {
            TimeUnit.MILLISECONDS.sleep(250);
            rval = HttpHelper.getResponseCodeEnsuringSampled(url);
        } catch (InterruptedException e) {
            throw e;
        } catch (Exception ignored) {
        }
    } while (rval == 404);
    assertEquals(200, rval);
}
Also used : Stopwatch(com.google.common.base.Stopwatch) TimeoutException(com.microsoft.applicationinsights.smoketest.exceptions.TimeoutException) SmokeTestException(com.microsoft.applicationinsights.smoketest.exceptions.SmokeTestException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(com.microsoft.applicationinsights.smoketest.exceptions.TimeoutException)

Aggregations

TimeoutException (com.microsoft.applicationinsights.smoketest.exceptions.TimeoutException)3 Stopwatch (com.google.common.base.Stopwatch)2 SmokeTestException (com.microsoft.applicationinsights.smoketest.exceptions.SmokeTestException)2 IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 ContainerInfo (com.microsoft.applicationinsights.smoketest.docker.ContainerInfo)1 BeforeWithParams (com.microsoft.applicationinsights.smoketest.fixtures.BeforeWithParams)1 Data (com.microsoft.applicationinsights.smoketest.schemav2.Data)1 Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)1 RemoteDependencyData (com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData)1 RequestData (com.microsoft.applicationinsights.smoketest.schemav2.RequestData)1