Search in sources :

Example 6 with BucketConfigStreamingResponse

use of com.couchbase.client.core.msg.manager.BucketConfigStreamingResponse in project couchbase-jvm-clients by couchbase.

the class ClusterManagerBucketRefresherTest method shouldReconnectIfStreamCloses.

/**
 * Unsubscription is driven purely from up the stack, so if the config stream should close for some
 * reason the refresher needs to try to establish a new connection.
 */
@Test
void shouldReconnectIfStreamCloses() {
    final AtomicReference<BucketConfigStreamingResponse> responseRef = new AtomicReference<>();
    final AtomicInteger streamingRequestAttempts = new AtomicInteger();
    doAnswer(i -> {
        streamingRequestAttempts.incrementAndGet();
        BucketConfigStreamingRequest request = i.getArgument(0);
        HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
        BucketConfigStreamingResponse response = request.decode(httpResponse, null);
        responseRef.set(response);
        request.succeed(response);
        return null;
    }).when(core).send(any(BucketConfigStreamingRequest.class));
    refresher.register("bucketName").block();
    // Let's pretend the successfully opened stream closes for whatever reason
    responseRef.get().completeStream();
    waitUntilCondition(() -> streamingRequestAttempts.get() >= 2);
}
Also used : BucketConfigStreamingResponse(com.couchbase.client.core.msg.manager.BucketConfigStreamingResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse) DefaultHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) BucketConfigStreamingRequest(com.couchbase.client.core.msg.manager.BucketConfigStreamingRequest) Test(org.junit.jupiter.api.Test)

Example 7 with BucketConfigStreamingResponse

use of com.couchbase.client.core.msg.manager.BucketConfigStreamingResponse in project couchbase-jvm-clients by couchbase.

the class ClusterManagerBucketRefresherTest method shouldReconnectIfStreamErrors.

/**
 * Unsubscription is driven purely from up the stack, so if the config stream should error for some
 * reason the refresher needs to try to establish a new connection.
 */
@Test
void shouldReconnectIfStreamErrors() {
    final AtomicReference<BucketConfigStreamingResponse> responseRef = new AtomicReference<>();
    final AtomicInteger streamingRequestAttempts = new AtomicInteger();
    doAnswer(i -> {
        streamingRequestAttempts.incrementAndGet();
        BucketConfigStreamingRequest request = i.getArgument(0);
        HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
        BucketConfigStreamingResponse response = request.decode(httpResponse, null);
        responseRef.set(response);
        request.succeed(response);
        return null;
    }).when(core).send(any(BucketConfigStreamingRequest.class));
    refresher.register("bucketName").block();
    // Let's pretend the successfully opened stream fails for whatever reason
    responseRef.get().failStream(new RuntimeException("Something Happened"));
    waitUntilCondition(() -> streamingRequestAttempts.get() >= 2);
}
Also used : BucketConfigStreamingResponse(com.couchbase.client.core.msg.manager.BucketConfigStreamingResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse) DefaultHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) BucketConfigStreamingRequest(com.couchbase.client.core.msg.manager.BucketConfigStreamingRequest) Test(org.junit.jupiter.api.Test)

Aggregations

HttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse)7 BucketConfigStreamingResponse (com.couchbase.client.core.msg.manager.BucketConfigStreamingResponse)7 DefaultHttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse)6 BucketConfigStreamingRequest (com.couchbase.client.core.msg.manager.BucketConfigStreamingRequest)6 Test (org.junit.jupiter.api.Test)6 HttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpContent)4 Core (com.couchbase.client.core.Core)3 CoreContext (com.couchbase.client.core.CoreContext)3 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)3 DefaultHttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpContent)3 DefaultLastHttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultLastHttpContent)3 HttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpRequest)3 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)3 EndpointContext (com.couchbase.client.core.endpoint.EndpointContext)3 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)2 Unpooled (com.couchbase.client.core.deps.io.netty.buffer.Unpooled)2 HttpMethod (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpMethod)2 HttpResponseStatus (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponseStatus)2