Search in sources :

Example 31 with IpPort

use of io.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.

the class TestVertxGetMethod method testVertxGetMethod.

@Test
public void testVertxGetMethod() {
    HttpClient client = Mockito.mock(HttpClient.class);
    Invocation invocation = Mockito.mock(Invocation.class);
    IpPort ipPort = Mockito.mock(IpPort.class);
    Mockito.when(ipPort.getPort()).thenReturn(10);
    assertEquals(10, ipPort.getPort());
    Mockito.when(ipPort.getHostOrIp()).thenReturn("ever");
    assertEquals("ever", ipPort.getHostOrIp());
    RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    HttpClientRequest obj = VertxGetMethod.INSTANCE.createRequest(client, invocation, ipPort, "good", operation, asyncResp);
    Assert.assertNull(obj);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClient(io.vertx.core.http.HttpClient) IpPort(io.servicecomb.foundation.common.net.IpPort) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 32 with IpPort

use of io.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.

the class TestVertxPostMethod method testVertxPostMethod.

@Test
public void testVertxPostMethod() {
    Invocation invocation = Mockito.mock(Invocation.class);
    HttpClient client = Mockito.mock(HttpClient.class);
    IpPort ipPort = Mockito.mock(IpPort.class);
    RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    Mockito.when(ipPort.getPort()).thenReturn(23);
    assertEquals(23, ipPort.getPort());
    Mockito.when(ipPort.getHostOrIp()).thenReturn("testCall");
    assertNotNull("testCall", ipPort.getHostOrIp());
    HttpClientRequest obj = VertxPostMethod.INSTANCE.createRequest(client, invocation, ipPort, "test", operation, asyncResp);
    Assert.assertNull(obj);
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) Invocation(io.servicecomb.core.Invocation) RestOperationMeta(io.servicecomb.common.rest.definition.RestOperationMeta) HttpClient(io.vertx.core.http.HttpClient) IpPort(io.servicecomb.foundation.common.net.IpPort) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 33 with IpPort

use of io.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.

the class MockForRestServerVerticle method mockRestServerVerticle.

public void mockRestServerVerticle() {
    final HttpServer server = Mockito.mock(HttpServer.class);
    new MockUp<RestServerVerticle>() {

        @Mock
        private void startListen(HttpServer server, IpPort ipPort, Future<Void> startFuture) {
        }

        @Mock
        private HttpServer createHttpServer(boolean isHttp_2) {
            return server;
        }
    };
}
Also used : HttpServer(io.vertx.core.http.HttpServer) Future(io.vertx.core.Future) MockUp(mockit.MockUp) IpPort(io.servicecomb.foundation.common.net.IpPort)

Example 34 with IpPort

use of io.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.

the class TestGrpcVerticle method testGrpcVerticle.

@Test
public void testGrpcVerticle(@Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject json) throws Exception {
    new Expectations() {

        {
            context.config();
            result = json;
            json.getString(anyString);
            result = "grpc://127.0.0.1:9090";
        }
    };
    GrpcVerticle grpcVerticle = new GrpcVerticle();
    grpcVerticle.init(vertx, context);
    @SuppressWarnings("unchecked") Future<Void> startFuture = Mockito.mock(Future.class);
    grpcVerticle.startListen(startFuture);
    MockUtil.getInstance().mockGrpcConfig();
    try {
        grpcVerticle.startListen(startFuture);
        Assert.assertTrue(true);
    } catch (Exception e) {
        Assert.assertTrue(false);
    }
    IpPort ipPort = Mockito.mock(IpPort.class);
    HttpServer server = Mockito.mock(HttpServer.class);
    Deencapsulation.invoke(grpcVerticle, "startListen", server, ipPort, startFuture);
    Assert.assertEquals("clientMgr", GrpcVerticle.CLIENT_MGR);
}
Also used : Expectations(mockit.Expectations) HttpServer(io.vertx.core.http.HttpServer) IpPort(io.servicecomb.foundation.common.net.IpPort) Test(org.junit.Test)

Example 35 with IpPort

use of io.servicecomb.foundation.common.net.IpPort in project java-chassis by ServiceComb.

the class GrpcVerticle method startListen.

protected void startListen(Future<Void> startFuture) {
    // 如果本地未配置grpc地址,则表示不必监听,只需要作为客户端使用即可
    if (StringUtils.isEmpty(this.endpoint)) {
        LOGGER.warn("grpc listen address is not configured, will not listen.");
        startFuture.complete();
        return;
    }
    Router mainRouter = Router.router(vertx);
    mainRouter.route().handler(new GrpcBodyHandler());
    new GrpcServer(mainRouter);
    HttpServerOptions serverOptions = new HttpServerOptions();
    serverOptions.setAcceptBacklog(ACCEPT_BACKLOG);
    serverOptions.setSendBufferSize(SEND_BUFFER_SIZE);
    serverOptions.setReceiveBufferSize(RECEIVE_BUFFER_SIZE);
    serverOptions.setUsePooledBuffers(true);
    String key = System.getProperty("store.key");
    if (key != null && !key.isEmpty()) {
        serverOptions.setUseAlpn(true);
        serverOptions.setSsl(true);
        serverOptions.setKeyStoreOptions(new JksOptions().setPath(System.getProperty("store.key")).setPassword(System.getProperty("store.pass")));
    }
    HttpServer server = vertx.createHttpServer(serverOptions).requestHandler(mainRouter::accept);
    IpPort ipPort = NetUtils.parseIpPortFromURI(this.endpoint);
    if (ipPort == null) {
        LOGGER.error("wrong grpc listen address {}", this.endpoint);
        return;
    }
    startListen(server, ipPort, startFuture);
}
Also used : JksOptions(io.vertx.core.net.JksOptions) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpServer(io.vertx.core.http.HttpServer) Router(io.vertx.ext.web.Router) IpPort(io.servicecomb.foundation.common.net.IpPort)

Aggregations

IpPort (io.servicecomb.foundation.common.net.IpPort)35 ClientException (io.servicecomb.serviceregistry.client.ClientException)15 CountDownLatch (java.util.concurrent.CountDownLatch)14 Holder (javax.xml.ws.Holder)14 Test (org.junit.Test)10 HttpClientRequest (io.vertx.core.http.HttpClientRequest)7 AsyncResponse (io.servicecomb.core.AsyncResponse)6 Invocation (io.servicecomb.core.Invocation)6 HttpClientResponse (io.vertx.core.http.HttpClientResponse)6 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)5 HttpClient (io.vertx.core.http.HttpClient)4 OperationMeta (io.servicecomb.core.definition.OperationMeta)3 HttpClientWithContext (io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)3 HttpServer (io.vertx.core.http.HttpServer)3 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)2 UpdatePropertiesRequest (io.servicecomb.serviceregistry.api.request.UpdatePropertiesRequest)2 GetExistenceResponse (io.servicecomb.serviceregistry.api.response.GetExistenceResponse)2 CacheEndpoint (io.servicecomb.serviceregistry.cache.CacheEndpoint)2 ArrayList (java.util.ArrayList)2 Expectations (mockit.Expectations)2