Search in sources :

Example 1 with CoreEnvironment

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();
    }
}
Also used : CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with CoreEnvironment

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();
    }
}
Also used : CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) SecureConnectionFailedEvent(com.couchbase.client.core.cnc.events.io.SecureConnectionFailedEvent) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) SecureConnectionFailedEvent(com.couchbase.client.core.cnc.events.io.SecureConnectionFailedEvent) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) Event(com.couchbase.client.core.cnc.Event) EndpointConnectionFailedEvent(com.couchbase.client.core.cnc.events.endpoint.EndpointConnectionFailedEvent) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with CoreEnvironment

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();
    }
}
Also used : HttpRequest(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpRequest) CoreContext(com.couchbase.client.core.CoreContext) BucketConfigStreamingResponse(com.couchbase.client.core.msg.manager.BucketConfigStreamingResponse) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) DefaultHttpContent(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpContent) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) HttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse) DefaultHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse) MockingDetails(org.mockito.MockingDetails) BucketConfigStreamingRequest(com.couchbase.client.core.msg.manager.BucketConfigStreamingRequest) BaseEndpoint(com.couchbase.client.core.endpoint.BaseEndpoint) DefaultHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpContent(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpContent) DefaultLastHttpContent(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultLastHttpContent) HttpContent(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpContent) Core(com.couchbase.client.core.Core) Test(org.junit.jupiter.api.Test)

Example 4 with CoreEnvironment

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);
}
Also used : CoreContext(com.couchbase.client.core.CoreContext) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) EventBus(com.couchbase.client.core.cnc.EventBus) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with CoreEnvironment

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());
}
Also used : HostAndPort(com.couchbase.client.core.util.HostAndPort) TimeoutConfig(com.couchbase.client.core.env.TimeoutConfig) CoreContext(com.couchbase.client.core.CoreContext) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) Authenticator(com.couchbase.client.core.env.Authenticator) Core(com.couchbase.client.core.Core) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)30 Core (com.couchbase.client.core.Core)20 CoreContext (com.couchbase.client.core.CoreContext)20 Test (org.junit.jupiter.api.Test)15 Authenticator (com.couchbase.client.core.env.Authenticator)13 SimpleEventBus (com.couchbase.client.core.cnc.SimpleEventBus)9 EndpointContext (com.couchbase.client.core.endpoint.EndpointContext)8 HostAndPort (com.couchbase.client.core.util.HostAndPort)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)6 Stability (com.couchbase.client.core.annotation.Stability)5 TimeoutConfig (com.couchbase.client.core.env.TimeoutConfig)5 Duration (java.time.Duration)5 List (java.util.List)5 Map (java.util.Map)5 Flux (reactor.core.publisher.Flux)5 Mono (reactor.core.publisher.Mono)5 Reactor (com.couchbase.client.core.Reactor)4 BucketConfig (com.couchbase.client.core.config.BucketConfig)4 CouchbaseBucketConfig (com.couchbase.client.core.config.CouchbaseBucketConfig)4