use of com.couchbase.client.core.deps.io.netty.channel.ChannelException in project couchbase-jvm-clients by couchbase.
the class BaseEndpointTest method retryOnFailureUntilEventuallyConnected.
/**
* The {@link #retryOnTimeoutUntilEventuallyConnected()} tests that a netty
* channel future does not return at all and we reconnect, this one tests that
* if netty returns with a failure we keep reconnecting until it succeeds.
*/
@Test
void retryOnFailureUntilEventuallyConnected() {
final AtomicInteger invocationAttempt = new AtomicInteger();
InstrumentedEndpoint endpoint = InstrumentedEndpoint.create(eventLoopGroup, ctx, () -> invocationAttempt.incrementAndGet() > 3 ? Mono.just(new EmbeddedChannel()) : Mono.error(new ChannelException("Could not connect for some reason")));
endpoint.connect();
waitUntilCondition(() -> endpoint.state() == EndpointState.CONNECTED);
assertEquals(4, eventBus.publishedEvents().size());
int warnings = 0;
int debug = 0;
for (Event event : eventBus.publishedEvents()) {
if (event.severity() == Event.Severity.WARN) {
assertTrue(event instanceof EndpointConnectionFailedEvent);
warnings++;
} else if (event.severity() == Event.Severity.DEBUG) {
assertTrue(event instanceof EndpointConnectedEvent);
debug++;
} else {
throw new RuntimeException("Unexpected Event" + event);
}
}
assertEquals(3, warnings);
assertEquals(1, debug);
}
Aggregations