List of usage examples for io.netty.buffer ByteBuf copy
public abstract ByteBuf copy();
From source file:com.couchbase.client.core.endpoint.binary.BinaryHandlerTest.java
License:Open Source License
@Test public void shouldDecodeReplicaGetResponse() throws Exception { ByteBuf content = Unpooled.copiedBuffer("content", CharsetUtil.UTF_8); FullBinaryMemcacheResponse response = new DefaultFullBinaryMemcacheResponse("key", Unpooled.EMPTY_BUFFER, content.copy()); response.setCAS(123456789L);// w w w. j a va2 s .co m response.setExtras(Unpooled.buffer().writeInt(123)); response.setExtrasLength((byte) 4); ReplicaGetRequest requestMock = mock(ReplicaGetRequest.class); when(requestMock.bucket()).thenReturn("bucket"); queue.add(requestMock); channel.writeInbound(response); channel.readInbound(); latch.await(1, TimeUnit.SECONDS); assertEquals(1, firedEvents.size()); GetResponse inbound = (GetResponse) firedEvents.get(0); assertEquals(ResponseStatus.SUCCESS, inbound.status()); assertEquals("bucket", inbound.bucket()); assertEquals(123456789L, inbound.cas()); assertEquals(123, inbound.flags()); assertEquals("content", inbound.content().toString(CharsetUtil.UTF_8)); assertTrue(queue.isEmpty()); ReferenceCountUtil.release(content); }
From source file:com.couchbase.client.core.endpoint.binary.BinaryHandlerTest.java
License:Open Source License
@Test public void shouldDecodeGetBucketConfigResponse() throws Exception { ByteBuf content = Unpooled.copiedBuffer("content", CharsetUtil.UTF_8); FullBinaryMemcacheResponse response = new DefaultFullBinaryMemcacheResponse("key", Unpooled.EMPTY_BUFFER, content.copy()); GetBucketConfigRequest requestMock = mock(GetBucketConfigRequest.class); when(requestMock.bucket()).thenReturn("bucket"); when(requestMock.hostname()).thenReturn(InetAddress.getLocalHost()); queue.add(requestMock);/*from w w w . j a v a 2s . c o m*/ channel.writeInbound(response); channel.readInbound(); latch.await(1, TimeUnit.SECONDS); assertEquals(1, firedEvents.size()); GetBucketConfigResponse inbound = (GetBucketConfigResponse) firedEvents.get(0); assertEquals(ResponseStatus.SUCCESS, inbound.status()); assertEquals("bucket", inbound.bucket()); assertEquals(InetAddress.getLocalHost(), inbound.hostname()); assertEquals("content", inbound.content().toString(CharsetUtil.UTF_8)); assertTrue(queue.isEmpty()); ReferenceCountUtil.release(content); }
From source file:com.couchbase.client.core.endpoint.kv.KeyValueHandlerTest.java
License:Apache License
@Test public void shouldDecodeSuccessfulGet() { ByteBuf content = Unpooled.copiedBuffer("content", CharsetUtil.UTF_8); FullBinaryMemcacheResponse response = new DefaultFullBinaryMemcacheResponse(KEY, Unpooled.EMPTY_BUFFER, content.copy()); response.setCAS(123456789L);/*from w ww . j av a 2s.c o m*/ response.setExtras(Unpooled.buffer().writeInt(123)); response.setExtrasLength((byte) 4); GetRequest requestMock = mock(GetRequest.class); when(requestMock.bucket()).thenReturn(BUCKET); requestQueue.add(requestMock); channel.writeInbound(response); assertEquals(1, eventSink.responseEvents().size()); GetResponse event = (GetResponse) eventSink.responseEvents().get(0).getMessage(); assertEquals(123456789L, event.cas()); assertEquals(123, event.flags()); assertEquals("content", event.content().toString(CHARSET)); assertEquals(BUCKET, event.bucket()); }
From source file:com.couchbase.client.core.endpoint.kv.KeyValueHandlerTest.java
License:Apache License
@Test public void shouldDecodeNotFoundGet() { ByteBuf content = Unpooled.copiedBuffer("Not Found", CharsetUtil.UTF_8); FullBinaryMemcacheResponse response = new DefaultFullBinaryMemcacheResponse(KEY, Unpooled.EMPTY_BUFFER, content.copy()); response.setStatus(BinaryMemcacheResponseStatus.KEY_ENOENT); GetRequest requestMock = mock(GetRequest.class); when(requestMock.bucket()).thenReturn(BUCKET); requestQueue.add(requestMock);//from w ww .j a v a2s .c om channel.writeInbound(response); assertEquals(1, eventSink.responseEvents().size()); GetResponse event = (GetResponse) eventSink.responseEvents().get(0).getMessage(); assertEquals(0, event.cas()); assertEquals(0, event.flags()); assertEquals("Not Found", event.content().toString(CHARSET)); assertEquals(BUCKET, event.bucket()); }
From source file:com.couchbase.client.core.endpoint.kv.KeyValueHandlerTest.java
License:Apache License
@Test public void shouldDecodeReplicaGetResponse() { ByteBuf content = Unpooled.copiedBuffer("content", CharsetUtil.UTF_8); FullBinaryMemcacheResponse response = new DefaultFullBinaryMemcacheResponse(KEY, Unpooled.EMPTY_BUFFER, content.copy()); response.setCAS(123456789L);/*from w w w . j a v a 2s . c o m*/ response.setExtras(Unpooled.buffer().writeInt(123)); response.setExtrasLength((byte) 4); ReplicaGetRequest requestMock = mock(ReplicaGetRequest.class); when(requestMock.bucket()).thenReturn(BUCKET); requestQueue.add(requestMock); channel.writeInbound(response); assertEquals(1, eventSink.responseEvents().size()); GetResponse event = (GetResponse) eventSink.responseEvents().get(0).getMessage(); assertEquals(123456789L, event.cas()); assertEquals(123, event.flags()); assertEquals("content", event.content().toString(CHARSET)); assertEquals(BUCKET, event.bucket()); }
From source file:com.couchbase.client.core.endpoint.kv.KeyValueHandlerTest.java
License:Apache License
@Test public void shouldEncodeInsertRequest() { ByteBuf content = Unpooled.copiedBuffer("content", CharsetUtil.UTF_8); InsertRequest request = new InsertRequest("key", content.copy(), "bucket"); request.partition((short) 512); channel.writeOutbound(request);//from w w w . j a v a 2 s. c om FullBinaryMemcacheRequest outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_INSERT, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals(0, outbound.getCAS()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); request = new InsertRequest("key", content.copy(), 10, 0, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_INSERT, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(10, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); request = new InsertRequest("key", content.copy(), 0, 5, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_INSERT, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(5, outbound.getExtras().readInt()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); request = new InsertRequest("key", content.copy(), 30, 99, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_INSERT, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(99, outbound.getExtras().readInt()); assertEquals(30, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); ReferenceCountUtil.release(content); }
From source file:com.couchbase.client.core.endpoint.kv.KeyValueHandlerTest.java
License:Apache License
@Test public void shouldEncodeUpsertRequest() { ByteBuf content = Unpooled.copiedBuffer("content", CharsetUtil.UTF_8); UpsertRequest request = new UpsertRequest("key", content.copy(), "bucket"); request.partition((short) 512); channel.writeOutbound(request);// w ww. ja v a 2 s .com FullBinaryMemcacheRequest outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_UPSERT, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals(0, outbound.getCAS()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); request = new UpsertRequest("key", content.copy(), 10, 0, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_UPSERT, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(10, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); request = new UpsertRequest("key", content.copy(), 0, 5, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_UPSERT, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(5, outbound.getExtras().readInt()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); request = new UpsertRequest("key", content.copy(), 30, 99, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_UPSERT, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(99, outbound.getExtras().readInt()); assertEquals(30, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); ReferenceCountUtil.release(content); }
From source file:com.couchbase.client.core.endpoint.kv.KeyValueHandlerTest.java
License:Apache License
@Test public void shouldEncodeReplaceRequest() { ByteBuf content = Unpooled.copiedBuffer("content", CharsetUtil.UTF_8); ReplaceRequest request = new ReplaceRequest("key", content.copy(), "bucket"); request.partition((short) 512); channel.writeOutbound(request);// ww w . java 2s . c o m FullBinaryMemcacheRequest outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_REPLACE, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals(0, outbound.getCAS()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); request = new ReplaceRequest("key", content.copy(), 0, 10, 0, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_REPLACE, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(10, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); request = new ReplaceRequest("key", content.copy(), 0, 0, 5, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_REPLACE, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(5, outbound.getExtras().readInt()); assertEquals(0, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); request = new ReplaceRequest("key", content.copy(), 0, 30, 99, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", new String(outbound.getKey(), CHARSET)); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(KeyValueHandler.OP_REPLACE, outbound.getOpcode()); assertEquals(8, outbound.getExtrasLength()); assertEquals(99, outbound.getExtras().readInt()); assertEquals(30, outbound.getExtras().readInt()); assertEquals(18, outbound.getTotalBodyLength()); assertEquals("content", outbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(outbound); ReferenceCountUtil.release(content); }
From source file:com.couchbase.client.core.endpoint.kv.KeyValueHandlerTest.java
License:Apache License
@Test public void shouldEncodeReplaceWithCASRequest() { ByteBuf content = Unpooled.copiedBuffer("content", CharsetUtil.UTF_8); ReplaceRequest request = new ReplaceRequest("key", content.copy(), 4234234234L, 30, 99, "bucket"); request.partition((short) 512); channel.writeOutbound(request);//from w w w. j ava 2 s . c o m FullBinaryMemcacheRequest outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertEquals(4234234234L, outbound.getCAS()); ReferenceCountUtil.releaseLater(outbound); ReferenceCountUtil.release(content); }
From source file:com.couchbase.client.core.endpoint.kv.KeyValueHandlerTest.java
License:Apache License
@Test public void shouldDecodeGetBucketConfigResponse() throws Exception { ByteBuf content = Unpooled.copiedBuffer("content", CharsetUtil.UTF_8); FullBinaryMemcacheResponse response = new DefaultFullBinaryMemcacheResponse(KEY, Unpooled.EMPTY_BUFFER, content.copy()); GetBucketConfigRequest requestMock = mock(GetBucketConfigRequest.class); when(requestMock.bucket()).thenReturn("bucket"); when(requestMock.hostname()).thenReturn(InetAddress.getLocalHost()); requestQueue.add(requestMock);/*w w w .j ava 2 s . c o m*/ channel.writeInbound(response); assertEquals(1, eventSink.responseEvents().size()); GetBucketConfigResponse event = (GetBucketConfigResponse) eventSink.responseEvents().get(0).getMessage(); assertEquals(BUCKET, event.bucket()); assertEquals(ResponseStatus.SUCCESS, event.status()); assertEquals(InetAddress.getLocalHost(), event.hostname()); assertEquals("content", event.content().toString(CHARSET)); ReferenceCountUtil.release(content); }