Search in sources :

Example 86 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class CompressionTest method doesNotCompressIfTooShortAppend.

@Test
void doesNotCompressIfTooShortAppend() {
    AppendRequest request = new AppendRequest(timeout, coreContext, cid, retryStrategy, key, shortContent, cas, durability, null);
    ByteBuf encoded = request.encode(allocator, 0, ctx(true));
    assertEquals(0, datatype(encoded));
    assertEquals(Unpooled.wrappedBuffer(shortContent), body(encoded).get());
    ReferenceCountUtil.release(encoded);
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 87 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class CompressionTest method doesCompressLongPrepend.

@Test
void doesCompressLongPrepend() {
    PrependRequest request = new PrependRequest(timeout, coreContext, cid, retryStrategy, key, longContent, cas, durability, null);
    ByteBuf encoded = request.encode(allocator, 0, ctx(true));
    assertEquals(MemcacheProtocol.Datatype.SNAPPY.datatype(), datatype(encoded));
    assertTrue(body(encoded).get().readableBytes() < longContent.length);
    ReferenceCountUtil.release(encoded);
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 88 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class CompressionTest method doesNotCompressIfDisabledReplace.

@Test
void doesNotCompressIfDisabledReplace() {
    ReplaceRequest request = new ReplaceRequest(key, longContent, expiry, preserveExpiry, flags, timeout, cas, coreContext, cid, retryStrategy, durability, null);
    ByteBuf encoded = request.encode(allocator, 0, ctx(false));
    assertEquals(0, datatype(encoded));
    assertEquals(Unpooled.wrappedBuffer(longContent), body(encoded).get());
    ReferenceCountUtil.release(encoded);
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 89 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class CompressionTest method doesCompressLongReplace.

@Test
void doesCompressLongReplace() {
    ReplaceRequest request = new ReplaceRequest(key, longContent, expiry, preserveExpiry, flags, timeout, cas, coreContext, cid, retryStrategy, durability, null);
    ByteBuf encoded = request.encode(allocator, 0, ctx(true));
    assertEquals(MemcacheProtocol.Datatype.SNAPPY.datatype(), datatype(encoded));
    assertTrue(body(encoded).get().readableBytes() < longContent.length);
    ReferenceCountUtil.release(encoded);
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 90 with ByteBuf

use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.

the class InsertRequest method encode.

@Override
public ByteBuf encode(ByteBufAllocator alloc, int opaque, KeyValueChannelContext ctx) {
    ByteBuf key = null;
    ByteBuf content = null;
    ByteBuf extras = null;
    ByteBuf flexibleExtras = mutationFlexibleExtras(this, ctx, alloc, syncReplicationType);
    try {
        key = encodedKeyWithCollection(alloc, ctx);
        byte datatype = 0;
        CompressionConfig config = ctx.compressionConfig();
        if (config != null && config.enabled() && this.content.length >= config.minSize()) {
            ByteBuf maybeCompressed = MemcacheProtocol.tryCompression(this.content, config.minRatio());
            if (maybeCompressed != null) {
                datatype |= MemcacheProtocol.Datatype.SNAPPY.datatype();
                content = maybeCompressed;
            } else {
                content = Unpooled.wrappedBuffer(this.content);
            }
        } else {
            content = Unpooled.wrappedBuffer(this.content);
        }
        extras = alloc.buffer(Integer.BYTES * 2);
        extras.writeInt(flags);
        extras.writeInt((int) expiration);
        return MemcacheProtocol.flexibleRequest(alloc, MemcacheProtocol.Opcode.ADD, datatype, partition(), opaque, noCas(), flexibleExtras, extras, key, content);
    } finally {
        ReferenceCountUtil.release(key);
        ReferenceCountUtil.release(extras);
        ReferenceCountUtil.release(flexibleExtras);
        ReferenceCountUtil.release(content);
    }
}
Also used : ByteBuf(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf) CompressionConfig(com.couchbase.client.core.env.CompressionConfig)

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