use of org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent in project pnc by project-ncl.
the class BuildExecutionTest method shouldReceiveBuildResultViaHttpCallback.
@Test(timeout = 10000L)
public void shouldReceiveBuildResultViaHttpCallback() throws IOException, NoSuchAlgorithmException, URISyntaxException, InterruptedException, ExecutionException, TimeoutException {
// given
TaskStatusUpdateEvent.Builder updateEventBuilder = TaskStatusUpdateEvent.newBuilder();
updateEventBuilder.taskId(UUID.randomUUID().toString()).newStatus(Status.COMPLETED).outputChecksum(Md5.digest("black"));
Credentials user = Credentials.USER;
List<Request.Header> headers = new ArrayList<>();
headers.add(new Request.Header(Headers.CONTENT_TYPE_STRING, MediaType.APPLICATION_JSON));
user.createAuthHeader((k, v) -> {
headers.add(new Request.Header(k, v));
return null;
});
String data = objectMapper.writeValueAsString(updateEventBuilder.build());
BlockingQueue<TaskStatusUpdateEvent> events = new ArrayBlockingQueue<>(10);
Consumer<TaskStatusUpdateEvent> statusChangeConsumer = (e) -> {
events.add(e);
};
BuildExecutionSession session = createFakeExectionSession(statusChangeConsumer);
// when
String executionId = "11";
((BuildExecutorMock) buildExecutor).addRunningExecution(executionId, session);
HttpClient httpClient = new HttpClient();
Request request = new Request(Request.Method.POST, URI.create("http://localhost:8080/pnc-rest/v2/build-execution/" + executionId + "/completed"), headers);
CompletableFuture<HttpClient.Response> responseFuture = httpClient.invoke(request, data);
// then
// event received
TaskStatusUpdateEvent event = events.take();
Assert.assertEquals(Status.COMPLETED, event.getNewStatus());
Assert.assertEquals(200, responseFuture.get(5, TimeUnit.SECONDS).getCode());
}
Aggregations