Search in sources :

Example 6 with SchemaMeta

use of io.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class TestHighwayServerInvoke method test.

@Test
public void test() {
    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(netSocket, 0, null, null));
    // 初始化成功
    requestHeader.setDestMicroservice(schemaMeta.getMicroserviceName());
    requestHeader.setSchemaId(schemaMeta.getSchemaId());
    requestHeader.setOperationName(operationMeta.getOperationId());
    Assert.assertTrue(highwayServerInvoke.init(netSocket, 0, requestHeader, null));
    // exe成功
    netSocketBuffer = null;
    highwayServerInvoke.execute();
    Assert.assertEquals(null, netSocketBuffer);
    // exe失败
    MockUtil.getInstance().decodeRequestSucc = false;
    highwayServerInvoke.execute();
    Assert.assertEquals(true, netSocketBuffer.toString().startsWith("CSE.TCP"));
}
Also used : SchemaMeta(io.servicecomb.core.definition.SchemaMeta) ReactiveExecutor(io.servicecomb.core.executor.ReactiveExecutor) RequestHeader(io.servicecomb.transport.highway.message.RequestHeader) OperationMeta(io.servicecomb.core.definition.OperationMeta) Test(org.junit.Test)

Example 7 with SchemaMeta

use of io.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class MockUtil method mockMicroserviceMetaManager.

public void mockMicroserviceMetaManager() {
    new MockUp<MicroserviceMetaManager>() {

        @Mock
        public SchemaMeta ensureFindSchemaMeta(String schemaId) {
            SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class);
            OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
            Mockito.when(schemaMeta.ensureFindOperation(null)).thenReturn(operationMeta);
            Method method = this.getClass().getMethods()[0];
            Mockito.when(operationMeta.getMethod()).thenReturn(method);
            OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
            Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
            Executor lExecutor = Mockito.mock(Executor.class);
            Mockito.when(operationMeta.getExecutor()).thenReturn(lExecutor);
            return schemaMeta;
        }
    };
}
Also used : Executor(java.util.concurrent.Executor) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) MockUp(mockit.MockUp) OperationMeta(io.servicecomb.core.definition.OperationMeta) Method(java.lang.reflect.Method)

Example 8 with SchemaMeta

use of io.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class TestGrpcCodec method testDecodeRequest.

@Test
public void testDecodeRequest() {
    boolean status = false;
    try {
        RoutingContext routingContext = Mockito.mock(RoutingContext.class);
        OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
        OperationProtobuf operationProtobuf = Mockito.mock(OperationProtobuf.class);
        WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(int.class);
        Mockito.when(operationProtobuf.getRequestSchema()).thenReturn(schema);
        Mockito.when(operationMeta.getExtData("protobuf")).thenReturn(operationProtobuf);
        Buffer bodyBuffer = Mockito.mock(Buffer.class);
        Mockito.when(routingContext.getBody()).thenReturn(bodyBuffer);
        HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
        Mockito.when(routingContext.request()).thenReturn(request);
        SchemaMeta schemaMeta = Mockito.mock(SchemaMeta.class);
        Mockito.when(operationMeta.getSchemaMeta()).thenReturn(schemaMeta);
        Mockito.when(request.getHeader(Const.CSE_CONTEXT)).thenReturn("{\"name\":\"test\"}");
        GrpcCodec.setGrpcTransport(new GrpcTransport());
        GrpcCodec.decodeRequest(routingContext, operationMeta);
    } catch (Exception e) {
        status = true;
    }
    Assert.assertFalse(status);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) RoutingContext(io.vertx.ext.web.RoutingContext) OperationProtobuf(io.servicecomb.codec.protobuf.definition.OperationProtobuf) HttpServerRequest(io.vertx.core.http.HttpServerRequest) SchemaMeta(io.servicecomb.core.definition.SchemaMeta) OperationMeta(io.servicecomb.core.definition.OperationMeta) WrapSchema(io.servicecomb.codec.protobuf.utils.WrapSchema) Test(org.junit.Test)

Example 9 with SchemaMeta

use of io.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class SchemaListenerManager method notifySchemaListener.

public void notifySchemaListener(MicroserviceMeta... microserviceMetas) {
    List<SchemaMeta> schemaMetaList = new ArrayList<>();
    for (MicroserviceMeta microserviceMeta : microserviceMetas) {
        schemaMetaList.addAll(microserviceMeta.getSchemaMetas());
    }
    notifySchemaListener(schemaMetaList.toArray(new SchemaMeta[schemaMetaList.size()]));
}
Also used : SchemaMeta(io.servicecomb.core.definition.SchemaMeta) ArrayList(java.util.ArrayList) MicroserviceMeta(io.servicecomb.core.definition.MicroserviceMeta)

Example 10 with SchemaMeta

use of io.servicecomb.core.definition.SchemaMeta in project java-chassis by ServiceComb.

the class SchemaLoader method registerSchema.

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(io.servicecomb.core.definition.SchemaMeta)

Aggregations

SchemaMeta (io.servicecomb.core.definition.SchemaMeta)26 MicroserviceMeta (io.servicecomb.core.definition.MicroserviceMeta)11 Test (org.junit.Test)10 OperationMeta (io.servicecomb.core.definition.OperationMeta)8 ArrayList (java.util.ArrayList)4 OperationProtobuf (io.servicecomb.codec.protobuf.definition.OperationProtobuf)3 WrapSchema (io.servicecomb.codec.protobuf.utils.WrapSchema)3 Invocation (io.servicecomb.core.Invocation)3 HashMap (java.util.HashMap)3 MockUp (mockit.MockUp)3 RestOperationMeta (io.servicecomb.common.rest.definition.RestOperationMeta)2 ServicePathManager (io.servicecomb.common.rest.locator.ServicePathManager)2 MicroserviceMetaManager (io.servicecomb.core.definition.MicroserviceMetaManager)2 ConsumerOperationMeta (io.servicecomb.core.provider.consumer.ConsumerOperationMeta)2 UnitTestMeta (io.servicecomb.core.unittest.UnitTestMeta)2 Swagger (io.swagger.models.Swagger)2 Buffer (io.vertx.core.buffer.Buffer)2 HttpServerRequest (io.vertx.core.http.HttpServerRequest)2 Executor (java.util.concurrent.Executor)2 ArgsNotWrapSchema (io.servicecomb.codec.protobuf.utils.schema.ArgsNotWrapSchema)1