Explorar el Código

update test case

reghao hace 2 años
padre
commit
c8d4e29a22

+ 1 - 3
dfs-store/src/main/java/cn/reghao/dfs/store/db/mapper/FileMetaMapper.java

@@ -23,8 +23,7 @@ public interface FileMetaMapper extends BaseMapper<FileMeta> {
 
     List<FileMeta> findAll0(@Param("bucket") String bucket, @Param("max") Integer max, @Param("regex") String regex);
     List<FileMeta> findAll1(@Param("bucket") String bucket, @Param("prefix") String prefix, @Param("max") Integer max);
-    List<FileMeta> findAll2(@Param("bucket") String bucket, @Param("prefix") String prefix,
-                            @Param("start") String start, @Param("max") Integer max);
+    List<FileMeta> findAll2(@Param("bucket") String bucket, @Param("prefix") String prefix, @Param("start") String start, @Param("max") Integer max);
 
     List<FileMeta> findFileMetaByPage(Page page);
     ObjectMeta findObjectMeta(String objectName);
@@ -34,7 +33,6 @@ public interface FileMetaMapper extends BaseMapper<FileMeta> {
     void updateFilename(@Param("objectId") String objectId, @Param("filename") String filename);
     void updateParent(@Param("objectId") String objectId, @Param("pid") String pid);
     void updateSetDelete(String objectId);
-    void deleteByObjectId(String objectId);
     void updateBatch(List<FileMeta> list);
 
     int countByPid(String pid);

+ 0 - 5
dfs-store/src/main/resources/mapper/FileMetaMapper.xml

@@ -117,11 +117,6 @@
         where object_id=#{objectId}
     </update>
 
-    <delete id="deleteByObjectId">
-        delete from file_meta
-        where object_id=#{objectId}
-    </delete>
-
     <select id="countByPid" resultType="java.lang.Integer">
         select count(*)
         from file_meta

+ 10 - 114
dfs-store/src/test/java/FileMetaTest.java

@@ -1,11 +1,7 @@
 import cn.reghao.dfs.store.DfsStoreApplication;
-import cn.reghao.dfs.store.db.mapper.DataBlockMapper;
 import cn.reghao.dfs.store.db.mapper.FileMetaMapper;
-import cn.reghao.dfs.store.model.po.DataBlock;
 import cn.reghao.dfs.store.model.po.FileMeta;
-import cn.reghao.dfs.api.dto.ObjectMeta;
 import cn.reghao.jutil.jdk.db.Page;
-import cn.reghao.jutil.jdk.security.DigestUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -14,16 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.FileVisitor;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.ArrayList;
 import java.util.List;
-import java.util.UUID;
 
 /**
  * @author reghao
@@ -36,16 +23,8 @@ import java.util.UUID;
 public class FileMetaTest {
     @Autowired
     FileMetaMapper fileMetaMapper;
-    @Autowired
-    DataBlockMapper dataBlockMapper;
 
-    /**
-     * 正则表达式查询测试
-     *
-     * @param
-     * @return
-     * @date 2023-05-23 11:06:07
-     */
+    // 正则表达式查询测试
     public void regexpTest() {
         String bucket = "";
         String prefix = "abc/d/";
@@ -61,105 +40,22 @@ public class FileMetaTest {
         }
     }
 
+    /**
+     * 分页处理
+     *
+     * @param
+     * @return
+     * @date 2023-05-30 00:26:07
+     */
     @Test
-    public void test2() {
-        int pageSize = 10000;
-        int pageNumber = 1;
-        Page page = new Page(pageNumber, pageSize);
-        List<DataBlock> dataBlocks = dataBlockMapper.findDataBlockByPage(page);
-        List<FileMeta> fileMetas = new ArrayList<>();
-        while (!dataBlocks.isEmpty()) {
-            dataBlocks.forEach(dataBlock -> {
-                String objectId = dataBlock.getObjectId();
-                String contentId = UUID.randomUUID().toString().replace("-", "");
-
-                FileMeta fileMeta = fileMetaMapper.findByObjectId(objectId);
-                if (fileMeta == null) {
-                    log.error("{} 不存在", objectId);
-                    return;
-                }
-
-                fileMeta.setContentId(contentId);
-                fileMetas.add(fileMeta);
-                dataBlock.setContentId(contentId);
-            });
-
-            long start = System.currentTimeMillis();
-            if (!fileMetas.isEmpty()) {
-                fileMetaMapper.updateBatch(fileMetas);
-                fileMetas.clear();
-                log.info("batch update FileMeta cost {}", System.currentTimeMillis()-start);
-            }
-
-            if (!dataBlocks.isEmpty()) {
-                dataBlockMapper.updateBatch(dataBlocks);
-                log.info("batch update DataBlock cost {}", System.currentTimeMillis()-start);
-            }
-
-            pageNumber++;
-            page = new Page(pageNumber, pageSize);
-            dataBlocks = dataBlockMapper.findDataBlockByPage(page);
-            log.info("page -> {}", pageNumber);
-        }
-    }
-
-    public void walkDir(Path path) throws IOException {
-        Files.walkFileTree(path, new FileVisitor<>() {
-            @Override
-            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
-                String absolutePath = file.toString();
-                process(absolutePath);
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-
-            @Override
-            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
-                return FileVisitResult.CONTINUE;
-            }
-        });
-    }
-
-    private void process(String absolutePath) {
-        try {
-            String sha256sum = DigestUtil.sha256sum(absolutePath);
-            FileMeta fileMeta = fileMetaMapper.findBySha256sum(sha256sum);
-            if (fileMeta == null) {
-                log.error("{} 不存在", absolutePath);
-            }
-        } catch (Exception ignore) {
-        }
-    }
-
-    @Test
-    public void test22() throws IOException {
-        String baseDir = "/home/reghao/mnt/zdata/porn/0.已完成/";
-        Path path = Path.of(baseDir);
-        walkDir(path);
-    }
-
-    @Test
-    public void test11() {
+    public void processByPage() {
         int pageSize = 10_000;
         int pageNumber = 1;
         Page page = new Page(pageNumber, pageSize);
         List<FileMeta> list = fileMetaMapper.findFileMetaByPage(page);
         while (!list.isEmpty()) {
             list.forEach(fileMeta -> {
-                String objectName = fileMeta.getObjectName();
-                ObjectMeta objectMeta = fileMetaMapper.findObjectMeta(objectName);
-                if (objectMeta == null) {
-                    log.error("{} 对应的文件不存在", objectName);
-                }
+
             });
 
             pageNumber++;

+ 0 - 3
dfs-store/src/test/java/RedisTest.java

@@ -1,5 +1,4 @@
 import cn.reghao.dfs.store.DfsStoreApplication;
-import cn.reghao.dfs.store.db.mapper.DataBlockMapper;
 import cn.reghao.dfs.store.db.mapper.FileMetaMapper;
 import cn.reghao.dfs.store.model.po.FileMeta;
 import cn.reghao.dfs.api.dto.ObjectMeta;
@@ -29,8 +28,6 @@ public class RedisTest {
     RedisStringObj redisString;
     @Autowired
     FileMetaMapper fileMetaMapper;
-    @Autowired
-    DataBlockMapper dataBlockMapper;
 
     @Test
     public void test() {