adoroszlai commented on code in PR #7465:
URL: https://github.com/apache/ozone/pull/7465#discussion_r1903971341
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneDebugShell.java:
##########
@@ -173,6 +176,37 @@ public void testLdbCliForOzoneSnapshot() throws Exception {
assertThat(cmdOut).contains(keyName);
}
+ @Test
+ public void testKeyPathRetriever() throws Exception {
+ final String volumeName = UUID.randomUUID().toString();
+ final String bucketName = UUID.randomUUID().toString();
+ StringWriter stdout = new StringWriter();
+ PrintWriter pstdout = new PrintWriter(stdout);
+ String[] args;
+ CommandLine cmd;
+ try (OzoneClient client = OzoneClientFactory.getRpcClient(conf)) {
+ TestDataUtil.createVolumeAndBucket(client, volumeName, bucketName,
BucketLayout.FILE_SYSTEM_OPTIMIZED);
+ OzoneBucket bucket =
client.getObjectStore().getVolume(volumeName).getBucket(bucketName);
+ bucket.createDirectory("dir1");
+ TestDataUtil.createKey(bucket, "dir1/file1", "test");
+ TestDataUtil.createKey(bucket, "dir1/file2", "test");
+ TestDataUtil.createKey(bucket, "dir1/file3", "test");
+ OzoneKeyDetails key1 = bucket.getKey("dir1/file1");
+ OzoneKeyDetails key3 = bucket.getKey("dir1/file2");
+ StringBuilder sb = new StringBuilder();
+ key1.getOzoneKeyLocations().forEach(e -> sb.append(e.getContainerID()));
+ key3.getOzoneKeyLocations().forEach(e ->
sb.append(",").append(e.getContainerID()));
+ String dbFile = OMStorage.getOmDbDir(conf).getPath() + "/om.db";
+ cmd = new CommandLine(new OzoneDebug()).addSubcommand(new
CommandLine(new KeyPathRetriever())).setOut(pstdout);
+ args = new String[] {"retrieve-key-fullpath", "--db", dbFile,
"--containers", sb.toString()};
+ }
+ int exitCode = cmd.execute(args);
+ assertEquals(0, exitCode);
+ String keyPrefix = volumeName + "/" + bucketName + "/dir1/";
+ assertThat(stdout.toString()).contains(keyPrefix +
"file1").contains(keyPrefix + "file2")
+ .doesNotContain(keyPrefix + "file3");
Review Comment:
nit: please wrap.
```suggestion
assertThat(stdout.toString())
.contains(keyPrefix + "file1")
.contains(keyPrefix + "file2")
.doesNotContain(keyPrefix + "file3");
```
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneDebugShell.java:
##########
@@ -173,6 +176,37 @@ public void testLdbCliForOzoneSnapshot() throws Exception {
assertThat(cmdOut).contains(keyName);
}
+ @Test
+ public void testKeyPathRetriever() throws Exception {
+ final String volumeName = UUID.randomUUID().toString();
+ final String bucketName = UUID.randomUUID().toString();
+ StringWriter stdout = new StringWriter();
+ PrintWriter pstdout = new PrintWriter(stdout);
+ String[] args;
+ CommandLine cmd;
+ try (OzoneClient client = OzoneClientFactory.getRpcClient(conf)) {
+ TestDataUtil.createVolumeAndBucket(client, volumeName, bucketName,
BucketLayout.FILE_SYSTEM_OPTIMIZED);
+ OzoneBucket bucket =
client.getObjectStore().getVolume(volumeName).getBucket(bucketName);
+ bucket.createDirectory("dir1");
+ TestDataUtil.createKey(bucket, "dir1/file1", "test");
+ TestDataUtil.createKey(bucket, "dir1/file2", "test");
+ TestDataUtil.createKey(bucket, "dir1/file3", "test");
+ OzoneKeyDetails key1 = bucket.getKey("dir1/file1");
+ OzoneKeyDetails key3 = bucket.getKey("dir1/file2");
+ StringBuilder sb = new StringBuilder();
+ key1.getOzoneKeyLocations().forEach(e -> sb.append(e.getContainerID()));
+ key3.getOzoneKeyLocations().forEach(e ->
sb.append(",").append(e.getContainerID()));
Review Comment:
This does not produce the expected output if `key1` has more than one
location.
```java
String containers =
Stream.concat(key1.getOzoneKeyLocations().stream(),
key3.getOzoneKeyLocations().stream())
.mapToLong(OzoneKeyLocation::getContainerID)
.mapToObj(String::valueOf)
.collect(Collectors.joining(","));
```
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneDebugShell.java:
##########
@@ -173,6 +176,37 @@ public void testLdbCliForOzoneSnapshot() throws Exception {
assertThat(cmdOut).contains(keyName);
}
+ @Test
+ public void testKeyPathRetriever() throws Exception {
+ final String volumeName = UUID.randomUUID().toString();
+ final String bucketName = UUID.randomUUID().toString();
+ StringWriter stdout = new StringWriter();
+ PrintWriter pstdout = new PrintWriter(stdout);
+ String[] args;
+ CommandLine cmd;
+ try (OzoneClient client = OzoneClientFactory.getRpcClient(conf)) {
+ TestDataUtil.createVolumeAndBucket(client, volumeName, bucketName,
BucketLayout.FILE_SYSTEM_OPTIMIZED);
+ OzoneBucket bucket =
client.getObjectStore().getVolume(volumeName).getBucket(bucketName);
+ bucket.createDirectory("dir1");
+ TestDataUtil.createKey(bucket, "dir1/file1", "test");
+ TestDataUtil.createKey(bucket, "dir1/file2", "test");
+ TestDataUtil.createKey(bucket, "dir1/file3", "test");
+ OzoneKeyDetails key1 = bucket.getKey("dir1/file1");
+ OzoneKeyDetails key3 = bucket.getKey("dir1/file2");
+ StringBuilder sb = new StringBuilder();
+ key1.getOzoneKeyLocations().forEach(e -> sb.append(e.getContainerID()));
+ key3.getOzoneKeyLocations().forEach(e ->
sb.append(",").append(e.getContainerID()));
+ String dbFile = OMStorage.getOmDbDir(conf).getPath() + "/om.db";
+ cmd = new CommandLine(new OzoneDebug()).addSubcommand(new
CommandLine(new KeyPathRetriever())).setOut(pstdout);
Review Comment:
Do not add subcommand manually.
```suggestion
cmd = new OzoneDebug().getCmd().setOut(pstdout);
```
##########
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestOzoneDebugShell.java:
##########
@@ -173,6 +176,37 @@ public void testLdbCliForOzoneSnapshot() throws Exception {
assertThat(cmdOut).contains(keyName);
}
+ @Test
+ public void testKeyPathRetriever() throws Exception {
+ final String volumeName = UUID.randomUUID().toString();
+ final String bucketName = UUID.randomUUID().toString();
+ StringWriter stdout = new StringWriter();
+ PrintWriter pstdout = new PrintWriter(stdout);
+ String[] args;
+ CommandLine cmd;
+ try (OzoneClient client = OzoneClientFactory.getRpcClient(conf)) {
+ TestDataUtil.createVolumeAndBucket(client, volumeName, bucketName,
BucketLayout.FILE_SYSTEM_OPTIMIZED);
+ OzoneBucket bucket =
client.getObjectStore().getVolume(volumeName).getBucket(bucketName);
+ bucket.createDirectory("dir1");
+ TestDataUtil.createKey(bucket, "dir1/file1", "test");
+ TestDataUtil.createKey(bucket, "dir1/file2", "test");
+ TestDataUtil.createKey(bucket, "dir1/file3", "test");
+ OzoneKeyDetails key1 = bucket.getKey("dir1/file1");
+ OzoneKeyDetails key3 = bucket.getKey("dir1/file2");
Review Comment:
nit: `key3` vs. `file2` is confusing, especially in final assertion, where
we expect `file2`, but not `file3`.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]