ArafatKhan2198 commented on code in PR #6231: URL: https://github.com/apache/ozone/pull/6231#discussion_r1522669116
########## hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestOMDBInsightSearchEndpoint.java: ########## @@ -0,0 +1,305 @@ +/** + * 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.recon.api; + +import org.apache.hadoop.hdds.client.StandaloneReplicationConfig; +import org.apache.hadoop.hdds.protocol.proto.HddsProtos; +import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager; +import org.apache.hadoop.hdds.utils.db.Table; +import org.apache.hadoop.ozone.om.OMMetadataManager; +import org.apache.hadoop.ozone.om.helpers.BucketLayout; +import org.apache.hadoop.ozone.om.helpers.OmBucketInfo; +import org.apache.hadoop.ozone.om.helpers.OmKeyInfo; +import org.apache.hadoop.ozone.om.helpers.OmVolumeArgs; +import org.apache.hadoop.ozone.recon.ReconTestInjector; +import org.apache.hadoop.ozone.recon.persistence.AbstractReconSqlDBTest; +import org.apache.hadoop.ozone.recon.persistence.ContainerHealthSchemaManager; +import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager; +import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade; +import org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider; +import org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl; +import org.apache.hadoop.ozone.recon.spi.impl.StorageContainerServiceProviderImpl; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import javax.ws.rs.core.Response; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; + +import static org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.getTestReconOmMetadataManager; +import static org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.initializeNewOmMetadataManager; +import static org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.getBucketLayout; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + +/** + * Test for OMDBInsightSearchEndpoint. + */ +public class TestOMDBInsightSearchEndpoint extends AbstractReconSqlDBTest { + @TempDir + private Path temporaryFolder; + private OMMetadataManager omMetadataManager; + private ReconOMMetadataManager reconOMMetadataManager; + private OMDBInsightSearchEndpoint omdbInsightSearchEndpoint; + private Random random = new Random(); + private Set<Long> generatedIds = new HashSet<>(); + public TestOMDBInsightSearchEndpoint() { + super(); + } + + private long generateUniqueRandomLong() { + long newValue; + do { + newValue = random.nextLong(); + } while (generatedIds.contains(newValue)); + + generatedIds.add(newValue); + return newValue; + } + + @BeforeEach + public void setUp() throws Exception { + omMetadataManager = initializeNewOmMetadataManager( + Files.createDirectory(temporaryFolder.resolve( + "JunitOmMetadata")).toFile()); + reconOMMetadataManager = getTestReconOmMetadataManager(omMetadataManager, + Files.createDirectory(temporaryFolder.resolve( + "JunitOmMetadataTest")).toFile()); + ReconTestInjector reconTestInjector = + new ReconTestInjector.Builder(temporaryFolder.toFile()) + .withReconSqlDb() + .withReconOm(reconOMMetadataManager) + .withOmServiceProvider(mock(OzoneManagerServiceProviderImpl.class)) + .addBinding(OzoneStorageContainerManager.class, + ReconStorageContainerManagerFacade.class) + .withContainerDB() + .addBinding(StorageContainerServiceProvider.class, + mock(StorageContainerServiceProviderImpl.class)) + .addBinding(OMDBInsightEndpoint.class) + .addBinding(ContainerHealthSchemaManager.class) + .build(); + omdbInsightSearchEndpoint = reconTestInjector.getInstance( + OMDBInsightSearchEndpoint.class); + } + + @Test + public void testSearchOpenKeys() throws Exception { + // Create 3 keys in 'bucketOne' and 2 keys in 'bucketTwo' + for (int i = 1; i <= 3; i++) { + OmKeyInfo omKeyInfo = + getOmKeyInfo("sampleVol", "bucketOne", "key_" + i, true); + String keyPath = String.format("/sampleVol/%s/key_%d", "bucketOne", i); + reconOMMetadataManager.getOpenKeyTable(getBucketLayout()) + .put(keyPath, omKeyInfo); + } + + for (int i = 1; i <= 2; i++) { + OmKeyInfo omKeyInfo = + getOmKeyInfo("sampleVol", "bucketTwo", "key_" + i, true); + String keyPath = String.format("/sampleVol/%s/key_%d", "bucketTwo", i); + reconOMMetadataManager.getOpenKeyTable(getBucketLayout()) + .put(keyPath, omKeyInfo); + } + + // Search for keys in 'bucketOne' + String searchPrefixBucketOne = "/sampleVol/bucketOne/"; Review Comment: I've added a test case for searching at the root level. To search within directories, subdirectories, and subpaths, it's essential to include both the volume and bucket names in the search, as they are crucial for defining the absolute path. -- 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]
