use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.
the class ConcurrentHashMapTest method testContainsValue.
/**
* containsValue returns true for held values
*/
public void testContainsValue() {
ConcurrentMap map = map5();
assertTrue(map.containsValue("A"));
assertFalse(map.containsValue("Z"));
}
use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.
the class ConcurrentHashMapTest method testSetValueWriteThrough.
/**
* SetValue of an EntrySet entry sets value in the map.
*/
public void testSetValueWriteThrough() {
// Adapted from a bug report by Eric Zoerner
ConcurrentMap map = map();
assertTrue(map.isEmpty());
for (int i = 0; i < 20; i++) {
map.put(i, i);
}
assertFalse(map.isEmpty());
Map.Entry entry1 = (Map.Entry) map.entrySet().iterator().next();
// cloned in map
if (!entry1.getKey().equals(16)) {
map.remove(16);
entry1.setValue("XYZ");
// fails if write-through broken
assertTrue(map.containsValue("XYZ"));
}
}
use of java.util.concurrent.ConcurrentMap in project caffeine by ben-manes.
the class ConcurrentHashMapTest method testPutIfAbsent2_NullPointerException.
/**
* putIfAbsent(x, null) throws NPE
*/
public void testPutIfAbsent2_NullPointerException() {
ConcurrentMap c = map();
try {
c.putIfAbsent("whatever", null);
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.concurrent.ConcurrentMap in project bazel by bazelbuild.
the class SkyframeActionExecutor method findAndStoreArtifactConflicts.
/**
* Find conflicts between generated artifacts. There are two ways to have conflicts. First, if
* two (unshareable) actions generate the same output artifact, this will result in an {@link
* ActionConflictException}. Second, if one action generates an artifact whose path is a prefix of
* another artifact's path, those two artifacts cannot exist simultaneously in the output tree.
* This causes an {@link ArtifactPrefixConflictException}. The relevant exceptions are stored in
* the executor in {@code badActionMap}, and will be thrown immediately when that action is
* executed. Those exceptions persist, so that even if the action is not executed this build, the
* first time it is executed, the correct exception will be thrown.
*
* <p>This method must be called if a new action was added to the graph this build, so
* whenever a new configured target was analyzed this build. It is somewhat expensive (~1s
* range for a medium build as of 2014), so it should only be called when necessary.
*
* <p>Conflicts found may not be requested this build, and so we may overzealously throw an error.
* For instance, if actions A and B generate the same artifact foo, and the user first requests
* A' depending on A, and then in a subsequent build B' depending on B, we will fail the second
* build, even though it would have succeeded if it had been the only build. However, since
* Skyframe does not know the transitive dependencies of the request, we err on the conservative
* side.
*
* <p>If the user first runs one action on the first build, and on the second build adds a
* conflicting action, only the second action's error may be reported (because the first action
* will be cached), whereas if both actions were requested for the first time, both errors would
* be reported. However, the first time an action is added to the build, we are guaranteed to find
* any conflicts it has, since this method will compare it against all other actions. So there is
* no sequence of builds that can evade the error.
*/
void findAndStoreArtifactConflicts(Iterable<ActionLookupValue> actionLookupValues) throws InterruptedException {
ConcurrentMap<ActionAnalysisMetadata, ConflictException> temporaryBadActionMap = new ConcurrentHashMap<>();
Pair<ActionGraph, SortedMap<PathFragment, Artifact>> result;
result = constructActionGraphAndPathMap(actionLookupValues, temporaryBadActionMap);
ActionGraph actionGraph = result.first;
SortedMap<PathFragment, Artifact> artifactPathMap = result.second;
Map<ActionAnalysisMetadata, ArtifactPrefixConflictException> actionsWithArtifactPrefixConflict = Actions.findArtifactPrefixConflicts(actionGraph, artifactPathMap);
for (Map.Entry<ActionAnalysisMetadata, ArtifactPrefixConflictException> actionExceptionPair : actionsWithArtifactPrefixConflict.entrySet()) {
temporaryBadActionMap.put(actionExceptionPair.getKey(), new ConflictException(actionExceptionPair.getValue()));
}
this.badActionMap = ImmutableMap.copyOf(temporaryBadActionMap);
}
use of java.util.concurrent.ConcurrentMap in project bazel by bazelbuild.
the class SkyframeActionExecutor method actionRegistration.
private static Runnable actionRegistration(final List<ActionLookupValue> values, final MutableActionGraph actionGraph, final ConcurrentMap<PathFragment, Artifact> artifactPathMap, final ConcurrentMap<ActionAnalysisMetadata, ConflictException> badActionMap) {
return new Runnable() {
@Override
public void run() {
for (ActionLookupValue value : values) {
Set<ActionAnalysisMetadata> registeredActions = new HashSet<>();
for (Map.Entry<Artifact, ActionAnalysisMetadata> entry : value.getMapForConsistencyCheck().entrySet()) {
ActionAnalysisMetadata action = entry.getValue();
// once.
if (registeredActions.add(action)) {
try {
actionGraph.registerAction(action);
} catch (ActionConflictException e) {
Exception oldException = badActionMap.put(action, new ConflictException(e));
Preconditions.checkState(oldException == null, "%s | %s | %s", action, e, oldException);
// error.
continue;
}
}
artifactPathMap.put(entry.getKey().getExecPath(), entry.getKey());
}
}
}
};
}
Aggregations