Example usage for io.netty.util ReferenceCountUtil releaseLater

List of usage examples for io.netty.util ReferenceCountUtil releaseLater

Introduction

In this page you can find the example usage for io.netty.util ReferenceCountUtil releaseLater.

Prototype

@Deprecated
public static <T> T releaseLater(T msg) 

Source Link

Document

Schedules the specified object to be released when the caller thread terminates.

Usage

From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java

License:Apache License

@Test
public void shouldReturnDeltaRangeOnCounterDeltaZero() {
    String path = "counter";
    long delta = 0L;

    SubCounterRequest request = new SubCounterRequest(testSubKey, path, delta, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();
    ReferenceCountUtil.releaseLater(response.content());
    String result = response.content().toString(CharsetUtil.UTF_8);

    assertEquals(0, result.length());//from w  w  w  .  j  a  v a 2s .  co  m
    assertEquals(ResponseStatus.SUBDOC_DELTA_RANGE, response.status());
}

From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java

License:Apache License

@Test
public void shouldReturnDeltaRangeOnCounterDeltaOverflow() {
    String path = "counter";
    long prepareOverFlow = 1L;
    long delta = Long.MAX_VALUE;

    //first request will bring the value to +1
    SubCounterRequest request = new SubCounterRequest(testSubKey, path, prepareOverFlow, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();
    ReferenceCountUtil.releaseLater(response.content());
    String result = response.content().toString(CharsetUtil.UTF_8);

    assertEquals("1", result);

    //second request will overflow
    request = new SubCounterRequest(testSubKey, path, delta, bucket());
    response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();
    ReferenceCountUtil.releaseLater(response.content());
    result = response.content().toString(CharsetUtil.UTF_8);

    assertEquals(result, 0, result.length());
    /*//  w  w w  .ja v  a  2 s .  c o  m
     * Was SUBDOC_DELTA_RANGE, but changed to VALUE_CANTINSERT between 4.5 dp and BETA.
     * See https://issues.couchbase.com/browse/JCBC-931, https://issues.couchbase.com/browse/MB-18169
     */
    assertEquals(ResponseStatus.SUBDOC_VALUE_CANTINSERT, response.status());
}

From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java

License:Apache License

@Test
public void shouldReturnDeltaRangeOnCounterDeltaUnderflow() {
    String path = "counter";
    long prepareUnderflow = -1L;
    long delta = Long.MIN_VALUE;

    //first request will bring the value to -1
    SubCounterRequest request = new SubCounterRequest(testSubKey, path, prepareUnderflow, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();
    ReferenceCountUtil.releaseLater(response.content());
    String result = response.content().toString(CharsetUtil.UTF_8);

    assertEquals("-1", result);

    //second request will underflow
    request = new SubCounterRequest(testSubKey, path, delta, bucket());
    response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();
    ReferenceCountUtil.releaseLater(response.content());
    result = response.content().toString(CharsetUtil.UTF_8);

    assertEquals(result, 0, result.length());
    assertEquals(ResponseStatus.SUBDOC_DELTA_RANGE, response.status());
}

From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java

License:Apache License

@Test
public void shouldApplyAllMultiMutationsAndReleaseCommandFragments() {
    ByteBuf counterFragment = Unpooled.copiedBuffer("-404", CharsetUtil.UTF_8);
    counterFragment.retain(2);/* www .  j  a  va 2 s  . c  o m*/

    ByteBuf stringFragment = Unpooled.copiedBuffer("\"mutated\"", CharsetUtil.UTF_8);
    stringFragment.retain(2);

    ByteBuf arrayInsertedFragment = Unpooled.copiedBuffer("\"inserted\"", CharsetUtil.UTF_8);
    ByteBuf arrayFirstFragment = Unpooled.copiedBuffer("\"first\"", CharsetUtil.UTF_8);
    ByteBuf arrayLastFragment = Unpooled.copiedBuffer("\"last\"", CharsetUtil.UTF_8);
    ByteBuf uniqueFragment = Unpooled.copiedBuffer("\"unique\"", CharsetUtil.UTF_8);

    MutationCommand[] commands = new MutationCommand[] {
            new MutationCommand(Mutation.COUNTER, "counter", counterFragment, false),
            new MutationCommand(Mutation.COUNTER, "another.counter", counterFragment, true),
            new MutationCommand(Mutation.COUNTER, "another.counter", counterFragment, false),
            new MutationCommand(Mutation.DICT_ADD, "sub.value2", stringFragment),
            new MutationCommand(Mutation.DICT_UPSERT, "sub.value3", stringFragment),
            new MutationCommand(Mutation.REPLACE, "value", stringFragment),
            new MutationCommand(Mutation.ARRAY_INSERT, "sub.array[1]", arrayInsertedFragment),
            new MutationCommand(Mutation.ARRAY_PUSH_FIRST, "sub.array", arrayFirstFragment),
            new MutationCommand(Mutation.ARRAY_PUSH_LAST, "sub.array", arrayLastFragment),
            new MutationCommand(Mutation.ARRAY_ADD_UNIQUE, "sub.array", uniqueFragment),
            new MutationCommand(Mutation.DELETE, "sub.value") };

    SubMultiMutationRequest request = new SubMultiMutationRequest(testSubKey, bucket(), commands);
    MultiMutationResponse response = cluster().<MultiMutationResponse>send(request).toBlocking().single();
    assertEquals(ResponseStatus.SUCCESS, response.status());
    assertEquals(Unpooled.EMPTY_BUFFER, response.content());
    assertEquals(-1, response.firstErrorIndex());
    assertEquals(ResponseStatus.SUCCESS, response.firstErrorStatus());

    assertEquals(0, stringFragment.refCnt());
    assertEquals(0, counterFragment.refCnt());
    assertEquals(0, arrayInsertedFragment.refCnt());
    assertEquals(0, arrayFirstFragment.refCnt());
    assertEquals(0, arrayLastFragment.refCnt());
    assertEquals(0, uniqueFragment.refCnt());

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < commands.length; i++) {
        MutationCommand command = commands[i];
        MultiResult result = response.responses().get(i);
        assertEquals(command.path(), result.path());
        assertEquals(command.mutation(), result.operation());

        sb.append('\n').append(result);
        ReferenceCountUtil.releaseLater(result.value());
    }
    if (sb.length() > 1)
        sb.deleteCharAt(0);

    String expectedResponse = "COUNTER(counter): SUCCESS = -404" + "\nCOUNTER(another.counter): SUCCESS = -404"
            + "\nCOUNTER(another.counter): SUCCESS = -808" +
            //values below have no content
            "\nDICT_ADD(sub.value2): SUCCESS" + "\nDICT_UPSERT(sub.value3): SUCCESS"
            + "\nREPLACE(value): SUCCESS" + "\nARRAY_INSERT(sub.array[1]): SUCCESS"
            + "\nARRAY_PUSH_FIRST(sub.array): SUCCESS" + "\nARRAY_PUSH_LAST(sub.array): SUCCESS"
            + "\nARRAY_ADD_UNIQUE(sub.array): SUCCESS" + "\nDELETE(sub.value): SUCCESS";
    assertEquals(expectedResponse, sb.toString());

    String expected = "{\"value\":\"mutated\"," + "\"sub\":{" +
    //                "\"value\":\"subStringValue\"," + //DELETED
            "\"array\":[\"first\",\"array1\",\"inserted\",2,true,\"last\",\"unique\"]"
            + ",\"value2\":\"mutated\"" + ",\"value3\":\"mutated\"}," + "\"counter\":-404,"
            + "\"another\":{\"counter\":-808}}";
    assertMutation(testSubKey, expected);
}

From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java

License:Apache License

/**
 * Helper method to get a whole document and assert its content against a subdoc mutation.
 * @param key the document ID.//from ww  w . j  a  v  a 2 s. com
 * @param expected the JSON content that is expected.
 */
private void assertMutation(String key, String expected) {
    //assert the mutation
    GetResponse finalState = cluster().<GetResponse>send(new GetRequest(key, bucket())).toBlocking().single();
    ReferenceCountUtil.releaseLater(finalState.content());
    String actual = finalState.content().toString(CharsetUtil.UTF_8);
    //work around MB-17143 and generally fact that no order/space guarantees
    // are made for JSON production by the subdoc API.
    try {
        Map actualMap = JSON.readValue(actual, Map.class);
        Map expectedMap = JSON.readValue(expected, Map.class);
        assertEquals("Expected mutation on " + key + " was not observed", expectedMap, actualMap);
    } catch (IOException e) {
        fail("Failure to compare JSON contents: " + e.toString());
    }
}

From source file:com.couchbase.client.core.cluster.ViewMessageTest.java

License:Apache License

@Test
public void shouldQueryNonExistentView() {
    ViewQueryResponse single = cluster().<ViewQueryResponse>send(
            new ViewQueryRequest("designdoc", "foobar", false, "debug=true", null, bucket(), password()))
            .toBlocking().single();/*from ww w  . ja va 2 s.  co  m*/
    assertEquals(ResponseStatus.NOT_EXISTS, single.status());
    String error = single.error().toBlocking().singleOrDefault(null);
    assertNotNull(error);

    single.rows().toBlocking().forEach(new Action1<ByteBuf>() {
        @Override
        public void call(ByteBuf byteBuf) {
            ReferenceCountUtil.releaseLater(byteBuf);
        }
    });
}

From source file:com.couchbase.client.core.endpoint.config.ConfigHandlerTest.java

License:Apache License

@Test
public void shouldDecodeInitialBucketStreamingResponse() throws Exception {
    HttpResponse responseHeader = new DefaultHttpResponse(HttpVersion.HTTP_1_1,
            new HttpResponseStatus(200, "OK"));

    BucketStreamingRequest requestMock = mock(BucketStreamingRequest.class);
    requestQueue.add(requestMock);//from w  w  w  .  j a  v  a2s.  c  o m
    channel.writeInbound(responseHeader);

    assertEquals(1, eventSink.responseEvents().size());
    BucketStreamingResponse event = (BucketStreamingResponse) eventSink.responseEvents().get(0).getMessage();

    assertEquals(ResponseStatus.SUCCESS, event.status());
    assertNotNull(event.configs());
    assertNotNull(event.host());
    assertEquals(0, requestQueue.size());
    ReferenceCountUtil.releaseLater(event);
    ReferenceCountUtil.releaseLater(responseHeader);
}

From source file:com.couchbase.client.core.endpoint.config.ConfigHandlerTest.java

License:Apache License

@Test
public void shouldDecodeFailingInitialBucketStreamingResponse() throws Exception {
    HttpResponse responseHeader = new DefaultHttpResponse(HttpVersion.HTTP_1_1,
            new HttpResponseStatus(404, "Object Not Found"));

    BucketStreamingRequest requestMock = mock(BucketStreamingRequest.class);
    requestQueue.add(requestMock);/*from  w  w w.  j  av  a 2 s .c om*/
    channel.writeInbound(responseHeader);

    assertEquals(1, eventSink.responseEvents().size());
    BucketStreamingResponse event = (BucketStreamingResponse) eventSink.responseEvents().get(0).getMessage();

    assertEquals(ResponseStatus.NOT_EXISTS, event.status());
    assertNull(event.configs());
    assertNotNull(event.host());
    assertEquals(0, requestQueue.size());
    ReferenceCountUtil.releaseLater(responseHeader);
    ReferenceCountUtil.releaseLater(event);

}

From source file:com.couchbase.client.core.endpoint.dcp.DCPHandlerTest.java

License:Apache License

@Test
public void shouldEncodeStreamRequestRequest() {
    StreamRequestRequest request = new StreamRequestRequest((short) 1234, (long) 5678, (long) 9012, (long) 3456,
            (long) 7890, (long) 12345, null, null, null);

    channel.writeOutbound(request);//from w ww . j a  v  a2 s .c  om
    BinaryMemcacheRequest outbound = (BinaryMemcacheRequest) channel.readOutbound();
    assertNotNull(outbound);
    assertEquals(DCPHandler.OP_STREAM_REQUEST, outbound.getOpcode());
    assertEquals(0, outbound.getKeyLength());
    assertEquals(48, outbound.getTotalBodyLength());
    assertEquals(1234, outbound.getReserved());
    assertEquals(48, outbound.getExtrasLength());
    assertEquals(0, outbound.getExtras().readInt()); // flags
    assertEquals(0, outbound.getExtras().readInt()); // reserved
    assertEquals(9012, outbound.getExtras().readLong()); // start sequence number
    assertEquals(3456, outbound.getExtras().readLong()); // end sequence number
    assertEquals(5678, outbound.getExtras().readLong()); // vbucket UUID
    assertEquals(7890, outbound.getExtras().readLong()); // snapshot start sequence number
    assertEquals(12345, outbound.getExtras().readLong()); // snapshot end sequence number

    ReferenceCountUtil.releaseLater(outbound);
}

From source file:com.couchbase.client.core.endpoint.kv.KeyValueHandlerTest.java

License:Apache License

@Test
public void shouldEncodeGet() {
    String id = "key";
    GetRequest request = new GetRequest(id, BUCKET);
    request.partition((short) 1);

    channel.writeOutbound(request);//from  w  w  w  . jav a  2s .co  m
    BinaryMemcacheRequest outbound = (BinaryMemcacheRequest) channel.readOutbound();
    assertNotNull(outbound);
    assertEquals(id, new String(outbound.getKey(), CHARSET));
    assertEquals(id.length(), outbound.getKeyLength());
    assertEquals(id.length(), outbound.getTotalBodyLength());
    assertEquals(1, outbound.getReserved());
    assertEquals(KeyValueHandler.OP_GET, outbound.getOpcode());
    assertEquals(0, outbound.getExtrasLength());
    assertEquals(request.opaque(), outbound.getOpaque());
    ReferenceCountUtil.releaseLater(outbound);
}