Search in sources :

Example 36 with MicroserviceInstances

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.

the class DiscoveryManager method findServiceInstances.

public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule, String revision) {
    MicroserviceInstances result = new MicroserviceInstances();
    // default values not suitable for aggregate, reset.
    result.setNeedRefresh(false);
    result.setMicroserviceNotExist(true);
    discoveryList.forEach(discovery -> {
        MicroserviceInstances instances = discovery.findServiceInstances(appId, serviceName, versionRule, revision);
        result.mergeMicroserviceInstances(instances);
    });
    return result;
}
Also used : MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances)

Example 37 with MicroserviceInstances

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.

the class RefreshableMicroserviceCacheTest method refresh_service_not_exist.

@Test
public void refresh_service_not_exist() {
    findServiceInstancesOprHolder.value = params -> {
        MicroserviceInstances microserviceInstances = new MicroserviceInstances();
        microserviceInstances.setMicroserviceNotExist(true);
        return microserviceInstances;
    };
    List<MicroserviceInstance> oldInstanceList = microserviceCache.getInstances();
    microserviceCache.refresh();
    Assert.assertEquals(MicroserviceCacheStatus.SERVICE_NOT_FOUND, microserviceCache.getStatus());
    Assert.assertSame(oldInstanceList, microserviceCache.getInstances());
}
Also used : MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 38 with MicroserviceInstances

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.

the class RefreshableMicroserviceCacheTest method forceRefresh.

@Test
public void forceRefresh() {
    MicroserviceInstance microserviceInstance = new MicroserviceInstance();
    microserviceInstance.setInstanceId("instanceId00");
    ArrayList<MicroserviceInstance> instances = new ArrayList<>();
    instances.add(microserviceInstance);
    findServiceInstancesOprHolder.value = params -> {
        Assert.assertEquals("consumerId", params[0]);
        Assert.assertEquals("app", params[1]);
        Assert.assertEquals("svc", params[2]);
        Assert.assertEquals("0.0.0.0+", params[3]);
        Assert.assertNull(params[4]);
        MicroserviceInstances microserviceInstances = new MicroserviceInstances();
        microserviceInstances.setNeedRefresh(true);
        microserviceInstances.setRevision("rev2");
        microserviceInstances.setMicroserviceNotExist(false);
        FindInstancesResponse instancesResponse = new FindInstancesResponse();
        instancesResponse.setInstances(instances);
        microserviceInstances.setInstancesResponse(instancesResponse);
        return microserviceInstances;
    };
    microserviceCache.revisionId = "rev";
    microserviceCache.forceRefresh();
    Assert.assertEquals(MicroserviceCacheStatus.REFRESHED, microserviceCache.getStatus());
    List<MicroserviceInstance> cachedInstances = microserviceCache.getInstances();
    Assert.assertEquals(1, cachedInstances.size());
    MicroserviceInstance instance = cachedInstances.iterator().next();
    Assert.assertEquals("instanceId00", instance.getInstanceId());
    Assert.assertEquals("rev2", microserviceCache.getRevisionId());
}
Also used : MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) FindInstancesResponse(org.apache.servicecomb.registry.api.registry.FindInstancesResponse) Test(org.junit.Test)

Example 39 with MicroserviceInstances

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.

the class RefreshableMicroserviceCacheTest method refresh_service_no_change.

@Test
public void refresh_service_no_change() {
    findServiceInstancesOprHolder.value = params -> {
        MicroserviceInstances microserviceInstances = new MicroserviceInstances();
        microserviceInstances.setMicroserviceNotExist(false);
        microserviceInstances.setNeedRefresh(false);
        return microserviceInstances;
    };
    List<MicroserviceInstance> oldInstanceList = microserviceCache.getInstances();
    microserviceCache.refresh();
    Assert.assertEquals(MicroserviceCacheStatus.NO_CHANGE, microserviceCache.getStatus());
    Assert.assertSame(oldInstanceList, microserviceCache.getInstances());
}
Also used : MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Example 40 with MicroserviceInstances

use of org.apache.servicecomb.registry.api.registry.MicroserviceInstances in project incubator-servicecomb-java-chassis by apache.

the class RefreshableMicroserviceCacheTest method setUp.

@Before
public void setUp() throws Exception {
    srClient = new MockUp<ServiceRegistryClient>() {

        @Mock
        MicroserviceInstances findServiceInstances(String consumerId, String appId, String serviceName, String versionRule, String revision) {
            return findServiceInstancesOprHolder.value.apply(new Object[] { consumerId, appId, serviceName, versionRule, revision });
        }
    }.getMockInstance();
    consumerService = new Microservice();
    consumerService.setServiceId("consumerId");
    microserviceCache = new RefreshableMicroserviceCache(consumerService, MicroserviceCacheKey.builder().env("env").appId("app").serviceName("svc").build(), srClient, false);
    findServiceInstancesOprHolder.value = params -> {
        MicroserviceInstances microserviceInstances = new MicroserviceInstances();
        microserviceInstances.setNeedRefresh(true);
        microserviceInstances.setRevision("rev0");
        microserviceInstances.setMicroserviceNotExist(false);
        FindInstancesResponse instancesResponse = new FindInstancesResponse();
        instancesResponse.setInstances(pulledInstances);
        microserviceInstances.setInstancesResponse(instancesResponse);
        return microserviceInstances;
    };
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) MockUp(mockit.MockUp) FindInstancesResponse(org.apache.servicecomb.registry.api.registry.FindInstancesResponse) Before(org.junit.Before)

Aggregations

MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)52 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)34 Test (org.junit.Test)22 FindInstancesResponse (org.apache.servicecomb.registry.api.registry.FindInstancesResponse)18 Microservice (org.apache.servicecomb.registry.api.registry.Microservice)12 ArrayList (java.util.ArrayList)8 MockUp (mockit.MockUp)8 Before (org.junit.Before)6 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Handler (io.vertx.core.Handler)2 Buffer (io.vertx.core.buffer.Buffer)2 HttpClientResponse (io.vertx.core.http.HttpClientResponse)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 Enumeration (java.util.Enumeration)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2