use of io.netty.handler.codec.http.HttpContent in project jocean-http by isdom.
the class DefaultHttpTradeTestCase method testTradeForMultiSubscribeRequestOnlyOneToSource.
@Test
public final void testTradeForMultiSubscribeRequestOnlyOneToSource() {
final DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
final HttpContent[] req_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final EmbeddedChannel channel = new EmbeddedChannel();
final HttpTrade trade = new DefaultHttpTrade(channel);
// trade.inboundHolder().setMaxBlockSize(-1);
final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber1 = new TestSubscriber<>();
trade.inbound().subscribe(reqSubscriber1);
final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber2 = new TestSubscriber<>();
trade.inbound().subscribe(reqSubscriber2);
final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber3 = new TestSubscriber<>();
trade.inbound().subscribe(reqSubscriber3);
writeToInboundAndFlush(channel, request);
writeToInboundAndFlush(channel, req_contents[0]);
reqSubscriber1.assertValueCount(2);
reqSubscriber1.assertValues(RxNettys.<HttpObject>wrap4release(request), RxNettys.<HttpObject>wrap4release(req_contents[0]));
reqSubscriber2.assertValueCount(2);
reqSubscriber2.assertValues(RxNettys.<HttpObject>wrap4release(request), RxNettys.<HttpObject>wrap4release(req_contents[0]));
reqSubscriber3.assertValueCount(2);
reqSubscriber3.assertValues(RxNettys.<HttpObject>wrap4release(request), RxNettys.<HttpObject>wrap4release(req_contents[0]));
}
use of io.netty.handler.codec.http.HttpContent in project jocean-http by isdom.
the class DefaultHttpTradeTestCase method testTradeForRequestAndContentsSourceAndDumpFullRequests.
@Test
public final void testTradeForRequestAndContentsSourceAndDumpFullRequests() throws IOException {
final DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
final HttpContent[] req_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final EmbeddedChannel channel = new EmbeddedChannel();
final HttpTrade trade = new DefaultHttpTrade(channel);
Observable.<HttpObject>concat(Observable.<HttpObject>just(request), Observable.<HttpObject>from(req_contents), Observable.<HttpObject>just(LastHttpContent.EMPTY_LAST_CONTENT)).map(obj -> writeToInboundAndFlush(channel, obj)).last().toBlocking().single().syncUninterruptibly();
callByteBufHolderBuilderOnceAndAssertDumpContentAndRefCnt(trade.inbound().compose(RxNettys.message2fullreq(trade)).toBlocking().single().unwrap(), REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
callByteBufHolderBuilderOnceAndAssertDumpContentAndRefCnt(trade.inbound().compose(RxNettys.message2fullreq(trade)).toBlocking().single().unwrap(), REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
}
use of io.netty.handler.codec.http.HttpContent in project jocean-http by isdom.
the class DefaultHttpTradeTestCase method testTradeForMultiSubscribeRequestOnlyOneToSource2.
// 3 subscriber subscribe inbound request at different time,
// so push with different httpobject
@Test
public final void testTradeForMultiSubscribeRequestOnlyOneToSource2() {
final DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
final HttpContent[] req_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final EmbeddedChannel channel = new EmbeddedChannel();
final HttpTrade trade = new DefaultHttpTrade(channel);
// trade.inboundHolder().setMaxBlockSize(-1);
final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber1 = new TestSubscriber<>();
trade.inbound().subscribe(reqSubscriber1);
writeToInboundAndFlush(channel, request);
reqSubscriber1.assertValueCount(1);
reqSubscriber1.assertValues(RxNettys.<HttpObject>wrap4release(request));
final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber2 = new TestSubscriber<>();
trade.inbound().subscribe(reqSubscriber2);
writeToInboundAndFlush(channel, req_contents[0]);
reqSubscriber1.assertValueCount(2);
reqSubscriber1.assertValues(RxNettys.<HttpObject>wrap4release(request), RxNettys.<HttpObject>wrap4release(req_contents[0]));
reqSubscriber2.assertValueCount(2);
reqSubscriber2.assertValues(RxNettys.<HttpObject>wrap4release(request), RxNettys.<HttpObject>wrap4release(req_contents[0]));
final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber3 = new TestSubscriber<>();
trade.inbound().subscribe(reqSubscriber3);
reqSubscriber1.assertValueCount(2);
reqSubscriber1.assertValues(RxNettys.<HttpObject>wrap4release(request), RxNettys.<HttpObject>wrap4release(req_contents[0]));
reqSubscriber2.assertValueCount(2);
reqSubscriber2.assertValues(RxNettys.<HttpObject>wrap4release(request), RxNettys.<HttpObject>wrap4release(req_contents[0]));
reqSubscriber3.assertValueCount(2);
reqSubscriber3.assertValues(RxNettys.<HttpObject>wrap4release(request), RxNettys.<HttpObject>wrap4release(req_contents[0]));
}
use of io.netty.handler.codec.http.HttpContent in project jocean-http by isdom.
the class NettysTestCase method test_httpobjs2fullresp_misshttpresp.
@Test
public final void test_httpobjs2fullresp_misshttpresp() throws Exception {
final HttpContent[] resp_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final List<HttpObject> resps = new ArrayList<HttpObject>() {
private static final long serialVersionUID = 1L;
{
this.addAll(Arrays.asList(resp_contents));
this.add(LastHttpContent.EMPTY_LAST_CONTENT);
}
};
RxActions.applyArrayBy(resp_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
FullHttpResponse fullresp = null;
thrown.expect(RuntimeException.class);
try {
fullresp = Nettys.httpobjs2fullresp(resps);
} finally {
assertNull(fullresp);
RxActions.applyArrayBy(resp_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
}
}
use of io.netty.handler.codec.http.HttpContent in project jocean-http by isdom.
the class NettysTestCase method test_httpobjs2fullresp_latercontentdisposed.
@Test
public final void test_httpobjs2fullresp_latercontentdisposed() throws Exception {
final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
final HttpContent[] resp_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final List<HttpObject> resps = new ArrayList<HttpObject>() {
private static final long serialVersionUID = 1L;
{
this.add(response);
this.addAll(Arrays.asList(resp_contents));
this.add(LastHttpContent.EMPTY_LAST_CONTENT);
}
};
RxActions.applyArrayBy(resp_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
// release [0]'s content
resp_contents[resp_contents.length - 1].release();
FullHttpResponse fullresp = null;
thrown.expect(IllegalReferenceCountException.class);
try {
fullresp = Nettys.httpobjs2fullresp(resps);
} finally {
assertNull(fullresp);
RxActions.applyArrayBy(Arrays.copyOfRange(resp_contents, 0, resp_contents.length - 1), new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
}
}
Aggregations