Search in sources :

Example 1 with ErrorMapUndecodableEvent

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

Aggregations

ErrorMapLoadedEvent (com.couchbase.client.core.cnc.events.io.ErrorMapLoadedEvent)1 ErrorMapUndecodableEvent (com.couchbase.client.core.cnc.events.io.ErrorMapUndecodableEvent)1 ByteBuf (com.couchbase.client.core.deps.io.netty.buffer.ByteBuf)1 ChannelFuture (com.couchbase.client.core.deps.io.netty.channel.ChannelFuture)1 InetSocketAddress (java.net.InetSocketAddress)1 Test (org.junit.jupiter.api.Test)1