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