Search in sources :

Example 96 with ConcurrentMap

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"));
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 97 with ConcurrentMap

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"));
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 98 with ConcurrentMap

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) {
    }
}
Also used : ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 99 with ConcurrentMap

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);
}
Also used : MutableActionGraph(com.google.devtools.build.lib.actions.MutableActionGraph) MapBasedActionGraph(com.google.devtools.build.lib.actions.MapBasedActionGraph) ActionGraph(com.google.devtools.build.lib.actions.ActionGraph) ActionConflictException(com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException) ArtifactPrefixConflictException(com.google.devtools.build.lib.actions.ArtifactPrefixConflictException) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) ArtifactPrefixConflictException(com.google.devtools.build.lib.actions.ArtifactPrefixConflictException) Artifact(com.google.devtools.build.lib.actions.Artifact) SortedMap(java.util.SortedMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 100 with ConcurrentMap

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());
                }
            }
        }
    };
}
Also used : ActionConflictException(com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException) ActionConflictException(com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException) ArtifactPrefixConflictException(com.google.devtools.build.lib.actions.ArtifactPrefixConflictException) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Artifact(com.google.devtools.build.lib.actions.Artifact) AlreadyReportedActionExecutionException(com.google.devtools.build.lib.actions.AlreadyReportedActionExecutionException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) ActionConflictException(com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException) TargetOutOfDateException(com.google.devtools.build.lib.actions.TargetOutOfDateException) FileNotFoundException(java.io.FileNotFoundException) PackageRootResolutionException(com.google.devtools.build.lib.actions.PackageRootResolutionException) EnvironmentalExecException(com.google.devtools.build.lib.actions.EnvironmentalExecException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ArtifactPrefixConflictException(com.google.devtools.build.lib.actions.ArtifactPrefixConflictException) HashSet(java.util.HashSet)

Aggregations

ConcurrentMap (java.util.concurrent.ConcurrentMap)218 Map (java.util.Map)53 Test (org.junit.Test)47 HashMap (java.util.HashMap)31 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)28 ArrayList (java.util.ArrayList)26 Set (java.util.Set)20 URL (com.alibaba.dubbo.common.URL)17 Iterator (java.util.Iterator)11 IOException (java.io.IOException)10 Collection (java.util.Collection)10 Arrays (java.util.Arrays)9 Collections (java.util.Collections)8 HashSet (java.util.HashSet)7 List (java.util.List)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 LongAdder (java.util.concurrent.atomic.LongAdder)6 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)5