Search in sources :

Example 36 with AsyncResponse

use of javax.ws.rs.container.AsyncResponse in project camunda-bpm-platform by camunda.

the class FetchAndLockHandlerTest method shouldResumeAsyncResponseDueToTooManyRequests.

@Test
public void shouldResumeAsyncResponseDueToTooManyRequests() {
    // given
    // when
    AsyncResponse asyncResponse = mock(AsyncResponse.class);
    handler.errorTooManyRequests(asyncResponse);
    // then
    ArgumentCaptor<InvalidRequestException> argumentCaptor = ArgumentCaptor.forClass(InvalidRequestException.class);
    verify(asyncResponse).resume(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue().getMessage(), is("At the moment the server has to handle too " + "many requests at the same time. Please try again later."));
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) AsyncResponse(javax.ws.rs.container.AsyncResponse) Test(org.junit.Test)

Example 37 with AsyncResponse

use of javax.ws.rs.container.AsyncResponse in project camunda-bpm-platform by camunda.

the class FetchAndLockHandlerTest method shouldRejectRequestDueToShutdown.

@Test
public void shouldRejectRequestDueToShutdown() {
    // given
    AsyncResponse asyncResponse = mock(AsyncResponse.class);
    handler.addPendingRequest(createDto(5000L), asyncResponse, processEngine);
    handler.acquire();
    // assume
    assertThat(handler.getPendingRequests().size(), is(1));
    // when
    handler.rejectPendingRequests();
    // then
    ArgumentCaptor<InvalidRequestException> argumentCaptor = ArgumentCaptor.forClass(InvalidRequestException.class);
    verify(asyncResponse).resume(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue().getMessage(), is("Request rejected due to shutdown of application server."));
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) AsyncResponse(javax.ws.rs.container.AsyncResponse) Test(org.junit.Test)

Example 38 with AsyncResponse

use of javax.ws.rs.container.AsyncResponse in project camunda-bpm-platform by camunda.

the class FetchAndLockHandlerTest method shouldResumeAsyncResponseDueToTimeoutExceeded.

@Test
public void shouldResumeAsyncResponseDueToTimeoutExceeded() {
    // given - no pending requests
    // assume
    assertThat(handler.getPendingRequests().size(), is(0));
    // when
    AsyncResponse asyncResponse = mock(AsyncResponse.class);
    handler.addPendingRequest(createDto(FetchAndLockHandlerImpl.MAX_TIMEOUT + 1), asyncResponse, processEngine);
    // then
    verify(handler, never()).suspend(anyLong());
    assertThat(handler.getPendingRequests().size(), is(0));
    ArgumentCaptor<InvalidRequestException> argumentCaptor = ArgumentCaptor.forClass(InvalidRequestException.class);
    verify(asyncResponse).resume(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue().getMessage(), is("The asynchronous response timeout cannot " + "be set to a value greater than " + FetchAndLockHandlerImpl.MAX_TIMEOUT + " milliseconds"));
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) AsyncResponse(javax.ws.rs.container.AsyncResponse) Test(org.junit.Test)

Example 39 with AsyncResponse

use of javax.ws.rs.container.AsyncResponse in project camunda-bpm-platform by camunda.

the class FetchAndLockHandlerTest method shouldNotResumeAsyncResponseDueToNoAvailableTasks.

@Test
public void shouldNotResumeAsyncResponseDueToNoAvailableTasks() {
    // given
    doReturn(Collections.emptyList()).when(fetchTopicBuilder).execute();
    AsyncResponse asyncResponse = mock(AsyncResponse.class);
    handler.addPendingRequest(createDto(5000L), asyncResponse, processEngine);
    // when
    handler.acquire();
    // then
    verify(asyncResponse, never()).resume(any());
    assertThat(handler.getPendingRequests().size(), is(1));
    verify(handler).suspend(5000L);
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) Test(org.junit.Test)

Example 40 with AsyncResponse

use of javax.ws.rs.container.AsyncResponse in project camunda-bpm-platform by camunda.

the class FetchAndLockHandlerTest method shouldResumeAsyncResponseDueToTimeoutExpired_1.

@Test
public void shouldResumeAsyncResponseDueToTimeoutExpired_1() {
    // given
    doReturn(Collections.emptyList()).when(fetchTopicBuilder).execute();
    AsyncResponse asyncResponse = mock(AsyncResponse.class);
    handler.addPendingRequest(createDto(5000L), asyncResponse, processEngine);
    handler.acquire();
    // assume
    assertThat(handler.getPendingRequests().size(), is(1));
    verify(handler).suspend(5000L);
    List<LockedExternalTask> tasks = new ArrayList<LockedExternalTask>();
    tasks.add(lockedExternalTaskMock);
    doReturn(tasks).when(fetchTopicBuilder).execute();
    addSecondsToClock(5);
    // when
    handler.acquire();
    // then
    verify(asyncResponse).resume(argThat(IsCollectionWithSize.hasSize(1)));
    assertThat(handler.getPendingRequests().size(), is(0));
    verify(handler).suspend(Long.MAX_VALUE - ClockUtil.getCurrentTime().getTime());
}
Also used : ArrayList(java.util.ArrayList) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) AsyncResponse(javax.ws.rs.container.AsyncResponse) Test(org.junit.Test)

Aggregations

AsyncResponse (javax.ws.rs.container.AsyncResponse)58 Response (javax.ws.rs.core.Response)22 Test (org.junit.Test)15 CompletableFuture (java.util.concurrent.CompletableFuture)12 Path (javax.ws.rs.Path)11 List (java.util.List)10 GET (javax.ws.rs.GET)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 Suspended (javax.ws.rs.container.Suspended)10 Status (javax.ws.rs.core.Response.Status)9 ArrayList (java.util.ArrayList)8 Context (javax.ws.rs.core.Context)8 MediaType (javax.ws.rs.core.MediaType)8 LoggerFactory (org.slf4j.LoggerFactory)8 AuthException (io.pravega.auth.AuthException)6 READ (io.pravega.auth.AuthHandler.Permissions.READ)6 READ_UPDATE (io.pravega.auth.AuthHandler.Permissions.READ_UPDATE)6 ClientConfig (io.pravega.client.ClientConfig)6 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)6 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)6