@Test public void shouldRethrowMultipleRunningTimestampServiceErrorsAsServiceNotAvailableExceptions() { RuntimeException response = allocationFailures.responseTo(MULTIPLE_RUNNING_SERVICES_FAILURE); assertThat(response instanceof ServiceNotAvailableException, is(true)); assertThat(response.getCause(), is(MULTIPLE_RUNNING_SERVICES_FAILURE)); }
@Override public synchronized void storeUpperLimit(long limit) { failures.verifyWeShouldIssueMoreTimestamps(); throwIfInterrupted(); try { delegate.storeUpperLimit(limit); } catch (Throwable t) { throw failures.responseTo(t); } }
@Test public void shouldRethrowServiceNotAvailableExceptionsWithoutWrapping() { RuntimeException response = allocationFailures.responseTo(SERVICE_NOT_AVAILABLE_EXCEPTION); assertThat(response instanceof ServiceNotAvailableException, is(true)); assertThat(response, is(SERVICE_NOT_AVAILABLE_EXCEPTION)); }
@SuppressWarnings("Slf4jConstantLogMessage") @Test public void shouldLog2DifferentExceptionsToError() { ignoringExceptions(() -> allocationFailures.responseTo(FAILURE)); ignoringExceptions(() -> allocationFailures.responseTo(MULTIPLE_RUNNING_SERVICES_FAILURE)); verify(log).error(anyString(), eq(FAILURE)); verify(log).error(anyString(), eq(MULTIPLE_RUNNING_SERVICES_FAILURE)); }
@Test public void shouldRethrowExceptions() { RuntimeException response = allocationFailures.responseTo(FAILURE); assertThat(response.getCause(), is(FAILURE)); assertThat(response, isA(RuntimeException.class)); assertThat(response.getMessage(), containsString("Could not allocate more timestamps")); }
@SuppressWarnings("Slf4jConstantLogMessage") @Test public void shouldLogTheSecondOfATypeOfExceptionToInfo() { ignoringExceptions(() -> allocationFailures.responseTo(FAILURE)); ignoringExceptions(() -> allocationFailures.responseTo(FAILURE)); verify(log).info(anyString(), eq(FAILURE)); }
@SuppressWarnings("Slf4jConstantLogMessage") @Test public void shouldLogTheFirstOfATypeOfExceptionToError() { ignoringExceptions(() -> allocationFailures.responseTo(FAILURE)); verify(log).error(anyString(), eq(FAILURE)); }
@Test public void shouldAllowTryingToIssueMoreTimestampsAfterANormalRuntimeException() { ignoringExceptions(() -> allocationFailures.responseTo(FAILURE)); allocationFailures.verifyWeShouldIssueMoreTimestamps(); }
@Test public void shouldAllowTryingToIssueMoreTimestampsAfterAServiceNotAvailableException() { ignoringExceptions(() -> allocationFailures.responseTo(SERVICE_NOT_AVAILABLE_EXCEPTION)); allocationFailures.verifyWeShouldIssueMoreTimestamps(); }
@Test public void shouldDisallowTryingToIssueMoreTimestampsAfterAMultipleRunningTimestampServicesFailure() { ignoringExceptions(() -> allocationFailures.responseTo(MULTIPLE_RUNNING_SERVICES_FAILURE)); exception.expectCause(is(MULTIPLE_RUNNING_SERVICES_FAILURE)); exception.expect(ServiceNotAvailableException.class); allocationFailures.verifyWeShouldIssueMoreTimestamps(); }
@Override public synchronized void storeUpperLimit(long limit) { failures.verifyWeShouldIssueMoreTimestamps(); throwIfInterrupted(); try { delegate.storeUpperLimit(limit); } catch (Throwable t) { throw failures.responseTo(t); } }