FlashLinePayMapperTest.java 1.8 KB

12345678910111213141516171819202122232425262728
  1. package com.ruoyi.system.mapper;
  2. import org.apache.ibatis.builder.xml.XMLMapperBuilder;
  3. import org.apache.ibatis.session.Configuration;
  4. import org.junit.jupiter.api.Test;
  5. import java.util.*;
  6. import static org.junit.jupiter.api.Assertions.*;
  7. class FlashLinePayMapperTest {
  8. private Configuration configuration(String name) throws Exception {
  9. String resource="mapper/flash/FlashDeliveryLine"+name+"Mapper.xml";Configuration config=new Configuration();
  10. try(var stream=getClass().getClassLoader().getResourceAsStream(resource)){new XMLMapperBuilder(stream,config,resource,config.getSqlFragments()).parse();}return config;
  11. }
  12. @Test void pickupQueriesEmitCurrentReads() throws Exception {
  13. Configuration payments=configuration("Payment"),refunds=configuration("Refund");
  14. String p="com.ruoyi.system.mapper.flash.FlashDeliveryLinePaymentMapper.selectLatestForUpdate";
  15. String r="com.ruoyi.system.mapper.flash.FlashDeliveryLineRefundMapper.selectByPaymentIdForUpdate";
  16. assertTrue(payments.hasStatement(p));assertTrue(refunds.hasStatement(r));
  17. assertTrue(payments.getMappedStatement(p).getBoundSql(Map.of("orderId",1L)).getSql().trim().endsWith("FOR UPDATE"));
  18. assertTrue(refunds.getMappedStatement(r).getBoundSql(Map.of("paymentId",22L)).getSql().trim().endsWith("FOR UPDATE"));
  19. }
  20. @Test void recoverySelectsOldestDueWorkBeforeId() throws Exception {
  21. for(String kind:List.of("Payment","Refund")){
  22. Configuration config=configuration(kind);
  23. String sql=config.getMappedStatement("com.ruoyi.system.mapper.flash.FlashDeliveryLine"+kind+"Mapper.selectDue")
  24. .getBoundSql(Map.of("now",new Date(),"limit",20)).getSql().replaceAll("\\s+"," ");
  25. assertTrue(sql.contains("ORDER BY next_reconcile_at, id LIMIT"),sql);
  26. }
  27. }
  28. }