Search in sources :

Example 1 with Endpoint

use of org.apache.servicecomb.core.Endpoint in project incubator-servicecomb-java-chassis by apache.

the class TestVertxRestTransport method testSendException.

@Test
public void testSendException() {
    boolean validAssert;
    Invocation invocation = Mockito.mock(Invocation.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    URIEndpointObject endpoint = Mockito.mock(URIEndpointObject.class);
    Endpoint end = Mockito.mock(Endpoint.class);
    Mockito.when(invocation.getEndpoint()).thenReturn(end);
    Mockito.when(invocation.getEndpoint().getAddress()).thenReturn(endpoint);
    try {
        validAssert = true;
        instance.send(invocation, asyncResp);
    } catch (Exception e) {
        validAssert = false;
    }
    Assert.assertFalse(validAssert);
}
Also used : Invocation(org.apache.servicecomb.core.Invocation) Endpoint(org.apache.servicecomb.core.Endpoint) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with Endpoint

use of org.apache.servicecomb.core.Endpoint in project incubator-servicecomb-java-chassis by apache.

the class AbstractTransport method setListenAddressWithoutSchema.

/*
   * 将配置的URI转换为endpoint
   * addressWithoutSchema 配置的URI,没有schema部分
   */
protected void setListenAddressWithoutSchema(String addressWithoutSchema, Map<String, String> pairs) {
    addressWithoutSchema = genAddressWithoutSchema(addressWithoutSchema, pairs);
    this.endpoint = new Endpoint(this, NetUtils.getRealListenAddress(getName(), addressWithoutSchema));
    if (this.endpoint.getEndpoint() != null) {
        this.publishEndpoint = new Endpoint(this, RegistryUtils.getPublishAddress(getName(), addressWithoutSchema));
    } else {
        this.publishEndpoint = null;
    }
}
Also used : Endpoint(org.apache.servicecomb.core.Endpoint)

Example 3 with Endpoint

use of org.apache.servicecomb.core.Endpoint in project incubator-servicecomb-java-chassis by apache.

the class TestEndpointDiscoveryFilter method createEndpointNormal.

@Test
public void createEndpointNormal(@Mocked Transport transport, @Mocked MicroserviceInstance instance) {
    String endpoint = "rest://ip:port";
    Object address = new Object();
    new Expectations() {

        {
            transportManager.findTransport(Const.RESTFUL);
            result = transport;
            transport.parseAddress(endpoint);
            result = address;
        }
    };
    Endpoint ep = (Endpoint) filter.createEndpoint(Const.RESTFUL, endpoint, instance);
    Assert.assertSame(transport, ep.getTransport());
    Assert.assertSame(address, ep.getAddress());
    Assert.assertSame(instance, ep.getMicroserviceInstance());
    Assert.assertEquals(endpoint, ep.getEndpoint());
}
Also used : Expectations(mockit.Expectations) Endpoint(org.apache.servicecomb.core.Endpoint) Test(org.junit.Test)

Example 4 with Endpoint

use of org.apache.servicecomb.core.Endpoint in project incubator-servicecomb-java-chassis by apache.

the class SimpleLoadBalanceHandler method handle.

@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
    DiscoveryContext context = new DiscoveryContext();
    context.setInputParameters(invocation);
    VersionedCache endpointsVersionedCache = discoveryTree.discovery(context, invocation.getAppId(), invocation.getMicroserviceName(), invocation.getMicroserviceVersionRule());
    if (endpointsVersionedCache.isEmpty()) {
        asyncResp.consumerFail(ExceptionUtils.lbAddressNotFound(invocation.getMicroserviceName(), invocation.getMicroserviceVersionRule(), endpointsVersionedCache.name()));
        return;
    }
    List<Endpoint> endpoints = endpointsVersionedCache.data();
    AtomicInteger index = indexMap.computeIfAbsent(endpointsVersionedCache.name(), name -> {
        LOGGER.info("Create loadBalancer for {}.", name);
        return new AtomicInteger();
    });
    LOGGER.debug("invocation {} use discoveryGroup {}.", invocation.getMicroserviceQualifiedName(), endpointsVersionedCache.name());
    int idx = Math.abs(index.getAndIncrement());
    idx = idx % endpoints.size();
    Endpoint endpoint = endpoints.get(idx);
    invocation.setEndpoint(endpoint);
    invocation.next(asyncResp);
}
Also used : DiscoveryContext(org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext) VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) Endpoint(org.apache.servicecomb.core.Endpoint) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Endpoint(org.apache.servicecomb.core.Endpoint)

Example 5 with Endpoint

use of org.apache.servicecomb.core.Endpoint in project incubator-servicecomb-java-chassis by apache.

the class Consumer method prepareEdge.

private URIEndpointObject prepareEdge() {
    Microservice microservice = RegistryUtils.getMicroservice();
    EndpointsCache endpointsCache = new EndpointsCache(microservice.getAppId(), "edge", "latest", "");
    Endpoint ep = endpointsCache.getLatestEndpoints().get(0);
    URIEndpointObject edgeAddress = (URIEndpointObject) ep.getAddress();
    edgePrefix = String.format("http://%s:%d/api/business", edgeAddress.getHostOrIp(), edgeAddress.getPort());
    return edgeAddress;
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) Endpoint(org.apache.servicecomb.core.Endpoint) EndpointsCache(org.apache.servicecomb.core.endpoint.EndpointsCache) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Aggregations

Endpoint (org.apache.servicecomb.core.Endpoint)14 Test (org.junit.Test)9 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)8 Invocation (org.apache.servicecomb.core.Invocation)5 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)5 Expectations (mockit.Expectations)4 RestOperationMeta (org.apache.servicecomb.common.rest.definition.RestOperationMeta)4 AsyncResponse (org.apache.servicecomb.swagger.invocation.AsyncResponse)4 URLPathBuilder (org.apache.servicecomb.common.rest.definition.path.URLPathBuilder)3 HttpClientRequest (io.vertx.core.http.HttpClientRequest)2 HttpClientResponse (io.vertx.core.http.HttpClientResponse)2 ProduceProcessor (org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor)2 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)2 Context (io.vertx.core.Context)1 HttpClient (io.vertx.core.http.HttpClient)1 HttpMethod (io.vertx.core.http.HttpMethod)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1