use of com.couchbase.client.core.env.CoreEnvironment in project couchbase-jvm-clients by couchbase.
the class TransportEncryptionIntegrationTest method performsKeyValueWithServerCert.
@Test
void performsKeyValueWithServerCert() throws Exception {
if (!config().clusterCerts().isPresent()) {
fail("Cluster Certificate must be present for this test!");
}
CoreEnvironment env = secureEnvironment(SecurityConfig.enableTls(true).trustCertificates(config().clusterCerts().get()), null);
Core core = Core.create(env, authenticator(), secureSeeds());
core.openBucket(config().bucketname());
waitUntilCondition(() -> core.clusterConfig().hasClusterOrBucketConfig());
try {
runKeyValueOperation(core, env);
} finally {
core.shutdown().block();
env.shutdown();
}
}
use of com.couchbase.client.core.env.CoreEnvironment in project couchbase-jvm-clients by couchbase.
the class TransportEncryptionIntegrationTest method failsIfWrongCertPresent.
@Test
@SuppressWarnings("unchecked")
void failsIfWrongCertPresent() {
SimpleEventBus eventBus = new SimpleEventBus(true);
CoreEnvironment env = secureEnvironment(SecurityConfig.enableTls(true).trustCertificates(mock(List.class)), eventBus);
Core core = Core.create(env, authenticator(), secureSeeds());
try {
core.openBucket(config().bucketname());
waitUntilCondition(() -> {
boolean hasEndpointConnectFailedEvent = false;
boolean hasSecureConnectionFailedEvent = false;
for (Event event : eventBus.publishedEvents()) {
if (event instanceof EndpointConnectionFailedEvent) {
hasEndpointConnectFailedEvent = true;
}
if (event instanceof SecureConnectionFailedEvent) {
hasSecureConnectionFailedEvent = true;
}
}
return hasEndpointConnectFailedEvent && hasSecureConnectionFailedEvent;
});
} finally {
core.shutdown().block();
env.shutdown();
}
}
use of com.couchbase.client.core.env.CoreEnvironment 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.env.CoreEnvironment in project couchbase-jvm-clients by couchbase.
the class MemcacheProtocolTest method before.
@BeforeEach
void before() {
eventBus = mock(EventBus.class);
CoreEnvironment env = mock(CoreEnvironment.class);
context = new CoreContext(mock(Core.class), 1, env, mock(Authenticator.class));
when(env.eventBus()).thenReturn(eventBus);
}
use of com.couchbase.client.core.env.CoreEnvironment 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());
}
Aggregations