use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class SaslListMechanismsHandlerTest method propagatesChannelActiveAfterSendingInitialRequest.
/**
* This test makes sure that after the initial request is sent, the channel active signal is
* propagated so that we do not regress bootstrap pipelining functionality.
*/
@Test
void propagatesChannelActiveAfterSendingInitialRequest() {
final SaslListMechanismsHandler handler = new SaslListMechanismsHandler(endpointContext);
final AtomicBoolean channelActiveFired = new AtomicBoolean();
channel.pipeline().addLast(handler).addLast(new SimpleChannelInboundHandler<ByteBuf>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
channelActiveFired.set(true);
}
});
assertEquals(handler, channel.pipeline().get(SaslListMechanismsHandler.class));
channel.connect(new InetSocketAddress("1.2.3.4", 1234));
channel.pipeline().fireChannelActive();
channel.runPendingTasks();
waitUntilCondition(channelActiveFired::get);
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class SaslListMechanismsHandlerTest method encodeAndSendListMechsRequest.
/**
* This test verifies that the client sends the proper KV command to the server
* when requesting the SASL mechanisms.
*/
@Test
void encodeAndSendListMechsRequest() {
SaslListMechanismsHandler handler = new SaslListMechanismsHandler(endpointContext);
channel.pipeline().addLast(handler);
assertEquals(handler, channel.pipeline().get(SaslListMechanismsHandler.class));
channel.connect(new InetSocketAddress("1.2.3.4", 1234));
channel.pipeline().fireChannelActive();
channel.runPendingTasks();
ByteBuf writtenRequest = channel.readOutbound();
verifyRequest(writtenRequest, MemcacheProtocol.Opcode.SASL_LIST_MECHS.opcode(), false, false, false);
ReferenceCountUtil.release(writtenRequest);
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class SaslListMechanismsHandlerTest method failConnectIfSaslMechsListEmpty.
@Test
void failConnectIfSaslMechsListEmpty() {
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_empty_response.txt", ErrorMapLoadingHandlerTest.class));
channel.writeInbound(response);
channel.runPendingTasks();
assertFalse(connectFuture.isSuccess());
AuthenticationFailureException cause = (AuthenticationFailureException) connectFuture.cause();
assertTrue(cause.getMessage().contains("Received empty mechanism list from server"));
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class JsonStreamParserTest method exampleUsage.
@Test
void exampleUsage() {
final List<String> matches = new ArrayList<>();
JsonStreamParser parser = JsonStreamParser.builder().doOnValue("/name", v -> matches.add("Hello " + v.readString())).doOnValue("/pets/-/name", v -> matches.add("I see you have a pet named " + v.readString())).doOnValue("/blob", v -> matches.add("Here's a blob of JSON: " + new String(v.readBytes(), UTF_8))).build();
byte[] json = "{'name':'Jon','pets':[{'name':'Odie'},{'name':'Garfield'}],'blob':{'magicWord':'xyzzy'}}".replace("'", "\"").getBytes(UTF_8);
int half = json.length / 2;
ByteBuf firstChunk = Unpooled.copiedBuffer(json, 0, half);
ByteBuf secondChunk = Unpooled.copiedBuffer(json, half, json.length - half);
try {
// parser takes ownership of the buffer and will release it.
parser.feed(firstChunk);
assertEquals(Arrays.asList("Hello Jon", "I see you have a pet named Odie"), matches);
matches.clear();
parser.feed(secondChunk);
assertEquals(Arrays.asList("I see you have a pet named Garfield", "Here's a blob of JSON: {\"magicWord\":\"xyzzy\"}"), matches);
matches.clear();
} finally {
// Must always call close() when done to release the buffers owned by the parser.
parser.close();
}
}
use of com.couchbase.client.core.deps.io.netty.buffer.ByteBuf in project couchbase-jvm-clients by couchbase.
the class CompressionTest method doesCompressLongAppend.
@Test
void doesCompressLongAppend() {
AppendRequest request = new AppendRequest(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);
}
Aggregations