Copilot commented on code in PR #19810: URL: https://github.com/apache/druid/pull/19810#discussion_r3686693791
########## indexing-service/src/test/java/org/apache/druid/indexing/worker/executor/ExecutorLifecycleTest.java: ########## @@ -0,0 +1,82 @@ +/* + * 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.druid.indexing.worker.executor; + +import org.apache.druid.indexing.common.actions.TaskActionClientFactory; +import org.apache.druid.indexing.common.config.TaskConfig; +import org.apache.druid.indexing.overlord.TaskRunner; +import org.apache.druid.jackson.DefaultObjectMapper; +import org.apache.druid.java.util.common.ISE; +import org.joda.time.Period; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; + +import java.io.File; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; + +public class ExecutorLifecycleTest +{ + @Test + public void testAcquireTaskFileLockRetriesUntilSuccess() throws Exception + { + final ExecutorLifecycle lifecycle = createLifecycle(Period.seconds(1)); + final FileChannel channel = Mockito.mock(FileChannel.class); + final FileLock lock = Mockito.mock(FileLock.class); + Mockito.when(channel.tryLock()).thenReturn(null, lock); + + Assert.assertSame(lock, lifecycle.acquireTaskFileLock(channel, new File("task.lock"))); + Mockito.verify(channel, Mockito.times(2)).tryLock(); Review Comment: This test will always incur a real ~100ms delay because the first `tryLock()` is stubbed to return `null`, which triggers `Thread.sleep(100)` inside `ExecutorLifecycle.acquireTaskFileLock(...)`. This slows the unit test suite and can contribute to timing flakiness. Consider refactoring the production code to make the retry sleep overrideable/injectable (e.g., a `Sleeper`/`sleepForLockRetry()` hook) so the test can validate retry behavior without waiting on wall-clock time. -- 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]
