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();
}
}
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();
}
}
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();
}
}
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());
}
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());
}
Aggregations