use of io.elastest.etm.test.util.StompTestUtils.WaitForMessagesHandler in project elastest-torm by elastest.
the class DockerServiceItTest method readLogInRabbit.
@Test
public void readLogInRabbit() throws Exception {
String imageId = "alpine";
if (!existsImage(imageId)) {
log.info("Pulling image '{}'", imageId);
dockerClient.pullImageCmd(imageId).exec(new PullImageResultCallback()).awaitSuccess();
}
String queueId = "test.default_log.1.log";
String tag = "test_1_exec";
WaitForMessagesHandler handler = connectToRabbitQueue(queueId);
LogConfig logConfig = getLogConfig(tag);
log.info("Creating container");
CreateContainerResponse container = dockerClient.createContainerCmd(imageId).withCmd("/bin/sh", "-c", "while true; do echo hello; sleep 1; done").withTty(false).withLogConfig(logConfig).withNetworkMode("bridge").exec();
String containerId = container.getId();
try {
log.info("Created container: {}", container.toString());
long start = System.currentTimeMillis();
dockerClient.startContainerCmd(containerId).exec();
log.info("Waiting for logs messages in Rabbit");
handler.waitForCompletion(5, TimeUnit.SECONDS);
long duration = System.currentTimeMillis() - start;
log.info("Log received in Rabbit in {} millis", duration);
} catch (Exception ex) {
log.info("Log NOT received in Rabbit");
throw ex;
} finally {
log.info("Cleaning up resources");
try {
log.info("Removing container " + containerId);
try {
dockerClient.stopContainerCmd(containerId).exec();
} catch (Exception ex) {
log.warn("Error stopping container {}", containerId, ex);
}
dockerClient.removeContainerCmd(containerId).exec();
} catch (Exception ex) {
log.warn("Error on ending test execution {}", containerId, ex);
}
}
}
use of io.elastest.etm.test.util.StompTestUtils.WaitForMessagesHandler in project elastest-torm by elastest.
the class TJobExecutionApiItTest method testExecuteTJob.
private void testExecuteTJob(boolean withSut) throws InterruptedException, ExecutionException, TimeoutException, MultipleFailuresError {
log.info("Start the test testExecuteTJob " + (withSut ? "with" : "without") + " SuT");
TJob tJob;
if (withSut) {
Long sutId = createSut(projectId).getId();
tJob = createTJob(projectId, sutId);
} else {
tJob = createTJob(projectId);
}
StompSession stompSession = connectToRabbitMQ(serverPort);
log.info("POST /api/tjob/{tjobId}/exec");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
String body = "{\"tJobParams\" : [{\"Param1\":\"NewValue1\"}], \"sutParams\" : [{\"Param1\":\"NewValue1\"}]}";
HttpEntity<String> entity = new HttpEntity<>(body, headers);
Map<String, Object> urlParams = new HashMap<>();
urlParams.put("tjobId", tJob.getId());
ResponseEntity<TJobExecution> response = httpClient.postForEntity("/api/tjob/{tjobId}/exec", entity, TJobExecution.class, urlParams);
TJobExecution exec = response.getBody();
log.info("TJobExecution creation response: " + response);
if (withSut) {
String queueToSuscribe = "/topic/" + "sut.default_log." + exec.getId() + ".log";
log.info("Sut log queue '" + queueToSuscribe + "'");
WaitForMessagesHandler handler = new WaitForMessagesHandler();
stompSession.subscribe(queueToSuscribe, handler);
handler.waitForCompletion(5, TimeUnit.SECONDS);
log.info("Sut log queue received a message");
}
String queueToSuscribe = "/topic/" + "test.default_log." + exec.getId() + ".log";
log.info("TJob log queue '" + queueToSuscribe + "'");
WaitForMessagesHandler handler = new WaitForMessagesHandler(msg -> msg.contains("BUILD SUCCESS") || msg.contains("BUILD FAILURE"));
stompSession.subscribe(queueToSuscribe, handler);
handler.waitForCompletion(180, TimeUnit.SECONDS);
assertAll("Validating TJobExecution Properties", () -> assertNotNull(response.getBody()), () -> assertNotNull(response.getBody().getId()), () -> assertTrue(response.getBody().getTjob().getId().equals(urlParams.get("tjobId"))));
while (true) {
exec = getTJobExecutionById(exec.getId(), tJob.getId()).getBody();
log.info("TJobExecution: " + exec);
if (exec.getResult() != ResultEnum.IN_PROGRESS) {
log.info("Test results:" + exec.getTestSuites());
break;
}
sleep(500);
}
deleteTJobExecution(exec.getId(), tJob.getId());
deleteTJob(tJob.getId());
log.info("Finished.");
}
use of io.elastest.etm.test.util.StompTestUtils.WaitForMessagesHandler in project elastest-torm by elastest.
the class DockerServiceItTest method connectToRabbitQueue.
private WaitForMessagesHandler connectToRabbitQueue(String queueId) throws InterruptedException, ExecutionException, TimeoutException {
StompSession stompSession = connectToRabbitMQ(serverPort);
String queueToSuscribe = "/topic/" + queueId;
log.info("Container log queue '" + queueToSuscribe + "'");
WaitForMessagesHandler handler = new WaitForMessagesHandler("1");
stompSession.subscribe(queueToSuscribe, handler);
return handler;
}
Aggregations