Search in sources :

Example 16 with HttpTrade

use of org.jocean.http.server.HttpServerBuilder.HttpTrade 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();
}
Also used : HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DisposableWrapper(org.jocean.idiom.DisposableWrapper) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) TestSubscriber(rx.observers.TestSubscriber) Nettys4Test(org.jocean.http.util.Nettys4Test) Test(org.junit.Test)

Example 17 with HttpTrade

use of org.jocean.http.server.HttpServerBuilder.HttpTrade 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]));
}
Also used : HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) DisposableWrapper(org.jocean.idiom.DisposableWrapper) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) TestSubscriber(rx.observers.TestSubscriber) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Nettys4Test(org.jocean.http.util.Nettys4Test) Test(org.junit.Test)

Example 18 with HttpTrade

use of org.jocean.http.server.HttpServerBuilder.HttpTrade in project jocean-http by isdom.

the class DefaultHttpTradeTestCase method testTradeForReadyOutboundResponseAfterResponseOnNext.

@Test
public final void testTradeForReadyOutboundResponseAfterResponseOnNext() {
    final HttpTrade trade = new DefaultHttpTrade(new EmbeddedChannel());
    assertTrue(trade.isActive());
    final SubscriberHolder<HttpObject> subsholder1 = new SubscriberHolder<>();
    final Subscription subscription1 = trade.outbound(Observable.unsafeCreate(subsholder1));
    assertNotNull(subscription1);
    final DefaultHttpRequest req1 = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
    Nettys4Test.emitHttpObjects(subsholder1.getAt(0), req1);
}
Also used : HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) HttpObject(io.netty.handler.codec.http.HttpObject) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Subscription(rx.Subscription) SubscriberHolder(org.jocean.idiom.rx.SubscriberHolder) Nettys4Test(org.jocean.http.util.Nettys4Test) Test(org.junit.Test)

Example 19 with HttpTrade

use of org.jocean.http.server.HttpServerBuilder.HttpTrade in project jocean-http by isdom.

the class DefaultHttpTradeTestCase method testInvokeDoOnClosedWhenUnactive.

@Test
public final void testInvokeDoOnClosedWhenUnactive() {
    final EmbeddedChannel channel = new EmbeddedChannel();
    final HttpTrade trade = new DefaultHttpTrade(channel);
    channel.disconnect().syncUninterruptibly();
    assertFalse(trade.isActive());
    final AtomicBoolean onClosed = new AtomicBoolean(false);
    trade.doOnTerminate(new Action1<HttpTrade>() {

        @Override
        public void call(final HttpTrade trade) {
            onClosed.set(true);
        }
    });
    assertTrue(onClosed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Nettys4Test(org.jocean.http.util.Nettys4Test) Test(org.junit.Test)

Example 20 with HttpTrade

use of org.jocean.http.server.HttpServerBuilder.HttpTrade 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);
}
Also used : HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DisposableWrapper(org.jocean.idiom.DisposableWrapper) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) TestSubscriber(rx.observers.TestSubscriber) Nettys4Test(org.jocean.http.util.Nettys4Test) Test(org.junit.Test)

Aggregations

HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)59 Test (org.junit.Test)56 Subscription (rx.Subscription)41 DisposableWrapper (org.jocean.idiom.DisposableWrapper)29 LocalAddress (io.netty.channel.local.LocalAddress)26 IOException (java.io.IOException)25 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)25 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)24 HttpInitiator (org.jocean.http.client.HttpClient.HttpInitiator)24 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)23 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)23 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)20 Nettys4Test (org.jocean.http.util.Nettys4Test)20 TestSubscriber (rx.observers.TestSubscriber)20 SSLException (javax.net.ssl.SSLException)18 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)17 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)17 HttpObject (io.netty.handler.codec.http.HttpObject)17 ConnectException (java.net.ConnectException)17 CertificateException (java.security.cert.CertificateException)17