Search in sources :

Example 1 with TaskStatusUpdateEvent

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());
}
Also used : Arquillian(org.jboss.arquillian.junit.Arquillian) Credentials(org.jboss.pnc.integration.setup.Credentials) URISyntaxException(java.net.URISyntaxException) RunWith(org.junit.runner.RunWith) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) BuildExecutorMock(org.jboss.pnc.mock.executor.BuildExecutorMock) URI(java.net.URI) Deployments(org.jboss.pnc.integration.setup.Deployments) TaskStatusUpdateEvent(org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent) EnterpriseArchive(org.jboss.shrinkwrap.api.spec.EnterpriseArchive) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) IOException(java.io.IOException) BlockingQueue(java.util.concurrent.BlockingQueue) BuildExecutionSessionMock(org.jboss.pnc.mock.executor.BuildExecutionSessionMock) UUID(java.util.UUID) BuildExecutor(org.jboss.pnc.spi.executor.BuildExecutor) Category(org.junit.experimental.categories.Category) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Md5(org.jboss.pnc.common.security.Md5) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Headers(io.undertow.util.Headers) Request(org.jboss.pnc.api.dto.Request) Status(org.jboss.pnc.buildagent.api.Status) EXECUTOR_JAR(org.jboss.pnc.integration.setup.Deployments.EXECUTOR_JAR) HttpClient(org.jboss.pnc.buildagent.common.http.HttpClient) Assert(org.junit.Assert) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) BuildExecutionSession(org.jboss.pnc.spi.executor.BuildExecutionSession) BuildExecutorMock(org.jboss.pnc.mock.executor.BuildExecutorMock) ArrayList(java.util.ArrayList) Request(org.jboss.pnc.api.dto.Request) TaskStatusUpdateEvent(org.jboss.pnc.buildagent.api.TaskStatusUpdateEvent) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) HttpClient(org.jboss.pnc.buildagent.common.http.HttpClient) Credentials(org.jboss.pnc.integration.setup.Credentials) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Headers (io.undertow.util.Headers)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 Consumer (java.util.function.Consumer)1 Inject (javax.inject.Inject)1 MediaType (javax.ws.rs.core.MediaType)1 Deployment (org.jboss.arquillian.container.test.api.Deployment)1 Arquillian (org.jboss.arquillian.junit.Arquillian)1