Skip to content

Commit

Permalink
Improve concurrency in TestPlan and AbstractTestDescriptor
Browse files Browse the repository at this point in the history
This commit takes some preliminary steps toward improving concurrency
within TestPlan and AbstractTestDescriptor.

Issue: #417
  • Loading branch information
sbrannen committed Jul 22, 2016
1 parent 791cb4d commit 7a72e1c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Expand Up @@ -46,7 +46,7 @@ public abstract class AbstractTestDescriptor implements TestDescriptor {


private TestSource source; private TestSource source;


private final Set<TestDescriptor> children = new LinkedHashSet<>(); private final Set<TestDescriptor> children = Collections.synchronizedSet(new LinkedHashSet<>(16));


/** /**
* Create a new {@code AbstractTestDescriptor} with the supplied * Create a new {@code AbstractTestDescriptor} with the supplied
Expand Down
Expand Up @@ -16,11 +16,12 @@
import static org.junit.platform.commons.meta.API.Usage.Internal; import static org.junit.platform.commons.meta.API.Usage.Internal;


import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashMap; import java.util.Collections;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate; import java.util.function.Predicate;


import org.junit.platform.commons.meta.API; import org.junit.platform.commons.meta.API;
Expand Down Expand Up @@ -53,9 +54,11 @@
@API(Experimental) @API(Experimental)
public final class TestPlan { public final class TestPlan {


private final Set<TestIdentifier> roots = new LinkedHashSet<>(); private final Set<TestIdentifier> roots = Collections.synchronizedSet(new LinkedHashSet<>(4));
private final Map<String, LinkedHashSet<TestIdentifier>> children = new LinkedHashMap<>();
private final Map<String, TestIdentifier> allIdentifiers = new LinkedHashMap<>(); private final Map<String, Set<TestIdentifier>> children = new ConcurrentHashMap<>(32);

private final Map<String, TestIdentifier> allIdentifiers = new ConcurrentHashMap<>(32);


/** /**
* Construct a new {@code TestPlan} from the supplied collection of * Construct a new {@code TestPlan} from the supplied collection of
Expand Down Expand Up @@ -91,7 +94,8 @@ public void add(TestIdentifier testIdentifier) {
allIdentifiers.put(testIdentifier.getUniqueId(), testIdentifier); allIdentifiers.put(testIdentifier.getUniqueId(), testIdentifier);
if (testIdentifier.getParentId().isPresent()) { if (testIdentifier.getParentId().isPresent()) {
String parentId = testIdentifier.getParentId().get(); String parentId = testIdentifier.getParentId().get();
Set<TestIdentifier> directChildren = children.computeIfAbsent(parentId, key -> new LinkedHashSet<>()); Set<TestIdentifier> directChildren = children.computeIfAbsent(parentId,
key -> Collections.synchronizedSet(new LinkedHashSet<>(16)));
directChildren.add(testIdentifier); directChildren.add(testIdentifier);
} }
else { else {
Expand Down Expand Up @@ -186,7 +190,7 @@ public long countTestIdentifiers(Predicate<? super TestIdentifier> predicate) {
*/ */
public Set<TestIdentifier> getDescendants(TestIdentifier parent) { public Set<TestIdentifier> getDescendants(TestIdentifier parent) {
Preconditions.notNull(parent, "parent must not be null"); Preconditions.notNull(parent, "parent must not be null");
Set<TestIdentifier> result = new LinkedHashSet<>(); Set<TestIdentifier> result = new LinkedHashSet<>(16);
Set<TestIdentifier> children = getChildren(parent); Set<TestIdentifier> children = getChildren(parent);
result.addAll(children); result.addAll(children);
for (TestIdentifier child : children) { for (TestIdentifier child : children) {
Expand Down
Expand Up @@ -35,7 +35,7 @@ class Root {
} }
}; };


private final Map<TestEngine, TestDescriptor> testEngineDescriptors = new LinkedHashMap<>(); private final Map<TestEngine, TestDescriptor> testEngineDescriptors = new LinkedHashMap<>(4);


/** /**
* Add an {@code engine}'s root {@link TestDescriptor}. * Add an {@code engine}'s root {@link TestDescriptor}.
Expand Down

0 comments on commit 7a72e1c

Please sign in to comment.