Copilot commented on code in PR #12060: URL: https://github.com/apache/ozone/pull/12060#discussion_r4609215858
########## hadoop-hdds/container-service/src/test/java/org/apache/hadoop/ozone/container/common/states/endpoint/TestHeartbeatEndpointTaskRecovery.java: ########## @@ -0,0 +1,178 @@ +/* + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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.container.common.states.endpoint; + +import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_HEARTBEAT_ADDRESS_REFRESH_MISSED_COUNT_THRESHOLD; +import static org.apache.hadoop.hdds.HddsConfigKeys.HDDS_HEARTBEAT_RE_REGISTER_MISSED_COUNT_THRESHOLD; +import static org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine.EndPointStates.GETVERSION; +import static org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine.EndPointStates.HEARTBEAT; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyLong; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.google.protobuf.Message; +import java.io.IOException; +import java.util.List; +import java.util.UUID; +import org.apache.hadoop.hdds.HDDSVersion; +import org.apache.hadoop.hdds.conf.OzoneConfiguration; +import org.apache.hadoop.hdds.protocol.DatanodeDetails; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatus; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.IncrementalContainerReportProto; +import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMCommandProto; +import org.apache.hadoop.hdds.scm.net.HostAndPort; +import org.apache.hadoop.hdfs.util.EnumCounters; +import org.apache.hadoop.ozone.container.common.ContainerTestUtils; +import org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine; +import org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine.DatanodeStates; +import org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine; +import org.apache.hadoop.ozone.container.common.statemachine.StateContext; +import org.apache.hadoop.ozone.container.upgrade.DatanodeVersionManager; +import org.apache.hadoop.ozone.protocolPB.StorageContainerDatanodeProtocolClientSideTranslatorPB; +import org.junit.jupiter.api.Test; + +/** + * Tests heartbeat failure recovery that resets only the affected endpoint. + */ +public class TestHeartbeatEndpointTaskRecovery { + + private static final HostAndPort SCM = new HostAndPort("test-scm-1", 9861); + + @Test + public void thresholdFailureResetsEndpointAndClearsCommandStatusQueue() throws Exception { + OzoneConfiguration conf = new OzoneConfiguration(); + conf.setInt(HDDS_HEARTBEAT_RE_REGISTER_MISSED_COUNT_THRESHOLD, 1); + conf.setInt(HDDS_HEARTBEAT_ADDRESS_REFRESH_MISSED_COUNT_THRESHOLD, 50); + DatanodeStateMachine dsm = mockDatanodeStateMachine(); + StateContext context = new StateContext(conf, DatanodeStates.RUNNING, dsm, ""); + StorageContainerDatanodeProtocolClientSideTranslatorPB proxy = failingProxy(); + try (EndpointStateMachine endpoint = new EndpointStateMachine(SCM, proxy, conf, "")) { + endpoint.setState(HEARTBEAT); + context.addEndpoint(SCM); + context.addIncrementalReport(newCommandStatusReport(11L)); + context.addIncrementalReport(IncrementalContainerReportProto.getDefaultInstance()); + + newHeartbeatTask(endpoint, conf, context).call(); + + assertEquals(GETVERSION, endpoint.getState()); + verify(dsm).setNextHB(anyLong()); + List<Message> pendingReports = context.getAllAvailableReports(SCM); + assertEquals(1, pendingReports.size()); + assertTrue(pendingReports.get(0) instanceof IncrementalContainerReportProto); Review Comment: The recovery tests register only one endpoint, so they do not verify the central isolation guarantee: clearing a failing SCM's command-status backlog must preserve the same reports queued for healthy SCMs. Please add a two-endpoint recovery test that seeds command-status and incremental-container reports for both, fails one endpoint at the threshold, and asserts that the other endpoint remains in HEARTBEAT with its reports intact. -- 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]
