From 14428fe04c70af0bc3919b879e050c312edd2f89 Mon Sep 17 00:00:00 2001 From: thu-david <125841840+thu-david@users.noreply.github.com> Date: Tue, 22 Aug 2023 20:50:15 +0800 Subject: [PATCH] Update PagedDoraWorkerTest.java update Rename and exists tests for PagedDoraWorker. --- .../worker/dora/PagedDoraWorkerTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/dora/core/server/worker/src/test/java/alluxio/worker/dora/PagedDoraWorkerTest.java b/dora/core/server/worker/src/test/java/alluxio/worker/dora/PagedDoraWorkerTest.java index 208b561109fc..5e2e77019302 100644 --- a/dora/core/server/worker/src/test/java/alluxio/worker/dora/PagedDoraWorkerTest.java +++ b/dora/core/server/worker/src/test/java/alluxio/worker/dora/PagedDoraWorkerTest.java @@ -30,11 +30,13 @@ import alluxio.grpc.CreateDirectoryPOptions; import alluxio.grpc.CreateFilePOptions; import alluxio.grpc.DeletePOptions; +import alluxio.grpc.ExistsPOptions; import alluxio.grpc.FileInfo; import alluxio.grpc.FileSystemMasterCommonPOptions; import alluxio.grpc.GetStatusPOptions; import alluxio.grpc.ListStatusPOptions; import alluxio.grpc.LoadFileFailure; +import alluxio.grpc.RenamePOptions; import alluxio.grpc.Route; import alluxio.grpc.RouteFailure; import alluxio.grpc.SetAttributePOptions; @@ -752,4 +754,35 @@ private void createDummyFile(File testFile, int length) throws Exception { mWorker.completeFile(testFile.getPath(), CompleteFilePOptions.getDefaultInstance(), handle.getUUID().toString()); } + + @Test + public void testExists() throws Exception { + File rootFolder = mTestFolder.newFolder("root"); + String rootPath = rootFolder.getAbsolutePath(); + assertTrue(mWorker.exists(rootPath, ExistsPOptions.getDefaultInstance())); + String fileContent = "foobar"; + File f = mTestFolder.newFile("root/f"); + Files.write(f.toPath(), fileContent.getBytes()); + assertTrue(mWorker.exists(f.getAbsolutePath(), ExistsPOptions.getDefaultInstance())); + mWorker.delete(f.getAbsolutePath(), DeletePOptions.getDefaultInstance()); + assertFalse(mWorker.exists(f.getAbsolutePath(), ExistsPOptions.getDefaultInstance())); + mWorker.delete(rootPath, DeletePOptions.getDefaultInstance()); + assertFalse(mWorker.exists(rootPath, ExistsPOptions.getDefaultInstance())); + } + + @Test + public void testRename() throws IOException, AccessControlException { + File srcFolder = mTestFolder.newFolder("root"); + String rootPath = srcFolder.getAbsolutePath(); + mWorker.rename(rootPath, rootPath + "2", RenamePOptions.getDefaultInstance()); + assertFalse(mWorker.exists(rootPath, ExistsPOptions.getDefaultInstance())); + assertTrue(mWorker.exists(rootPath + "2", ExistsPOptions.getDefaultInstance())); + String fileContent = "foobar"; + File f = mTestFolder.newFile("root2/f"); + Files.write(f.toPath(), fileContent.getBytes()); + mWorker.rename(f.getAbsolutePath(), f.getAbsolutePath() + "2", + RenamePOptions.getDefaultInstance()); + assertFalse(mWorker.exists(f.getAbsolutePath(), ExistsPOptions.getDefaultInstance())); + assertTrue(mWorker.exists(f.getAbsolutePath() + "2", ExistsPOptions.getDefaultInstance())); + } }