Search in sources :

Example 46 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class LocalServiceRegistryClientImplTest method getMicroserviceId_latest.

@Test
public void getMicroserviceId_latest() {
    Microservice v2 = mockRegisterMicroservice(appId, microserviceName, "2.0.0");
    mockRegisterMicroservice(appId, microserviceName, "1.0.0");
    String serviceId = registryClient.getMicroserviceId(appId, microserviceName, DefinitionConst.VERSION_RULE_LATEST, "");
    Assert.assertEquals(v2.getServiceId(), serviceId);
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Example 47 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class Consumer method prepareEdge.

private URIEndpointObject prepareEdge(String prefix) {
    Microservice microservice = RegistrationManager.INSTANCE.getMicroservice();
    MicroserviceInstance microserviceInstance = (MicroserviceInstance) DiscoveryManager.INSTANCE.getAppManager().getOrCreateMicroserviceVersionRule(microservice.getAppId(), "edge", DefinitionConst.VERSION_RULE_ALL).getVersionedCache().mapData().values().stream().findFirst().get();
    URIEndpointObject edgeAddress = new URIEndpointObject(microserviceInstance.getEndpoints().get(0));
    edgePrefix = String.format("http://%s:%d/%s/business", edgeAddress.getHostOrIp(), edgeAddress.getPort(), prefix);
    return edgeAddress;
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) URIEndpointObject(org.apache.servicecomb.foundation.common.net.URIEndpointObject)

Example 48 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class MockMicroserviceVersions method findInstances.

public List<MicroserviceInstance> findInstances(String... strVersions) {
    List<String> unifyVersions = Arrays.stream(strVersions).map(version -> new Version(version).getVersion()).collect(Collectors.toList());
    List<MicroserviceInstance> instances = new ArrayList<>();
    for (MicroserviceInstance instance : mockedInstances) {
        Microservice microservice = mockedMicroservices.get(instance.getServiceId());
        for (String version : unifyVersions) {
            if (version.equals(microservice.getVersion())) {
                instances.add(instance);
                break;
            }
        }
    }
    return instances;
}
Also used : Arrays(java.util.Arrays) MockUp(mockit.MockUp) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Version(org.apache.servicecomb.foundation.common.Version) Matchers(org.hamcrest.Matchers) HashMap(java.util.HashMap) DiscoveryManager(org.apache.servicecomb.registry.DiscoveryManager) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) AppManager(org.apache.servicecomb.registry.consumer.AppManager) MicroserviceVersion(org.apache.servicecomb.registry.consumer.MicroserviceVersion) Map(java.util.Map) MicroserviceVersions(org.apache.servicecomb.registry.consumer.MicroserviceVersions) Mock(mockit.Mock) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) MicroserviceVersionRule(org.apache.servicecomb.registry.consumer.MicroserviceVersionRule) Assert(org.junit.Assert) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Version(org.apache.servicecomb.foundation.common.Version) MicroserviceVersion(org.apache.servicecomb.registry.consumer.MicroserviceVersion) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance)

Example 49 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class MockMicroserviceVersions method addMock.

public void addMock(String version, int instanceCount) {
    version = new Version(version).getVersion();
    Microservice microservice = new Microservice();
    microservice.setAppId(getAppId());
    microservice.setServiceName(getMicroserviceName());
    microservice.setServiceId("sid-" + version);
    microservice.setVersion(version);
    mockedMicroservices.put(microservice.getServiceId(), microservice);
    for (int idx = 0; idx < instanceCount; idx++) {
        MicroserviceInstance instance = new MicroserviceInstance();
        instance.setServiceId(microservice.getServiceId());
        instance.setInstanceId(String.format("iid-%s-%d", version, idx));
        mockedInstances.add(instance);
    }
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Version(org.apache.servicecomb.foundation.common.Version) MicroserviceVersion(org.apache.servicecomb.registry.consumer.MicroserviceVersion) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance)

Example 50 with Microservice

use of org.apache.servicecomb.registry.api.registry.Microservice in project java-chassis by ServiceComb.

the class TestRegistry method testDelegate.

@SuppressWarnings("deprecation")
@Test
public void testDelegate() {
    ServiceRegistry serviceRegistry = LocalServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    RegistryUtils.init();
    serviceRegistry.run();
    RegistryUtils.setServiceRegistry(serviceRegistry);
    Assert.assertEquals(serviceRegistry, RegistryUtils.getServiceRegistry());
    Assert.assertEquals(serviceRegistry.getServiceRegistryClient(), RegistryUtils.getServiceRegistryClient());
    Microservice microservice = RegistryUtils.getMicroservice();
    Assert.assertEquals(serviceRegistry.getMicroservice(), microservice);
    Assert.assertEquals(serviceRegistry.getMicroserviceInstance(), RegistryUtils.getMicroserviceInstance());
    List<MicroserviceInstance> instanceList = RegistryUtils.findServiceInstance("default", "default", "0.0.1");
    Assert.assertEquals(1, instanceList.size());
    Assert.assertEquals(RegistryUtils.getMicroservice().getServiceId(), instanceList.get(0).getServiceId());
    instanceList = RegistryUtils.findServiceInstance("default", "notExists", "0.0.1");
    Assert.assertNull(instanceList);
    MicroserviceInstances microserviceInstances = RegistryUtils.findServiceInstances("default", "default", "0.0.1");
    List<MicroserviceInstance> instanceLists = microserviceInstances.getInstancesResponse().getInstances();
    Assert.assertEquals(1, instanceLists.size());
    Assert.assertEquals(RegistryUtils.getMicroservice().getServiceId(), instanceLists.get(0).getServiceId());
    Map<String, String> properties = new HashMap<>();
    properties.put("k", "v");
    RegistryUtils.updateInstanceProperties(properties);
    Assert.assertEquals(properties, RegistryUtils.getMicroserviceInstance().getProperties());
    Assert.assertEquals(microservice, RegistryUtils.getMicroservice(microservice.getServiceId()));
    RegistryUtils.updateMicroserviceProperties(properties);
    Assert.assertEquals(properties, RegistryUtils.getMicroservice().getProperties());
    Assert.assertEquals("default", RegistryUtils.getAppId());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) HashMap(java.util.HashMap) MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Test(org.junit.Test)

Aggregations

Microservice (org.apache.servicecomb.registry.api.registry.Microservice)86 Test (org.junit.Test)53 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)20 Expectations (mockit.Expectations)15 ArrayList (java.util.ArrayList)14 List (java.util.List)13 GetSchemaResponse (org.apache.servicecomb.serviceregistry.api.response.GetSchemaResponse)10 Holder (org.apache.servicecomb.serviceregistry.client.http.Holder)10 HashMap (java.util.HashMap)9 MicroserviceFactory (org.apache.servicecomb.registry.api.registry.MicroserviceFactory)9 Swagger (io.swagger.models.Swagger)8 Before (org.junit.Before)8 MockUp (mockit.MockUp)6 Configuration (org.apache.commons.configuration.Configuration)6 AccessController (org.apache.servicecomb.authentication.provider.AccessController)6 Subscribe (com.google.common.eventbus.Subscribe)5 MicroserviceInstances (org.apache.servicecomb.registry.api.registry.MicroserviceInstances)5 EventBus (com.google.common.eventbus.EventBus)4 Version (org.apache.servicecomb.foundation.common.Version)4 HashSet (java.util.HashSet)3