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);
}
}
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;
}
}
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);
}
Aggregations