use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class ErrorMapLoadingHandlerTest method encodeAndSendErrorMapRequest.
/**
* This test verifies that the client sends the proper KV command to the server
* when requesting the KV error map.
*/
@Test
void encodeAndSendErrorMapRequest() {
ErrorMapLoadingHandler handler = new ErrorMapLoadingHandler(endpointContext);
channel.pipeline().addLast(handler);
assertEquals(handler, channel.pipeline().get(ErrorMapLoadingHandler.class));
channel.connect(new InetSocketAddress("1.2.3.4", 1234));
channel.pipeline().fireChannelActive();
channel.runPendingTasks();
ByteBuf writtenRequest = channel.readOutbound();
verifyRequest(writtenRequest, MemcacheProtocol.Opcode.ERROR_MAP.opcode(), false, false, true);
// sanity check the body payload
assertTrue(ProtocolVerifier.body(writtenRequest).isPresent());
ByteBuf body = ProtocolVerifier.body(writtenRequest).get();
assertEquals(2, body.readableBytes());
// we are checking for version 2 here
assertEquals((short) 2, body.readShort());
ReferenceCountUtil.release(writtenRequest);
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class ErrorMapLoadingHandlerTest method decodeSuccessfulErrorMapV2.
/**
* Verify that we can decode v2 of the error map.
*/
@Test
void decodeSuccessfulErrorMapV2() {
ErrorMapLoadingHandler handler = new ErrorMapLoadingHandler(endpointContext);
channel.pipeline().addLast(handler);
assertEquals(handler, channel.pipeline().get(ErrorMapLoadingHandler.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.ERROR_MAP.opcode(), false, false, true);
assertNotNull(channel.pipeline().get(ErrorMapLoadingHandler.class));
ReferenceCountUtil.release(writtenRequest);
ByteBuf response = decodeHexDump(readResource("success_errormapv2_response.txt", ErrorMapLoadingHandlerTest.class));
channel.writeInbound(response);
channel.runPendingTasks();
assertTrue(connectFuture.isSuccess());
assertEquals(1, eventBus.publishedEvents().size());
ErrorMapLoadedEvent event = (ErrorMapLoadedEvent) eventBus.publishedEvents().get(0);
assertEquals(Event.Severity.DEBUG, event.severity());
Optional<ErrorMap> maybeMap = event.errorMap();
assertTrue(maybeMap.isPresent());
assertNotNull(maybeMap.get());
ErrorMap errorMap = channel.attr(ChannelAttributes.ERROR_MAP_KEY).get();
assertEquals(errorMap, maybeMap.get());
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class ErrorMapLoadingHandlerTest method decodeSuccessfulResponseWithEmptyMap.
/**
* This seems to be a real edge case, but when the server returns a successful
* response but with no map, we should still handle it gracefully.
*/
@Test
void decodeSuccessfulResponseWithEmptyMap() {
ErrorMapLoadingHandler handler = new ErrorMapLoadingHandler(endpointContext);
channel.pipeline().addLast(handler);
assertEquals(handler, channel.pipeline().get(ErrorMapLoadingHandler.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.ERROR_MAP.opcode(), false, false, true);
assertNotNull(channel.pipeline().get(ErrorMapLoadingHandler.class));
ReferenceCountUtil.release(writtenRequest);
ByteBuf response = decodeHexDump(readResource("success_empty_errormap_response.txt", ErrorMapLoadingHandlerTest.class));
channel.writeInbound(response);
channel.runPendingTasks();
assertTrue(connectFuture.isSuccess());
assertEquals(2, eventBus.publishedEvents().size());
ErrorMapUndecodableEvent undecodableEvent = (ErrorMapUndecodableEvent) eventBus.publishedEvents().get(0);
assertEquals("KV Error Map loaded but undecodable. " + "Message: \"No content in response\", Content: \"\"", undecodableEvent.description());
ErrorMapLoadedEvent event = (ErrorMapLoadedEvent) eventBus.publishedEvents().get(1);
assertEquals(Event.Severity.DEBUG, event.severity());
Optional<ErrorMap> maybeMap = event.errorMap();
assertFalse(maybeMap.isPresent());
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class CompressionTest method doesNotCompressIfDisabledUpsert.
@Test
void doesNotCompressIfDisabledUpsert() {
UpsertRequest request = new UpsertRequest(key, longContent, expiry, preserveExpiry, flags, timeout, coreContext, cid, retryStrategy, Optional.empty(), 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 doesNotCompressIfDisabledAppend.
@Test
void doesNotCompressIfDisabledAppend() {
AppendRequest request = new AppendRequest(timeout, coreContext, cid, retryStrategy, key, longContent, cas, durability, null);
ByteBuf encoded = request.encode(allocator, 0, ctx(false));
assertEquals(0, datatype(encoded));
assertEquals(Unpooled.wrappedBuffer(longContent), body(encoded).get());
ReferenceCountUtil.release(encoded);
}
Aggregations