Search in sources :

Example 1 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project buck by facebook.

the class ProjectGenerator method createXcodeProjects.

public void createXcodeProjects() throws IOException {
    LOG.debug("Creating projects for targets %s", initialTargets);
    boolean hasAtLeastOneTarget = false;
    try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(buckEventBus, PerfEventId.of("xcode_project_generation"), ImmutableMap.of("Path", getProjectPath()))) {
        for (TargetNode<?, ?> targetNode : targetGraph.getNodes()) {
            if (isBuiltByCurrentProject(targetNode.getBuildTarget())) {
                LOG.debug("Including rule %s in project", targetNode);
                // Trigger the loading cache to call the generateProjectTarget function.
                Optional<PBXTarget> target = targetNodeToProjectTarget.getUnchecked(targetNode);
                if (target.isPresent()) {
                    targetNodeToGeneratedProjectTargetBuilder.put(targetNode, target.get());
                }
                if (targetNode.getBuildTarget().matchesUnflavoredTargets(focusModules)) {
                    // If the target is not included, we still need to do other operations to generate
                    // the required header maps.
                    hasAtLeastOneTarget = true;
                }
            } else {
                LOG.verbose("Excluding rule %s (not built by current project)", targetNode);
            }
        }
        if (!hasAtLeastOneTarget && focusModules.isPresent()) {
            return;
        }
        if (targetToBuildWithBuck.isPresent()) {
            generateBuildWithBuckTarget(targetGraph.get(targetToBuildWithBuck.get()));
        }
        for (String configName : targetConfigNamesBuilder.build()) {
            XCBuildConfiguration outputConfig = project.getBuildConfigurationList().getBuildConfigurationsByName().getUnchecked(configName);
            outputConfig.setBuildSettings(new NSDictionary());
        }
        if (!shouldGenerateHeaderSymlinkTreesOnly()) {
            writeProjectFile(project);
        }
        projectGenerated = true;
    } catch (UncheckedExecutionException e) {
        // if any code throws an exception, they tend to get wrapped in LoadingCache's
        // UncheckedExecutionException. Unwrap it if its cause is HumanReadable.
        UncheckedExecutionException originalException = e;
        while (e.getCause() instanceof UncheckedExecutionException) {
            e = (UncheckedExecutionException) e.getCause();
        }
        if (e.getCause() instanceof HumanReadableException) {
            throw (HumanReadableException) e.getCause();
        } else {
            throw originalException;
        }
    }
}
Also used : PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) XCBuildConfiguration(com.facebook.buck.apple.xcode.xcodeproj.XCBuildConfiguration) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) NSDictionary(com.dd.plist.NSDictionary) HumanReadableException(com.facebook.buck.util.HumanReadableException) NSString(com.dd.plist.NSString) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent)

Example 2 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project buck by facebook.

the class DaemonicParserState method invalidateBasedOn.

public void invalidateBasedOn(WatchEvent<?> event) {
    if (!WatchEvents.isPathChangeEvent(event)) {
        // Non-path change event, likely an overflow due to many change events: invalidate everything.
        LOG.debug("Received non-path change event %s, assuming overflow and checking caches.", event);
        if (invalidateAllCaches()) {
            LOG.warn("Invalidated cache on watch event %s.", event);
            cacheInvalidatedByWatchOverflowCounter.inc();
        }
        return;
    }
    filesChangedCounter.inc();
    Path path = (Path) event.context();
    try (AutoCloseableLock readLock = cellStateLock.readLock()) {
        for (DaemonicCellState state : cellPathToDaemonicState.values()) {
            try {
                // rule key change.  For parsing, these are the only events we need to care about.
                if (isPathCreateOrDeleteEvent(event)) {
                    Cell cell = state.getCell();
                    BuildFileTree buildFiles = buildFileTrees.get(cell);
                    if (path.endsWith(cell.getBuildFileName())) {
                        LOG.debug("Build file %s changed, invalidating build file tree for cell %s", path, cell);
                        // If a build file has been added or removed, reconstruct the build file tree.
                        buildFileTrees.invalidate(cell);
                    }
                    // "containing" {@code path} unless its filename matches a temp file pattern.
                    if (!isTempFile(cell, path)) {
                        invalidateContainingBuildFile(cell, buildFiles, path);
                    } else {
                        LOG.debug("Not invalidating the owning build file of %s because it is a temporary file.", state.getCellRoot().resolve(path).toAbsolutePath().toString());
                    }
                }
            } catch (ExecutionException | UncheckedExecutionException e) {
                try {
                    Throwables.throwIfInstanceOf(e, BuildFileParseException.class);
                    Throwables.throwIfUnchecked(e);
                    throw new RuntimeException(e);
                } catch (BuildFileParseException bfpe) {
                    LOG.warn("Unable to parse already parsed build file.", bfpe);
                }
            }
        }
    }
    invalidatePath(path);
}
Also used : Path(java.nio.file.Path) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) AutoCloseableLock(com.facebook.buck.util.concurrent.AutoCloseableLock) BuildFileTree(com.facebook.buck.model.BuildFileTree) FilesystemBackedBuildFileTree(com.facebook.buck.model.FilesystemBackedBuildFileTree) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Cell(com.facebook.buck.rules.Cell) BuildFileParseException(com.facebook.buck.json.BuildFileParseException)

Example 3 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project azure-sdk-for-java by Azure.

the class CachingKeyResolverTest method KeyVault_CachingKeyResolverThrows.

/* 
     * Tests the behavior of CachingKeyResolver when resolving key throws 
     * and validate that the failed entity is not added to the cache. 
     */
@Test
public void KeyVault_CachingKeyResolverThrows() {
    IKeyResolver mockedKeyResolver = mock(IKeyResolver.class);
    CachingKeyResolver resolver = new CachingKeyResolver(10, mockedKeyResolver);
    // First throw exception and for the second call return a value
    when(mockedKeyResolver.resolveKeyAsync(keyId)).thenThrow(new RuntimeException("test")).thenReturn(ikeyAsync);
    try {
        resolver.resolveKeyAsync(keyId);
        assertFalse("Should have thrown an exception.", true);
    } catch (UncheckedExecutionException e) {
        assertTrue("RuntimeException is expected.", e.getCause() instanceof RuntimeException);
    }
    resolver.resolveKeyAsync(keyId);
    resolver.resolveKeyAsync(keyId);
    verify(mockedKeyResolver, times(2)).resolveKeyAsync(keyId);
}
Also used : IKeyResolver(com.microsoft.azure.keyvault.core.IKeyResolver) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) CachingKeyResolver(com.microsoft.azure.keyvault.extensions.CachingKeyResolver) Test(org.junit.Test)

Example 4 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project gerrit by GerritCodeReview.

the class MergeabilityCacheImpl method get.

@Override
public boolean get(ObjectId commit, Ref intoRef, SubmitType submitType, String mergeStrategy, Branch.NameKey dest, Repository repo) {
    ObjectId into = intoRef != null ? intoRef.getObjectId() : ObjectId.zeroId();
    EntryKey key = new EntryKey(commit, into, submitType, mergeStrategy);
    try {
        return cache.get(key, () -> {
            if (key.into.equals(ObjectId.zeroId())) {
                // Assume yes on new branch.
                return true;
            }
            try (CodeReviewRevWalk rw = CodeReviewCommit.newRevWalk(repo)) {
                Set<RevCommit> accepted = SubmitDryRun.getAlreadyAccepted(repo, rw);
                accepted.add(rw.parseCommit(key.into));
                accepted.addAll(Arrays.asList(rw.parseCommit(key.commit).getParents()));
                return submitDryRun.run(key.submitType, repo, rw, dest, key.into, key.commit, accepted);
            }
        });
    } catch (ExecutionException | UncheckedExecutionException e) {
        log.error(String.format("Error checking mergeability of %s into %s (%s)", key.commit.name(), key.into.name(), key.submitType.name()), e.getCause());
        return false;
    }
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ObjectId(org.eclipse.jgit.lib.ObjectId) CodeReviewRevWalk(com.google.gerrit.server.git.CodeReviewCommit.CodeReviewRevWalk) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 5 with UncheckedExecutionException

use of com.google.common.util.concurrent.UncheckedExecutionException in project caffeine by ben-manes.

the class CacheLoadingTest method testReloadAfterFailure.

public void testReloadAfterFailure() throws ExecutionException {
    final AtomicInteger count = new AtomicInteger();
    final RuntimeException e = new IllegalStateException("exception to trigger failure on first load()");
    CacheLoader<Integer, String> failOnceFunction = new CacheLoader<Integer, String>() {

        @Override
        public String load(Integer key) {
            if (count.getAndIncrement() == 0) {
                throw e;
            }
            return key.toString();
        }
    };
    CountingRemovalListener<Integer, String> removalListener = countingRemovalListener();
    LoadingCache<Integer, String> cache = CaffeinatedGuava.build(Caffeine.newBuilder().removalListener(removalListener).executor(MoreExecutors.directExecutor()), failOnceFunction);
    try {
        cache.getUnchecked(1);
        fail();
    } catch (UncheckedExecutionException ue) {
        assertSame(e, ue.getCause());
    }
    assertEquals("1", cache.getUnchecked(1));
    assertEquals(0, removalListener.getCount());
    count.set(0);
    cache.refresh(2);
    checkLoggedCause(e);
    assertEquals("2", cache.getUnchecked(2));
    assertEquals(0, removalListener.getCount());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)101 ExecutionException (java.util.concurrent.ExecutionException)60 IOException (java.io.IOException)29 InvalidCacheLoadException (com.google.common.cache.CacheLoader.InvalidCacheLoadException)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Test (org.junit.Test)9 Map (java.util.Map)8 TimeoutException (java.util.concurrent.TimeoutException)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 Stopwatch (com.google.common.base.Stopwatch)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 HashMap (java.util.HashMap)5 List (java.util.List)5 NoSuchElementException (java.util.NoSuchElementException)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)4 Callable (java.util.concurrent.Callable)4 SirixIOException (org.sirix.exception.SirixIOException)4 GenericPageProcessor (com.facebook.presto.operator.GenericPageProcessor)3