use of org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode in project incubator-servicecomb-java-chassis by apache.
the class TestOperationInstancesDiscoveryFilter method discovery_v1_0_0.
@Test
public void discovery_v1_0_0() {
regMicroservice("1", "1.0.0", V1_0_0.class, 2);
MicroserviceVersions MicroserviceVersions = serviceRegistry.getAppManager().getOrCreateMicroserviceVersions(appId, microserviceName);
MicroserviceVersions.submitPull();
MicroserviceVersionRule microserviceVersionRule = MicroserviceVersions.getOrCreateMicroserviceVersionRule(DefinitionConst.VERSION_RULE_ALL);
MicroserviceVersionMeta latestMicroserviceVersionMeta = microserviceVersionRule.getLatestMicroserviceVersion();
latestOperationMeta = latestMicroserviceVersionMeta.getMicroserviceMeta().ensureFindOperation("sid.add");
DiscoveryTreeNode parent = new DiscoveryTreeNode().fromCache(microserviceVersionRule.getVersionedCache());
setupOnChange();
result = filter.discovery(context, parent);
Assert.assertEquals(2, result.mapData().size());
result.mapData().values().forEach(instance -> {
Assert.assertEquals("1", ((MicroserviceInstance) instance).getServiceId());
});
}
use of org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode in project incubator-servicecomb-java-chassis by apache.
the class TestOperationInstancesDiscoveryFilter method discovery_v1_1_0_dec.
@Test
public void discovery_v1_1_0_dec() {
regMicroservice("1", "1.0.0", V1_0_0.class, 2);
regMicroservice("2", "1.1.0", V1_1_0.class, 2);
MicroserviceVersions MicroserviceVersions = serviceRegistry.getAppManager().getOrCreateMicroserviceVersions(appId, microserviceName);
MicroserviceVersions.submitPull();
MicroserviceVersionRule microserviceVersionRule = MicroserviceVersions.getOrCreateMicroserviceVersionRule(DefinitionConst.VERSION_RULE_ALL);
MicroserviceVersionMeta latestMicroserviceVersionMeta = microserviceVersionRule.getLatestMicroserviceVersion();
latestOperationMeta = latestMicroserviceVersionMeta.getMicroserviceMeta().ensureFindOperation("sid.dec");
DiscoveryTreeNode parent = new DiscoveryTreeNode().fromCache(microserviceVersionRule.getVersionedCache());
setupOnChange();
result = filter.discovery(context, parent);
Assert.assertEquals(2, result.mapData().size());
Set<String> ids = new HashSet<>();
result.mapData().values().forEach(instance -> {
ids.add(((MicroserviceInstance) instance).getServiceId());
});
Assert.assertThat(ids, Matchers.containsInAnyOrder("2"));
}
use of org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode in project incubator-servicecomb-java-chassis by apache.
the class OperationInstancesDiscoveryFilter method initOperationNodes.
protected Map<String, DiscoveryTreeNode> initOperationNodes(DiscoveryTreeNode parent, Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> versionMap) {
Map<String, DiscoveryTreeNode> tmpChildren = new ConcurrentHashMapEx<>();
versionMap.keySet().stream().sorted(Comparator.comparing(MicroserviceVersion::getVersion)).forEach(meta -> {
for (OperationMeta operationMeta : meta.getMicroserviceMeta().getOperations()) {
tmpChildren.computeIfAbsent(operationMeta.getMicroserviceQualifiedName(), qualifiedName -> {
VersionRule versionRule = VersionRuleUtils.getOrCreate(meta.getVersion().getVersion() + "+");
return new DiscoveryTreeNode().attribute(VERSION_RULE, versionRule).subName(parent, versionRule.getVersionRule()).data(new HashMap<>());
});
}
});
return tmpChildren;
}
use of org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode in project incubator-servicecomb-java-chassis by apache.
the class TestOperationInstancesDiscoveryFilter method discovery_v1_1_0_add.
@Test
public void discovery_v1_1_0_add() {
regMicroservice("1", "1.0.0", V1_0_0.class, 2);
regMicroservice("2", "1.1.0", V1_1_0.class, 2);
MicroserviceVersions MicroserviceVersions = serviceRegistry.getAppManager().getOrCreateMicroserviceVersions(appId, microserviceName);
MicroserviceVersions.submitPull();
MicroserviceVersionRule microserviceVersionRule = MicroserviceVersions.getOrCreateMicroserviceVersionRule(DefinitionConst.VERSION_RULE_ALL);
MicroserviceVersionMeta latestMicroserviceVersionMeta = microserviceVersionRule.getLatestMicroserviceVersion();
latestOperationMeta = latestMicroserviceVersionMeta.getMicroserviceMeta().ensureFindOperation("sid.add");
DiscoveryTreeNode parent = new DiscoveryTreeNode().fromCache(microserviceVersionRule.getVersionedCache());
setupOnChange();
result = filter.discovery(context, parent);
Assert.assertEquals(4, result.mapData().size());
Set<String> ids = new HashSet<>();
result.mapData().values().forEach(instance -> {
ids.add(((MicroserviceInstance) instance).getServiceId());
});
Assert.assertThat(ids, Matchers.containsInAnyOrder("1", "2"));
}
Aggregations