Search in sources :

Example 11 with Endpoint

use of io.servicecomb.core.Endpoint in project java-chassis by ServiceComb.

the class TestServletRestTransport method testSendException.

@Test
public void testSendException() {
    boolean status = true;
    Invocation invocation = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
    Endpoint endpoint1 = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(endpoint1);
    Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
    try {
        transport.send(invocation, asyncResp);
    } catch (Exception exce) {
        Assert.assertNotNull(exce);
        status = false;
    }
    Assert.assertFalse(status);
}
Also used : Invocation(io.servicecomb.core.Invocation) Endpoint(io.servicecomb.core.Endpoint) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject) AsyncResponse(io.servicecomb.core.AsyncResponse) Test(org.junit.Test)

Example 12 with Endpoint

use of io.servicecomb.core.Endpoint in project java-chassis by ServiceComb.

the class TestRestServerVerticle method testRestServerVerticleWithRouterSSL.

@Test
public void testRestServerVerticleWithRouterSSL(@Mocked Transport transport, @Mocked Vertx vertx, @Mocked Context context, @Mocked JsonObject jsonObject, @Mocked Future<Void> startFuture) throws Exception {
    URIEndpointObject endpointObject = new URIEndpointObject("http://127.0.0.1:8080?sslEnabled=true");
    new Expectations() {

        {
            transport.parseAddress("http://127.0.0.1:8080?sslEnabled=true");
            result = endpointObject;
        }
    };
    Endpoint endpiont = new Endpoint(transport, "http://127.0.0.1:8080?sslEnabled=true");
    new Expectations() {

        {
            context.config();
            result = jsonObject;
            jsonObject.getValue(AbstractTransport.ENDPOINT_KEY);
            result = endpiont;
        }
    };
    RestServerVerticle server = new RestServerVerticle();
    // process stuff done by Expectations
    server.init(vertx, context);
    server.start(startFuture);
}
Also used : Expectations(mockit.Expectations) Endpoint(io.servicecomb.core.Endpoint) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject) Test(org.junit.Test)

Example 13 with Endpoint

use of io.servicecomb.core.Endpoint in project java-chassis by ServiceComb.

the class TransportManager method init.

public void init() throws Exception {
    AbstractEndpointsCache.setTransportManager(this);
    for (Transport transport : transportList) {
        transportMap.put(transport.getName(), transport);
        if (transport.init()) {
            Endpoint endpoint = transport.getPublishEndpoint();
            if (endpoint != null && endpoint.getEndpoint() != null) {
                LOGGER.info("endpoint to publish: {}", endpoint.getEndpoint());
                RegistryUtils.getMicroserviceInstance().getEndpoints().add(endpoint.getEndpoint());
            }
            continue;
        }
    }
}
Also used : Endpoint(io.servicecomb.core.Endpoint) Transport(io.servicecomb.core.Transport)

Example 14 with Endpoint

use of io.servicecomb.core.Endpoint in project java-chassis by ServiceComb.

the class SimpleLoadBalanceHandler method handle.

@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
    // 调用者未指定transport时,这里得到的是"",也直接使用,不必特殊处理
    String transportName = invocation.getConfigTransportName();
    EndpointsCache endpointsCache = endpointsCacheMap.get(transportName);
    if (endpointsCache == null) {
        synchronized (this) {
            endpointsCache = endpointsCacheMap.get(invocation.getConfigTransportName());
            if (endpointsCache == null) {
                endpointsCache = new EndpointsCache(invocation.getAppId(), invocation.getMicroserviceName(), invocation.getMicroserviceVersionRule(), transportName);
                endpointsCacheMap.put(transportName, endpointsCache);
            }
        }
    }
    List<Endpoint> endpoints = endpointsCache.getLatestEndpoints();
    if (endpoints == null || endpoints.isEmpty()) {
        asyncResp.consumerFail(ExceptionUtils.lbAddressNotFound(invocation.getMicroserviceName(), invocation.getMicroserviceVersionRule(), transportName));
        return;
    }
    int idx = Math.abs(index.getAndIncrement());
    idx = idx % endpoints.size();
    Endpoint endpoint = endpoints.get(idx);
    invocation.setEndpoint(endpoint);
    invocation.next(asyncResp);
}
Also used : Endpoint(io.servicecomb.core.Endpoint) EndpointsCache(io.servicecomb.core.endpoint.EndpointsCache) Endpoint(io.servicecomb.core.Endpoint)

Aggregations

Endpoint (io.servicecomb.core.Endpoint)14 Test (org.junit.Test)10 Invocation (io.servicecomb.core.Invocation)7 OperationMeta (io.servicecomb.core.definition.OperationMeta)6 URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)6 AsyncResponse (io.servicecomb.core.AsyncResponse)5 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)3 URLPathBuilder (io.servicecomb.common.rest.definition.path.URLPathBuilder)3 Expectations (mockit.Expectations)3 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)2 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)2 ProduceProcessor (io.servicecomb.common.rest.codec.produce.ProduceProcessor)2 HttpClientWithContext (io.servicecomb.foundation.vertx.client.http.HttpClientWithContext)2 HttpClientResponse (io.vertx.core.http.HttpClientResponse)2 Response (io.servicecomb.core.Response)1 Transport (io.servicecomb.core.Transport)1 EndpointsCache (io.servicecomb.core.endpoint.EndpointsCache)1 CommonExceptionData (io.servicecomb.core.exception.CommonExceptionData)1 InvocationException (io.servicecomb.core.exception.InvocationException)1 ProducerOperation (io.servicecomb.core.provider.producer.ProducerOperation)1