Search in sources :

Example 6 with ServiceRegistry

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

the class TestLocalServiceRegistry method testUpdateProperties.

@Test
public void testUpdateProperties() {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    serviceRegistry.run();
    Microservice microservice = serviceRegistry.getMicroservice();
    Map<String, String> properties = new HashMap<>();
    properties.put("k", "v");
    try {
        serviceRegistry.getServiceRegistryClient().updateInstanceProperties(microservice.getServiceId(), "notExist", properties);
        Assert.fail("must throw exception");
    } catch (IllegalArgumentException e) {
        Assert.assertEquals("Invalid argument. microserviceId=" + microservice.getServiceId() + ", microserviceInstanceId=notExist.", e.getMessage());
    }
    serviceRegistry.updateMicroserviceProperties(properties);
    Assert.assertEquals(properties, microservice.getProperties());
    serviceRegistry.updateInstanceProperties(properties);
    Assert.assertEquals(properties, microservice.getInstance().getProperties());
    properties.put("k1", "v1");
    serviceRegistry.updateMicroserviceProperties(properties);
    Assert.assertEquals(properties, microservice.getProperties());
    serviceRegistry.updateInstanceProperties(properties);
    Assert.assertEquals(properties, microservice.getInstance().getProperties());
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) HashMap(java.util.HashMap) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) Test(org.junit.Test)

Example 7 with ServiceRegistry

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

the class TestServiceRegistryFactory method testGetRemoteRegistryClient.

@Test
public void testGetRemoteRegistryClient() {
    EventBus eventBus = new EventBus();
    ServiceRegistryConfig serviceRegistryConfig = ServiceRegistryConfig.INSTANCE;
    MicroserviceDefinition microserviceDefinition = new MicroserviceDefinition(Collections.emptyList());
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.create(eventBus, serviceRegistryConfig, microserviceDefinition);
    serviceRegistry.init();
    ServiceRegistryClient client = serviceRegistry.getServiceRegistryClient();
    Assert.assertTrue(client instanceof ServiceRegistryClientImpl);
    serviceRegistry = ServiceRegistryFactory.getOrCreate(eventBus, serviceRegistryConfig, microserviceDefinition);
    Assert.assertTrue(serviceRegistry instanceof RemoteServiceRegistry);
    Assert.assertEquals(serviceRegistry, ServiceRegistryFactory.getServiceRegistry());
    Deencapsulation.setField(ServiceRegistryFactory.class, "serviceRegistry", null);
    System.setProperty("local.registry.file", "/tmp/test.yaml");
    serviceRegistry = ServiceRegistryFactory.create(eventBus, serviceRegistryConfig, microserviceDefinition);
    serviceRegistry.init();
    client = serviceRegistry.getServiceRegistryClient();
    Assert.assertTrue(client instanceof LocalServiceRegistryClientImpl);
    Assert.assertTrue(ServiceRegistryFactory.getOrCreate(eventBus, serviceRegistryConfig, microserviceDefinition) instanceof LocalServiceRegistry);
    System.clearProperty("local.registry.file");
}
Also used : ServiceRegistryConfig(org.apache.servicecomb.serviceregistry.config.ServiceRegistryConfig) LocalServiceRegistryClientImpl(org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl) MicroserviceDefinition(org.apache.servicecomb.serviceregistry.definition.MicroserviceDefinition) ServiceRegistryClient(org.apache.servicecomb.serviceregistry.client.ServiceRegistryClient) EventBus(com.google.common.eventbus.EventBus) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) LocalServiceRegistryClientImpl(org.apache.servicecomb.serviceregistry.client.LocalServiceRegistryClientImpl) ServiceRegistryClientImpl(org.apache.servicecomb.serviceregistry.client.http.ServiceRegistryClientImpl) Test(org.junit.Test)

Example 8 with ServiceRegistry

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

the class TestHighwayCodec method setUp.

@Before
public void setUp() throws Exception {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    RegistryUtils.setServiceRegistry(serviceRegistry);
    header = Mockito.mock(RequestHeader.class);
    operationProtobuf = Mockito.mock(OperationProtobuf.class);
    bodyBuffer = Mockito.mock(Buffer.class);
    schema = Mockito.mock(WrapSchema.class);
    schemaMeta = Mockito.mock(SchemaMeta.class);
    operationMeta = Mockito.mock(OperationMeta.class);
    lByteBuf = Mockito.mock(ByteBuf.class);
    nioBuffer = Mockito.mock(ByteBuffer.class);
    invocation = Mockito.mock(Invocation.class);
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(io.vertx.core.buffer.Buffer) Invocation(org.apache.servicecomb.core.Invocation) OperationProtobuf(org.apache.servicecomb.codec.protobuf.definition.OperationProtobuf) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) RequestHeader(org.apache.servicecomb.transport.highway.message.RequestHeader) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) NotWrapSchema(org.apache.servicecomb.codec.protobuf.utils.schema.NotWrapSchema) WrapSchema(org.apache.servicecomb.codec.protobuf.utils.WrapSchema) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) ByteBuf(io.netty.buffer.ByteBuf) ByteBuffer(java.nio.ByteBuffer) Before(org.junit.Before)

Example 9 with ServiceRegistry

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

the class TestDynamicSchemaLoader method init.

@BeforeClass
public static void init() {
    UnitTestMeta.init();
    loader.setMicroserviceMetaManager(microserviceMetaManager);
    SchemaListenerManager schemaListenerManager = new SchemaListenerManager();
    schemaListenerManager.setSchemaListenerList(Collections.emptyList());
    CseContext context = CseContext.getInstance();
    context.setSchemaLoader(loader);
    context.setSchemaListenerManager(schemaListenerManager);
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    microservice = serviceRegistry.getMicroservice();
    RegistryUtils.setServiceRegistry(serviceRegistry);
}
Also used : CseContext(org.apache.servicecomb.core.CseContext) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) BeforeClass(org.junit.BeforeClass)

Example 10 with ServiceRegistry

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

the class TestProducerSchemaFactory method init.

@BeforeClass
public static void init() {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    RegistryUtils.setServiceRegistry(serviceRegistry);
    ConverterMgr converterMgr = new ConverterMgr();
    ProducerArgumentsMapperFactory producerArgsMapperFactory = new ProducerArgumentsMapperFactory();
    producerArgsMapperFactory.setConverterMgr(converterMgr);
    MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
    SchemaLoader schemaLoader = new SchemaLoader() {

        @Override
        public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
        }
    };
    CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
    producerSchemaFactory.setSwaggerEnv(swaggerEnv);
    ReflectUtils.setField(producerSchemaFactory, "microserviceMetaManager", microserviceMetaManager);
    ReflectUtils.setField(producerSchemaFactory, "schemaLoader", schemaLoader);
    ReflectUtils.setField(producerSchemaFactory, "compositeSwaggerGeneratorContext", compositeSwaggerGeneratorContext);
    Executor reactiveExecutor = new ReactiveExecutor();
    Executor normalExecutor = (cmd) -> {
    };
    new MockUp<BeanUtils>() {

        @SuppressWarnings("unchecked")
        @Mock
        <T> T getBean(String name) {
            if (ExecutorManager.EXECUTOR_REACTIVE.equals(name)) {
                return (T) reactiveExecutor;
            }
            return (T) normalExecutor;
        }
    };
    // ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
    // BeanUtils.setContext(applicationContext);
    // Mockito.when(applicationContext.getBean(ExecutorManager.EXECUTOR_REACTIVE)).thenReturn(new ReactiveExecutor());
    UnitTestMeta.init();
    schemaMeta = producerSchemaFactory.getOrCreateProducerSchema("app:ms", "schema", TestProducerSchemaFactoryImpl.class, new TestProducerSchemaFactoryImpl());
}
Also used : BeanUtils(org.apache.servicecomb.foundation.common.utils.BeanUtils) CommonExceptionData(org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData) InvocationException(org.apache.servicecomb.swagger.invocation.exception.InvocationException) ExecutorManager(org.apache.servicecomb.core.executor.ExecutorManager) BeforeClass(org.junit.BeforeClass) SwaggerEnvironment(org.apache.servicecomb.swagger.engine.SwaggerEnvironment) RegistryUtils(org.apache.servicecomb.serviceregistry.RegistryUtils) BootstrapNormal(org.apache.servicecomb.swagger.engine.bootstrap.BootstrapNormal) SchemaLoader(org.apache.servicecomb.core.definition.loader.SchemaLoader) CompletableFuture(java.util.concurrent.CompletableFuture) ProducerArgumentsMapperFactory(org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperFactory) Mock(mockit.Mock) Response(org.apache.servicecomb.swagger.invocation.Response) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) AfterClass(org.junit.AfterClass) MockUp(mockit.MockUp) Executor(java.util.concurrent.Executor) Const(org.apache.servicecomb.core.Const) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) ReflectUtils(org.apache.servicecomb.foundation.common.utils.ReflectUtils) MicroserviceMetaManager(org.apache.servicecomb.core.definition.MicroserviceMetaManager) CompositeSwaggerGeneratorContext(org.apache.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext) Invocation(org.apache.servicecomb.core.Invocation) SwaggerProducerOperation(org.apache.servicecomb.swagger.engine.SwaggerProducerOperation) ConverterMgr(org.apache.servicecomb.swagger.invocation.converter.ConverterMgr) ServiceRegistryFactory(org.apache.servicecomb.serviceregistry.registry.ServiceRegistryFactory) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) Holder(javax.xml.ws.Holder) Endpoint(org.apache.servicecomb.core.Endpoint) UnitTestMeta(org.apache.servicecomb.core.unittest.UnitTestMeta) Assert(org.junit.Assert) MicroserviceMetaManager(org.apache.servicecomb.core.definition.MicroserviceMetaManager) SchemaLoader(org.apache.servicecomb.core.definition.loader.SchemaLoader) ProducerArgumentsMapperFactory(org.apache.servicecomb.swagger.invocation.arguments.producer.ProducerArgumentsMapperFactory) CompositeSwaggerGeneratorContext(org.apache.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) MockUp(mockit.MockUp) ConverterMgr(org.apache.servicecomb.swagger.invocation.converter.ConverterMgr) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) Executor(java.util.concurrent.Executor) ServiceRegistry(org.apache.servicecomb.serviceregistry.ServiceRegistry) BeforeClass(org.junit.BeforeClass)

Aggregations

ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)11 Test (org.junit.Test)7 SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)4 BeforeClass (org.junit.BeforeClass)4 Invocation (org.apache.servicecomb.core.Invocation)3 UnitTestMeta (org.apache.servicecomb.core.unittest.UnitTestMeta)3 Microservice (org.apache.servicecomb.serviceregistry.api.registry.Microservice)3 EventBus (com.google.common.eventbus.EventBus)2 Holder (javax.xml.ws.Holder)2 MicroserviceMetaManager (org.apache.servicecomb.core.definition.MicroserviceMetaManager)2 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)2 SchemaLoader (org.apache.servicecomb.core.definition.loader.SchemaLoader)2 ByteBuf (io.netty.buffer.ByteBuf)1 Buffer (io.vertx.core.buffer.Buffer)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Executor (java.util.concurrent.Executor)1 Expectations (mockit.Expectations)1