import cn.reghao.oss.store.OssStoreApplication; import cn.reghao.oss.store.db.mapper.DataBlockMapper; import cn.reghao.oss.store.db.mapper.FileMetaMapper; import cn.reghao.oss.store.model.po.DataBlock; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import java.util.List; /** * @author reghao * @date 2023-07-16 19:19:12 */ @Slf4j @ActiveProfiles("dev") @SpringBootTest(classes = OssStoreApplication.class) public class FileMetaTest { @Autowired FileMetaMapper fileMetaMapper; // 正则表达式查询测试 public void regexpTest() { String bucket = ""; String prefix = "abc/d/"; String startAfter = "abc/d/e"; Integer maxKeys = 10; StringBuilder regex = new StringBuilder(); regex.append("^").append(prefix).append("([^/])+/?$"); if (startAfter.isBlank()) { fileMetaMapper.findAll0(bucket, maxKeys, regex.toString()); } else { fileMetaMapper.findAll2(bucket, prefix, startAfter, maxKeys); } } @Autowired DataBlockMapper dataBlockMapper; @Test public void dataBlockTest() { int pageSize = 10000; int nextId = 0; List list = dataBlockMapper.findDataBlocks(pageSize, nextId); while (!list.isEmpty()) { // process DataBlocks nextId = list.get(list.size()-1).getId(); list = dataBlockMapper.findDataBlocks(pageSize, nextId); log.info("nextId -> {}", nextId); } } }