hemantk-12 commented on code in PR #5724: URL: https://github.com/apache/ozone/pull/5724#discussion_r1503337656
########## hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/debug/TestFindContainerKeys.java: ########## @@ -0,0 +1,286 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS,WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.hadoop.ozone.debug; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.apache.hadoop.hdds.client.BlockID; +import org.apache.hadoop.hdds.client.RatisReplicationConfig; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.utils.db.DBStore; +import org.apache.hadoop.hdds.utils.db.DBStoreBuilder; +import org.apache.hadoop.hdds.utils.db.Table; +import org.apache.hadoop.ozone.ClientVersion; +import org.apache.hadoop.ozone.debug.container.ContainerCommands; +import org.apache.hadoop.ozone.debug.container.ContainerKeyInfo; +import org.apache.hadoop.ozone.debug.container.ContainerKeyInfoResponse; +import org.apache.hadoop.ozone.debug.container.FindContainerKeys; +import org.apache.hadoop.ozone.om.helpers.OmDirectoryInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyLocationInfoGroup; +import org.apache.hadoop.ozone.om.request.OMRequestTestUtils; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import picocli.CommandLine; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationFactor.ONE; +import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX; +import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.DIRECTORY_TABLE; +import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.FILE_TABLE; +import static org.apache.hadoop.ozone.om.OmMetadataManagerImpl.KEY_TABLE; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Test class for {@link FindContainerKeys}. + */ +public class TestFindContainerKeys { + private DBStore dbStore; + @TempDir + private File tempDir; + private StringWriter stdout, stderr; + private PrintWriter pstdout, pstderr; + private CommandLine cmd; + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + private String[] cmdArgs; + + @BeforeEach + public void setup() throws IOException { + OzoneConfiguration conf = new OzoneConfiguration(); + stdout = new StringWriter(); + pstdout = new PrintWriter(stdout); + stderr = new StringWriter(); + pstderr = new PrintWriter(stderr); + + cmd = new CommandLine(new OzoneDebug()) + .addSubcommand(new ContainerCommands()) + .addSubcommand(new FindContainerKeys()) + .setOut(pstdout) + .setErr(pstderr); + + dbStore = DBStoreBuilder.newBuilder(conf).setName("om.db") + .setPath(tempDir.toPath()).addTable(KEY_TABLE).addTable(FILE_TABLE) + .addTable(DIRECTORY_TABLE) + .build(); + + cmdArgs = + new String[]{"find-keys", "--om-db", dbStore.getDbLocation().getAbsolutePath(), "--container-ids", "1 2 3"}; + } + + @AfterEach + public void shutdown() throws IOException { + closeDbStore(); + pstderr.close(); + stderr.close(); + pstdout.close(); + stdout.close(); + } + + @Test + void testFSO() throws Exception { + /* + Structure: + keyName (container id) + + /vol1/bucet1 + - key1 (1) + - dir1 + - key2 (2) + - dir2 + - key3 (3) + - key4 (3) + - key5 (4) + */ + long volumeId = -123L; + long bucketId = -456L; + long dirObjectId1 = -789L; + long dirObjectId2 = -788L; + createDirectory(volumeId, bucketId, bucketId, dirObjectId1, "dir1"); + createDirectory(volumeId, bucketId, dirObjectId1, dirObjectId2, "dir2"); + createFile(volumeId, bucketId, "key1", -987L, bucketId, 1L); + createFile(volumeId, bucketId, "key2", -986L, dirObjectId1, 2L); + createFile(volumeId, bucketId, "key3", -985L, dirObjectId2, 3L); + createFile(volumeId, bucketId, "key4", -984L, dirObjectId2, 3L); + createFile(volumeId, bucketId, "key5", -983L, dirObjectId2, 4L); + + closeDbStore(); Review Comment: Why do we need to close it in individual test when we are closing it in `@AfterEach`? -- 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]
