Search in sources :

Example 31 with SchemaMeta

use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.

the class TestHighwayServerInvoke method test.

@Test
public void test() {
    Holder<InvocationStartEvent> startHolder = new Holder<>();
    Holder<InvocationFinishEvent> finishHolder = new Holder<>();
    Object subscriber = new Object() {

        @Subscribe
        public void onStart(InvocationStartEvent event) {
            startHolder.value = event;
        }

        @Subscribe
        public void onFinish(InvocationFinishEvent event) {
            finishHolder.value = event;
        }
    };
    EventManager.register(subscriber);
    MockUtil.getInstance().mockHighwayCodec();
    SchemaMeta schemaMeta = unitTestMeta.getOrCreateSchemaMeta(Impl.class);
    OperationMeta operationMeta = schemaMeta.ensureFindOperation("add");
    operationMeta.setExecutor(new ReactiveExecutor());
    HighwayServerInvoke highwayServerInvoke = new HighwayServerInvoke();
    highwayServerInvoke.setMicroserviceMetaManager(unitTestMeta.getMicroserviceMetaManager());
    RequestHeader requestHeader = MockUtil.getInstance().requestHeader;
    // 初始化失败
    requestHeader.setDestMicroservice(null);
    Assert.assertFalse(highwayServerInvoke.init(connection, 0, null, null));
    // 初始化成功
    requestHeader.setDestMicroservice(schemaMeta.getMicroserviceName());
    requestHeader.setSchemaId(schemaMeta.getSchemaId());
    requestHeader.setOperationName(operationMeta.getOperationId());
    Assert.assertTrue(highwayServerInvoke.init(connection, 0, requestHeader, null));
    // exe失败
    MockUtil.getInstance().decodeRequestSucc = false;
    highwayServerInvoke.execute();
    EventManager.unregister(subscriber);
    Assert.assertEquals(true, Buffer.buffer(netSocketBuffer).toString().startsWith("CSE.TCP"));
    Assert.assertSame(highwayServerInvoke.invocation, startHolder.value.getInvocation());
    Assert.assertSame(highwayServerInvoke.invocation, finishHolder.value.getInvocation());
    Assert.assertTrue(highwayServerInvoke.invocation.getStartExecutionTime() != 0);
}
Also used : InvocationFinishEvent(org.apache.servicecomb.core.event.InvocationFinishEvent) Holder(javax.xml.ws.Holder) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) ReactiveExecutor(org.apache.servicecomb.core.executor.ReactiveExecutor) RequestHeader(org.apache.servicecomb.transport.highway.message.RequestHeader) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) InvocationStartEvent(org.apache.servicecomb.core.event.InvocationStartEvent) Test(org.junit.Test)

Example 32 with SchemaMeta

use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.

the class ProducerProviderManager method init.

public void init() throws Exception {
    for (ProducerProvider provider : producerProviderList) {
        provider.init();
    }
    Microservice microservice = RegistryUtils.getMicroservice();
    MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(microservice);
    for (SchemaMeta schemaMeta : microserviceMeta.getSchemaMetas()) {
        String content = SchemaUtils.swaggerToString(schemaMeta.getSwagger());
        microservice.addSchema(schemaMeta.getSchemaId(), content);
    }
}
Also used : Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) ProducerProvider(org.apache.servicecomb.core.ProducerProvider) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta)

Example 33 with SchemaMeta

use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.

the class TestDynamicSchemaLoader method testRegisterSchemas.

@SuppressWarnings("deprecation")
@Test
public void testRegisterSchemas() {
    DynamicSchemaLoader.INSTANCE.registerSchemas("classpath*:test/test/schema.yaml");
    SchemaMeta schemaMeta = microserviceMetaManager.ensureFindSchemaMeta("perfClient", "schema");
    Assert.assertEquals("cse.gen.app.perfClient.schema", schemaMeta.getPackageName());
}
Also used : SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) Test(org.junit.Test)

Example 34 with SchemaMeta

use of org.apache.servicecomb.core.definition.SchemaMeta in project incubator-servicecomb-java-chassis by apache.

the class TestSchemaListenerManager method testInitializationListener.

@Test
public void testInitializationListener() {
    SchemaListener listener = new SchemaListener() {

        @Override
        public void onSchemaLoaded(SchemaMeta... schemaMetas) {
            Assert.assertEquals(1, schemaMetas.length);
            Assert.assertEquals("test", schemaMetas[0].getSchemaId());
        }
    };
    SchemaListenerManager mgr = new SchemaListenerManager();
    mgr.setSchemaListenerList(Arrays.asList(listener));
    mgr.setMicroserviceMetaManager(new MicroserviceMetaManager());
    mgr.notifySchemaListener(schemaMeta);
}
Also used : MicroserviceMetaManager(org.apache.servicecomb.core.definition.MicroserviceMetaManager) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) Test(org.junit.Test)

Example 35 with SchemaMeta

use of org.apache.servicecomb.core.definition.SchemaMeta 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

SchemaMeta (org.apache.servicecomb.core.definition.SchemaMeta)58 OperationMeta (org.apache.servicecomb.core.definition.OperationMeta)28 MicroserviceMeta (org.apache.servicecomb.core.definition.MicroserviceMeta)25 Test (org.junit.Test)24 Invocation (org.apache.servicecomb.core.Invocation)13 Swagger (io.swagger.models.Swagger)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)6 Executor (java.util.concurrent.Executor)5 InvocationRuntimeType (org.apache.servicecomb.core.definition.InvocationRuntimeType)5 ReferenceConfig (org.apache.servicecomb.core.provider.consumer.ReferenceConfig)5 MicroserviceInstance (org.apache.servicecomb.registry.api.registry.MicroserviceInstance)5 SwaggerProducerOperation (org.apache.servicecomb.swagger.engine.SwaggerProducerOperation)5 MockUp (mockit.MockUp)4 NonSwaggerInvocation (org.apache.servicecomb.core.NonSwaggerInvocation)4 Transport (org.apache.servicecomb.core.Transport)4 TransportManager (org.apache.servicecomb.core.transport.TransportManager)4 InstanceCacheManager (org.apache.servicecomb.registry.cache.InstanceCacheManager)4 DiscoveryTreeNode (org.apache.servicecomb.registry.discovery.DiscoveryTreeNode)4 ServiceRegistry (org.apache.servicecomb.serviceregistry.ServiceRegistry)4