List of usage examples for io.netty.util ReferenceCountUtil release
public static boolean release(Object msg)
From source file:com.couchbase.client.core.cluster.ObserveTest.java
License:Apache License
/** * Test that a previously inserted document is replicated to at least one replica. * * This test assumes a cluster setup where at least one replica is configured on the bucket and more or equal * to two nodes are available in order to correctly complete the test. *//* www . ja v a 2 s. c om*/ @Test public void shouldObserveReplicateToOne() { Assume.assumeTrue(numberOfReplicas >= 1 && numberOfNodes >= 2); InsertRequest request = new InsertRequest("persInsDoc2", Unpooled.copiedBuffer("test", CharsetUtil.UTF_8), bucket()); InsertResponse response = cluster().<InsertResponse>send(request).toBlocking().single(); assertTrue(response.status().isSuccess()); ReferenceCountUtil.release(response); Boolean observeSuccess = Observe .call(cluster(), bucket(), "persInsDoc2", response.cas(), false, Observe.PersistTo.NONE, Observe.ReplicateTo.ONE, BestEffortRetryStrategy.INSTANCE) .timeout(5, TimeUnit.SECONDS).toBlocking().single(); assertTrue(observeSuccess); }
From source file:com.couchbase.client.core.cluster.ObserveTest.java
License:Apache License
/** * Test that both persistence and replication are working against a previously inserted doc. * * This test assumes a cluster setup where at least one replica is configured on the bucket and more or equal * to two nodes are available in order to correctly complete the test. */// ww w. j ava 2s. c o m @Test public void shouldObserveReplicateToOneAndPersistToMaster() { Assume.assumeTrue(numberOfReplicas >= 1 && numberOfNodes >= 2); InsertRequest request = new InsertRequest("persInsDoc3", Unpooled.copiedBuffer("test", CharsetUtil.UTF_8), bucket()); InsertResponse response = cluster().<InsertResponse>send(request).toBlocking().single(); assertTrue(response.status().isSuccess()); ReferenceCountUtil.release(response); Boolean observeSuccess = Observe .call(cluster(), bucket(), "persInsDoc3", response.cas(), false, Observe.PersistTo.MASTER, Observe.ReplicateTo.ONE, BestEffortRetryStrategy.INSTANCE) .timeout(5, TimeUnit.SECONDS).toBlocking().single(); assertTrue(observeSuccess); }
From source file:com.couchbase.client.core.cluster.ObserveTest.java
License:Apache License
/** * Test the persisting requirement on any node (either master or replica), whoever is first. *///from w w w .j a v a 2 s .c o m @Test public void shouldObservePersistToOne() { InsertRequest request = new InsertRequest("persInsDoc4", Unpooled.copiedBuffer("test", CharsetUtil.UTF_8), bucket()); InsertResponse response = cluster().<InsertResponse>send(request).toBlocking().single(); assertTrue(response.status().isSuccess()); ReferenceCountUtil.release(response); Boolean observeSuccess = Observe .call(cluster(), bucket(), "persInsDoc4", response.cas(), false, Observe.PersistTo.ONE, Observe.ReplicateTo.NONE, BestEffortRetryStrategy.INSTANCE) .timeout(5, TimeUnit.SECONDS).toBlocking().single(); assertTrue(observeSuccess); }
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldHaveIndividualResultsOnSparseMultiLookup() { String expected = "EXIST(sub): SUCCESS\n" + "EXIST(sub2): SUBDOC_PATH_NOT_FOUND\n" + "GET(sub): SUCCESS = {\"value\": \"subStringValue\",\"array\": [\"array1\", 2, true]}\n" + "GET(sub.array[1]): SUCCESS = 2\n" + "GET(sub2): SUBDOC_PATH_NOT_FOUND\n"; SubMultiLookupRequest request = new SubMultiLookupRequest(testSubKey, bucket(), new LookupCommand(Lookup.EXIST, "sub"), new LookupCommand(Lookup.EXIST, "sub2"), new LookupCommand(Lookup.GET, "sub"), new LookupCommand(Lookup.GET, "sub.array[1]"), new LookupCommand(Lookup.GET, "sub2")); MultiLookupResponse response = cluster().<MultiLookupResponse>send(request).toBlocking().single(); assertEquals(Unpooled.EMPTY_BUFFER, response.content()); StringBuilder body = new StringBuilder(); for (MultiResult r : response.responses()) { body.append(r.toString()).append('\n'); ReferenceCountUtil.release(r.value()); }// w w w . j a v a 2 s . co m assertTrue(response.cas() != 0); assertEquals(ResponseStatus.SUBDOC_MULTI_PATH_FAILURE, response.status()); assertEquals(expected, body.toString()); }
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldHaveIndividualResultsOnFullySuccessfulMultiLookup() { String expected = "EXIST(sub): SUCCESS\n" + "GET(sub.array[1]): SUCCESS = 2\n"; SubMultiLookupRequest request = new SubMultiLookupRequest(testSubKey, bucket(), new LookupCommand(Lookup.EXIST, "sub"), new LookupCommand(Lookup.GET, "sub.array[1]")); MultiLookupResponse response = cluster().<MultiLookupResponse>send(request).toBlocking().single(); assertEquals(Unpooled.EMPTY_BUFFER, response.content()); StringBuilder body = new StringBuilder(); for (MultiResult r : response.responses()) { body.append(r.toString()).append('\n'); ReferenceCountUtil.release(r.value()); }//from ww w .j a v a 2 s .co m assertTrue(response.cas() != 0); assertEquals(ResponseStatus.SUCCESS, response.status()); assertEquals(expected, body.toString()); }
From source file:com.couchbase.client.core.endpoint.binary.BinaryHandlerTest.java
License:Open Source 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 ww. j a va2 s. co m FullBinaryMemcacheRequest outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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)); request = new InsertRequest("key", content.copy(), 10, 0, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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)); request = new InsertRequest("key", content.copy(), 0, 5, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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)); request = new InsertRequest("key", content.copy(), 30, 99, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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.release(content); }
From source file:com.couchbase.client.core.endpoint.binary.BinaryHandlerTest.java
License:Open Source 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);//www .j ava 2s . c om FullBinaryMemcacheRequest outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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)); request = new UpsertRequest("key", content.copy(), 10, 0, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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)); request = new UpsertRequest("key", content.copy(), 0, 5, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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)); request = new UpsertRequest("key", content.copy(), 30, 99, "bucket"); request.partition((short) 512); channel.writeOutbound(request); outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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.release(content); }
From source file:com.couchbase.client.core.endpoint.binary.BinaryHandlerTest.java
License:Open Source 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);//from w w w . j a v a2s . c o m FullBinaryMemcacheRequest outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertNotNull(outbound); assertEquals("key", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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)); 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", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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)); 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", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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)); 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", outbound.getKey()); assertEquals("key".length(), outbound.getKeyLength()); assertEquals(512, outbound.getReserved()); assertEquals(BinaryHandler.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.release(content); }
From source file:com.couchbase.client.core.endpoint.binary.BinaryHandlerTest.java
License:Open Source 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);// ww w .j a v a 2s . co m FullBinaryMemcacheRequest outbound = (FullBinaryMemcacheRequest) channel.readOutbound(); assertEquals(4234234234L, outbound.getCAS()); ReferenceCountUtil.release(content); }
From source file:com.couchbase.client.core.endpoint.binary.BinaryHandlerTest.java
License:Open Source License
@Test public void shouldDecodeGetSuccessResponse() throws Exception { ByteBuf content = Unpooled.copiedBuffer("content", CharsetUtil.UTF_8); FullBinaryMemcacheResponse response = new DefaultFullBinaryMemcacheResponse("key", Unpooled.EMPTY_BUFFER, content.copy());//from w w w. j av a 2 s . c o m response.setCAS(123456789L); response.setExtras(Unpooled.buffer().writeInt(123)); response.setExtrasLength((byte) 4); GetRequest requestMock = mock(GetRequest.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); }