Search in sources :

Example 6 with MicroserviceVersionRule

use of org.apache.servicecomb.registry.consumer.MicroserviceVersionRule in project java-chassis by ServiceComb.

the class TestConsumers method delete_disconnect_cache.

@Test
public void delete_disconnect_cache() {
    MicroserviceVersionRule microserviceVersionRule = appManager.getOrCreateMicroserviceVersionRule(appId, serviceName, versionRule);
    Assert.assertEquals("0.0.0.0+", microserviceVersionRule.getVersionRule().getVersionRule());
    Assert.assertEquals(1, microserviceManager.getVersionsByName().size());
    mockDisconnect();
    appManager.pullInstances();
    Assert.assertEquals(1, microserviceManager.getVersionsByName().size());
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) Test(org.junit.Test)

Example 7 with MicroserviceVersionRule

use of org.apache.servicecomb.registry.consumer.MicroserviceVersionRule in project java-chassis by ServiceComb.

the class TestConsumers method testCreateRuleServiceNotExists.

@Test
public void testCreateRuleServiceNotExists() {
    serviceName = "notExist";
    MicroserviceVersions microserviceVersions = microserviceManager.getOrCreateMicroserviceVersions(serviceName);
    MicroserviceVersionRule microserviceVersionRule = microserviceVersions.getOrCreateMicroserviceVersionRule(versionRule);
    Assert.assertEquals("0.0.0.0+", microserviceVersionRule.getVersionRule().getVersionRule());
    Assert.assertNull(microserviceVersionRule.getLatestMicroserviceVersion());
    Assert.assertEquals(0, microserviceManager.getVersionsByName().size());
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) MicroserviceVersions(org.apache.servicecomb.registry.consumer.MicroserviceVersions) Test(org.junit.Test)

Example 8 with MicroserviceVersionRule

use of org.apache.servicecomb.registry.consumer.MicroserviceVersionRule in project java-chassis by ServiceComb.

the class TestConsumers method watchDeleteEvent.

@Test
public void watchDeleteEvent() {
    MicroserviceVersionRule microserviceVersionRule = appManager.getOrCreateMicroserviceVersionRule(appId, serviceName, versionRule);
    Assert.assertEquals("0.0.0.0+", microserviceVersionRule.getVersionRule().getVersionRule());
    Assert.assertEquals(1, microserviceManager.getVersionsByName().size());
    mockNotExist();
    MicroserviceKey key = new MicroserviceKey();
    MicroserviceInstanceChangedEvent event = new MicroserviceInstanceChangedEvent();
    event.setKey(key);
    key.setAppId(appId);
    key.setServiceName(serviceName);
    eventBus.post(event);
    Assert.assertEquals(0, microserviceManager.getVersionsByName().size());
}
Also used : MicroserviceInstanceChangedEvent(org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent) MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) MicroserviceKey(org.apache.servicecomb.registry.api.MicroserviceKey) Test(org.junit.Test)

Example 9 with MicroserviceVersionRule

use of org.apache.servicecomb.registry.consumer.MicroserviceVersionRule in project java-chassis by ServiceComb.

the class ITUtils method waitMicroserviceReady.

public static Map<String, MicroserviceInstance> waitMicroserviceReady(String appId, String microserviceName, String strVersionRule, int minInstanceCount) {
    LOGGER.info("waiting for microservice online. appId={}, name={}, minInstanceCount={}", appId, microserviceName, minInstanceCount);
    Map<String, MicroserviceInstance> instances;
    for (; ; ) {
        MicroserviceVersionRule microserviceVersionRule = DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceVersionRule(appId, microserviceName, strVersionRule);
        instances = microserviceVersionRule.getInstances();
        if (instances.size() >= minInstanceCount) {
            break;
        }
        LOGGER.info("waiting for microservice online. appId={}, name={}, expect minInstanceCount={}, real instanceCount={}.", appId, microserviceName, minInstanceCount, instances.size());
        // pull at once
        DiscoveryManager.INSTANCE.getAppManager().pullInstances();
        forceWait(TimeUnit.SECONDS, 1);
    }
    LOGGER.info("microservice already online. appId={}, name={}, instanceCount={}", appId, microserviceName, minInstanceCount);
    return instances;
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance)

Example 10 with MicroserviceVersionRule

use of org.apache.servicecomb.registry.consumer.MicroserviceVersionRule in project java-chassis by ServiceComb.

the class TestInstanceCacheCheckerWithoutMock method check_StaticMicroservice.

@Test
public void check_StaticMicroservice() {
    microserviceName = appId + ":" + microserviceName;
    RegistrationManager.INSTANCE.registerMicroserviceMappingByEndpoints(microserviceName, "1", Arrays.asList("rest://localhost:8080"), ThirdPartyServiceForUT.class);
    MicroserviceVersionRule microserviceVersionRule = DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceVersionRule(appId, microserviceName, DefinitionConst.VERSION_RULE_ALL);
    Assert.assertEquals(microserviceName, microserviceVersionRule.getLatestMicroserviceVersion().getMicroserviceName());
    InstanceCacheSummary instanceCacheSummary = checker.check();
    expectedSummary.setStatus(Status.NORMAL);
    Assert.assertEquals(Json.encode(expectedSummary), Json.encode(instanceCacheSummary));
}
Also used : MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) Test(org.junit.Test)

Aggregations

MicroserviceVersionRule (org.apache.servicecomb.registry.consumer.MicroserviceVersionRule)10 Test (org.junit.Test)7 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)3 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)1 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)1 MicroserviceReferenceConfig (org.apache.servicecomb.core.provider.consumer.MicroserviceReferenceConfig)1 URIEndpointObject (org.apache.servicecomb.foundation.common.net.URIEndpointObject)1 MicroserviceKey (org.apache.servicecomb.registry.api.MicroserviceKey)1 MicroserviceInstanceChangedEvent (org.apache.servicecomb.registry.api.event.MicroserviceInstanceChangedEvent)1 MicroserviceVersion (org.apache.servicecomb.registry.consumer.MicroserviceVersion)1 MicroserviceVersions (org.apache.servicecomb.registry.consumer.MicroserviceVersions)1