Search in sources :

Example 6 with HostAndPort

use of com.couchbase.client.core.util.HostAndPort in project couchbase-jvm-clients by couchbase.

the class SaslListMechanismsHandlerTest method failConnectIfPromiseTimesOut.

/**
 * This test makes sure that the timer fires if the connect future is not completed
 * otherwise.
 */
@Test
void failConnectIfPromiseTimesOut() throws Exception {
    channel = new EmbeddedChannel();
    eventBus = new SimpleEventBus(true);
    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(100));
    CoreContext coreContext = new CoreContext(mock(Core.class), 1, env, mock(Authenticator.class));
    EndpointContext endpointContext = new EndpointContext(coreContext, new HostAndPort("127.0.0.1", 1234), null, ServiceType.KV, Optional.empty(), Optional.empty(), Optional.empty());
    SaslListMechanismsHandler handler = new SaslListMechanismsHandler(endpointContext);
    channel.pipeline().addLast(handler);
    final ChannelFuture connect = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
    channel.pipeline().fireChannelActive();
    Thread.sleep(Duration.ofMillis(100).toMillis() + 5);
    channel.runScheduledPendingTasks();
    assertTrue(connect.isDone());
    assertTrue(connect.cause() instanceof TimeoutException);
    assertEquals("SASL Mechanism listing timed out after 100ms", connect.cause().getMessage());
}
Also used : ChannelFuture(com.couchbase.client.core.deps.io.netty.channel.ChannelFuture) 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) InetSocketAddress(java.net.InetSocketAddress) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) HostAndPort(com.couchbase.client.core.util.HostAndPort) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) Authenticator(com.couchbase.client.core.env.Authenticator) Core(com.couchbase.client.core.Core) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.jupiter.api.Test)

Example 7 with HostAndPort

use of com.couchbase.client.core.util.HostAndPort in project couchbase-jvm-clients by couchbase.

the class SelectBucketHandlerTest method setup.

@BeforeEach
void setup() {
    channel = new EmbeddedChannel();
    SimpleEventBus simpleEventBus = new SimpleEventBus(true);
    CoreEnvironment env = mock(CoreEnvironment.class);
    TimeoutConfig timeoutConfig = mock(TimeoutConfig.class);
    when(env.eventBus()).thenReturn(simpleEventBus);
    when(env.timeoutConfig()).thenReturn(timeoutConfig);
    when(timeoutConfig.connectTimeout()).thenReturn(Duration.ofMillis(10));
    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) SimpleEventBus(com.couchbase.client.core.cnc.SimpleEventBus) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) Authenticator(com.couchbase.client.core.env.Authenticator) Core(com.couchbase.client.core.Core) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with HostAndPort

use of com.couchbase.client.core.util.HostAndPort in project couchbase-jvm-clients by couchbase.

the class QueryMessageHandlerBackpressureTest method requestRecordsExplicitly.

/**
 * This test makes sure that even if the server returns a good bunch of data, each individual
 * chunk is requested by the caller explicitly.
 */
@Test
void requestRecordsExplicitly() throws Exception {
    EndpointContext endpointContext = new EndpointContext(core.context(), new HostAndPort("127.0.0.1", 1234), NoopCircuitBreaker.INSTANCE, ServiceType.QUERY, Optional.empty(), Optional.empty(), Optional.empty());
    BaseEndpoint endpoint = mock(BaseEndpoint.class);
    when(endpoint.pipelined()).thenReturn(false);
    Bootstrap client = new Bootstrap().channel(LocalChannel.class).group(new DefaultEventLoopGroup()).remoteAddress(new LocalAddress("s1")).handler(new ChannelInitializer<LocalChannel>() {

        @Override
        protected void initChannel(LocalChannel ch) {
            ch.pipeline().addLast(new HttpClientCodec()).addLast(new QueryMessageHandler(endpoint, endpointContext));
        }
    });
    Channel channel = client.connect().awaitUninterruptibly().channel();
    final List<byte[]> rows = Collections.synchronizedList(new ArrayList<>());
    QueryRequest request = new QueryRequest(Duration.ofSeconds(1), endpointContext, BestEffortRetryStrategy.INSTANCE, endpointContext.authenticator(), "select 1=1", "myquery".getBytes(UTF_8), true, null, null, null, null, null);
    channel.writeAndFlush(request);
    final QueryResponse response = request.response().get();
    assertEquals(0, rows.size());
    StepVerifier.create(response.rows().map(v -> new String(v.data(), UTF_8)), 0).thenRequest(1).expectNext("{\"foo\":1}").thenRequest(1).expectNext("{\"bar\":1}").thenRequest(2).expectNext("{\"faz\":1}", "{\"baz\":1}").thenRequest(4).expectNext("{\"fazz\":1}", "{\"bazz\":1}", "{\"fizz\":1}", "{\"bizz\":1}").expectComplete().verify();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) QueryRequest(com.couchbase.client.core.msg.query.QueryRequest) HttpHeaderNames(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpHeaderNames) ReferenceCountUtil(com.couchbase.client.core.deps.io.netty.util.ReferenceCountUtil) BestEffortRetryStrategy(com.couchbase.client.core.retry.BestEffortRetryStrategy) ServerBootstrap(com.couchbase.client.core.deps.io.netty.bootstrap.ServerBootstrap) AfterAll(org.junit.jupiter.api.AfterAll) PasswordAuthenticator(com.couchbase.client.core.env.PasswordAuthenticator) ChannelInboundHandlerAdapter(com.couchbase.client.core.deps.io.netty.channel.ChannelInboundHandlerAdapter) BeforeAll(org.junit.jupiter.api.BeforeAll) ServiceType(com.couchbase.client.core.service.ServiceType) Duration(java.time.Duration) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) Channel(com.couchbase.client.core.deps.io.netty.channel.Channel) ChannelHandlerContext(com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext) Unpooled(com.couchbase.client.core.deps.io.netty.buffer.Unpooled) BaseEndpoint(com.couchbase.client.core.endpoint.BaseEndpoint) LocalServerChannel(com.couchbase.client.core.deps.io.netty.channel.local.LocalServerChannel) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) DefaultHttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse) DefaultEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.DefaultEventLoopGroup) Test(org.junit.jupiter.api.Test) List(java.util.List) Optional(java.util.Optional) HostAndPort(com.couchbase.client.core.util.HostAndPort) Mockito.mock(org.mockito.Mockito.mock) QueryResponse(com.couchbase.client.core.msg.query.QueryResponse) HttpVersion(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpVersion) DefaultHttpContent(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpContent) SeedNode(com.couchbase.client.core.env.SeedNode) HttpResponse(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse) HttpServerCodec(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpServerCodec) ArrayList(java.util.ArrayList) LocalAddress(com.couchbase.client.core.deps.io.netty.channel.local.LocalAddress) DefaultLastHttpContent(com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultLastHttpContent) LocalChannel(com.couchbase.client.core.deps.io.netty.channel.local.LocalChannel) NoopCircuitBreaker(com.couchbase.client.core.endpoint.NoopCircuitBreaker) HttpResponseStatus(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponseStatus) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ChannelInitializer(com.couchbase.client.core.deps.io.netty.channel.ChannelInitializer) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Mockito.when(org.mockito.Mockito.when) EventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup) TimeUnit(java.util.concurrent.TimeUnit) HttpClientCodec(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpClientCodec) AfterEach(org.junit.jupiter.api.AfterEach) Core(com.couchbase.client.core.Core) Collections(java.util.Collections) Bootstrap(com.couchbase.client.core.deps.io.netty.bootstrap.Bootstrap) LocalAddress(com.couchbase.client.core.deps.io.netty.channel.local.LocalAddress) QueryRequest(com.couchbase.client.core.msg.query.QueryRequest) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) LocalChannel(com.couchbase.client.core.deps.io.netty.channel.local.LocalChannel) Channel(com.couchbase.client.core.deps.io.netty.channel.Channel) LocalServerChannel(com.couchbase.client.core.deps.io.netty.channel.local.LocalServerChannel) LocalChannel(com.couchbase.client.core.deps.io.netty.channel.local.LocalChannel) HttpClientCodec(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpClientCodec) DefaultEventLoopGroup(com.couchbase.client.core.deps.io.netty.channel.DefaultEventLoopGroup) HostAndPort(com.couchbase.client.core.util.HostAndPort) BaseEndpoint(com.couchbase.client.core.endpoint.BaseEndpoint) QueryResponse(com.couchbase.client.core.msg.query.QueryResponse) ServerBootstrap(com.couchbase.client.core.deps.io.netty.bootstrap.ServerBootstrap) Bootstrap(com.couchbase.client.core.deps.io.netty.bootstrap.Bootstrap) Test(org.junit.jupiter.api.Test)

Example 9 with HostAndPort

use of com.couchbase.client.core.util.HostAndPort in project couchbase-jvm-clients by couchbase.

the class QueryMessageHandlerTest method setup.

@BeforeAll
static void setup() {
    ENV = CoreEnvironment.create();
    CORE_CTX = new CoreContext(mock(Core.class), 1, ENV, PasswordAuthenticator.create("user", "pass"));
    ENDPOINT_CTX = new EndpointContext(CORE_CTX, new HostAndPort("127.0.0.1", 1234), NoopCircuitBreaker.INSTANCE, ServiceType.QUERY, Optional.empty(), Optional.empty(), Optional.empty());
}
Also used : HostAndPort(com.couchbase.client.core.util.HostAndPort) CoreContext(com.couchbase.client.core.CoreContext) EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 10 with HostAndPort

use of com.couchbase.client.core.util.HostAndPort in project couchbase-jvm-clients by couchbase.

the class ErrorMapLoadingHandlerTest 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

HostAndPort (com.couchbase.client.core.util.HostAndPort)12 EndpointContext (com.couchbase.client.core.endpoint.EndpointContext)11 Core (com.couchbase.client.core.Core)10 CoreContext (com.couchbase.client.core.CoreContext)9 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)8 Authenticator (com.couchbase.client.core.env.Authenticator)5 TimeoutConfig (com.couchbase.client.core.env.TimeoutConfig)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 SimpleEventBus (com.couchbase.client.core.cnc.SimpleEventBus)4 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)4 BeforeAll (org.junit.jupiter.api.BeforeAll)4 ChannelFuture (com.couchbase.client.core.deps.io.netty.channel.ChannelFuture)3 InetSocketAddress (java.net.InetSocketAddress)3 TimeoutException (java.util.concurrent.TimeoutException)3 Test (org.junit.jupiter.api.Test)3 Bootstrap (com.couchbase.client.core.deps.io.netty.bootstrap.Bootstrap)2 Channel (com.couchbase.client.core.deps.io.netty.channel.Channel)2 ChannelInitializer (com.couchbase.client.core.deps.io.netty.channel.ChannelInitializer)2 DefaultEventLoopGroup (com.couchbase.client.core.deps.io.netty.channel.DefaultEventLoopGroup)2 EventLoopGroup (com.couchbase.client.core.deps.io.netty.channel.EventLoopGroup)2