alibaba / jvm-sandbox-repeater

A Java server-side recording and playback solution based on JVM-Sandbox
Apache License 2.0
2.51k stars 700 forks source link

lambda表达式中操作Mybatis mock成功,但是流程中断,Mock的数据没能正常返回 #226

Open EthanCui6 opened 3 months ago

EthanCui6 commented 3 months ago

如标题: lambda表达式中操作mysql, Mybatis mock成功,但是流程中断,Mock的数据没能正常返回 like this,使用的pagehelper的组件 PageHelper.startPage(1,15).doSelectPageInfo(() -> dao.select(arg1,arg2));

Aresxue commented 2 months ago

因为total是线程变量为0所以不会返回,要把PageHelper的一些方法也录制下来

@MetaInfServices(InvokePlugin.class)
public class PageHelperPlugin extends AbstractInvokePluginAdapter {

  @Override
  protected List<EnhanceModel> getEnhanceModelList() {
    EnhanceModel enhanceModel = EnhanceModel.builder()
        .classPattern("com.github.pagehelper.Page")
        .methodPatterns(
            MethodPattern.transform("getTotal", "getCountColumn", "getDialectClass", "getEndRow",
                "getOrderBy", "getPageNum", "getPages", "getPageSize", "getPageSizeZero",
                "getReasonable", "getStartRow"))
        .watchTypes(EnhanceModel.RECORD_EVENT_TYPE).build();

    return CollectionUtil.newArrayList(enhanceModel);
  }

  @Override
  protected InvocationProcessor getInvocationProcessor() {
    return new PageHelperInvocationProcessor(getType());
  }

  @Override
  public InvokeType getType() {
    return InvokeType.PAGE_HELPER;
  }

  @Override
  public boolean isEntrance() {
    return false;
  }

}