FileMetaTest.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import cn.reghao.oss.store.OssStoreApplication;
  2. import cn.reghao.oss.store.db.mapper.DataBlockMapper;
  3. import cn.reghao.oss.store.db.mapper.FileMetaMapper;
  4. import cn.reghao.oss.store.model.po.DataBlock;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.junit.Test;
  7. import org.junit.runner.RunWith;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.boot.test.context.SpringBootTest;
  10. import org.springframework.test.context.ActiveProfiles;
  11. import org.springframework.test.context.junit4.SpringRunner;
  12. import java.util.List;
  13. /**
  14. * @author reghao
  15. * @date 2023-07-16 19:19:12
  16. */
  17. @Slf4j
  18. @ActiveProfiles("dev")
  19. @SpringBootTest(classes = OssStoreApplication.class)
  20. @RunWith(SpringRunner.class)
  21. public class FileMetaTest {
  22. @Autowired
  23. FileMetaMapper fileMetaMapper;
  24. // 正则表达式查询测试
  25. public void regexpTest() {
  26. String bucket = "";
  27. String prefix = "abc/d/";
  28. String startAfter = "abc/d/e";
  29. Integer maxKeys = 10;
  30. StringBuilder regex = new StringBuilder();
  31. regex.append("^").append(prefix).append("([^/])+/?$");
  32. if (startAfter.isBlank()) {
  33. fileMetaMapper.findAll0(bucket, maxKeys, regex.toString());
  34. } else {
  35. fileMetaMapper.findAll2(bucket, prefix, startAfter, maxKeys);
  36. }
  37. }
  38. @Autowired
  39. DataBlockMapper dataBlockMapper;
  40. @Test
  41. public void dataBlockTest() {
  42. int pageSize = 10000;
  43. int nextId = 0;
  44. List<DataBlock> list = dataBlockMapper.findDataBlocks(pageSize, nextId);
  45. while (!list.isEmpty()) {
  46. // process DataBlocks
  47. nextId = list.get(list.size()-1).getId();
  48. list = dataBlockMapper.findDataBlocks(pageSize, nextId);
  49. log.info("nextId -> {}", nextId);
  50. }
  51. }
  52. }