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"));
}
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;
}
};
}
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);
}
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()]));
}
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);
}
}
Aggregations