Search in sources :

Example 1 with ChannelException

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) EndpointDisconnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectionFailedEvent) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) EndpointConnectionAbortedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionAbortedEvent) EndpointConnectedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectedEvent) EndpointConnectionIgnoredEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionIgnoredEvent) Event(com.couchbase.client.core.cnc.Event) EndpointStateChangedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointStateChangedEvent) EndpointDisconnectedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectedEvent) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) ChannelException(com.couchbase.client.core.deps.io.netty.channel.ChannelException) EndpointConnectedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

Event (com.couchbase.client.core.cnc.Event)1 EndpointConnectedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectedEvent)1 EndpointConnectionAbortedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionAbortedEvent)1 EndpointConnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent)1 EndpointConnectionIgnoredEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionIgnoredEvent)1 EndpointDisconnectedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectedEvent)1 EndpointDisconnectionFailedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectionFailedEvent)1 EndpointStateChangedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointStateChangedEvent)1 ChannelException (com.couchbase.client.core.deps.io.netty.channel.ChannelException)1 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.jupiter.api.Test)1