use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractTransportDiscoveryFilter method createInstance.
private MicroserviceInstance createInstance(String... schemas) {
String id = UUID.randomUUID().toString();
MicroserviceInstance instance = new MicroserviceInstance();
instance.setInstanceId(id);
for (int idx = 0; idx < schemas.length; idx++) {
String schema = schemas[idx];
instance.getEndpoints().add(String.format("%s://%s:%d", schema, id, 8080 + idx));
}
return instance;
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestAbstractTransportDiscoveryFilter method createDiscoveryTree_ignoreInvalid.
@Test
public void createDiscoveryTree_ignoreInvalid() {
MicroserviceInstance instance1 = createInstance("a", "b");
MicroserviceInstance instance2 = createInstance("");
Map<String, MicroserviceInstance> instances = createMicroserviceInstances("name", instance1, instance2);
parent.data(instances);
result = filter.createDiscoveryTreeNode("", context, parent);
Assert.assertEquals("parent/", result.name());
Assert.assertThat(result.collectionData(), Matchers.contains(instance1.getEndpoints().toArray()));
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class InstanceStatusDiscoveryFilter method init.
@Override
public void init(DiscoveryContext context, DiscoveryTreeNode parent) {
Map<String, MicroserviceInstance> instances = parent.data();
Map<String, MicroserviceInstance> filteredServers = new HashMap<>();
for (Entry<String, MicroserviceInstance> instanceEntry : instances.entrySet()) {
MicroserviceInstance instance = instanceEntry.getValue();
if (MicroserviceInstanceStatus.UP == instance.getStatus()) {
filteredServers.put(instanceEntry.getKey(), instance);
}
}
if (filteredServers.isEmpty()) {
return;
}
DiscoveryTreeNode child = new DiscoveryTreeNode().subName(parent, UP_INSTANCES).data(filteredServers);
parent.child(UP_INSTANCES, child);
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class Test3rdPartyInvocation method beforeClass.
@BeforeClass
public static void beforeClass() {
String endpoint = ((ITSCBRestTemplate) consumersJaxrs.getSCBRestTemplate()).getAddress(Const.RESTFUL);
RegistrationManager.INSTANCE.registerMicroserviceMappingByEndpoints(THIRD_PARTY_MICROSERVICE_NAME, "1.2.1", Collections.singletonList(endpoint), DataTypeJaxrsSchemaIntf.class);
MicroserviceInstance instance = new MicroserviceInstance();
instance.setEndpoints(Collections.singletonList(endpoint));
RegistrationManager.INSTANCE.registerMicroserviceMapping(ASYNC_THIRD_PARTY_MICROSERVICE_NAME, "1.1.1", Collections.singletonList(instance), DataTypeJaxrsSchemaAsyncIntf.class);
dataTypeJaxrsSchema = Invoker.createProxy(THIRD_PARTY_MICROSERVICE_NAME, THIRD_PARTY_MICROSERVICE_NAME, DataTypeJaxrsSchemaIntf.class);
dataTypeJaxrsSchemaAsync = Invoker.createProxy(ASYNC_THIRD_PARTY_MICROSERVICE_NAME, ASYNC_THIRD_PARTY_MICROSERVICE_NAME, DataTypeJaxrsSchemaAsyncIntf.class);
}
use of org.apache.servicecomb.registry.api.registry.MicroserviceInstance in project incubator-servicecomb-java-chassis by apache.
the class TestInstanceCacheCheckerMock method check_findInstances_cacheNotMatch.
@Test
public void check_findInstances_cacheNotMatch() {
Holder<MicroserviceInstances> findHolder = createFindServiceInstancesResult();
new MockUp<RegistryUtils>() {
@Mock
MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule) {
return findHolder.value;
}
};
registerMicroservice(appId, microserviceName);
MicroserviceVersions microserviceVersions = DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceVersions(appId, microserviceName);
microserviceVersions.setRevision("first");
microserviceVersions.getOrCreateMicroserviceVersionRule(DefinitionConst.VERSION_RULE_ALL);
Holder<MicroserviceInstances> newFindHolder = createFindServiceInstancesResult();
newFindHolder.value.getInstancesResponse().getInstances().add(new MicroserviceInstance());
findHolder.value = newFindHolder.value;
InstanceCacheSummary instanceCacheSummary = checker.check();
InstanceCacheResult instanceCacheResult = new InstanceCacheResult();
instanceCacheResult.setAppId(appId);
instanceCacheResult.setMicroserviceName(microserviceName);
instanceCacheResult.setStatus(Status.ABNORMAL);
instanceCacheResult.setDetail("instance cache not match");
instanceCacheResult.setPulledInstances(new ArrayList<>());
expectedSummary.getProducers().add(instanceCacheResult);
expectedSummary.setStatus(Status.ABNORMAL);
Assert.assertEquals(Json.encode(expectedSummary), Json.encode(instanceCacheSummary));
Assert.assertNull(microserviceVersions.getRevision());
}
Aggregations