Search in sources :

Example 11 with Microservice

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

the class TestMicroserviceFactory method testAllowCrossApp.

@Test
public void testAllowCrossApp() {
    Microservice microservice = new Microservice();
    Assert.assertFalse(microservice.allowCrossApp());
    microservice.getProperties().put(CONFIG_ALLOW_CROSS_APP_KEY, "true");
    Assert.assertTrue(microservice.allowCrossApp());
    microservice.getProperties().put(CONFIG_ALLOW_CROSS_APP_KEY, "false");
    Assert.assertFalse(microservice.allowCrossApp());
    microservice.getProperties().put(CONFIG_ALLOW_CROSS_APP_KEY, "asfas");
    Assert.assertFalse(microservice.allowCrossApp());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Example 12 with Microservice

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

the class TestRestProducerInvocation method findRestOperationNameFromRegistry.

@Test
public void findRestOperationNameFromRegistry() {
    Microservice microservice = new Microservice();
    microservice.setServiceName("ms");
    new Expectations(ServicePathManager.class) {

        {
            // just make the method throw Exception
            ServicePathManager.getServicePathManager(microserviceMeta);
            result = null;
        }
    };
    restProducerInvocation = new RestProducerInvocation();
    initRestProducerInvocation();
    expectedException.expect(Exception.class);
    expectedException.expectMessage("[message=Not Found]");
    restProducerInvocation.findRestOperation();
}
Also used : Expectations(mockit.Expectations) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Test(org.junit.Test)

Example 13 with Microservice

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

the class LocalRegistryStore method findServiceInstances.

// local registry do not care about version and revision
public MicroserviceInstances findServiceInstances(String appId, String serviceName, String versionRule, String revision) {
    MicroserviceInstances microserviceInstances = new MicroserviceInstances();
    FindInstancesResponse findInstancesResponse = new FindInstancesResponse();
    List<MicroserviceInstance> instances = new ArrayList<>();
    Collectors.toList();
    microserviceInstanceMap.values().forEach(allInstances -> allInstances.values().stream().filter(aInstance -> {
        Microservice service = microserviceMap.get(aInstance.getServiceId());
        return service.getAppId().equals(appId) && service.getServiceName().equals(serviceName);
    }).forEach(item -> instances.add(item)));
    if (instances.isEmpty()) {
        microserviceInstances.setMicroserviceNotExist(true);
    } else {
        findInstancesResponse.setInstances(instances);
        microserviceInstances.setMicroserviceNotExist(false);
        microserviceInstances.setInstancesResponse(findInstancesResponse);
    }
    return microserviceInstances;
}
Also used : BeanUtils(org.apache.servicecomb.foundation.common.utils.BeanUtils) MicroserviceFactory(org.apache.servicecomb.registry.api.registry.MicroserviceFactory) MicroserviceInstance(org.apache.servicecomb.registry.api.registry.MicroserviceInstance) Enumeration(java.util.Enumeration) URL(java.net.URL) SwaggerGenerator(org.apache.servicecomb.swagger.generator.SwaggerGenerator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) HashMap(java.util.HashMap) SwaggerUtils(org.apache.servicecomb.swagger.SwaggerUtils) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) JvmUtils(org.apache.servicecomb.foundation.common.utils.JvmUtils) Instance(org.apache.servicecomb.localregistry.RegistryBean.Instance) ArrayList(java.util.ArrayList) YAMLUtil(org.apache.servicecomb.config.YAMLUtil) MicroserviceInstances(org.apache.servicecomb.registry.api.registry.MicroserviceInstances) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FindInstancesResponse(org.apache.servicecomb.registry.api.registry.FindInstancesResponse) InputStream(java.io.InputStream) Microservice(org.apache.servicecomb.registry.api.registry.Microservice) 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)

Example 14 with Microservice

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

the class AbstractLightweightDiscovery method onSchemaChanged.

@SuppressWarnings("unused")
@Subscribe
public void onSchemaChanged(SchemaChangedEvent event) {
    Microservice microservice = event.getMicroservice();
    appManager.markWaitingDelete(microservice.getAppId(), microservice.getServiceName());
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Subscribe(com.google.common.eventbus.Subscribe)

Example 15 with Microservice

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

the class TestSwaggerLoader method loadFromResource_sameApp_dirWithoutApp.

@Test
public void loadFromResource_sameApp_dirWithoutApp() {
    Swagger swagger = SwaggerGenerator.generate(Hello.class);
    mockLocalResource(swagger, String.format("microservices/%s/%s.yaml", serviceName, schemaId));
    RegistrationManager.INSTANCE.getSwaggerLoader().unregisterSwagger(appId, serviceName, schemaId);
    Microservice microservice = appManager.getOrCreateMicroserviceVersions(appId, serviceName).getVersions().values().iterator().next().getMicroservice();
    Swagger loadedSwagger = RegistrationManager.INSTANCE.getSwaggerLoader().loadSwagger(microservice, null, schemaId);
    Assert.assertNotSame(swagger, loadedSwagger);
    Assert.assertEquals(swagger, loadedSwagger);
}
Also used : Microservice(org.apache.servicecomb.registry.api.registry.Microservice) Swagger(io.swagger.models.Swagger) 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