use of org.jocean.idiom.DisposableWrapper in project jocean-http by isdom.
the class DefaultHttpTradeTestCase method testTradeForCallAbortAfterRequestPublish.
@Test
public final void testTradeForCallAbortAfterRequestPublish() {
final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Nettys4Test.buildByteBuf("testcontent"));
final EmbeddedChannel channel = new EmbeddedChannel();
final HttpTrade trade = new DefaultHttpTrade(channel);
final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber = new TestSubscriber<>();
trade.inbound().subscribe(reqSubscriber);
writeToInboundAndFlush(channel, request);
trade.close();
assertFalse(trade.isActive());
reqSubscriber.assertValueCount(1);
reqSubscriber.assertValue(RxNettys.<HttpObject>wrap4release(request));
reqSubscriber.assertCompleted();
reqSubscriber.assertNoErrors();
}
use of org.jocean.idiom.DisposableWrapper 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 org.jocean.idiom.DisposableWrapper in project jocean-http by isdom.
the class DefaultHttpTradeTestCase method testTradeForCallAbortAndUseInboundRequest.
@Test
public final void testTradeForCallAbortAndUseInboundRequest() {
final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Nettys4Test.buildByteBuf("testcontent"));
final EmbeddedChannel channel = new EmbeddedChannel();
final HttpTrade trade = new DefaultHttpTrade(channel);
writeToInboundAndFlush(channel, request);
trade.close();
assertTrue(!trade.isActive());
final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber = new TestSubscriber<>();
trade.inbound().subscribe(reqSubscriber);
reqSubscriber.assertTerminalEvent();
reqSubscriber.assertError(Exception.class);
reqSubscriber.assertValueCount(0);
}
use of org.jocean.idiom.DisposableWrapper 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 org.jocean.idiom.DisposableWrapper in project jocean-http by isdom.
the class DefaultHttpClientTestCase method testInitiatorInteractionClientCanceledAsHttp.
@Test(timeout = 5000)
public void testInitiatorInteractionClientCanceledAsHttp() throws Exception {
// 配置 池化分配器 为 取消缓存,使用 Heap
configDefaultAllocator();
final PooledByteBufAllocator allocator = defaultAllocator();
final BlockingQueue<HttpTrade> trades = new ArrayBlockingQueue<>(1);
final String addr = UUID.randomUUID().toString();
final Subscription server = TestHttpUtil.createTestServerWith(addr, trades, Feature.ENABLE_LOGGING);
final DefaultHttpClient client = new DefaultHttpClient(new TestChannelCreator(), Feature.ENABLE_LOGGING);
assertEquals(0, allActiveAllocationsCount(allocator));
try {
startInteraction(client.initiator().remoteAddress(new LocalAddress(addr)), Observable.just(fullHttpRequest()), new Interaction() {
@Override
public void interact(final HttpInitiator initiator, final Observable<DisposableWrapper<FullHttpResponse>> getresp) throws Exception {
final TestSubscriber<DisposableWrapper<FullHttpResponse>> subscriber = new TestSubscriber<>();
final Subscription subscription = getresp.subscribe(subscriber);
// server side recv req
final HttpTrade trade = trades.take();
// recv request from client side
trade.inbound().doOnNext(DISPOSE_EACH).toCompletable().await();
// server not send response, and client cancel this interaction
subscription.unsubscribe();
TerminateAware.Util.awaitTerminated(trade);
TerminateAware.Util.awaitTerminated(initiator);
assertTrue(!initiator.isActive());
subscriber.assertNoTerminalEvent();
subscriber.assertNoValues();
}
});
assertEquals(0, allActiveAllocationsCount(allocator));
} finally {
client.close();
server.unsubscribe();
}
}
Aggregations