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();
}
}
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);
}
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());
}
}
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);
}
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);
}
Aggregations