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."));
}
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."));
}
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"));
}
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);
}
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());
}
Aggregations