Xushaohong commented on code in PR #3615: URL: https://github.com/apache/ozone/pull/3615#discussion_r928591364
########## hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/shell/TestDeletedBlockRetryCountRenewer.java: ########## @@ -0,0 +1,166 @@ +/* + * 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.shell; + +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.scm.ScmConfigKeys; +import org.apache.hadoop.hdds.scm.block.DeletedBlockLog; +import org.apache.hadoop.hdds.scm.cli.ContainerOperationClient; +import org.apache.hadoop.hdds.scm.server.StorageContainerManager; +import org.apache.hadoop.ozone.MiniOzoneCluster; +import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl; +import org.apache.hadoop.ozone.debug.DeletedBlockRetryCountRenewer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import picocli.CommandLine; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; + +import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_BLOCK_DELETION_MAX_RETRY; + +/** + * Test for DeletedBlockRetryCountRenewer Cli. + */ +public class TestDeletedBlockRetryCountRenewer { + + private static final Logger LOG = LoggerFactory + .getLogger(TestDeletedBlockRetryCountRenewer.class); + private MiniOzoneHAClusterImpl cluster = null; + private OzoneConfiguration conf; + private String clusterId; + private String scmId; + private String scmServiceId; + private int numOfSCMs = 3; + + /** + * Create a MiniOzoneHACluster for testing. + * + * @throws IOException + */ + @BeforeEach + public void init() throws Exception { + conf = new OzoneConfiguration(); + clusterId = UUID.randomUUID().toString(); + scmId = UUID.randomUUID().toString(); + scmServiceId = "scm-service-test1"; + + conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, true); + conf.setInt(OZONE_SCM_BLOCK_DELETION_MAX_RETRY, 20); + + cluster = (MiniOzoneHAClusterImpl) MiniOzoneCluster.newOMHABuilder(conf) + .setClusterId(clusterId) + .setScmId(scmId) + .setSCMServiceId(scmServiceId) + .setNumOfStorageContainerManagers(numOfSCMs) + .setNumOfActiveSCMs(numOfSCMs) + .setNumOfOzoneManagers(1) + .build(); + cluster.waitForClusterToBeReady(); + } + + /** + * Shutdown MiniDFSCluster. + */ + @AfterEach + public void shutdown() { + if (cluster != null) { + cluster.shutdown(); + } + } + + //<containerID, List<blockID>> + private Map<Long, List<Long>> generateData(int dataSize) { + Map<Long, List<Long>> blockMap = new HashMap<>(); + Random random = new Random(1); + int continerIDBase = random.nextInt(100); + int localIDBase = random.nextInt(1000); + for (int i = 0; i < dataSize; i++) { + long containerID = continerIDBase + i; + List<Long> blocks = new ArrayList<>(); + for (int j = 0; j < 5; j++) { + long localID = localIDBase + j; + blocks.add(localID); + } + blockMap.put(containerID, blocks); + } + return blockMap; + } + + private StorageContainerManager getSCMLeader() { + return cluster.getStorageContainerManagersList() + .stream().filter(a -> a.getScmContext().isLeaderReady()) + .collect(Collectors.toList()).get(0); + } + + @Test + public void testRenewCmd() throws IOException, TimeoutException { + int maxRetry = conf.getInt(OZONE_SCM_BLOCK_DELETION_MAX_RETRY, 20); + // add some block deletion transactions + DeletedBlockLog deletedBlockLog = getSCMLeader(). + getScmBlockManager().getDeletedBlockLog(); + deletedBlockLog.addTransactions(generateData(30)); + getSCMLeader().getScmHAManager().asSCMHADBTransactionBuffer().flush(); + LOG.info("Valid num of txns: {}", deletedBlockLog. + getNumOfValidTransactions()); + Assertions.assertEquals(deletedBlockLog.getNumOfValidTransactions(), 30); Review Comment: Got it! -- 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]
