Search in sources :

Example 11 with VersionedCache

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

the class TestDateTimeSchema method testDateTimeSchemaMulticast.

private void testDateTimeSchemaMulticast() throws Exception {
    DiscoveryContext context = new DiscoveryContext();
    VersionedCache serversVersionedCache = discoveryTree.discovery(context, "springmvctest", "springmvc", "0+");
    List<String> enpoints = serversVersionedCache.data();
    for (String endpoint : enpoints) {
        InvocationContext invocationContext = new InvocationContext();
        invocationContext.addLocalContext(LoadbalanceHandler.SERVICECOMB_SERVER_ENDPOINT, endpoint);
        Date date = new Date();
        TestMgr.check(date.getTime(), dateTimeSchemaWithContextInf.getDate(invocationContext, date).getTime());
        invocationContext = new InvocationContext();
        invocationContext.addLocalContext(LoadbalanceHandler.SERVICECOMB_SERVER_ENDPOINT, parseEndpoint(endpoint));
        date = new Date();
        TestMgr.check(date.getTime(), dateTimeSchemaWithContextInf.getDate(invocationContext, date).getTime());
    }
}
Also used : DiscoveryContext(org.apache.servicecomb.registry.discovery.DiscoveryContext) VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 12 with VersionedCache

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

the class MicroserviceVersionRule method initData.

private void initData(MicroserviceVersionRuleData data) {
    if (data.latestVersion == null) {
        data.latestVersion = findLatest(data.versions, data.instances.values());
    }
    data.instanceCache = new InstanceCache(appId, microserviceName, versionRule.getVersionRule(), data.instances);
    data.versionedCache = new VersionedCache().name(versionRule.getVersionRule()).autoCacheVersion().data(data.instances);
}
Also used : VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) InstanceCache(org.apache.servicecomb.registry.cache.InstanceCache)

Example 13 with VersionedCache

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

the class TestDiscoveryTree method getOrCreateRoot_expired.

@Test
public void getOrCreateRoot_expired() {
    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.assertSame(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 14 with VersionedCache

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

the class TestDiscoveryTreeNode method fromCache.

@Test
public void fromCache() {
    Object data = new Object();
    VersionedCache other = new VersionedCache().cacheVersion(1).name("cache").data(data);
    node.fromCache(other);
    Assert.assertEquals(1, node.cacheVersion());
    Assert.assertEquals("cache", node.name());
    Assert.assertSame(data, node.data());
}
Also used : VersionedCache(org.apache.servicecomb.foundation.common.cache.VersionedCache) Test(org.junit.Test)

Example 15 with VersionedCache

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

the class LoadbalanceHandler method getOrCreateLoadBalancer.

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

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