use of com.rabbitmq.stream.impl.StreamEnvironment.LocatorNotAvailableException in project rabbitmq-stream-java-client by rabbitmq.
the class StreamEnvironmentUnitTest method locatorOperationShouldRetryAndReturnResultIfLocatorException.
@Test
void locatorOperationShouldRetryAndReturnResultIfLocatorException() {
AtomicInteger counter = new AtomicInteger();
int result = StreamEnvironment.locatorOperation(c -> {
if (counter.incrementAndGet() < 2) {
throw new LocatorNotAvailableException();
} else {
return counter.get();
}
}, () -> null, BackOffDelayPolicy.fixed(Duration.ofMillis(10)));
assertThat(result).isEqualTo(2);
}
use of com.rabbitmq.stream.impl.StreamEnvironment.LocatorNotAvailableException in project rabbitmq-stream-java-client by rabbitmq.
the class StreamEnvironmentUnitTest method locatorOperationShouldThrowLocatorExceptionWhenRetryExhausts.
@Test
void locatorOperationShouldThrowLocatorExceptionWhenRetryExhausts() {
AtomicInteger counter = new AtomicInteger();
assertThatThrownBy(() -> StreamEnvironment.locatorOperation(c -> {
counter.incrementAndGet();
throw new LocatorNotAvailableException();
}, () -> null, BackOffDelayPolicy.fixed(Duration.ofMillis(10)))).isInstanceOf(LocatorNotAvailableException.class);
assertThat(counter).hasValue(3);
}
use of com.rabbitmq.stream.impl.StreamEnvironment.LocatorNotAvailableException in project rabbitmq-stream-java-client by rabbitmq.
the class StreamEnvironmentUnitTest method locatorOperationShouldThrowInterruptedExceptionAsCauseIfInterrupted.
@Test
void locatorOperationShouldThrowInterruptedExceptionAsCauseIfInterrupted() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
AtomicReference<Exception> exception = new AtomicReference<>();
Thread thread = new Thread(() -> {
try {
StreamEnvironment.locatorOperation(c -> {
latch.countDown();
throw new LocatorNotAvailableException();
}, () -> null, BackOffDelayPolicy.fixed(Duration.ofMinutes(10)));
} catch (StreamException e) {
exception.set(e);
}
});
thread.start();
latchAssert(latch).completes();
Thread.sleep(100);
thread.interrupt();
Thread.sleep(100);
assertThat(exception.get()).isInstanceOf(StreamException.class).hasCauseInstanceOf(InterruptedException.class);
}
Aggregations