use of io.vertx.core.http.HttpClient in project incubator-servicecomb-java-chassis by apache.
the class TestConfigCenterClient method testConfigRefresh.
@SuppressWarnings("unchecked")
@Test
public void testConfigRefresh() {
ConfigCenterConfigurationSourceImpl impl = new ConfigCenterConfigurationSourceImpl();
impl.init(ConfigUtil.createLocalConfig());
UpdateHandler updateHandler = impl.new UpdateHandler();
HttpClientRequest request = Mockito.mock(HttpClientRequest.class);
Mockito.when(request.headers()).thenReturn(MultiMap.caseInsensitiveMultiMap());
Buffer rsp = Mockito.mock(Buffer.class);
Mockito.when(rsp.toString()).thenReturn("{\"application\":{\"2\":\"2\",\"aa\":\"1\"},\"vmalledge\":{\"aa\":\"3\"}}");
HttpClientResponse event = Mockito.mock(HttpClientResponse.class);
Mockito.when(event.bodyHandler(Mockito.any(Handler.class))).then(invocation -> {
Handler<Buffer> handler = invocation.getArgumentAt(0, Handler.class);
handler.handle(rsp);
return null;
});
Mockito.when(event.statusCode()).thenReturn(200);
Buffer buf = Mockito.mock(Buffer.class);
Mockito.when(buf.toJsonObject()).thenReturn(new JsonObject("{\"action\":\"UPDATE\",\"key\":\"vmalledge\",\"value\":\"{\\\"aa\\\":\\\"3\\\"}\"}"));
WebSocket websocket = Mockito.mock(WebSocket.class);
Mockito.when(websocket.handler(Mockito.any(Handler.class))).then(invocation -> {
Handler<Buffer> handler = invocation.getArgumentAt(0, Handler.class);
handler.handle(buf);
return websocket;
});
HttpClient httpClient = Mockito.mock(HttpClient.class);
Mockito.when(httpClient.get(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.any(Handler.class))).then(invocation -> {
Handler<HttpClientResponse> handler = invocation.getArgumentAt(3, Handler.class);
handler.handle(event);
return request;
});
Mockito.when(httpClient.websocket(Mockito.anyInt(), Mockito.anyString(), Mockito.anyString(), Mockito.any(MultiMap.class), Mockito.any(Handler.class), Mockito.any(Handler.class))).then(invocation -> {
Handler<WebSocket> handler = invocation.getArgumentAt(4, Handler.class);
handler.handle(websocket);
return null;
});
new MockUp<HttpClientWithContext>() {
@Mock
public void runOnContext(RunHandler handler) {
handler.run(httpClient);
}
};
ConfigCenterClient cc = new ConfigCenterClient(updateHandler);
ParseConfigUtils parseConfigUtils = new ParseConfigUtils(updateHandler);
MemberDiscovery memberdis = new MemberDiscovery(Arrays.asList("http://configcentertest:30103"));
ConfigRefresh refresh = cc.new ConfigRefresh(parseConfigUtils, memberdis);
refresh.run();
Map<String, Object> flatItems = Deencapsulation.getField(parseConfigUtils, "flatItems");
Assert.assertEquals(2, flatItems.size());
Deencapsulation.setField(cc, "refreshMode", 0);
refresh.run();
}
use of io.vertx.core.http.HttpClient in project vertx-micrometer-metrics by vert-x3.
the class VertxHttpClientServerMetricsTest method httpRequest.
private void httpRequest(HttpClient httpClient, TestContext ctx) {
Async async = ctx.async(HTTP_SENT_COUNT);
for (int i = 0; i < HTTP_SENT_COUNT; i++) {
httpClient.post(9195, "127.0.0.1", "/resource", response -> {
async.countDown();
if (response.statusCode() != 200) {
ctx.fail(response.statusMessage());
}
}).exceptionHandler(t -> {
async.countDown();
ctx.fail(t);
}).putHeader("Content-Length", String.valueOf(CLIENT_REQUEST.getBytes().length)).write(CLIENT_REQUEST).end();
}
async.await();
}
use of io.vertx.core.http.HttpClient in project vertx-micrometer-metrics by vert-x3.
the class MetricsServiceImplTest method shouldGetHttpServerSnapshot.
@Test
public void shouldGetHttpServerSnapshot(TestContext ctx) throws InterruptedException {
HttpClient httpClient = vertx.createHttpClient();
runClientRequests(ctx, httpClient, 5, "/r2");
httpClient.close();
JsonObject snapshot = MetricsService.create(httpServer).getMetricsSnapshot();
assertThat(snapshot).extracting(Map.Entry::getKey).containsExactly("vertx.http.server.bytesReceived", "vertx.http.server.bytesSent", "vertx.http.server.connections", "vertx.http.server.requestCount", "vertx.http.server.requests", "vertx.http.server.responseTime");
}
use of io.vertx.core.http.HttpClient in project sonar-java by SonarSource.
the class A method test_saveUser.
@Test
public void test_saveUser() {
// Compliant even if this test may not be run correctly - assertion is present
TestSuite suite = TestSuite.create("suite_user_save");
HttpClient client = vertx.createHttpClient();
suite.test("user_save", context -> {
client.getNow(port, host, requestURI, resp -> {
resp.bodyHandler(body -> {
// assertion
context.assertNotEquals("created", body.toString());
client.close();
});
});
});
}
use of io.vertx.core.http.HttpClient in project sonar-java by SonarSource.
the class A method test_getAuthURL.
@Test
public void test_getAuthURL(TestContext contextVertx) {
// Compliant
HttpClient client = vertx.createHttpClient();
Async async = contextVertx.async();
client.getNow(port, "localhost", requestURI, resp -> {
resp.bodyHandler(body -> {
// assertion
contextVertx.assertEquals(urlString, body.toString());
client.close();
async.complete();
});
});
}
Aggregations