List of usage examples for io.netty.util ReferenceCountUtil releaseLater
@Deprecated public static <T> T releaseLater(T msg)
From source file:com.couchbase.client.core.endpoint.query.QueryHandlerTest.java
License:Apache License
@Test public void shouldDecodeOneRowResponseWithShortClientID() throws Exception { String response = Resources.read("short_client_id.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)); GenericQueryRequest requestMock = mock(GenericQueryRequest.class); queue.add(requestMock);/*from ww w . jav a 2 s .com*/ channel.writeInbound(responseHeader, responseChunk); latch.await(1, TimeUnit.SECONDS); assertEquals(1, firedEvents.size()); GenericQueryResponse inbound = (GenericQueryResponse) firedEvents.get(0); final AtomicInteger invokeCounter1 = new AtomicInteger(); assertResponse(inbound, true, ResponseStatus.SUCCESS, FAKE_REQUESTID, "123456789", "success", FAKE_SIGNATURE, new Action1<ByteBuf>() { @Override public void call(ByteBuf buf) { invokeCounter1.incrementAndGet(); String response = buf.toString(CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(buf); try { Map found = mapper.readValue(response, Map.class); assertEquals(12, found.size()); assertEquals("San Francisco", found.get("city")); assertEquals("United States", found.get("country")); Map geo = (Map) found.get("geo"); assertNotNull(geo); assertEquals(3, geo.size()); assertEquals("ROOFTOP", geo.get("accuracy")); } catch (IOException e) { assertFalse(true); } } }, new Action1<ByteBuf>() { @Override public void call(ByteBuf buf) { fail("no error expected"); } }, expectedMetricsCounts(0, 1)); assertEquals(1, invokeCounter1.get()); }
From source file:com.couchbase.client.core.endpoint.query.QueryHandlerTest.java
License:Apache License
@Test public void shouldDecodeOneRowResponseWithNoClientID() throws Exception { String response = Resources.read("no_client_id.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)); GenericQueryRequest requestMock = mock(GenericQueryRequest.class); queue.add(requestMock);/*from w w w . j av a 2s . co m*/ channel.writeInbound(responseHeader, responseChunk); latch.await(1, TimeUnit.SECONDS); assertEquals(1, firedEvents.size()); GenericQueryResponse inbound = (GenericQueryResponse) firedEvents.get(0); final AtomicInteger invokeCounter1 = new AtomicInteger(); assertResponse(inbound, true, ResponseStatus.SUCCESS, FAKE_REQUESTID, "", "success", FAKE_SIGNATURE, new Action1<ByteBuf>() { @Override public void call(ByteBuf buf) { invokeCounter1.incrementAndGet(); String response = buf.toString(CharsetUtil.UTF_8); try { Map found = mapper.readValue(response, Map.class); assertEquals(12, found.size()); assertEquals("San Francisco", found.get("city")); assertEquals("United States", found.get("country")); Map geo = (Map) found.get("geo"); assertNotNull(geo); assertEquals(3, geo.size()); assertEquals("ROOFTOP", geo.get("accuracy")); } catch (IOException e) { assertFalse(true); } ReferenceCountUtil.releaseLater(buf); } }, new Action1<ByteBuf>() { @Override public void call(ByteBuf buf) { fail("no error expected"); } }, expectedMetricsCounts(0, 1)); assertEquals(1, invokeCounter1.get()); }
From source file:com.couchbase.client.core.endpoint.query.QueryHandlerTest.java
License:Apache License
@Test public void testBigChunkedResponseWithEscapedBackslashInRowObject() throws Exception { String response = Resources.read("chunkedResponseWithDoubleBackslashes.txt", this.getClass()); String[] chunks = response.split("(?m)^[0-9a-f]+"); HttpResponse responseHeader = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(200, "OK")); responseHeader.headers().add("Transfer-Encoding", "chunked"); responseHeader.headers().add("Content-Type", "application/json; version=1.0.0"); Object[] httpChunks = new Object[chunks.length]; httpChunks[0] = responseHeader;/*from ww w . j a v a 2 s .c o m*/ for (int i = 1; i < chunks.length; i++) { String chunk = chunks[i]; if (i == chunks.length - 1) { httpChunks[i] = new DefaultLastHttpContent(Unpooled.copiedBuffer(chunk, CharsetUtil.UTF_8)); } else { httpChunks[i] = new DefaultHttpContent(Unpooled.copiedBuffer(chunk, CharsetUtil.UTF_8)); } } Subject<CouchbaseResponse, CouchbaseResponse> obs = AsyncSubject.create(); GenericQueryRequest requestMock = mock(GenericQueryRequest.class); when(requestMock.observable()).thenReturn(obs); queue.add(requestMock); channel.writeInbound(httpChunks); GenericQueryResponse inbound = (GenericQueryResponse) obs.timeout(1, TimeUnit.SECONDS).toBlocking().last(); final AtomicInteger found = new AtomicInteger(0); final AtomicInteger errors = new AtomicInteger(0); inbound.rows().timeout(5, TimeUnit.SECONDS).toBlocking().forEach(new Action1<ByteBuf>() { @Override public void call(ByteBuf byteBuf) { int rowNumber = found.incrementAndGet(); String content = byteBuf.toString(CharsetUtil.UTF_8); byteBuf.release(); assertNotNull(content); assertFalse(content.isEmpty()); } }); inbound.errors().timeout(5, TimeUnit.SECONDS).toBlocking().forEach(new Action1<ByteBuf>() { @Override public void call(ByteBuf buf) { buf.release(); errors.incrementAndGet(); } }); //ignore signature ReferenceCountUtil.release(inbound.signature().timeout(5, TimeUnit.SECONDS).toBlocking().single()); String status = inbound.queryStatus().timeout(5, TimeUnit.SECONDS).toBlocking().single(); List<ByteBuf> metricList = inbound.info().timeout(1, TimeUnit.SECONDS).toList().toBlocking().single(); assertEquals(1, metricList.size()); ByteBuf metricsBuf = metricList.get(0); ReferenceCountUtil.releaseLater(metricsBuf); Map metrics = mapper.readValue(metricsBuf.toString(CharsetUtil.UTF_8), Map.class); assertEquals("success", status); assertEquals(5, found.get()); assertEquals(0, errors.get()); assertEquals(found.get(), metrics.get("resultCount")); }
From source file:com.couchbase.client.core.endpoint.view.ViewHandlerTest.java
License:Apache License
@Test public void shouldEncodeGetDesignDocumentRequest() { GetDesignDocumentRequest request = new GetDesignDocumentRequest("name", true, "bucket", "password"); channel.writeOutbound(request);/*from www .j a va2 s . co 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)); assertEquals("Couchbase Client Mock", outbound.headers().get(HttpHeaders.Names.USER_AGENT)); assertTrue(outbound.headers().contains(HttpHeaders.Names.HOST)); 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 shouldDecodeSuccessfulGetDesignDocumentResponse() throws Exception { String response = Resources.read("designdoc_success.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)); GetDesignDocumentRequest requestMock = mock(GetDesignDocumentRequest.class); when(requestMock.name()).thenReturn("name"); when(requestMock.development()).thenReturn(true); queue.add(requestMock);/*from w w w. j ava2s .c o m*/ channel.writeInbound(responseHeader, responseChunk); latch.await(1, TimeUnit.SECONDS); assertEquals(1, firedEvents.size()); GetDesignDocumentResponse inbound = (GetDesignDocumentResponse) firedEvents.get(0); assertTrue(inbound.status().isSuccess()); assertEquals("name", inbound.name()); assertEquals(true, inbound.development()); assertEquals(response, inbound.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(inbound); }
From source file:com.couchbase.client.core.endpoint.view.ViewHandlerTest.java
License:Apache License
@Test public void shouldEncodeViewQueryRequest() { ViewQueryRequest request = new ViewQueryRequest("design", "view", true, "query", null, "bucket", "password"); channel.writeOutbound(request);//w w w . j ava 2 s .com HttpRequest outbound = (HttpRequest) channel.readOutbound(); assertEquals(HttpMethod.GET, outbound.getMethod()); assertEquals(HttpVersion.HTTP_1_1, outbound.getProtocolVersion()); assertEquals("/bucket/_design/dev_design/_view/view?query", outbound.getUri()); assertTrue(outbound.headers().contains(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 shouldDecodeWithDebugViewQueryResponse() throws Exception { String response = Resources.read("query_debug.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 w w. j a v a2 s . co 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(5, countAndRelease(inbound.rows())); inbound.info().toBlocking().forEach(new Action1<ByteBuf>() { @Override public void call(ByteBuf byteBuf) { try { Map found = mapper.readValue(byteBuf.toString(CharsetUtil.UTF_8), Map.class); assertEquals(2, found.size()); assertTrue(found.containsKey("debug_info")); assertTrue(found.containsKey("total_rows")); } catch (IOException e) { e.printStackTrace(); assertFalse(true); } ReferenceCountUtil.releaseLater(byteBuf); } }); }
From source file:com.couchbase.client.core.endpoint.view.ViewHandlerTest.java
License:Apache License
@Test public void shouldDecodeEmptyViewQueryResponse() throws Exception { String response = Resources.read("query_empty.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);/*ww w .j av a 2s . 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()); assertTrue(inbound.rows().toList().toBlocking().single().isEmpty()); final AtomicInteger called = new AtomicInteger(); inbound.info().toBlocking().forEach(new Action1<ByteBuf>() { @Override public void call(ByteBuf byteBuf) { called.incrementAndGet(); assertEquals("{\"total_rows\":7303}", byteBuf.toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(byteBuf); } }); assertEquals(1, called.get()); }
From source file:com.couchbase.client.core.endpoint.view.ViewHandlerTest.java
License:Apache License
@Test public void shouldDecodeOneViewQueryResponse() throws Exception { String response = Resources.read("query_one.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);/*from w w w . j a v a 2 s . com*/ 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()); final AtomicInteger calledRow = new AtomicInteger(); inbound.rows().toBlocking().forEach(new Action1<ByteBuf>() { @Override public void call(ByteBuf byteBuf) { calledRow.incrementAndGet(); try { Map found = mapper.readValue(byteBuf.toString(CharsetUtil.UTF_8), Map.class); assertEquals(3, found.size()); assertTrue(found.containsKey("id")); assertTrue(found.containsKey("key")); assertTrue(found.containsKey("value")); } catch (IOException e) { e.printStackTrace(); assertFalse(true); } ReferenceCountUtil.releaseLater(byteBuf); } }); assertEquals(1, calledRow.get()); final AtomicInteger called = new AtomicInteger(); inbound.info().toBlocking().forEach(new Action1<ByteBuf>() { @Override public void call(ByteBuf byteBuf) { called.incrementAndGet(); assertEquals("{\"total_rows\":7303}", byteBuf.toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(byteBuf); } }); assertEquals(1, called.get()); }
From source file:com.couchbase.client.core.endpoint.view.ViewHandlerTest.java
License:Apache License
@Test public void shouldDecodeManyViewQueryResponse() throws Exception { String response = Resources.read("query_many.json", this.getClass()); HttpResponse responseHeader = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(200, "OK")); HttpContent responseChunk1 = new DefaultHttpContent( Unpooled.copiedBuffer(response.substring(0, 500), CharsetUtil.UTF_8)); HttpContent responseChunk2 = new DefaultHttpContent( Unpooled.copiedBuffer(response.substring(500, 1234), CharsetUtil.UTF_8)); HttpContent responseChunk3 = new DefaultLastHttpContent( Unpooled.copiedBuffer(response.substring(1234), CharsetUtil.UTF_8)); ViewQueryRequest requestMock = mock(ViewQueryRequest.class); queue.add(requestMock);//from w w w . ja v a 2 s. co m channel.writeInbound(responseHeader, responseChunk1, responseChunk2, responseChunk3); latch.await(1, TimeUnit.SECONDS); assertEquals(1, firedEvents.size()); ViewQueryResponse inbound = (ViewQueryResponse) firedEvents.get(0); assertTrue(inbound.status().isSuccess()); final AtomicInteger calledRow = new AtomicInteger(); inbound.rows().toBlocking().forEach(new Action1<ByteBuf>() { @Override public void call(ByteBuf byteBuf) { calledRow.incrementAndGet(); try { Map found = mapper.readValue(byteBuf.toString(CharsetUtil.UTF_8), Map.class); assertEquals(3, found.size()); assertTrue(found.containsKey("id")); assertTrue(found.containsKey("key")); assertTrue(found.containsKey("value")); } catch (IOException e) { e.printStackTrace(); assertFalse(true); } ReferenceCountUtil.releaseLater(byteBuf); } }); assertEquals(500, calledRow.get()); final AtomicInteger called = new AtomicInteger(); inbound.info().toBlocking().forEach(new Action1<ByteBuf>() { @Override public void call(ByteBuf byteBuf) { called.incrementAndGet(); assertEquals("{\"total_rows\":7303}", byteBuf.toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(byteBuf); } }); assertEquals(1, called.get()); }