use of org.apache.flink.shaded.netty4.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 org.apache.flink.shaded.netty4.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());
}
});
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpContent in project jocean-http by isdom.
the class NettysTestCase method test_httpobjs2fullreq_latercontentdisposed.
@Test
public final void test_httpobjs2fullreq_latercontentdisposed() throws Exception {
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 List<HttpObject> reqs = new ArrayList<HttpObject>() {
private static final long serialVersionUID = 1L;
{
this.add(request);
this.addAll(Arrays.asList(req_contents));
this.add(LastHttpContent.EMPTY_LAST_CONTENT);
}
};
RxActions.applyArrayBy(req_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
// release [0]'s content
req_contents[req_contents.length - 1].release();
FullHttpRequest fullreq = null;
thrown.expect(IllegalReferenceCountException.class);
try {
fullreq = Nettys.httpobjs2fullreq(reqs);
} finally {
assertNull(fullreq);
RxActions.applyArrayBy(Arrays.copyOfRange(req_contents, 0, req_contents.length - 1), new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpContent in project jocean-http by isdom.
the class NettysTestCase method test_httpobjs2fullreq_success.
@Test
public final void test_httpobjs2fullreq_success() throws Exception {
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 List<HttpObject> reqs = new ArrayList<HttpObject>() {
private static final long serialVersionUID = 1L;
{
this.add(request);
this.addAll(Arrays.asList(req_contents));
this.add(LastHttpContent.EMPTY_LAST_CONTENT);
}
};
RxActions.applyArrayBy(req_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
final FullHttpRequest fullreq = Nettys.httpobjs2fullreq(reqs);
assertNotNull(fullreq);
RxActions.applyArrayBy(req_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(2, c.content().refCnt());
}
});
assertEquals(REQ_CONTENT, new String(Nettys.dumpByteBufAsBytes(fullreq.content()), Charsets.UTF_8));
fullreq.release();
RxActions.applyArrayBy(req_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpContent in project jocean-http by isdom.
the class NettysTestCase method test_httpobjs2fullreq_misshttpreq.
@Test
public final void test_httpobjs2fullreq_misshttpreq() throws Exception {
final HttpContent[] req_contents = Nettys4Test.buildContentArray(REQ_CONTENT.getBytes(Charsets.UTF_8), 1);
final List<HttpObject> reqs = new ArrayList<HttpObject>() {
private static final long serialVersionUID = 1L;
{
this.addAll(Arrays.asList(req_contents));
this.add(LastHttpContent.EMPTY_LAST_CONTENT);
}
};
RxActions.applyArrayBy(req_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
FullHttpRequest fullreq = null;
thrown.expect(RuntimeException.class);
try {
fullreq = Nettys.httpobjs2fullreq(reqs);
} finally {
assertNull(fullreq);
RxActions.applyArrayBy(req_contents, new Action1<HttpContent>() {
@Override
public void call(final HttpContent c) {
assertEquals(1, c.content().refCnt());
}
});
}
}
Aggregations