From 394492fd09f305d1b5e6241851aa6b0e8a4a4314 Mon Sep 17 00:00:00 2001 From: sullis Date: Mon, 15 Jul 2024 16:10:47 -0700 Subject: [PATCH] add unit test for S3PinotFS move operation (#13608) --- .../plugin/filesystem/S3PinotFSTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pinot-plugins/pinot-file-system/pinot-s3/src/test/java/org/apache/pinot/plugin/filesystem/S3PinotFSTest.java b/pinot-plugins/pinot-file-system/pinot-s3/src/test/java/org/apache/pinot/plugin/filesystem/S3PinotFSTest.java index 226254e76942..a41391034d65 100644 --- a/pinot-plugins/pinot-file-system/pinot-s3/src/test/java/org/apache/pinot/plugin/filesystem/S3PinotFSTest.java +++ b/pinot-plugins/pinot-file-system/pinot-s3/src/test/java/org/apache/pinot/plugin/filesystem/S3PinotFSTest.java @@ -418,6 +418,37 @@ public void testMkdir() Assert.assertTrue(headObjectResponse.sdkHttpResponse().isSuccessful()); } + @Test + public void testMoveFile() + throws Exception { + + String fileName = "file-to-move"; + int fileSize = 5000; + + File file = new File(TEMP_FILE, fileName); + + try { + createDummyFile(file, fileSize); + URI sourceUri = URI.create(String.format(FILE_FORMAT, SCHEME, BUCKET, fileName)); + + _s3PinotFS.copyFromLocalFile(file, sourceUri); + + URI targetUri = URI.create(String.format(FILE_FORMAT, SCHEME, BUCKET, "move-target")); + + boolean moveResult = _s3PinotFS.move(sourceUri, targetUri, false); + Assert.assertTrue(moveResult); + + Assert.assertFalse(_s3PinotFS.exists(sourceUri)); + Assert.assertTrue(_s3PinotFS.exists(targetUri)); + + HeadObjectResponse headObjectResponse = + _s3Client.headObject(S3TestUtils.getHeadObjectRequest(BUCKET, "move-target")); + Assert.assertEquals(headObjectResponse.contentLength(), fileSize); + } finally { + FileUtils.deleteQuietly(file); + } + } + private static void createDummyFile(File file, int size) throws IOException { FileUtils.deleteQuietly(file);