use of org.apache.dubbo.mock.api.MockResult in project dubbo-admin by apache.
the class MockRuleServiceImpl method getMockData.
@Override
public MockResult getMockData(MockContext mockContext) {
QueryWrapper<MockRule> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("service_name", mockContext.getServiceName());
queryWrapper.eq("method_name", mockContext.getMethodName());
MockRule mockRule = mockRuleMapper.selectOne(queryWrapper);
MockResult mockResult = new MockResult();
if (Objects.isNull(mockRule)) {
return mockResult;
}
mockResult.setEnable(mockRule.getEnable());
mockResult.setContent(mockRule.getRule());
return mockResult;
}
use of org.apache.dubbo.mock.api.MockResult in project dubbo-spi-extensions by apache.
the class AdminMockFilter method invoke.
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
// check if open the admin mock config, global config.
if (!ENABLE_ADMIN_MOCK) {
return invoker.invoke(invocation);
}
String interfaceName = invocation.getTargetServiceUniqueName();
String methodName = invocation.getMethodName();
Object[] params = solveParams(invocation.getArguments());
// check if the MockService's invoker, then request.
if (Objects.equals(interfaceName, MockService.class.getName())) {
return invoker.invoke(invocation);
}
MockService mockService = getMockService();
if (Objects.isNull(mockService)) {
log.warn("[Admin Mock] cloud not find MockService, will ignore this mock.");
return invoker.invoke(invocation);
}
// parse the result from MockService, build the real method's return value.
MockContext mockContext = MockContext.newMockContext().serviceName(interfaceName).methodName(methodName).arguments(params).build();
MockResult mockResult = mockService.mock(mockContext);
if (!mockResult.getEnable()) {
return invoker.invoke(invocation);
}
// parse the return data.
Class<?> returnType = ((RpcInvocation) invocation).getReturnType();
ResultContext resultContext = ResultContext.newResultContext().data(mockResult.getContent()).targetType(returnType).serviceName(interfaceName).methodName(methodName).build();
Object data = typeHandler.handleResult(resultContext);
AppResponse appResponse = new AppResponse(data);
CompletableFuture<AppResponse> appResponseFuture = new CompletableFuture<>();
appResponseFuture.complete(appResponse);
return new AsyncRpcResult(appResponseFuture, invocation);
}
use of org.apache.dubbo.mock.api.MockResult in project incubator-dubbo-ops by apache.
the class MockRuleServiceImpl method getMockData.
@Override
public MockResult getMockData(MockContext mockContext) {
QueryWrapper<MockRule> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("service_name", mockContext.getServiceName());
queryWrapper.eq("method_name", mockContext.getMethodName());
MockRule mockRule = mockRuleMapper.selectOne(queryWrapper);
MockResult mockResult = new MockResult();
if (Objects.isNull(mockRule)) {
return mockResult;
}
mockResult.setEnable(mockRule.getEnable());
mockResult.setContent(mockRule.getRule());
return mockResult;
}
Aggregations