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);
}
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);
}
Aggregations