Copilot commented on code in PR #7744: URL: https://github.com/apache/ignite-3/pull/7744#discussion_r2912112826
########## modules/compute/src/integrationTest/java/org/example/jobs/embedded/CancelAwareSleepJob.java: ########## @@ -0,0 +1,37 @@ +/* + * 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.example.jobs.embedded; + +import java.util.concurrent.CancellationException; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.JobExecutionContext; + +/** Compute job that sleeps for a number of seconds and throws {@link CancellationException} if interrupted. */ +public class CancelAwareSleepJob implements ComputeJob<Long, Void> { + @Override + public CompletableFuture<Void> executeAsync(JobExecutionContext jobExecutionContext, Long timeout) { + try { + TimeUnit.SECONDS.sleep(timeout); + } catch (InterruptedException e) { + throw new CancellationException(); + } + return null; Review Comment: `executeAsync` returns `null` on the success path. This should return a completed `CompletableFuture` to avoid NPEs and to comply with `ComputeJob`'s async contract. ```suggestion return CompletableFuture.completedFuture(null); ``` ########## modules/compute/src/jobs/java/org/example/jobs/standalone/CancelAwareSleepJob.java: ########## @@ -0,0 +1,37 @@ +/* + * 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.example.jobs.standalone; + +import java.util.concurrent.CancellationException; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.JobExecutionContext; + +/** Compute job that sleeps for a number of seconds and throws {@link CancellationException} if interrupted. */ +public class CancelAwareSleepJob implements ComputeJob<Long, Void> { + @Override + public CompletableFuture<Void> executeAsync(JobExecutionContext jobExecutionContext, Long timeout) { + try { + TimeUnit.SECONDS.sleep(timeout); + } catch (InterruptedException e) { + throw new CancellationException(); + } + return null; Review Comment: `executeAsync` returns `null` on the success path, which violates the `CompletableFuture` return contract and can cause `NullPointerException` in callers/executors expecting a future. Return a completed future instead (e.g., `CompletableFuture.completedFuture(null)`). ```suggestion return CompletableFuture.completedFuture(null); ``` ########## modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeBaseTest.java: ########## @@ -545,7 +545,7 @@ void cancelComputeExecuteBroadcastAsync(boolean local) { CompletableFuture<Collection<Void>> resultsFut = compute().executeAsync( BroadcastJobTarget.nodes(executeNodes), - silentSleepJob(), 100L, cancelHandle.token() + cancelAwareSleepJob(), 100L, cancelHandle.token() Review Comment: `CancelAwareSleepJob` sleeps using `TimeUnit.SECONDS` (per its implementation), but these tests pass `100L` as the timeout. If cancellation doesn’t trigger for any reason, this can turn into a 100-second hang and slow/flaky runs (previous jobs often use ms-level sleeps). Consider switching the job to milliseconds, or reduce these arguments to a small bounded duration appropriate for tests. ########## modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeBaseTest.java: ########## @@ -527,7 +527,7 @@ void cancelComputeExecute(boolean local) { CancelHandle cancelHandle = CancelHandle.create(); CompletableFuture<Void> runFut = IgniteTestUtils.runAsync(() -> compute() - .execute(JobTarget.node(clusterNode(executeNode)), silentSleepJob(), 100L, cancelHandle.token())); + .execute(JobTarget.node(clusterNode(executeNode)), cancelAwareSleepJob(), 100L, cancelHandle.token())); Review Comment: `CancelAwareSleepJob` sleeps using `TimeUnit.SECONDS` (per its implementation), but these tests pass `100L` as the timeout. If cancellation doesn’t trigger for any reason, this can turn into a 100-second hang and slow/flaky runs (previous jobs often use ms-level sleeps). Consider switching the job to milliseconds, or reduce these arguments to a small bounded duration appropriate for tests. ########## modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeBaseTest.java: ########## @@ -512,7 +512,7 @@ void cancelComputeExecuteAsync(boolean local) { CancelHandle cancelHandle = CancelHandle.create(); CompletableFuture<Void> execution = compute() - .executeAsync(JobTarget.node(clusterNode(executeNode)), silentSleepJob(), 100L, cancelHandle.token()); + .executeAsync(JobTarget.node(clusterNode(executeNode)), cancelAwareSleepJob(), 100L, cancelHandle.token()); Review Comment: `CancelAwareSleepJob` sleeps using `TimeUnit.SECONDS` (per its implementation), but these tests pass `100L` as the timeout. If cancellation doesn’t trigger for any reason, this can turn into a 100-second hang and slow/flaky runs (previous jobs often use ms-level sleeps). Consider switching the job to milliseconds, or reduce these arguments to a small bounded duration appropriate for tests. ########## modules/compute/src/test/java/org/apache/ignite/internal/compute/queue/PriorityQueueExecutorTest.java: ########## @@ -234,7 +234,7 @@ void taskCatchesInterruption() { try { latch.await(); } catch (InterruptedException e) { - return completedFuture(0); + throw new CancellationException(); } Review Comment: This change makes interruption result in `CancellationException`, which conflicts with the surrounding test name `taskCatchesInterruption` (it no longer 'catches and completes', it propagates cancellation). Consider renaming the test or restoring the previous behavior if the intent is to test interruption being handled gracefully. ########## modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeBaseTest.java: ########## @@ -564,7 +564,7 @@ void cancelComputeExecuteBroadcast(boolean local) { CompletableFuture<Collection<Void>> runFut = IgniteTestUtils.runAsync(() -> compute().execute( BroadcastJobTarget.nodes(executeNodes), - silentSleepJob(), 100L, cancelHandle.token() + cancelAwareSleepJob(), 100L, cancelHandle.token() Review Comment: `CancelAwareSleepJob` sleeps using `TimeUnit.SECONDS` (per its implementation), but these tests pass `100L` as the timeout. If cancellation doesn’t trigger for any reason, this can turn into a 100-second hang and slow/flaky runs (previous jobs often use ms-level sleeps). Consider switching the job to milliseconds, or reduce these arguments to a small bounded duration appropriate for tests. -- 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]
