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;
}
}
}
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);
}
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);
}
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;
}
}
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());
}
Aggregations