use of com.couchbase.client.core.msg.RequestContext in project couchbase-jvm-clients by couchbase.
the class BaseEndpointTest method writeAndFlushToChannelIfFullyConnected.
/**
* If we are fully connected and the circuit breaker is closed, make sure that we can
* write the request into the channel and it is flushed as well.
*/
@Test
@SuppressWarnings({ "unchecked" })
void writeAndFlushToChannelIfFullyConnected() {
EmbeddedChannel channel = new EmbeddedChannel();
InstrumentedEndpoint endpoint = connectSuccessfully(channel);
assertEquals(0, endpoint.lastResponseReceived());
Request<Response> request = mock(Request.class);
CompletableFuture<Response> response = new CompletableFuture<>();
when(request.response()).thenReturn(response);
when(request.context()).thenReturn(new RequestContext(ctx, request));
assertEquals(0, endpoint.outstandingRequests());
endpoint.send(request);
assertEquals(1, endpoint.outstandingRequests());
assertEquals(request, channel.readOutbound());
assertEquals(0, endpoint.lastResponseReceived());
response.complete(mock(Response.class));
endpoint.markRequestCompletion();
assertTrue(endpoint.lastResponseReceived() > 0);
assertEquals(0, endpoint.outstandingRequests());
}
use of com.couchbase.client.core.msg.RequestContext in project couchbase-jvm-clients by couchbase.
the class RetryOrchestratorTest method cancelIfNoMoreRetriesAllowed.
@Test
@SuppressWarnings({ "unchecked" })
void cancelIfNoMoreRetriesAllowed() {
RetryStrategy retryStrategy = mock(RetryStrategy.class);
when(retryStrategy.shouldRetry(any(Request.class), any(RetryReason.class))).thenReturn(CompletableFuture.completedFuture(RetryAction.noRetry()));
Request<?> request = mock(Request.class);
when(request.completed()).thenReturn(false);
when(request.retryStrategy()).thenReturn(retryStrategy);
RequestContext requestContext = mock(RequestContext.class);
when(request.context()).thenReturn(requestContext);
CoreEnvironment env = mock(CoreEnvironment.class);
SimpleEventBus eventBus = new SimpleEventBus(true);
when(env.eventBus()).thenReturn(eventBus);
CoreContext context = new CoreContext(mock(Core.class), 1, env, mock(Authenticator.class));
RetryOrchestrator.maybeRetry(context, request, RetryReason.UNKNOWN);
verify(request, times(1)).cancel(CancellationReason.noMoreRetries(RetryReason.UNKNOWN), Function.identity());
assertEquals(1, eventBus.publishedEvents().size());
RequestNotRetriedEvent retryEvent = (RequestNotRetriedEvent) eventBus.publishedEvents().get(0);
assertEquals(Event.Severity.INFO, retryEvent.severity());
assertEquals(Event.Category.REQUEST.path(), retryEvent.category());
assertEquals(requestContext, retryEvent.context());
}
use of com.couchbase.client.core.msg.RequestContext in project couchbase-jvm-clients by couchbase.
the class LoggingEventConsumerTest method doesNotAttachClientContextByDefault.
@Test
void doesNotAttachClientContextByDefault() {
RequestContext context = mock(RequestContext.class);
Map<String, Object> userContext = new HashMap<>();
userContext.put("hello", "world");
when(context.clientContext()).thenReturn(userContext);
RequestRetryScheduledEvent retryEvent = new RequestRetryScheduledEvent(Duration.ofSeconds(1), context, GetRequest.class, RetryReason.UNKNOWN);
loggingEventConsumer.accept(retryEvent);
verify(logger, never()).attachContext(userContext);
}
Aggregations