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);
}
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;
}
}
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());
}
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);
}
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;
}
Aggregations