use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class MemcacheProtocolDecodeHandlerTest method shouldDecodeInput.
/**
* Runs through all provided inputs and makes sure even if they are sliced
* and diced they come out whole at the end.
*
* <p>For now each input is tried 100 times with different chunk sizes to increase
* the chance of finding a problem, this can be increased or decreased as
* needed.</p>
*/
@ParameterizedTest(name = "{0}")
@MethodSource("inputProvider")
void shouldDecodeInput(final InputHolder inputHolder) {
final EmbeddedChannel channel = new EmbeddedChannel(new MemcacheProtocolDecodeHandler());
try {
for (int i = 0; i < 100; i++) {
ByteBuf copy = inputHolder.input.copy();
writeAsRandomChunks(channel, copy);
ByteBuf read = channel.readInbound();
copy.resetReaderIndex();
assertEquals(inputHolder.input, read);
ReferenceCountUtil.release(copy);
ReferenceCountUtil.release(read);
}
ReferenceCountUtil.release(inputHolder.input);
} finally {
channel.finishAndReleaseAll();
}
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class MemcacheProtocolTest method flexibleSyncReplicationTimeoutRightAtFloor.
@Test
void flexibleSyncReplicationTimeoutRightAtFloor() {
// 1667 is valid, and should not log
ByteBuf result = MemcacheProtocol.flexibleSyncReplication(ALLOC.buffer(), DurabilityLevel.MAJORITY, Duration.ofMillis(1667), context);
try {
// 4 bytes total for these flexible extras
assertEquals(4, result.readableBytes());
// sync replication id 1 and length 3
assertEquals(0x13, result.getByte(0));
// majority has id of 1
assertEquals(0x01, result.getByte(1));
// expect what you asked for (well, 90% of it)
assertEquals(1500, result.getShort(2));
verify(eventBus, never()).publish(any(DurabilityTimeoutCoercedEvent.class));
} finally {
ReferenceCountUtil.release(result);
}
// 1666 actually will log...
result = MemcacheProtocol.flexibleSyncReplication(ALLOC.buffer(), DurabilityLevel.MAJORITY, Duration.ofMillis(1666), context);
try {
// 4 bytes total for these flexible extras
assertEquals(4, result.readableBytes());
// sync replication id 1 and length 3
assertEquals(0x13, result.getByte(0));
// majority has id of 1
assertEquals(0x01, result.getByte(1));
// expect what you asked for
assertEquals(1500, result.getShort(2));
verify(eventBus, times(1)).publish(any(DurabilityTimeoutCoercedEvent.class));
} finally {
ReferenceCountUtil.release(result);
}
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf 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.buffer.ByteBuf 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.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class SaslListMechanismsHandlerTest method ignoresUnknownSaslMech.
@Test
void ignoresUnknownSaslMech() {
SaslListMechanismsHandler handler = new SaslListMechanismsHandler(endpointContext);
channel.pipeline().addLast(handler);
assertEquals(handler, channel.pipeline().get(SaslListMechanismsHandler.class));
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("1.2.3.4", 1234));
assertFalse(connectFuture.isDone());
channel.pipeline().fireChannelActive();
channel.runPendingTasks();
ByteBuf writtenRequest = channel.readOutbound();
verifyRequest(writtenRequest, MemcacheProtocol.Opcode.SASL_LIST_MECHS.opcode(), false, false, false);
assertNotNull(channel.pipeline().get(SaslListMechanismsHandler.class));
ReferenceCountUtil.release(writtenRequest);
ByteBuf response = decodeHexDump(readResource("success_sasl_list_mechs_unknown_mech_response.txt", ErrorMapLoadingHandlerTest.class));
channel.writeInbound(response);
channel.runPendingTasks();
assertTrue(connectFuture.isSuccess());
Set<SaslMechanism> saslMechanisms = channel.attr(ChannelAttributes.SASL_MECHS_KEY).get();
assertEquals(saslMechanisms, EnumSet.of(SaslMechanism.SCRAM_SHA1, SaslMechanism.SCRAM_SHA256, SaslMechanism.SCRAM_SHA512));
UnknownSaslMechanismDetectedEvent event = (UnknownSaslMechanismDetectedEvent) eventBus.publishedEvents().get(0);
assertEquals("FLAUN", event.mechanism());
}
Aggregations