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.endpoint.view.ViewHandlerTest.java

License:Apache License

@Test
public void shouldEncodeLongViewQueryRequestWithPOST() {
    String keys = Resources.read("key_many.json", this.getClass());
    String query = "stale=false&endKey=test";
    ViewQueryRequest request = new ViewQueryRequest("design", "view", true, query, keys, "bucket", "password");
    channel.writeOutbound(request);//w w w .  j av a 2  s  .  com
    DefaultFullHttpRequest outbound = (DefaultFullHttpRequest) channel.readOutbound();
    assertEquals(HttpMethod.POST, outbound.getMethod());
    assertFalse(outbound.getUri().contains("keys="));
    assertTrue(outbound.getUri().endsWith("?stale=false&endKey=test"));
    String content = outbound.content().toString(CharsetUtil.UTF_8);
    assertTrue(content.startsWith("{\"keys\":["));
    assertTrue(content.endsWith("]}"));
    ReferenceCountUtil.releaseLater(outbound);
}

From source file:com.couchbase.client.core.endpoint.view.ViewHandlerTest.java

License:Apache License

@Test
public void shouldUrlEncodeShortKeys() {
    String urlEncodedKeys = "%5B%221%22%2C%222%22%2C%223%22%5D";
    String keys = "[\"1\",\"2\",\"3\"]";
    String query = "stale=false&endKey=test";
    ViewQueryRequest request = new ViewQueryRequest("design", "view", true, query, keys, "bucket", "password");
    channel.writeOutbound(request);//from w w w . j ava2  s .com
    DefaultFullHttpRequest outbound = (DefaultFullHttpRequest) channel.readOutbound();
    String failMsg = outbound.getUri();
    assertEquals(HttpMethod.GET, outbound.getMethod());
    assertTrue(failMsg, outbound.getUri().contains("keys="));
    assertTrue(failMsg, outbound.getUri().endsWith("?stale=false&endKey=test&keys=" + urlEncodedKeys));
    String content = outbound.content().toString(CharsetUtil.UTF_8);
    assertTrue(content.isEmpty());
    ReferenceCountUtil.releaseLater(outbound); //NO-OP since content is empty but still...
}

From source file:com.couchbase.client.core.endpoint.view.ViewHandlerTest.java

License:Apache License

@Test
public void shouldProduceValidUrlIfShortKeysAndNoOtherQueryParam() {
    String urlEncodedKeys = "%5B%221%22%2C%222%22%2C%223%22%5D";
    String keys = "[\"1\",\"2\",\"3\"]";
    String query = "";
    ViewQueryRequest request = new ViewQueryRequest("design", "view", true, query, keys, "bucket", "password");
    channel.writeOutbound(request);//from   ww w . ja v a  2  s.  c o  m
    DefaultFullHttpRequest outbound = (DefaultFullHttpRequest) channel.readOutbound();
    String failMsg = outbound.getUri();
    assertEquals(HttpMethod.GET, outbound.getMethod());
    assertTrue(failMsg, outbound.getUri().endsWith("?keys=" + urlEncodedKeys));
    String content = outbound.content().toString(CharsetUtil.UTF_8);
    assertTrue(content.isEmpty());
    ReferenceCountUtil.releaseLater(outbound); //NO-OP since content is empty but still...
}

From source file:com.couchbase.client.core.endpoint.view.ViewHandlerTest.java

License:Apache License

@Test
public void shouldDoNothingOnNullKeys() {
    String keys = null;//from   w  w  w .j  a  v  a 2 s . c om
    String query = "stale=false&endKey=test";
    ViewQueryRequest request = new ViewQueryRequest("design", "view", true, query, keys, "bucket", "password");
    channel.writeOutbound(request);
    DefaultFullHttpRequest outbound = (DefaultFullHttpRequest) channel.readOutbound();
    assertEquals(HttpMethod.GET, outbound.getMethod());
    assertFalse(outbound.getUri().contains("keys="));
    assertTrue(outbound.getUri().endsWith("?stale=false&endKey=test"));
    String content = outbound.content().toString(CharsetUtil.UTF_8);
    assertTrue(content.isEmpty());
    ReferenceCountUtil.releaseLater(outbound); //NO-OP since content is empty but still...
}

From source file:com.couchbase.client.core.endpoint.view.ViewHandlerTest.java

License:Apache License

@Test
public void shouldDoNothingOnEmptyKeys() {
    String keys = "";
    String query = "stale=false&endKey=test";
    ViewQueryRequest request = new ViewQueryRequest("design", "view", true, query, keys, "bucket", "password");
    channel.writeOutbound(request);//from  w  w w  . j  av  a2  s.  c o m
    DefaultFullHttpRequest outbound = (DefaultFullHttpRequest) channel.readOutbound();
    assertEquals(HttpMethod.GET, outbound.getMethod());
    assertFalse(outbound.getUri().contains("keys="));
    assertTrue(outbound.getUri().endsWith("?stale=false&endKey=test"));
    String content = outbound.content().toString(CharsetUtil.UTF_8);
    assertTrue(content.isEmpty());
    ReferenceCountUtil.releaseLater(outbound); //NO-OP since content is empty but still...
}

From source file:com.couchbase.client.core.endpoint.view.ViewHandlerTest.java

License:Apache License

@Test
public void shouldNotBreakLinesOnLongAuth() {
    String longPassword = "thisIsAveryLongPasswordWhichShouldNotContainLineBreaksAfterEncodingOtherwise"
            + "itWillBreakTheRequestResponseFlowWithTheServer";
    GetDesignDocumentRequest request = new GetDesignDocumentRequest("name", true, "bucket", longPassword);

    channel.writeOutbound(request);//w  w  w.  ja v  a  2 s  .  c  o m
    HttpRequest outbound = (HttpRequest) channel.readOutbound();

    assertEquals(HttpMethod.GET, outbound.getMethod());
    assertEquals(HttpVersion.HTTP_1_1, outbound.getProtocolVersion());
    assertEquals("/bucket/_design/dev_name", outbound.getUri());
    assertTrue(outbound.headers().contains(HttpHeaders.Names.AUTHORIZATION));
    assertNotNull(outbound.headers().get(HttpHeaders.Names.AUTHORIZATION));
    assertEquals("Couchbase Client Mock", outbound.headers().get(HttpHeaders.Names.USER_AGENT));
    ReferenceCountUtil.releaseLater(outbound); //for consistency, but it uses Unpooled
}

From source file:com.couchbase.client.core.endpoint.view.ViewHandlerTest.java

License:Apache License

@Test
public void shouldParseRowWithBracketInIdKeysAndValue() throws Exception {
    String response = Resources.read("query_brackets.json", this.getClass());
    HttpResponse responseHeader = new DefaultHttpResponse(HttpVersion.HTTP_1_1,
            new HttpResponseStatus(200, "OK"));
    HttpContent responseChunk = new DefaultLastHttpContent(Unpooled.copiedBuffer(response, CharsetUtil.UTF_8));

    ViewQueryRequest requestMock = mock(ViewQueryRequest.class);
    queue.add(requestMock);// w ww .j  a  v a2  s .  c o m
    channel.writeInbound(responseHeader, responseChunk);
    latch.await(1, TimeUnit.SECONDS);
    assertEquals(1, firedEvents.size());
    ViewQueryResponse inbound = (ViewQueryResponse) firedEvents.get(0);

    assertTrue(inbound.status().isSuccess());
    assertEquals(200, inbound.responseCode());
    assertEquals("OK", inbound.responsePhrase());

    ByteBuf singleRow = inbound.rows().toBlocking().single(); //single will blow up if not exactly one
    String singleRowData = singleRow.toString(CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(singleRow);
    Map found = null;
    try {
        found = mapper.readValue(singleRowData, Map.class);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Failed parsing JSON on data " + singleRowData);
    }

    assertEquals(3, found.size());
    assertTrue(found.containsKey("id"));
    assertTrue(found.containsKey("key"));
    assertTrue(found.containsKey("value"));
    assertEquals("IdClosing}BracketId", found.get("id"));
    assertEquals(Arrays.asList("KeyClosing}BracketKey", "KeySquareClosing]SquareBracketKey"), found.get("key"));
    assertEquals("ValueClosing}BracketValue", found.get("value"));

    final AtomicInteger called = new AtomicInteger();
    inbound.info().toBlocking().forEach(new Action1<ByteBuf>() {
        @Override
        public void call(ByteBuf byteBuf) {
            called.incrementAndGet();
            assertEquals("{\"total_rows\":1}", byteBuf.toString(CharsetUtil.UTF_8));
            ReferenceCountUtil.releaseLater(byteBuf);
        }
    });
    assertEquals(1, called.get());
}

From source file:com.digitalpetri.opcua.stack.ChunkSerializationTest.java

License:Apache License

@Test(dataProvider = "getAsymmetricSecurityParameters")
public void testAsymmetricMessage(SecurityPolicy securityPolicy, MessageSecurityMode messageSecurity,
        int messageSize) throws Exception {

    logger.info("Asymmetric chunk serialization, securityPolicy={}, messageSecurityMode={}, messageSize={}",
            securityPolicy, messageSecurity, messageSize);

    ChunkEncoder encoder = new ChunkEncoder(parameters);
    ChunkDecoder decoder = new ChunkDecoder(parameters);

    SecureChannel[] channels = generateChannels(securityPolicy, messageSecurity);
    ClientSecureChannel clientChannel = (ClientSecureChannel) channels[0];
    ServerSecureChannel serverChannel = (ServerSecureChannel) channels[1];

    clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE)
            .setIfAbsent(new LongSequence(1L, UInteger.MAX_VALUE));

    LongSequence requestId = clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE).get();

    byte[] messageBytes = new byte[messageSize];
    for (int i = 0; i < messageBytes.length; i++) {
        messageBytes[i] = (byte) i;
    }//  w  ww.  j a  v  a  2 s.c  o  m

    ByteBuf messageBuffer = BufferUtil.buffer().writeBytes(messageBytes);

    List<ByteBuf> chunkBuffers = encoder.encodeAsymmetric(clientChannel, MessageType.OpenSecureChannel,
            messageBuffer, requestId.getAndIncrement());

    ByteBuf decodedBuffer = decoder.decodeAsymmetric(serverChannel, chunkBuffers);

    ReferenceCountUtil.releaseLater(messageBuffer);
    ReferenceCountUtil.releaseLater(decodedBuffer);

    messageBuffer.readerIndex(0);
    assertEquals(decodedBuffer, messageBuffer);
}

From source file:com.digitalpetri.opcua.stack.ChunkSerializationTest.java

License:Apache License

@Test(dataProvider = "getSymmetricSecurityParameters")
public void testSymmetricMessage(SecurityPolicy securityPolicy, MessageSecurityMode messageSecurity,
        int messageSize) throws Exception {

    logger.info("Symmetric chunk serialization, securityPolicy={}, messageSecurityMode={}, messageSize={}",
            securityPolicy, messageSecurity, messageSize);

    ChunkEncoder encoder = new ChunkEncoder(parameters);
    ChunkDecoder decoder = new ChunkDecoder(parameters);

    SecureChannel[] channels = generateChannels(securityPolicy, messageSecurity);
    ClientSecureChannel clientChannel = (ClientSecureChannel) channels[0];
    ServerSecureChannel serverChannel = (ServerSecureChannel) channels[1];

    clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE)
            .setIfAbsent(new LongSequence(1L, UInteger.MAX_VALUE));

    LongSequence requestId = clientChannel.attr(ClientSecureChannel.KEY_REQUEST_ID_SEQUENCE).get();

    byte[] messageBytes = new byte[messageSize];
    for (int i = 0; i < messageBytes.length; i++) {
        messageBytes[i] = (byte) i;
    }// w  ww .  jav  a  2  s . co m

    ByteBuf messageBuffer = BufferUtil.buffer().writeBytes(messageBytes);

    List<ByteBuf> chunkBuffers = encoder.encodeSymmetric(clientChannel, MessageType.SecureMessage,
            messageBuffer, requestId.getAndIncrement());

    ByteBuf decodedBuffer = decoder.decodeSymmetric(serverChannel, chunkBuffers);

    ReferenceCountUtil.releaseLater(messageBuffer);
    ReferenceCountUtil.releaseLater(decodedBuffer);

    messageBuffer.readerIndex(0);
    assertEquals(decodedBuffer, messageBuffer);
}

From source file:com.spotify.netty4.handler.codec.zmtp.ZMQIntegrationTest.java

License:Apache License

private void testReqRep(final ZMTPSocket req, final ZMQ.Socket rep, final String zmqIdentity)
        throws InterruptedException, TimeoutException {

    // Verify that sockets are connected
    verify(handler, timeout(5000)).connected(eq(req), any(ZMTPSocket.ZMTPPeer.class));

    // Verify that the peer identity was correctly received
    verifyPeerIdentity(req, zmqIdentity);

    // Send request
    final ZMTPMessage request = ZMTPMessage.fromUTF8("envelope", "", "hello", "world");
    request.retain();/*from  ww  w.  j a  v  a  2 s  . c  om*/
    req.send(request);

    // Receive request
    final ZMsg receivedRequest = ZMsg.recvMsg(rep);

    // Send reply
    receivedRequest.send(rep, false);

    // Receive reply
    verify(handler, timeout(5000)).message(eq(req), any(ZMTPSocket.ZMTPPeer.class), messageCaptor.capture());
    final ZMTPMessage reply = messageCaptor.getValue();
    ReferenceCountUtil.releaseLater(reply);

    // Verify echo
    assertEquals(request, reply);
    request.release();
}