private static Container createContainer(int uiPort, File testDir) throws Exception {
File adminFile = new File(testDir, "admin.json");
Files.asCharSink(adminFile, Charsets.UTF_8).write("{\"web\":{\"port\":" + uiPort + "}}");
Container container;
if (Containers.useJavaagent()) {
container = new JavaagentContainer(testDir, true, ImmutableList.of());
} else {
container = new LocalContainer(testDir, true, ImmutableMap.of());
}
// wait for UI to be available (UI starts asynchronously in order to not block startup)
CloseableHttpClient httpClient = HttpClients.custom()
.setRedirectStrategy(new DefaultRedirectStrategy())
.build();
Stopwatch stopwatch = Stopwatch.createStarted();
Exception lastException = null;
while (stopwatch.elapsed(SECONDS) < 10) {
HttpGet request = new HttpGet("http://localhost:" + uiPort);
try (CloseableHttpResponse response = httpClient.execute(request);
InputStream content = response.getEntity().getContent()) {
ByteStreams.exhaust(content);
lastException = null;
break;
} catch (Exception e) {
lastException = e;
}
}
httpClient.close();
if (lastException != null) {
throw new IllegalStateException("Timed out waiting for Glowroot UI", lastException);
}
return container;
}
WebDriverSetup.java 文件源码
java
阅读 24
收藏 0
点赞 0
评论 0
项目:glowroot
作者:
评论列表
文章目录