use of org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext in project incubator-servicecomb-java-chassis by apache.
the class WebsocketUtils method open.
public static void open(IpPort ipPort, String url, Handler<Void> onOpen, Handler<Void> onClose, Handler<Buffer> onMessage, Handler<Throwable> onException, Handler<Throwable> onConnectFailed) {
HttpClientWithContext vertxHttpClient = WebsocketClientPool.INSTANCE.getClient();
vertxHttpClient.runOnContext(client -> {
client.websocket(ipPort.getPort(), ipPort.getHostOrIp(), url, RestUtils.getDefaultHeaders().addAll(RestUtils.getSignAuthHeaders(RestUtils.createSignRequest(null, ipPort, new RequestParam(), url, new HashMap<>()))), ws -> {
onOpen.handle(null);
ws.exceptionHandler(v -> {
onException.handle(v);
try {
ws.close();
} catch (Exception err) {
LOGGER.error("ws close error.", err);
}
});
ws.closeHandler(v -> {
onClose.handle(v);
try {
ws.close();
} catch (Exception err) {
LOGGER.error("ws close error.", err);
}
});
ws.handler(onMessage);
}, onConnectFailed);
});
}
use of org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext in project incubator-servicecomb-java-chassis by apache.
the class TestClientPoolManager method findByContext_reactive.
@Test
public void findByContext_reactive() {
HttpClientWithContext notMatchPool = new HttpClientWithContext(null, null);
pools.add(notMatchPool);
new Expectations(VertxImpl.class) {
{
factory.createClientPool();
result = new HttpClientWithContext(null, null);
VertxImpl.context();
result = context;
}
};
HttpClientWithContext result = poolMgr.findByContext();
Assert.assertNotSame(notMatchPool, result);
// find again, get the same result
Assert.assertSame(result, poolMgr.findByContext());
}
use of org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext in project incubator-servicecomb-java-chassis by apache.
the class TestClientPoolManager method findByContext_otherVertx.
@Test
public void findByContext_otherVertx(@Mocked Vertx otherVertx, @Mocked Context otherContext) {
HttpClientWithContext pool = new HttpClientWithContext(null, null);
pools.add(pool);
new Expectations(VertxImpl.class) {
{
VertxImpl.context();
result = otherContext;
otherContext.owner();
result = otherVertx;
}
};
Assert.assertSame(pool, poolMgr.findByContext());
}
use of org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext in project incubator-servicecomb-java-chassis by apache.
the class TestClientVerticle method start.
@Test
public void start(@Mocked Context context) throws Exception {
AtomicInteger count = new AtomicInteger();
ClientPoolManager<HttpClientWithContext> clientMgr = new MockUp<ClientPoolManager<HttpClientWithContext>>() {
@Mock
HttpClientWithContext createClientPool() {
count.incrementAndGet();
return null;
}
}.getMockInstance();
clientVerticle.init(null, context);
JsonObject config = new SimpleJsonObject();
config.put(ClientVerticle.CLIENT_MGR, clientMgr);
new Expectations() {
{
context.config();
result = config;
}
};
clientVerticle.start();
Assert.assertEquals(1, count.get());
}
use of org.apache.servicecomb.foundation.vertx.client.http.HttpClientWithContext in project incubator-servicecomb-java-chassis by apache.
the class TestVertxHttpMethod method testDoMethodNullPointerException.
@Test
public void testDoMethodNullPointerException(@Mocked HttpClient httpClient) throws Exception {
Context context = new MockUp<Context>() {
@Mock
public void runOnContext(Handler<Void> action) {
action.handle(null);
}
}.getMockInstance();
HttpClientWithContext httpClientWithContext = new HttpClientWithContext(httpClient, context);
Invocation invocation = mock(Invocation.class);
AsyncResponse asyncResp = mock(AsyncResponse.class);
try {
this.doMethod(httpClientWithContext, invocation, asyncResp);
fail("Expect to throw NullPointerException, but got none");
} catch (NullPointerException e) {
}
}
Aggregations