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