linyiqun commented on a change in pull request #1847: URL: https://github.com/apache/ozone/pull/1847#discussion_r565172470
########## File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestObjectStoreV1.java ########## @@ -264,6 +268,95 @@ public void testLookupKey() throws Exception { dirPathC.getObjectID(), true); } + @Test + public void testRenameKey() throws IOException { + String fromKeyName = UUID.randomUUID().toString(); + String value = "sample value"; + OzoneClient client = cluster.getClient(); + + ObjectStore objectStore = client.getObjectStore(); + OzoneVolume volume = objectStore.getVolume(volumeName); + OzoneBucket bucket = volume.getBucket(bucketName); + createTestKey(bucket, fromKeyName, value); + + // Rename to empty string should fail. + OMException oe = null; + String toKeyName = ""; + try { + bucket.renameKey(fromKeyName, toKeyName); + fail("Rename to empty string should fail!"); + } catch (OMException e) { + oe = e; + } + Assert.assertEquals(OMException.ResultCodes.INVALID_KEY_NAME, + oe.getResult()); + + toKeyName = UUID.randomUUID().toString(); + bucket.renameKey(fromKeyName, toKeyName); + + // Lookup for old key should fail. + try { + bucket.getKey(fromKeyName); + fail("Lookup for old from key name should fail!"); + } catch (OMException e) { + oe = e; + } + Assert.assertEquals(KEY_NOT_FOUND, oe.getResult()); + + OzoneKey key = bucket.getKey(toKeyName); + Assert.assertEquals(toKeyName, key.getName()); Review comment: Can we additionally add a case for renamed to an existed key? There should be returned KEY_ALREADY_EXISTS error. ########## File path: hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestObjectStoreV1.java ########## @@ -264,6 +268,95 @@ public void testLookupKey() throws Exception { dirPathC.getObjectID(), true); } + @Test + public void testRenameKey() throws IOException { + String fromKeyName = UUID.randomUUID().toString(); + String value = "sample value"; + OzoneClient client = cluster.getClient(); + + ObjectStore objectStore = client.getObjectStore(); + OzoneVolume volume = objectStore.getVolume(volumeName); + OzoneBucket bucket = volume.getBucket(bucketName); + createTestKey(bucket, fromKeyName, value); + + // Rename to empty string should fail. + OMException oe = null; + String toKeyName = ""; + try { + bucket.renameKey(fromKeyName, toKeyName); + fail("Rename to empty string should fail!"); + } catch (OMException e) { + oe = e; + } + Assert.assertEquals(OMException.ResultCodes.INVALID_KEY_NAME, + oe.getResult()); Review comment: Can we simplified all this check to below? I didn't see _oe_ is used in other place. ```java try { bucket.renameKey(fromKeyName, toKeyName); fail("Rename to empty string should fail!"); } catch (OMException e) { Assert.assertEquals(OMException.ResultCodes.INVALID_KEY_NAME, e.getResult()); } ``` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org