Search in sources :

Example 16 with VersionedCache

use of org.apache.servicecomb.foundation.common.cache.VersionedCache in project incubator-servicecomb-java-chassis by apache.

the class TestLoadbalanceHandler method getOrCreateLoadBalancer.

@Test
public void getOrCreateLoadBalancer() throws Exception {
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setInstanceId("id");
    instance.getEndpoints().add("rest://localhost:8080");
    Map<String, MicroserviceInstance> instanceMap = new HashMap<>();
    instanceMap.put(instance.getInstanceId(), instance);
    VersionedCache instanceVersionedCache = new VersionedCache().autoCacheVersion().name("instanceCache").data(instanceMap);
    new Expectations() {

        {
            invocation.getConfigTransportName();
            result = "rest";
            instanceCacheManager.getOrCreateVersionedCache(anyString, anyString, anyString);
            result = instanceVersionedCache;
        }
    };
    LoadBalancer lb = handler.getOrCreateLoadBalancer(invocation);
    Assert.assertEquals(2, lb.getFilterSize());
    Assert.assertEquals("instanceCache/rest", lb.getName());
    Assert.assertEquals("[rest://localhost:8080]", Deencapsulation.getField(lb, "serverList").toString());
}
Also used : Expectations(mockit.Expectations) VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) HashMap(java.util.HashMap) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 17 with VersionedCache

use of org.apache.servicecomb.foundation.common.cache.VersionedCache in project java-chassis by ServiceComb.

the class TestInstanceCache method getVersionedCache.

@Test
public void getVersionedCache() {
    VersionedCache versionedCache = instanceCache.getVersionedCache();
    Assert.assertEquals("1.0", versionedCache.name());
    Assert.assertSame(instMap, versionedCache.data());
}
Also used : VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) Test(org.junit.Test)

Example 18 with VersionedCache

use of org.apache.servicecomb.foundation.common.cache.VersionedCache in project java-chassis by ServiceComb.

the class CommonHttpEdgeDispatcher method getOrCreateLoadBalancer.

protected LoadBalancer getOrCreateLoadBalancer(Invocation invocation, String microserviceName, String versionRule) {
    DiscoveryContext context = new DiscoveryContext();
    context.setInputParameters(invocation);
    VersionedCache serversVersionedCache = discoveryTree.discovery(context, RegistrationManager.INSTANCE.getMicroservice().getAppId(), microserviceName, versionRule);
    invocation.addLocalContext(LoadbalanceHandler.CONTEXT_KEY_SERVER_LIST, serversVersionedCache.data());
    return loadBalancerMap.computeIfAbsent(microserviceName, name -> createLoadBalancer(microserviceName));
}
Also used : DiscoveryContext(org.apache.servicecomb.registry.discovery.DiscoveryContext) VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache)

Example 19 with VersionedCache

use of org.apache.servicecomb.foundation.common.cache.VersionedCache in project java-chassis by ServiceComb.

the class TestDiscoveryTree method getOrCreateRoot_tempRoot.

@Test
public void getOrCreateRoot_tempRoot() {
    Deencapsulation.setField(discoveryTree, "root", parent);
    VersionedCache inputCache = new VersionedCache().cacheVersion(parent.cacheVersion() - 1);
    DiscoveryTreeNode root = discoveryTree.getOrCreateRoot(inputCache);
    Assert.assertEquals(inputCache.cacheVersion(), root.cacheVersion());
    Assert.assertNotSame(Deencapsulation.getField(discoveryTree, "root"), root);
}
Also used : VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) DiscoveryTreeNode(org.apache.servicecomb.registry.discovery.DiscoveryTreeNode) Test(org.junit.Test)

Example 20 with VersionedCache

use of org.apache.servicecomb.foundation.common.cache.VersionedCache in project java-chassis by ServiceComb.

the class TestDiscoveryTree method avoidConcurrentProblem.

@Test
public void avoidConcurrentProblem() {
    Deencapsulation.setField(discoveryTree, "root", parent.cacheVersion(1));
    Assert.assertTrue(parent.children().isEmpty());
    discoveryTree.discovery(context, new VersionedCache().cacheVersion(0).name("input"));
    Assert.assertTrue(parent.children().isEmpty());
}
Also used : VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) Test(org.junit.Test)

Aggregations

VersionedCache (org.apache.servicecomb.foundation.common.cache.VersionedCache)20 Test (org.junit.Test)9 DiscoveryContext (org.apache.servicecomb.registry.discovery.DiscoveryContext)5 DiscoveryContext (org.apache.servicecomb.serviceregistry.discovery.DiscoveryContext)4 MicroserviceInstance (org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance)3 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Endpoint (org.apache.servicecomb.core.Endpoint)2 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)2 DiscoveryTreeNode (org.apache.servicecomb.registry.discovery.DiscoveryTreeNode)2 InvocationContext (org.apache.servicecomb.swagger.invocation.context.InvocationContext)2 Server (com.netflix.loadbalancer.Server)1 HashMap (java.util.HashMap)1 Expectations (mockit.Expectations)1 CseHttpEntity (org.apache.servicecomb.provider.springmvc.reference.CseHttpEntity)1 InstanceCache (org.apache.servicecomb.registry.cache.InstanceCache)1 InstanceCache (org.apache.servicecomb.serviceregistry.cache.InstanceCache)1 DiscoveryTree (org.apache.servicecomb.serviceregistry.discovery.DiscoveryTree)1