use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.
the class ManagerMessageHandlerTest method disconnectsEndpointOnRedialTimeout.
/**
* When a http streaming connection is outstanding, the handler needs to notify the endpoint that it disconnects
* itself in an orderly manner.
*/
@Test
void disconnectsEndpointOnRedialTimeout() throws Exception {
CoreEnvironment env = CoreEnvironment.builder().ioConfig(IoConfig.configIdleRedialTimeout(Duration.ofSeconds(2))).build();
try {
CoreContext ctx = new CoreContext(mock(Core.class), 1, env, PasswordAuthenticator.create(USER, PASS));
BaseEndpoint endpoint = mock(BaseEndpoint.class);
EndpointContext endpointContext = mock(EndpointContext.class);
when(endpointContext.environment()).thenReturn(env);
when(endpoint.context()).thenReturn(endpointContext);
EmbeddedChannel channel = new EmbeddedChannel(new ManagerMessageHandler(endpoint, ctx));
BucketConfigStreamingRequest request = new BucketConfigStreamingRequest(Duration.ofSeconds(1), ctx, BestEffortRetryStrategy.INSTANCE, "bucket", ctx.authenticator());
channel.write(request);
HttpRequest outboundHeader = channel.readOutbound();
assertEquals(HttpMethod.GET, outboundHeader.method());
assertEquals("/pools/default/bs/bucket", outboundHeader.uri());
assertEquals(HttpVersion.HTTP_1_1, outboundHeader.protocolVersion());
HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
HttpContent httpContent = new DefaultHttpContent(Unpooled.copiedBuffer("{}\n\n\n\n", StandardCharsets.UTF_8));
channel.writeInbound(httpResponse, httpContent);
BucketConfigStreamingResponse response = request.response().get();
assertEquals("{}", response.configs().blockFirst());
waitUntilCondition(() -> {
channel.runPendingTasks();
MockingDetails mockingDetails = Mockito.mockingDetails(endpoint);
return mockingDetails.getInvocations().stream().anyMatch(i -> i.getMethod().getName().equals("disconnect"));
});
channel.finish();
} finally {
env.shutdown();
}
}
use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.
the class FeatureNegotiatingHandlerTest method beforeEach.
@BeforeEach
@Override
protected void beforeEach() {
super.beforeEach();
CoreEnvironment env = mock(CoreEnvironment.class);
timeoutConfig = mock(TimeoutConfig.class);
when(env.eventBus()).thenReturn(eventBus);
when(env.timeoutConfig()).thenReturn(timeoutConfig);
when(env.userAgent()).thenReturn(new UserAgent("some", Optional.empty(), Optional.empty(), Optional.empty()));
when(timeoutConfig.connectTimeout()).thenReturn(Duration.ofMillis(1000));
CoreContext coreContext = new CoreContext(mock(Core.class), 1, env, mock(Authenticator.class));
endpointContext = new EndpointContext(coreContext, new HostAndPort("127.0.0.1", 1234), null, ServiceType.KV, Optional.empty(), Optional.empty(), Optional.empty());
}
use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.
the class KeyValueMessageHandlerTest method setup.
@BeforeAll
static void setup() {
ENV = CoreEnvironment.builder().eventBus(new SimpleEventBus(true)).build();
Core core = mock(Core.class);
CoreContext coreContext = new CoreContext(core, 1, ENV, PasswordAuthenticator.create("foo", "bar"));
ConfigurationProvider configurationProvider = mock(ConfigurationProvider.class);
when(configurationProvider.collectionMap()).thenReturn(new CollectionMap());
when(core.configurationProvider()).thenReturn(configurationProvider);
CTX = new EndpointContext(coreContext, new HostAndPort("127.0.0.1", 1234), null, ServiceType.KV, Optional.empty(), Optional.empty(), Optional.empty());
}
use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.
the class SaslListMechanismsHandlerTest method beforeEach.
@BeforeEach
@Override
protected void beforeEach() {
super.beforeEach();
CoreEnvironment env = mock(CoreEnvironment.class);
TimeoutConfig timeoutConfig = mock(TimeoutConfig.class);
when(env.eventBus()).thenReturn(eventBus);
when(env.timeoutConfig()).thenReturn(timeoutConfig);
when(timeoutConfig.connectTimeout()).thenReturn(Duration.ofMillis(1000));
CoreContext coreContext = new CoreContext(mock(Core.class), 1, env, mock(Authenticator.class));
endpointContext = new EndpointContext(coreContext, new HostAndPort("127.0.0.1", 1234), null, ServiceType.KV, Optional.empty(), Optional.empty(), Optional.empty());
}
use of com.couchbase.client.core.endpoint.EndpointContext in project couchbase-jvm-clients by couchbase.
the class NonChunkedHttpMessageHandlerTest method setup.
@BeforeEach
void setup() {
endpoint = mock(BaseEndpoint.class);
EndpointContext endpointContext = mock(EndpointContext.class);
when(endpointContext.environment()).thenReturn(env);
when(endpointContext.authenticator()).thenReturn(PasswordAuthenticator.create("user", "pass"));
when(endpoint.context()).thenReturn(endpointContext);
channel = new EmbeddedChannel();
}
Aggregations