Search in sources :

Example 11 with ByteBuf

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;
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)

Example 12 with ByteBuf

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);
    }
}
Also used : DurabilityTimeoutCoercedEvent(com.couchbase.client.core.cnc.events.io.DurabilityTimeoutCoercedEvent) Duration(java.time.Duration) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 13 with ByteBuf

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);
    }
}
Also used : DurabilityTimeoutCoercedEvent(com.couchbase.client.core.cnc.events.io.DurabilityTimeoutCoercedEvent) Duration(java.time.Duration) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 14 with ByteBuf

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);
    }
}
Also used : DurabilityTimeoutCoercedEvent(com.couchbase.client.core.cnc.events.io.DurabilityTimeoutCoercedEvent) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 15 with ByteBuf

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);
}
Also used : ChannelFuture(com.couchbase.client.core.deps.io.netty.channel.ChannelFuture) SaslMechanismsListedEvent(com.couchbase.client.core.cnc.events.io.SaslMechanismsListedEvent) InetSocketAddress(java.net.InetSocketAddress) SaslMechanism(com.couchbase.client.core.env.SaslMechanism) ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Aggregations

ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)107 Test (org.junit.jupiter.api.Test)54 InetSocketAddress (java.net.InetSocketAddress)17 EmbeddedChannel (com.couchbase.client.core.deps.io.netty.channel.embedded.EmbeddedChannel)12 ChannelFuture (com.couchbase.client.core.deps.io.netty.channel.ChannelFuture)11 Duration (java.time.Duration)10 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)9 CoreContext (com.couchbase.client.core.CoreContext)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 CompressionConfig (com.couchbase.client.core.env.CompressionConfig)6 ResponseStatus (com.couchbase.client.core.msg.ResponseStatus)6 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)6 ChannelHandlerContext (com.couchbase.client.core.deps.io.netty.channel.ChannelHandlerContext)5 AuthenticationFailureException (com.couchbase.client.core.error.AuthenticationFailureException)5 ArrayList (java.util.ArrayList)5 DurabilityTimeoutCoercedEvent (com.couchbase.client.core.cnc.events.io.DurabilityTimeoutCoercedEvent)4 FeaturesNegotiatedEvent (com.couchbase.client.core.cnc.events.io.FeaturesNegotiatedEvent)4 CompositeByteBuf (com.couchbase.client.core.deps.io.netty.buffer.CompositeByteBuf)4 FullHttpRequest (com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpRequest)4 BaseEndpoint (com.couchbase.client.core.endpoint.BaseEndpoint)4