-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MRESOLVER-321] Make collection and visiting interruptable (#380)
Currently the two collector implementations are not interrupt-able, do not sense interruption directly, only by some side-effect like IO. Moreover, the BF new collector may enter a "busy loop" as we seen (it was due bug, but nothing prevents us to have more bugs). Make main loop in both collector detect thread interruption and use global (per-collection) Args to carry state of the, interruption effectively the whole ST or MT collection. Same stands for dependency visitor: it may also enter busy loop in case of cycles, hence, it should be made also interrupt-able. Visitor OTOH should not reset the interrupted flag, it should just stop when it is set, and let the flag be handled at higher level (for example in collector). --- https://issues.apache.org/jira/browse/MRESOLVER-321
- Loading branch information
Showing
6 changed files
with
130 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
maven-resolver-api/src/test/java/org/eclipse/aether/graph/DefaultDependencyNodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.eclipse.aether.graph; | ||
|
||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import org.eclipse.aether.artifact.DefaultArtifact; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
/** | ||
*/ | ||
public class DefaultDependencyNodeTest { | ||
@Test | ||
void testVisitorInterrupt() throws Exception { | ||
DefaultDependencyNode node = | ||
new DefaultDependencyNode(new Dependency(new DefaultArtifact("gid:aid:ver"), "compile")); | ||
// we just use dummy visitor, as it is not visiting that matters | ||
DependencyVisitor visitor = new DependencyVisitor() { | ||
@Override | ||
public boolean visitEnter(DependencyNode node) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean visitLeave(DependencyNode node) { | ||
return true; | ||
} | ||
}; | ||
AtomicReference<Exception> thrown = new AtomicReference<>(null); | ||
Thread t = new Thread(() -> { | ||
Thread.currentThread().interrupt(); | ||
try { | ||
node.accept(visitor); | ||
fail("Should fail"); | ||
} catch (Exception e) { | ||
thrown.set(e); | ||
} | ||
}); | ||
t.start(); | ||
t.join(); | ||
|
||
assertTrue(thrown.get() instanceof RuntimeException, String.valueOf(thrown.get())); | ||
assertTrue(thrown.get().getCause() instanceof InterruptedException, String.valueOf(thrown.get())); | ||
assertTrue(t.isInterrupted()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters