FileMetaTest.java 1.7 KB

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