Search in sources :

Example 61 with MicroserviceInstance

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;
}
Also used : MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance)

Example 62 with MicroserviceInstance

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()));
}
Also used : MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 63 with MicroserviceInstance

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);
}
Also used : HashMap(java.util.HashMap) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance)

Example 64 with MicroserviceInstance

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);
}
Also used : MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) ITSCBRestTemplate(org.apache.servicecomb.it.extend.engine.ITSCBRestTemplate) BeforeClass(org.junit.BeforeClass)

Example 65 with MicroserviceInstance

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());
}
Also used : MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) MockUp(mockit.MockUp) MicroserviceVersions(org.apache.servicecomb.registry.consumer.MicroserviceVersions) Test(org.junit.Test)

Aggregations

MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)232 Test (org.junit.Test)136 ArrayList (java.util.ArrayList)60 HashMap (java.util.HashMap)42 Invocation (org.apache.servicecomb.core.Invocation)40 DiscoveryTreeNode (org.apache.servicecomb.registry.discovery.DiscoveryTreeNode)40 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)38 Expectations (mockit.Expectations)36 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)32 CacheEndpoint (org.apache.servicecomb.registry.cache.CacheEndpoint)30 List (java.util.List)22 Transport (org.apache.servicecomb.core.Transport)22 Before (org.junit.Before)22 Map (java.util.Map)18 TransportManager (org.apache.servicecomb.core.transport.TransportManager)18 InstanceCacheManager (org.apache.servicecomb.registry.cache.InstanceCacheManager)18 MockUp (mockit.MockUp)16 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)14 ServiceCombServer (org.apache.servicecomb.loadbalance.ServiceCombServer)14 Server (com.netflix.loadbalancer.Server)12