use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class HealthMonitorDataProvider method getMonitorData.
private MonitorData getMonitorData() {
Collection<HystrixCommandMetrics> instances = HystrixCommandMetrics.getInstances();
MonitorData monitorData = new MonitorData();
Microservice microservice = RegistryUtils.getMicroservice();
MicroserviceInstance microserviceInstance = RegistryUtils.getMicroserviceInstance();
monitorData.setAppId(microservice.getAppId());
monitorData.setName(microservice.getServiceName());
monitorData.setVersion(microservice.getVersion());
monitorData.setServiceId(microservice.getServiceId());
monitorData.setInstance(microserviceInstance.getHostName());
monitorData.setInstanceId(microserviceInstance.getInstanceId());
if (MonitorConstant.insCacheEnabled()) {
InstanceCacheChecker checker = new InstanceCacheChecker(DiscoveryManager.INSTANCE.getAppManager());
monitorData.setProvidersCache(checker.check().getProducers());
}
exactProcessInfo(monitorData);
synchronized (lock) {
if (this.instanceCacheSummary != null) {
Diagnosis diagnosis = new Diagnosis();
diagnosis.setInstanceCache(instanceCacheSummary);
monitorData.setDiagnosis(diagnosis);
this.instanceCacheSummary = null;
}
}
if (instances.isEmpty()) {
return monitorData;
}
for (HystrixCommandMetrics instance : instances) {
monitorData.appendInterfaceInfo(instance);
}
return monitorData;
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class TestServiceCombServer method setUp.
@Before
public void setUp() {
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId("123456");
cs = new ServiceCombServer(null, transport, new CacheEndpoint("abcd", instance));
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance 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);
MicroserviceInstance instance1 = new MicroserviceInstance();
instance1.setInstanceId("1234");
ServiceCombServer mockedServer = new ServiceCombServer(null, transport, new CacheEndpoint("rest:127.0.0.1:8889", instance1));
Invocation invocation = mock(Invocation.class);
LoadBalancerStats stats = mock(LoadBalancerStats.class);
Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats);
Deencapsulation.invoke(rule, "chooseServerWhenTimeout", Arrays.asList(mockedServer), invocation);
mockedServer.setAlive(true);
mockedServer.setReadyToServe(true);
List<ServiceCombServer> allServers = Arrays.asList(mockedServer);
rule.setLoadBalancer(mockedLb);
Server s = rule.choose(allServers, invocation);
Assert.assertEquals(s, mockedServer);
s = rule.choose(allServers, invocation);
Assert.assertEquals(s, mockedServer);
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class PriorityInstancePropertyDiscoveryFilterTest method testGetFilteredListOfServers.
@Test
public void testGetFilteredListOfServers() {
// complete match
executeTest("", Sets.newHashSet("instance.empty"));
executeTest("local", Sets.newHashSet("instance.local"));
executeTest("local.feature1", Sets.newHashSet("instance.local.feature1"));
executeTest("local.feature1.sprint1", Sets.newHashSet("instance.local.feature1.sprint1"));
// priority match
executeTest("test", Sets.newHashSet("instance.empty"));
executeTest("local.feature2", Sets.newHashSet("instance.local"));
executeTest("local.feature1.sprint2", Sets.newHashSet("instance.local.feature1"));
executeTest("local.feature2.sprint1", Sets.newHashSet("instance.local"));
executeTest("local.feature1.sprint2.temp", Sets.newHashSet("instance.local.feature1"));
// none match
MicroserviceInstance instance1 = instances.remove("instance.empty");
executeTest("", Collections.emptySet());
executeTest("foo", Collections.emptySet());
instances.put("instance.empty", instance1);
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project java-chassis by ServiceComb.
the class TestEnvAdapterManager method testProcessInstance.
@Test
public void testProcessInstance() {
MicroserviceInstance instance = new MicroserviceInstance();
manager.processInstanceWithAdapters(instance);
assertEquals("order=0", instance.getProperties().get("cas_env_one"));
assertEquals("order=0", instance.getProperties().get("cas_env_two"));
assertNull(instance.getProperties().get("default-env-adapter"));
}
Aggregations