Search in sources :

Example 1 with SchemaMeta

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

the class SchemaLoader method registerSchema.

/*
   * resource的路径格式,至少是以这个形式结尾:schemaId.yaml
   */
public SchemaMeta registerSchema(String microserviceName, Resource resource) {
    try {
        String schemaId = FilenameUtils.getBaseName(resource.getFilename());
        String swaggerContent = IOUtils.toString(resource.getURL());
        SchemaMeta schemaMeta = registerSchema(microserviceName, schemaId, swaggerContent);
        return schemaMeta;
    } catch (Throwable e) {
        throw new Error(e);
    }
}
Also used : SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta)

Example 2 with SchemaMeta

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

the class UnitTestMeta method getOrCreateSchemaMeta.

public SchemaMeta getOrCreateSchemaMeta(String appId, String microserviceName, String schemaId, Class<?> impl) {
    String longName = appId + ":" + microserviceName;
    MicroserviceMeta microserviceMeta = microserviceMetaManager.getOrCreateMicroserviceMeta(longName);
    SchemaMeta schemaMeta = microserviceMeta.findSchemaMeta(schemaId);
    if (schemaMeta != null) {
        return schemaMeta;
    }
    Swagger swagger = UnitTestSwaggerUtils.generateSwagger(impl).getSwagger();
    return schemaLoader.registerSchema(microserviceMeta, schemaId, swagger);
}
Also used : SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) Swagger(io.swagger.models.Swagger) MicroserviceMeta(org.apache.servicecomb.core.definition.MicroserviceMeta)

Example 3 with SchemaMeta

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

the class TestConsumer method testInvocation.

@Test
public void testInvocation() {
    OperationMeta oOperationMeta = Mockito.mock(OperationMeta.class);
    SchemaMeta oSchemaMeta = Mockito.mock(SchemaMeta.class);
    AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
    List<Handler> oHandlerList = new ArrayList<>();
    Mockito.when(oSchemaMeta.getProviderHandlerChain()).thenReturn(oHandlerList);
    Mockito.when(oSchemaMeta.getMicroserviceName()).thenReturn("TMK");
    Mockito.when(oOperationMeta.getSchemaMeta()).thenReturn(oSchemaMeta);
    Endpoint oEndpoint = Mockito.mock(Endpoint.class);
    Transport oTransport = Mockito.mock(Transport.class);
    Mockito.when(oEndpoint.getTransport()).thenReturn(oTransport);
    Mockito.when(oOperationMeta.getOperationId()).thenReturn("TMK");
    Invocation oInvocation = new Invocation(oEndpoint, oOperationMeta, null);
    Assert.assertNotNull(oInvocation.getTransport());
    Assert.assertNotNull(oInvocation.getInvocationType());
    oInvocation.setResponseExecutor(Mockito.mock(Executor.class));
    Assert.assertNotNull(oInvocation.getResponseExecutor());
    Assert.assertNotNull(oInvocation.getSchemaMeta());
    Assert.assertNotNull(oInvocation.getOperationMeta());
    Assert.assertNull(oInvocation.getArgs());
    Assert.assertNotNull(oInvocation.getEndpoint());
    oInvocation.setEndpoint(null);
    Map<String, String> map = oInvocation.getContext();
    Assert.assertNotNull(map);
    String str = oInvocation.getSchemaId();
    Assert.assertEquals(null, str);
    String str1 = oInvocation.getMicroserviceName();
    Assert.assertEquals("TMK", str1);
    Map<String, Object> mapp = oInvocation.getHandlerContext();
    Assert.assertNotNull(mapp);
    Assert.assertEquals(true, oInvocation.getHandlerIndex() >= 0);
    oInvocation.setHandlerIndex(8);
    Assert.assertEquals("TMK", oInvocation.getOperationName());
    Assert.assertEquals("TMK", oInvocation.getMicroserviceName());
    boolean validAssert;
    try {
        validAssert = true;
        oInvocation.next(asyncResp);
    } catch (Exception e) {
        validAssert = false;
    }
    Assert.assertFalse(validAssert);
}
Also used : ArrayList(java.util.ArrayList) SyncResponseExecutor(org.apache.servicecomb.core.provider.consumer.SyncResponseExecutor) Executor(java.util.concurrent.Executor) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) OperationMeta(org.apache.servicecomb.core.definition.OperationMeta) AsyncResponse(org.apache.servicecomb.swagger.invocation.AsyncResponse) Test(org.junit.Test)

Example 4 with SchemaMeta

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

the class TestDynamicSchemaLoader method testRegisterShemasAcrossApp.

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

Example 5 with SchemaMeta

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

the class TestConsumerSchemaFactory method init.

@BeforeClass
public static void init() {
    ServiceRegistry serviceRegistry = ServiceRegistryFactory.createLocal();
    serviceRegistry.init();
    RegistryUtils.setServiceRegistry(serviceRegistry);
    SchemaListenerManager schemaListenerManager = new SchemaListenerManager();
    schemaListenerManager.setSchemaListenerList(Arrays.asList(schemaListener));
    MicroserviceMetaManager microserviceMetaManager = new MicroserviceMetaManager();
    SchemaLoader schemaLoader = new SchemaLoader() {

        @Override
        public void putSelfBasePathIfAbsent(String microserviceName, String basePath) {
        }
    };
    CompositeSwaggerGeneratorContext compositeSwaggerGeneratorContext = new CompositeSwaggerGeneratorContext();
    ReflectUtils.setField(consumerSchemaFactory, "schemaListenerManager", schemaListenerManager);
    ReflectUtils.setField(consumerSchemaFactory, "microserviceMetaManager", microserviceMetaManager);
    ReflectUtils.setField(consumerSchemaFactory, "schemaLoader", schemaLoader);
    ReflectUtils.setField(consumerSchemaFactory, "compositeSwaggerGeneratorContext", compositeSwaggerGeneratorContext);
    SchemaMeta schemaMeta = new UnitTestMeta().getOrCreateSchemaMeta(TestConsumerSchemaFactoryImpl.class);
    String content = UnitTestSwaggerUtils.pretty(schemaMeta.getSwagger());
    Microservice microservice = new Microservice();
    microservice.setAppId("app");
    microservice.setServiceId("0");
    microservice.setServiceName("ms");
    microservice.setVersion("1.0.0");
    microservice.addSchema("schema", content);
    serviceRegistry.getServiceRegistryClient().registerMicroservice(microservice);
    MicroserviceInstance instance = new MicroserviceInstance();
    instance.setServiceId("0");
    instance.setInstanceId("0");
    serviceRegistry.getServiceRegistryClient().registerMicroserviceInstance(instance);
}
Also used : MicroserviceMetaManager(org.apache.servicecomb.core.definition.MicroserviceMetaManager) SchemaLoader(org.apache.servicecomb.core.definition.loader.SchemaLoader) Microservice(org.apache.servicecomb.serviceregistry.api.registry.Microservice) UnitTestMeta(org.apache.servicecomb.core.unittest.UnitTestMeta) CompositeSwaggerGeneratorContext(org.apache.servicecomb.swagger.generator.core.CompositeSwaggerGeneratorContext) SchemaMeta(org.apache.servicecomb.core.definition.SchemaMeta) MicroserviceInstance(org.apache.servicecomb.serviceregistry.api.registry.MicroserviceInstance) SchemaListenerManager(org.apache.servicecomb.core.definition.loader.SchemaListenerManager) 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