Search in sources :

Example 16 with EmbeddedChannel

use of com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel in project couchbase-jvm-clients by couchbase.

the class MemcacheProtocolVerificationHandlerTest method shouldVerifyCorrectResponses.

/**
 * Verifies good responses are passed through.
 *
 * @param inputHolder the good input packets.
 */
@ParameterizedTest(name = "{0}")
@MethodSource
void shouldVerifyCorrectResponses(final InputHolder inputHolder) {
    EndpointContext ctx = mock(EndpointContext.class);
    final EmbeddedChannel channel = new EmbeddedChannel(new MemcacheProtocolVerificationHandler(ctx));
    try {
        channel.writeInbound(inputHolder.input);
        ByteBuf written = channel.readInbound();
        assertEquals(inputHolder.input, written);
    } finally {
        channel.finishAndReleaseAll();
    }
}
Also used : EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 17 with EmbeddedChannel

use of com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel in project couchbase-jvm-clients by couchbase.

the class MemcacheProtocolVerificationHandlerTest method shouldVerifyCorrectRequests.

/**
 * Verifies good requests are passed through.
 *
 * @param inputHolder the good input packets.
 */
@ParameterizedTest(name = "{0}")
@MethodSource
void shouldVerifyCorrectRequests(final InputHolder inputHolder) {
    EndpointContext ctx = mock(EndpointContext.class);
    final EmbeddedChannel channel = new EmbeddedChannel(new MemcacheProtocolVerificationHandler(ctx));
    try {
        channel.writeOutbound(inputHolder.input);
        ByteBuf written = channel.readOutbound();
        assertEquals(inputHolder.input, written);
    } finally {
        channel.finishAndReleaseAll();
    }
}
Also used : EndpointContext(com.couchbase.client.core.endpoint.EndpointContext) EmbeddedChannel(com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 18 with EmbeddedChannel

use of com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel in project couchbase-jvm-clients by couchbase.

the class MemcacheProtocolVerificationHandlerTest method shouldCloseOnInvalidResponses.

/**
 * Verifies that invalid responses are not let through.
 *
 * @param inputHolder the bad input packets.
 */
@ParameterizedTest(name = "{0}")
@MethodSource
void shouldCloseOnInvalidResponses(final InputHolder inputHolder) {
    SimpleEventBus eventBus = new SimpleEventBus(true);
    CoreEnvironment env = mock(CoreEnvironment.class);
    EndpointContext ctx = mock(EndpointContext.class);
    when(ctx.environment()).thenReturn(env);
    when(env.eventBus()).thenReturn(eventBus);
    final EmbeddedChannel channel = new EmbeddedChannel(new MemcacheProtocolVerificationHandler(ctx));
    try {
        channel.writeInbound(inputHolder.input);
        assertFalse(channel.isOpen());
        InvalidPacketDetectedEvent event = (InvalidPacketDetectedEvent) eventBus.publishedEvents().get(0);
        assertEquals(Event.Severity.ERROR, event.severity());
        assertEquals(Event.Category.IO.path(), event.category());
        assertTrue(event.description().contains("Invalid Packet detected:"));
    } finally {
        channel.finishAndReleaseAll();
    }
}
Also used : 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) InvalidPacketDetectedEvent(com.couchbase.client.core.cnc.events.io.InvalidPacketDetectedEvent) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 19 with EmbeddedChannel

use of com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel 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 20 with EmbeddedChannel

use of com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel 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)

Aggregations

EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)32 Test (org.junit.jupiter.api.Test)23 EndpointContext (com.couchbase.client.core.endpoint.EndpointContext)15 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)13 Core (com.couchbase.client.core.Core)8 CoreContext (com.couchbase.client.core.CoreContext)8 CoreEnvironment (com.couchbase.client.core.env.CoreEnvironment)8 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)7 SimpleEventBus (com.couchbase.client.core.cnc.SimpleEventBus)6 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)6 DefaultHttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpResponse)5 DefaultLastHttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultLastHttpContent)5 HttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpContent)5 HttpResponse (com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 EndpointDisconnectedEvent (com.couchbase.client.core.cnc.events.endpoint.EndpointDisconnectedEvent)4 DefaultHttpContent (com.couchbase.client.core.deps.io.netty.handler.codec.http.DefaultHttpContent)4 HostAndPort (com.couchbase.client.core.util.HostAndPort)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4