Caideyipi commented on code in PR #18076: URL: https://github.com/apache/iotdb/pull/18076#discussion_r3503844773
########## iotdb-core/confignode/src/test/java/org/apache/iotdb/confignode/procedure/impl/pipe/AbstractOperatePipeProcedureV2Test.java: ########## @@ -0,0 +1,172 @@ +/* + * 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.iotdb.confignode.procedure.impl.pipe; + +import org.apache.iotdb.confignode.persistence.pipe.PipeTaskInfo; +import org.apache.iotdb.confignode.procedure.Procedure; +import org.apache.iotdb.confignode.procedure.impl.StateMachineProcedure; +import org.apache.iotdb.confignode.procedure.state.pipe.task.OperatePipeTaskState; +import org.apache.iotdb.pipe.api.exception.PipeException; + +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicReference; + +public class AbstractOperatePipeProcedureV2Test { + + @Test + public void testSuccessfulStateDoesNotYield() throws Exception { + final TestOperatePipeProcedure procedure = new TestOperatePipeProcedure(); + + Assert.assertEquals( + StateMachineProcedure.Flow.HAS_MORE_STATE, + procedure.executeFromState(null, OperatePipeTaskState.VALIDATE_TASK)); + + Assert.assertFalse(procedure.isYieldAfterExecution(null)); + Assert.assertEquals(1, procedure.validateExecutionCount); + } + + @Test + public void testRetryStateYieldsWithoutSleepingAndResetsAfterNextExecution() throws Exception { + final TestOperatePipeProcedure procedure = new TestOperatePipeProcedure(); + procedure.failValidation = true; + + final long startTime = System.nanoTime(); + Assert.assertEquals( + StateMachineProcedure.Flow.HAS_MORE_STATE, + procedure.executeFromState(null, OperatePipeTaskState.VALIDATE_TASK)); + final long elapsedTimeInMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime); + + Assert.assertTrue(procedure.isYieldAfterExecution(null)); + Assert.assertTrue("Retry should not sleep while holding pipe locks", elapsedTimeInMs < 1000); Review Comment: Removed the wall-clock elapsed-time assertion and kept the retry-yield/reset assertions, so the test no longer depends on JVM pause behavior. Also moved the multi-pipe helper out of DataNodeInternalRPCServiceImpl to avoid class static initialization in the focused unit test. -- 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]
