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