Search in sources :

Example 1 with CacheEndpoint

use of io.servicecomb.serviceregistry.cache.CacheEndpoint 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;
}
Also used : CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Transport(io.servicecomb.core.Transport)

Example 2 with CacheEndpoint

use of io.servicecomb.serviceregistry.cache.CacheEndpoint 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);
}
Also used : Server(com.netflix.loadbalancer.Server) CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint) LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats) Transport(io.servicecomb.core.Transport) Test(org.junit.Test)

Example 3 with CacheEndpoint

use of io.servicecomb.serviceregistry.cache.CacheEndpoint in project java-chassis by ServiceComb.

the class IpPortManager method get.

public IpPort get() {
    List<CacheEndpoint> addresses = getAddressCaches();
    if (addresses == null || addresses.size() == 0) {
        return getDefaultIpPort();
    }
    synchronized (lockObj) {
        int id = indexForAuto.get();
        addressCanUsed.putIfAbsent(id, true);
        return new URIEndpointObject(addresses.get(id).getEndpoint());
    }
}
Also used : CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject) CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint)

Example 4 with CacheEndpoint

use of io.servicecomb.serviceregistry.cache.CacheEndpoint in project java-chassis by ServiceComb.

the class IpPortManager method next.

public IpPort next() {
    List<CacheEndpoint> addresses = getAddressCaches();
    if ((addresses == null || addresses.size() == 0)) {
        return nextDefaultIpPort();
    }
    synchronized (lockObj) {
        int id = indexForAuto.get();
        // 重置可用的地址为false
        if (addressCanUsed.get(id) != null && addressCanUsed.get(id)) {
            addressCanUsed.put(id, false);
            if (id == addresses.size() - 1) {
                indexForAuto.set(0);
                // 重新轮询
                addressCanUsed.clear();
                LOGGER.warn("service center has no available instance");
                return null;
            } else {
                indexForAuto.getAndIncrement();
            }
            LOGGER.warn("service center instance {} is unreachable, try another instance {}", addresses.get(id).getEndpoint(), addresses.get(indexForAuto.get()).getEndpoint());
        }
        return new URIEndpointObject(addresses.get(indexForAuto.get()).getEndpoint());
    }
}
Also used : CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint) URIEndpointObject(io.servicecomb.foundation.common.net.URIEndpointObject) CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint)

Example 5 with CacheEndpoint

use of io.servicecomb.serviceregistry.cache.CacheEndpoint in project java-chassis by ServiceComb.

the class TestServerListCache method testCreateEndpointTransportString.

@Test
public void testCreateEndpointTransportString() {
    Server server = instance.createEndpoint(transport, new CacheEndpoint("stringAddress", null));
    Assert.assertNotNull(server);
}
Also used : Server(com.netflix.loadbalancer.Server) CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint) Test(org.junit.Test)

Aggregations

CacheEndpoint (io.servicecomb.serviceregistry.cache.CacheEndpoint)6 Test (org.junit.Test)3 Server (com.netflix.loadbalancer.Server)2 Transport (io.servicecomb.core.Transport)2 URIEndpointObject (io.servicecomb.foundation.common.net.URIEndpointObject)2 ArrayList (java.util.ArrayList)2 LoadBalancerStats (com.netflix.loadbalancer.LoadBalancerStats)1 HashMap (java.util.HashMap)1 List (java.util.List)1 MockUp (mockit.MockUp)1