use of exec.StreamConsumer in project tessera by ConsenSys.
the class AwsKeyVaultIT method keyGenerationRequestCreateSecretCallToAws.
@Test
public void keyGenerationRequestCreateSecretCallToAws() throws Exception {
List<String> nodesToGenerateKeysFor = List.of("nodeA", "nodeB", "nodeC");
final List<String> args = new ExecArgsBuilder().withStartScript(startScript).withClassPathItem(distDirectory).withArg("-keygen").withArg("-keygenvaulttype", "AWS").withArg("-filename", String.join(",", nodesToGenerateKeysFor)).withArg("-keygenvaulturl", keyVaultUrl).build();
ProcessBuilder processBuilder = new ProcessBuilder(args);
processBuilder.environment().putAll(env());
processBuilder.redirectErrorStream(false);
Process process = processBuilder.start();
executorService.submit(new StreamConsumer(process.getInputStream(), LOGGER::info));
executorService.submit(new StreamConsumer(process.getErrorStream(), LOGGER::error));
process.waitFor();
assertThat(process.exitValue()).isZero();
final String apiTarget = "secretsmanager.CreateSecret";
assertThat(httpHandler.getRequests()).containsOnlyKeys(apiTarget);
assertThat(httpHandler.getRequests().get(apiTarget)).hasSize(6);
List<JsonObject> requests = httpHandler.getRequests().get(apiTarget);
List<String> expectedNames = nodesToGenerateKeysFor.stream().flatMap(n -> Stream.of(n.concat("Pub"), n.concat("Key"))).collect(Collectors.toList());
assertThat(requests.stream().map(j -> j.getString("Name")).collect(Collectors.toList())).containsExactlyInAnyOrderElementsOf(expectedNames);
}
use of exec.StreamConsumer in project tessera by ConsenSys.
the class AzureKeyVaultIT method doStuff.
@Test
public void doStuff() throws Exception {
Map<String, Object> params = Map.of("azureKeyVaultUrl", keyVaultUrl);
Path tempTesseraConfig = ElUtil.createTempFileFromTemplate(getClass().getResource("/vault/tessera-azure-config.json"), params);
List<String> args = new ExecArgsBuilder().withStartScript(startScript).withClassPathItem(distDirectory).withArg("-configfile", tempTesseraConfig.toString()).withArg("-pidfile", pid.toAbsolutePath().toString()).withArg("-jdbc.autoCreateTables", "true").build();
ProcessBuilder processBuilder = new ProcessBuilder(args);
processBuilder.environment().putAll(env());
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
executorService.submit(new StreamConsumer(process.getInputStream()));
executorService.submit(() -> {
int exitCode = process.waitFor();
assertThat(exitCode).describedAs("Tessera node exited with code %d", exitCode).isEqualTo(0);
return null;
});
final Config config = JaxbUtil.unmarshal(Files.newInputStream(tempTesseraConfig), Config.class);
final URI bindingUrl = UriBuilder.fromUri(config.getP2PServerConfig().getBindingUri()).path("upcheck").build();
HttpClient httpClient = HttpClient.newHttpClient();
final HttpRequest request = HttpRequest.newBuilder().uri(bindingUrl).GET().build();
CountDownLatch startUpLatch = new CountDownLatch(1);
executorService.submit(() -> {
while (true) {
try {
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
startUpLatch.countDown();
}
} catch (InterruptedException | IOException e) {
}
}
});
assertThat(startUpLatch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(httpHandler.getCounter()).isEqualTo(2);
}
use of exec.StreamConsumer in project tessera by ConsenSys.
the class AwsKeyVaultIT method tesseraStartupRequestsKeysWhosIdsAreConfigured.
@Test
public void tesseraStartupRequestsKeysWhosIdsAreConfigured() throws Exception {
Map<String, Object> params = Map.of("awsSecretsManagerEndpoint", keyVaultUrl);
Path tempTesseraConfig = ElUtil.createTempFileFromTemplate(getClass().getResource("/vault/tessera-aws-config.json"), params);
List<String> args = new ExecArgsBuilder().withStartScript(startScript).withClassPathItem(distDirectory).withArg("-configfile", tempTesseraConfig.toString()).withArg("-pidfile", pid.toAbsolutePath().toString()).withArg("-jdbc.autoCreateTables", "true").build();
ProcessBuilder processBuilder = new ProcessBuilder(args);
processBuilder.environment().putAll(env());
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
executorService.submit(new StreamConsumer(process.getInputStream(), LOGGER::info));
executorService.submit(() -> {
int exitCode = process.waitFor();
assertThat(exitCode).describedAs("Tessera node exited with code %d", exitCode).isEqualTo(0);
return null;
});
final Config config = JaxbUtil.unmarshal(Files.newInputStream(tempTesseraConfig), Config.class);
final URI bindingUrl = Optional.of(config).map(Config::getP2PServerConfig).map(ServerConfig::getBindingUri).map(UriBuilder::fromUri).map(u -> u.path("upcheck")).map(UriBuilder::build).get();
HttpClient httpClient = HttpClient.newHttpClient();
final HttpRequest request = HttpRequest.newBuilder().uri(bindingUrl).GET().build();
CountDownLatch startUpLatch = new CountDownLatch(1);
executorService.submit(() -> {
while (true) {
try {
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
startUpLatch.countDown();
}
} catch (InterruptedException | IOException e) {
}
}
});
assertThat(startUpLatch.await(2, TimeUnit.MINUTES)).isTrue();
assertThat(httpHandler.getCounter()).isEqualTo(2);
List<JsonObject> requests = httpHandler.getRequests().get("secretsmanager.GetSecretValue");
assertThat(requests).hasSize(2);
List<String> secretIds = requests.stream().map(j -> j.getString("SecretId")).collect(Collectors.toList());
assertThat(secretIds).containsExactlyInAnyOrder("secretIdPub", "secretIdKey");
}
Aggregations