Search in sources :

Example 26 with HttpMethod

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project jocean-http by isdom.

the class DefaultSignalClientTestCase method testSignalClientOnlySignalForPostWithQueryParam.

@Test
public void testSignalClientOnlySignalForPostWithQueryParam() throws Exception {
    final TestResponse respToSendback = new TestResponse("0", "OK");
    final AtomicReference<HttpMethod> reqMethodReceivedRef = new AtomicReference<>();
    final AtomicReference<String> reqpathReceivedRef = new AtomicReference<>();
    final AtomicReference<TestRequestByPostWithQueryParam> reqbeanReceivedRef = new AtomicReference<>();
    final Action2<FullHttpRequest, HttpTrade> requestAndTradeAwareWhenCompleted = new Action2<FullHttpRequest, HttpTrade>() {

        @Override
        public void call(final FullHttpRequest req, final HttpTrade trade) {
            try {
                reqMethodReceivedRef.set(req.method());
                final QueryStringDecoder decoder = new QueryStringDecoder(req.uri());
                reqpathReceivedRef.set(decoder.path());
                final TestRequestByPostWithQueryParam reqbean = (TestRequestByPostWithQueryParam) JSON.parseObject(Nettys.dumpByteBufAsBytes(req.content()), TestRequestByPostWithQueryParam.class);
                reqbean._queryp = decoder.parameters().get("p").get(0);
                reqbeanReceivedRef.set(reqbean);
            } catch (IOException e) {
                LOG.warn("exception when Nettys.dumpByteBufAsBytes, detail: {}", ExceptionUtils.exception2detail(e));
            }
            trade.outbound(buildResponse(respToSendback, trade.onTerminate()));
        }
    };
    final String testAddr = UUID.randomUUID().toString();
    final Subscription server = TestHttpUtil.createTestServerWith(testAddr, requestAndTradeAwareWhenCompleted, Feature.ENABLE_LOGGING, Feature.ENABLE_COMPRESSOR);
    try {
        final TestChannelCreator creator = new TestChannelCreator();
        final TestChannelPool pool = new TestChannelPool(1);
        final DefaultHttpClient httpclient = new DefaultHttpClient(creator, pool);
        final DefaultSignalClient signalClient = new DefaultSignalClient(new URI("http://test"), httpclient);
        signalClient.registerRequestType(TestRequestByPostWithQueryParam.class, TestResponse.class, null, buildUri2Addr(testAddr), Feature.ENABLE_LOGGING);
        final TestRequestByPostWithQueryParam reqToSend = new TestRequestByPostWithQueryParam("1", "test");
        final TestResponse respReceived = ((SignalClient) signalClient).interaction().request(reqToSend).<TestResponse>build().timeout(1, TimeUnit.SECONDS).toBlocking().single();
        assertEquals(HttpMethod.POST, reqMethodReceivedRef.get());
        assertEquals("/test/simpleRequest", reqpathReceivedRef.get());
        assertEquals(reqToSend, reqbeanReceivedRef.get());
        assertEquals(respToSendback, respReceived);
        pool.awaitRecycleChannels();
    } finally {
        server.unsubscribe();
    }
}
Also used : FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) Action2(rx.functions.Action2) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) URI(java.net.URI) DefaultHttpClient(org.jocean.http.client.impl.DefaultHttpClient) QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) TestChannelPool(org.jocean.http.client.impl.TestChannelPool) DefaultSignalClient(org.jocean.http.rosa.impl.DefaultSignalClient) Subscription(rx.Subscription) HttpMethod(io.netty.handler.codec.http.HttpMethod) TestChannelCreator(org.jocean.http.client.impl.TestChannelCreator) Test(org.junit.Test)

Example 27 with HttpMethod

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.

the class RouterPathTest method testStreamPath.

@Test
public void testStreamPath() throws Exception {
    // Following URIs might not give actual results but we want to test resilience of Router Path Lookup
    String streamPath = "/v3/namespaces/default/streams";
    HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), streamPath);
    RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, streamPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.STREAMS_SERVICE, result);
    streamPath = "///v3/namespaces/default/streams///";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("POST"), streamPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, streamPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.STREAMS_SERVICE, result);
    streamPath = "v3/namespaces/default///streams///";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("PUT"), streamPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, streamPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.STREAMS_SERVICE, result);
    streamPath = "//v3/namespaces/default///streams/HelloStream//programs///";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), streamPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, streamPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
    streamPath = "//v3/namespaces/default///streams/HelloStream//programs///";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("DELETE"), streamPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, streamPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.STREAMS_SERVICE, result);
    streamPath = "//v3/namespaces/default///streams/HelloStream//programs///";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("POST"), streamPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, streamPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.STREAMS_SERVICE, result);
    streamPath = "v3/namespaces/default//streams//flows///";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("DELETE"), streamPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, streamPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.STREAMS_SERVICE, result);
    streamPath = "v3/namespaces/default//streams/InvalidStreamName/programs/";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), streamPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, streamPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
    streamPath = "v3/namespaces/default//streams/InvalidStreamName/programs";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), streamPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, streamPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
    streamPath = "v3/namespaces/default//streams/InvalidStreamName/programs/";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("DELETE"), streamPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, streamPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.STREAMS_SERVICE, result);
    streamPath = "v3/namespaces/default//streams/InvalidStreamName/info/";
    httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), streamPath);
    result = pathLookup.getRoutingService(FALLBACKSERVICE, streamPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.STREAMS_SERVICE, result);
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 28 with HttpMethod

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.

the class RouterPathTest method testUserServicePath.

@Test
public void testUserServicePath() {
    for (ProgramType programType : EnumSet.of(ProgramType.SERVICE, ProgramType.SPARK)) {
        String path = "/v3/namespaces/n1/apps/a1/" + programType.getCategoryName() + "/s1/methods/m1";
        HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), path);
        RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
        Assert.assertEquals(ServiceDiscoverable.getName("n1", "a1", programType, "s1"), result.getServiceName());
        Assert.assertTrue(ServiceDiscoverable.isUserService(result.getServiceName()));
        Assert.assertNull(result.getVersion());
        path = "/v3/namespaces/n1/apps/a1/versions/v1/" + programType.getCategoryName() + "/s1/methods/m1";
        httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), path);
        result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
        Assert.assertEquals(ServiceDiscoverable.getName("n1", "a1", programType, "s1"), result.getServiceName());
        Assert.assertTrue(ServiceDiscoverable.isUserService(result.getServiceName()));
        Assert.assertEquals("v1", result.getVersion());
    }
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) ProgramType(co.cask.cdap.proto.ProgramType) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 29 with HttpMethod

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.

the class RouterPathTest method testRouterFlowPathLookUp.

@Test
public void testRouterFlowPathLookUp() throws Exception {
    String flowPath = "/v3/namespaces/default//apps/ResponseCodeAnalytics/flows/LogAnalyticsFlow/status";
    HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), flowPath);
    RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, flowPath, httpRequest);
    Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 30 with HttpMethod

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.

the class RouterPathTest method testMetricsPath.

private void testMetricsPath(String path) {
    HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), path);
    RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
    Assert.assertEquals(RouterPathLookup.METRICS, result);
}
Also used : DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpMethod(io.netty.handler.codec.http.HttpMethod)

Aggregations

HttpMethod (io.netty.handler.codec.http.HttpMethod)83 Test (org.junit.Test)44 HttpRequest (io.netty.handler.codec.http.HttpRequest)24 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)23 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)20 URI (java.net.URI)15 IOException (java.io.IOException)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 DefaultHttpClient (org.jocean.http.client.impl.DefaultHttpClient)11 TestChannelCreator (org.jocean.http.client.impl.TestChannelCreator)11 TestChannelPool (org.jocean.http.client.impl.TestChannelPool)11 DefaultSignalClient (org.jocean.http.rosa.impl.DefaultSignalClient)11 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)11 Subscription (rx.Subscription)11 Action2 (rx.functions.Action2)11 ByteBuf (io.netty.buffer.ByteBuf)10 HttpVersion (io.netty.handler.codec.http.HttpVersion)10 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)9 Map (java.util.Map)9 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)8