use of org.apache.servicecomb.transport.highway.message.RequestHeader in project incubator-servicecomb-java-chassis by apache.
the class TestHighwayServerConnection method testRequestNormal.
@Test
public void testRequestNormal(@Mocked MicroserviceMeta microserviceMeta, @Mocked OperationMeta operationMeta, @Mocked SchemaMeta schemaMeta) throws Exception {
header.setMsgType(MsgType.REQUEST);
Buffer headerBuffer = createBuffer(requestHeaderSchema, header);
Buffer bodyBuffer = Buffer.buffer();
new Expectations(CseContext.getInstance()) {
{
CseContext.getInstance().getMicroserviceMetaManager();
result = microserviceMetaManager;
microserviceMetaManager.ensureFindValue(null);
result = microserviceMeta;
microserviceMeta.ensureFindSchemaMeta(header.getSchemaId());
result = schemaMeta;
}
};
new Expectations(ProtobufManager.class) {
{
ProtobufManager.getOrCreateOperation(operationMeta);
result = null;
}
};
Holder<Boolean> holder = new Holder<>();
new MockUp<HighwayServerInvoke>() {
@Mock
public boolean init(NetSocket netSocket, long msgId, RequestHeader header, Buffer bodyBuffer) {
return true;
}
@Mock
public void execute() {
holder.value = true;
}
};
connection.handle(0, headerBuffer, bodyBuffer);
Assert.assertEquals(null, connection.getProtocol());
Assert.assertEquals(null, connection.getZipName());
Assert.assertEquals(true, holder.value);
}
use of org.apache.servicecomb.transport.highway.message.RequestHeader 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);
}
use of org.apache.servicecomb.transport.highway.message.RequestHeader in project incubator-servicecomb-java-chassis by apache.
the class HighwayCodec method encodeRequest.
public static TcpOutputStream encodeRequest(long msgId, Invocation invocation, OperationProtobuf operationProtobuf, ProtobufFeature protobufFeature) throws Exception {
// 写header
RequestHeader header = new RequestHeader();
header.setMsgType(MsgType.REQUEST);
header.setFlags(0);
header.setDestMicroservice(invocation.getMicroserviceName());
header.setSchemaId(invocation.getSchemaId());
header.setOperationName(invocation.getOperationName());
header.setContext(invocation.getContext());
HighwayOutputStream os = new HighwayOutputStream(msgId, protobufFeature);
os.write(header, operationProtobuf.getRequestSchema(), invocation.getArgs());
return os;
}
Aggregations