use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class SelectBucketHandler method buildSelectBucketRequest.
/**
* Helper method to build the select bucket request.
*
* @param ctx the {@link ChannelHandlerContext} for which the channel active operation is made.
* @return the created request as a {@link ByteBuf}.
*/
private ByteBuf buildSelectBucketRequest(final ChannelHandlerContext ctx) {
ByteBuf key = Unpooled.copiedBuffer(bucketName, UTF_8);
ByteBuf request = request(ctx.alloc(), MemcacheProtocol.Opcode.SELECT_BUCKET, noDatatype(), noPartition(), BaseKeyValueRequest.nextOpaque(), noCas(), noExtras(), key, noBody());
key.release();
return request;
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class MemcacheProtocolTest method flexibleSyncReplicationTimeoutFloor.
@Test
void flexibleSyncReplicationTimeoutFloor() {
Duration tooLowTimeout = Duration.ofSeconds(1);
ByteBuf result = MemcacheProtocol.flexibleSyncReplication(ALLOC.buffer(), DurabilityLevel.MAJORITY, tooLowTimeout, 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));
// we cannot go below 1500 per server spec so no 90%.
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 MemcacheProtocolTest method flexibleSyncReplicationTimeoutMaxValues.
@Test
void flexibleSyncReplicationTimeoutMaxValues() {
Duration duration = Duration.ofMillis(65535);
ByteBuf result = MemcacheProtocol.flexibleSyncReplication(ALLOC.buffer(), DurabilityLevel.MAJORITY, duration, context);
try {
assertEquals(65534, result.getUnsignedShort(2));
verify(eventBus, times(1)).publish(any(DurabilityTimeoutCoercedEvent.class));
reset(eventBus);
} finally {
ReferenceCountUtil.release(result);
}
duration = Duration.ofMillis(Long.MAX_VALUE);
result = MemcacheProtocol.flexibleSyncReplication(ALLOC.buffer(), DurabilityLevel.MAJORITY, duration, context);
try {
assertEquals(65534, result.getUnsignedShort(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 MemcacheProtocolTest method flexibleSyncReplicationUserTimeout.
@Test
void flexibleSyncReplicationUserTimeout() {
ByteBuf result = MemcacheProtocol.flexibleSyncReplication(ALLOC.buffer(), DurabilityLevel.MAJORITY_AND_PERSIST_TO_ACTIVE, Duration.ofSeconds(3), 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 and persist on active has id 2
assertEquals(0x02, result.getByte(1));
// 2700 -> 90% of the 3000ms user timeout
assertEquals(2700, result.getShort(2));
verify(eventBus, never()).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 SaslListMechanismsHandlerTest method decodesSuccessfulSaslMechsList.
@Test
void decodesSuccessfulSaslMechsList() {
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_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.PLAIN, SaslMechanism.SCRAM_SHA1, SaslMechanism.SCRAM_SHA256, SaslMechanism.SCRAM_SHA512));
assertTrue(eventBus.publishedEvents().get(0) instanceof SaslMechanismsListedEvent);
}
Aggregations