Xuanwo commented on code in PR #3238:
URL: 
https://github.com/apache/incubator-opendal/pull/3238#discussion_r1349550980


##########
bindings/java/src/test/java/org/apache/opendal/test/behavior/AbstractBehaviorTest.java:
##########
@@ -605,6 +757,158 @@ public void testBlockingCopyOverwrite() {
         }
     }
 
+    @TestInstance(TestInstance.Lifecycle.PER_CLASS)
+    @Nested
+    class BlockingRenameTest {
+        @BeforeAll
+        public void precondition() {
+            final Capability capability = blockingOperator.info.fullCapability;
+            assumeTrue(
+                    capability.read && capability.write && capability.copy && 
capability.blocking && capability.rename);
+        }
+
+        /**
+         * Rename a file and test with stat.
+         */
+        @Test
+        public void testBlockingRenameFile() {
+            final String sourcePath = UUID.randomUUID().toString();
+            final byte[] sourceContent = generateBytes();
+
+            blockingOperator.write(sourcePath, sourceContent);
+
+            final String targetPath = UUID.randomUUID().toString();
+
+            blockingOperator.rename(sourcePath, targetPath);
+
+            assertThatThrownBy(() -> blockingOperator.stat(sourcePath))
+                    
.is(OpenDALExceptionCondition.ofAsync(OpenDALException.Code.NotFound));
+
+            
assertThat(blockingOperator.stat(targetPath).getContentLength()).isEqualTo(sourceContent.length);
+
+            blockingOperator.delete(sourcePath);
+            blockingOperator.delete(targetPath);
+        }
+
+        /**
+         * Rename a nonexistent source should return an error.
+         */
+        @Test
+        public void testBlockingRenameNonExistingSource() {
+            final String sourcePath = UUID.randomUUID().toString();
+            final String targetPath = UUID.randomUUID().toString();
+
+            assertThatThrownBy(() -> blockingOperator.rename(sourcePath, 
targetPath))
+                    
.is(OpenDALExceptionCondition.ofAsync(OpenDALException.Code.NotFound));
+        }
+
+        /**
+         * Rename a dir as source should return an error.
+         */
+        @Test
+        public void testBlockingRenameSourceDir() {

Review Comment:
   This is un-defined behavior. OpenDAL doesn't give a promise on what happened 
in this case.



##########
bindings/java/src/test/java/org/apache/opendal/test/behavior/AbstractBehaviorTest.java:
##########
@@ -605,6 +757,158 @@ public void testBlockingCopyOverwrite() {
         }
     }
 
+    @TestInstance(TestInstance.Lifecycle.PER_CLASS)
+    @Nested
+    class BlockingRenameTest {
+        @BeforeAll
+        public void precondition() {
+            final Capability capability = blockingOperator.info.fullCapability;
+            assumeTrue(
+                    capability.read && capability.write && capability.copy && 
capability.blocking && capability.rename);

Review Comment:
   rename test doesn't depend on copy



##########
bindings/java/src/test/java/org/apache/opendal/test/behavior/AbstractBehaviorTest.java:
##########
@@ -605,6 +757,158 @@ public void testBlockingCopyOverwrite() {
         }
     }
 
+    @TestInstance(TestInstance.Lifecycle.PER_CLASS)
+    @Nested
+    class BlockingRenameTest {
+        @BeforeAll
+        public void precondition() {
+            final Capability capability = blockingOperator.info.fullCapability;
+            assumeTrue(
+                    capability.read && capability.write && capability.copy && 
capability.blocking && capability.rename);
+        }
+
+        /**
+         * Rename a file and test with stat.
+         */
+        @Test
+        public void testBlockingRenameFile() {
+            final String sourcePath = UUID.randomUUID().toString();
+            final byte[] sourceContent = generateBytes();
+
+            blockingOperator.write(sourcePath, sourceContent);
+
+            final String targetPath = UUID.randomUUID().toString();
+
+            blockingOperator.rename(sourcePath, targetPath);
+
+            assertThatThrownBy(() -> blockingOperator.stat(sourcePath))
+                    
.is(OpenDALExceptionCondition.ofAsync(OpenDALException.Code.NotFound));
+
+            
assertThat(blockingOperator.stat(targetPath).getContentLength()).isEqualTo(sourceContent.length);
+
+            blockingOperator.delete(sourcePath);
+            blockingOperator.delete(targetPath);
+        }
+
+        /**
+         * Rename a nonexistent source should return an error.
+         */
+        @Test
+        public void testBlockingRenameNonExistingSource() {
+            final String sourcePath = UUID.randomUUID().toString();
+            final String targetPath = UUID.randomUUID().toString();
+
+            assertThatThrownBy(() -> blockingOperator.rename(sourcePath, 
targetPath))
+                    
.is(OpenDALExceptionCondition.ofAsync(OpenDALException.Code.NotFound));
+        }
+
+        /**
+         * Rename a dir as source should return an error.
+         */
+        @Test
+        public void testBlockingRenameSourceDir() {
+            final String sourcePath = String.format("%s/", 
UUID.randomUUID().toString());
+            final String targetPath = UUID.randomUUID().toString();
+
+            blockingOperator.createDir(sourcePath);
+
+            assertThatThrownBy(() -> blockingOperator.rename(sourcePath, 
targetPath))
+                    
.is(OpenDALExceptionCondition.ofAsync(OpenDALException.Code.IsADirectory));
+        }
+
+        /**
+         * Rename to a dir should return an error.
+         */
+        @Test
+        public void testBlockingRenameTargetDir() {
+            final String sourcePath = UUID.randomUUID().toString();
+            final byte[] sourceContent = generateBytes();
+
+            blockingOperator.write(sourcePath, sourceContent);
+
+            final String targetPath = String.format("%s/", 
UUID.randomUUID().toString());
+
+            blockingOperator.createDir(targetPath);
+
+            assertThatThrownBy(() -> blockingOperator.rename(sourcePath, 
targetPath))
+                    
.is(OpenDALExceptionCondition.ofAsync(OpenDALException.Code.IsADirectory));
+
+            blockingOperator.delete(sourcePath);
+            blockingOperator.delete(targetPath);
+        }
+
+        /**
+         * Rename a file to self should return an error.
+         */
+        @Test
+        public void testBlockingRenameSelf() {
+            final String sourcePath = UUID.randomUUID().toString();
+            final byte[] sourceContent = generateBytes();
+
+            blockingOperator.write(sourcePath, sourceContent);
+
+            assertThatThrownBy(() -> blockingOperator.rename(sourcePath, 
sourcePath))
+                    
.is(OpenDALExceptionCondition.ofAsync(OpenDALException.Code.IsSameFile));
+
+            blockingOperator.delete(sourcePath);
+        }
+
+        /**
+         * Rename to a nested path, parent path should be created successfully.
+         */
+        @Test
+        public void testBlockingRenameNested() {

Review Comment:
   The same. Please check opendal's behavior test first before adding bindings 
tests.
   



##########
bindings/java/src/test/java/org/apache/opendal/test/behavior/AbstractBehaviorTest.java:
##########
@@ -605,6 +757,158 @@ public void testBlockingCopyOverwrite() {
         }
     }
 
+    @TestInstance(TestInstance.Lifecycle.PER_CLASS)
+    @Nested
+    class BlockingRenameTest {
+        @BeforeAll
+        public void precondition() {
+            final Capability capability = blockingOperator.info.fullCapability;
+            assumeTrue(
+                    capability.read && capability.write && capability.copy && 
capability.blocking && capability.rename);
+        }
+
+        /**
+         * Rename a file and test with stat.
+         */
+        @Test
+        public void testBlockingRenameFile() {
+            final String sourcePath = UUID.randomUUID().toString();
+            final byte[] sourceContent = generateBytes();
+
+            blockingOperator.write(sourcePath, sourceContent);
+
+            final String targetPath = UUID.randomUUID().toString();
+
+            blockingOperator.rename(sourcePath, targetPath);
+
+            assertThatThrownBy(() -> blockingOperator.stat(sourcePath))
+                    
.is(OpenDALExceptionCondition.ofAsync(OpenDALException.Code.NotFound));
+
+            
assertThat(blockingOperator.stat(targetPath).getContentLength()).isEqualTo(sourceContent.length);
+
+            blockingOperator.delete(sourcePath);
+            blockingOperator.delete(targetPath);
+        }
+
+        /**
+         * Rename a nonexistent source should return an error.
+         */
+        @Test
+        public void testBlockingRenameNonExistingSource() {
+            final String sourcePath = UUID.randomUUID().toString();
+            final String targetPath = UUID.randomUUID().toString();
+
+            assertThatThrownBy(() -> blockingOperator.rename(sourcePath, 
targetPath))
+                    
.is(OpenDALExceptionCondition.ofAsync(OpenDALException.Code.NotFound));
+        }
+
+        /**
+         * Rename a dir as source should return an error.
+         */
+        @Test
+        public void testBlockingRenameSourceDir() {
+            final String sourcePath = String.format("%s/", 
UUID.randomUUID().toString());
+            final String targetPath = UUID.randomUUID().toString();
+
+            blockingOperator.createDir(sourcePath);
+
+            assertThatThrownBy(() -> blockingOperator.rename(sourcePath, 
targetPath))
+                    
.is(OpenDALExceptionCondition.ofAsync(OpenDALException.Code.IsADirectory));
+        }
+
+        /**
+         * Rename to a dir should return an error.
+         */
+        @Test
+        public void testBlockingRenameTargetDir() {

Review Comment:
   The same



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to