use of io.servicecomb.core.Transport in project java-chassis by ServiceComb.
the class AbstractEndpointsCache method createEndpoints.
protected List<ENDPOINT> createEndpoints(Map<String, List<CacheEndpoint>> transportMap) {
List<ENDPOINT> tmpEndpoints = new ArrayList<>();
for (Entry<String, List<CacheEndpoint>> entry : transportMap.entrySet()) {
Transport transport = transportManager.findTransport(entry.getKey());
if (transport == null) {
continue;
}
List<CacheEndpoint> endpointList = entry.getValue();
if (endpointList == null) {
continue;
}
for (CacheEndpoint cacheEndpont : endpointList) {
ENDPOINT endpoint = createEndpoint(transport, cacheEndpont);
tmpEndpoints.add(endpoint);
}
}
return tmpEndpoints;
}
use of io.servicecomb.core.Transport in project java-chassis by ServiceComb.
the class TestServerListCache method mockTestCases.
private void mockTestCases() {
final Microservice microService = new Microservice();
microService.setAppId("appId");
new MockUp<RegistryUtils>() {
@Mock
public Microservice getMicroservice() {
return microService;
}
@Mock
private Microservice createMicroserviceFromDefinition() {
return microService;
}
};
new MockUp<InstanceCacheManager>() {
@Mock
public InstanceCache getOrCreate(String appId, String microserviceName, String microserviceVersionRule) {
return null;
}
};
transport = Mockito.mock(Transport.class);
}
use of io.servicecomb.core.Transport in project java-chassis by ServiceComb.
the class TestSessionSticknessRule method testRuleFullOperation.
@Test
public void testRuleFullOperation() {
SessionStickinessRule rule = new SessionStickinessRule();
LoadBalancer mockedLb = mock(LoadBalancer.class);
Transport transport = mock(Transport.class);
CseServer mockedServer = new CseServer(transport, new CacheEndpoint("rest:127.0.0.1:8888", null));
Object key = Mockito.mock(Object.class);
LoadBalancerStats stats = mock(LoadBalancerStats.class);
Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats);
Deencapsulation.invoke(rule, "chooseServerWhenTimeout", key);
mockedServer.setAlive(true);
mockedServer.setReadyToServe(true);
List<Server> allServers = Arrays.asList(mockedServer);
when(mockedLb.getReachableServers()).thenReturn(allServers);
when(mockedLb.getAllServers()).thenReturn(allServers);
rule.setLoadBalancer(mockedLb);
Assert.assertEquals(rule.getLoadBalancer(), mockedLb);
Server s = rule.choose("default");
Assert.assertEquals(s, mockedServer);
s = rule.choose("default");
Assert.assertEquals(s, mockedServer);
}
use of io.servicecomb.core.Transport 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;
}
}
}
Aggregations