Search in sources :

Example 1 with MicroserviceDefinition

use of org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition in project incubator-servicecomb-java-chassis by apache.

the class RegistryUtils method init.

public static void init() {
    MicroserviceConfigLoader loader = ConfigUtil.getMicroserviceConfigLoader();
    MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(loader.getConfigModels());
    serviceRegistry = ServiceRegistryFactory.getOrCreate(EventManager.eventBus, ServiceRegistryConfig.INSTANCE, microserviceDefinition);
    serviceRegistry.init();
}
Also used : MicroserviceConfigLoader(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader) MicroserviceDefinition(org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition)

Example 2 with MicroserviceDefinition

use of org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition in project incubator-servicecomb-java-chassis by apache.

the class TestPropertiesLoader method testCanNotAssignExtendedClass.

@Test
public void testCanNotAssignExtendedClass() {
    ConfigModel configModel = MicroserviceDefinition.createConfigModel("default", "invalidExtendedClass");
    @SuppressWarnings("unchecked") Map<String, Object> desc = (Map<String, Object>) configModel.getConfig().get(CONFIG_SERVICE_DESCRIPTION_KEY);
    desc.put("propertyExtentedClass", "java.lang.String");
    MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(Arrays.asList(configModel));
    try {
        microserviceFactory.create(microserviceDefinition);
        Assert.fail("Must throw exception");
    } catch (Error e) {
        Assert.assertEquals("Define propertyExtendedClass java.lang.String in yaml, but not implement the interface PropertyExtended.", e.getMessage());
    }
}
Also used : ConfigModel(org.apache.servicecomb.config.archaius.sources.ConfigModel) MicroserviceDefinition(org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with MicroserviceDefinition

use of org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition in project incubator-servicecomb-java-chassis by apache.

the class TestMicroserviceFactory method testInit.

@Test
public void testInit() {
    MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
    loader.loadAndSort();
    MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(loader.getConfigModels());
    MicroserviceFactory factory = new MicroserviceFactory();
    Microservice microservice = factory.create(microserviceDefinition);
    String microserviceName = "default";
    Assert.assertEquals(microserviceName, microservice.getServiceName());
}
Also used : MicroserviceConfigLoader(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader) MicroserviceDefinition(org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition) Test(org.junit.Test)

Example 4 with MicroserviceDefinition

use of org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition in project incubator-servicecomb-java-chassis by apache.

the class TestPropertiesLoader method testInvalidExtendedClass.

@Test
public void testInvalidExtendedClass() {
    ConfigModel configModel = MicroserviceDefinition.createConfigModel("default", "invalidExtendedClass");
    @SuppressWarnings("unchecked") Map<String, Object> desc = (Map<String, Object>) configModel.getConfig().get(CONFIG_SERVICE_DESCRIPTION_KEY);
    desc.put("propertyExtentedClass", "invalidClass");
    MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(Arrays.asList(configModel));
    try {
        microserviceFactory.create(microserviceDefinition);
        Assert.fail("Must throw exception");
    } catch (Error e) {
        Assert.assertEquals(ClassNotFoundException.class, e.getCause().getClass());
        Assert.assertEquals("invalidClass", e.getCause().getMessage());
    }
}
Also used : ConfigModel(org.apache.servicecomb.config.archaius.sources.ConfigModel) MicroserviceDefinition(org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with MicroserviceDefinition

use of org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition in project incubator-servicecomb-java-chassis by apache.

the class ServiceRegistryFactory method createLocal.

public static ServiceRegistry createLocal() {
    EventBus eventBus = new EventBus();
    ServiceRegistryConfig serviceRegistryConfig = ServiceRegistryConfig.INSTANCE;
    MicroserviceConfigLoader loader = new MicroserviceConfigLoader();
    loader.loadAndSort();
    MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(loader.getConfigModels());
    return new LocalServiceRegistry(eventBus, serviceRegistryConfig, microserviceDefinition);
}
Also used : ServiceRegistryConfig(org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig) MicroserviceConfigLoader(org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader) MicroserviceDefinition(org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition) EventBus(com.google.common.eventbus.EventBus)

Aggregations

MicroserviceDefinition (org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition)6 Test (org.junit.Test)4 MicroserviceConfigLoader (org.apache.servicecomb.config.archaius.sources.MicroserviceConfigLoader)3 EventBus (com.google.common.eventbus.EventBus)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConfigModel (org.apache.servicecomb.config.archaius.sources.ConfigModel)2 ServiceRegistryConfig (org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig)2 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)1 LocalServiceRegistryClientImpl (org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl)1 ServiceRegistryClient (org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient)1 ServiceRegistryClientImpl (org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl)1