use of uk.gov.justice.services.eventsourcing.repository.jdbc.exception.OptimisticLockingRetryException in project microservice_framework by CJSCommonPlatform.
the class RetryInterceptorTest method shouldRetryIfExceptionThrownByDispatcher.
@Test
public void shouldRetryIfExceptionThrownByDispatcher() throws Exception {
final InterceptorContext currentContext = interceptorContextWithInput(envelope().with(metadataWithRandomUUID("nameABC")).build());
final InterceptorContext nextInChain = interceptorContextWithInput(mock(JsonEnvelope.class));
when(interceptorChain.processNext(currentContext)).thenThrow(new OptimisticLockingRetryException("Locking Error")).thenReturn(nextInChain);
retryInterceptor.maxRetry = "2";
retryInterceptor.waitTime = "500";
retryInterceptor.immediateRetries = "0";
assertThat(retryInterceptor.process(currentContext, interceptorChain), is(nextInChain));
}
use of uk.gov.justice.services.eventsourcing.repository.jdbc.exception.OptimisticLockingRetryException in project microservice_framework by CJSCommonPlatform.
the class RetryInterceptor method process.
@Override
public InterceptorContext process(final InterceptorContext interceptorContext, final InterceptorChain interceptorChain) {
final int maxRetryCount = parseInt(maxRetry);
final int retryWaitTime = parseInt(waitTime);
final int maxImmediateRetries = parseInt(immediateRetries);
final JsonObject metadata = interceptorContext.inputEnvelope().metadata().asJsonObject();
int retries = 0;
while (maxRetryCount == 0 || retries < maxRetryCount) {
try {
return interceptorChain.processNext(interceptorContext);
} catch (OptimisticLockingRetryException e) {
logger.debug(format("Optimistic locking failed on command %s at retry attempt %d", metadata, retries));
retries++;
if (retries > maxImmediateRetries) {
waitFor(retryWaitTime);
}
}
}
throw new OptimisticLockingRetryFailedException(format("Retry count of %d exceeded for command %s", maxRetryCount, metadata));
}
Aggregations