use of com.facebook.buck.model.BuildId in project buck by facebook.
the class HttpArtifactCacheTest method createFinishedEventBuilder.
private static HttpArtifactCacheEvent.Finished.Builder createFinishedEventBuilder() {
HttpArtifactCacheEvent.Started started = HttpArtifactCacheEvent.newFetchStartedEvent(new RuleKey("1234"));
started.configure(-1, -1, -1, -1, new BuildId());
return HttpArtifactCacheEvent.newFinishedEventBuilder(started);
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class HttpArtifactCacheTest method errorTextReplaced.
@Test
public void errorTextReplaced() throws InterruptedException {
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
final String cacheName = "http cache";
final RuleKey ruleKey = new RuleKey("00000000000000000000000000000000");
final RuleKey otherRuleKey = new RuleKey("11111111111111111111111111111111");
final String data = "data";
final AtomicBoolean consoleEventReceived = new AtomicBoolean(false);
argsBuilder.setCacheName(cacheName).setProjectFilesystem(filesystem).setBuckEventBus(new BuckEventBus(new IncrementingFakeClock(), new BuildId()) {
@Override
public void post(BuckEvent event) {
if (event instanceof ConsoleEvent) {
consoleEventReceived.set(true);
ConsoleEvent consoleEvent = (ConsoleEvent) event;
assertThat(consoleEvent.getMessage(), Matchers.containsString(cacheName));
assertThat(consoleEvent.getMessage(), Matchers.containsString("incorrect key name"));
}
}
}).setFetchClient(withMakeRequest((path, requestBuilder) -> {
Request request = requestBuilder.url(SERVER + path).build();
Response response = new Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(HttpURLConnection.HTTP_OK).body(createResponseBody(ImmutableSet.of(otherRuleKey), ImmutableMap.of(), ByteSource.wrap(data.getBytes(Charsets.UTF_8)), data)).build();
return new OkHttpResponseWrapper(response);
}));
HttpArtifactCache cache = new HttpArtifactCache(argsBuilder.build());
Path output = Paths.get("output/file");
CacheResult result = cache.fetch(ruleKey, LazyPath.ofInstance(output));
assertEquals(CacheResultType.ERROR, result.getType());
assertEquals(Optional.empty(), filesystem.readFileIfItExists(output));
assertTrue(consoleEventReceived.get());
cache.close();
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class BuildIdSamplerTest method testAcceptHalf.
@Test
public void testAcceptHalf() {
BuildIdSampler sampler = new BuildIdSampler(SampleRate.of(0.5f));
for (BuildId buildId : buildIdToExpectedHashMap.keySet()) {
boolean shouldAccept = buildIdToExpectedHashMap.get(buildId) < 0.5f;
assertThat(String.format("BuildId %s", buildId), sampler.apply(buildId), Matchers.equalTo(shouldAccept));
}
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class Main method runMainThenExit.
/* Define all error handling surrounding main command */
private void runMainThenExit(String[] args, Optional<NGContext> context, final long initTimestamp) {
installUncaughtExceptionHandler(context);
Path projectRoot = Paths.get(".");
int exitCode = FAIL_EXIT_CODE;
BuildId buildId = getBuildId(context);
// Only post an overflow event if Watchman indicates a fresh instance event
// after our initial query.
WatchmanWatcher.FreshInstanceAction watchmanFreshInstanceAction = daemon == null ? WatchmanWatcher.FreshInstanceAction.NONE : WatchmanWatcher.FreshInstanceAction.POST_OVERFLOW_EVENT;
// Get the client environment, either from this process or from the Nailgun context.
ImmutableMap<String, String> clientEnvironment = getClientEnvironment(context);
try {
CommandMode commandMode = CommandMode.RELEASE;
exitCode = runMainWithExitCode(buildId, projectRoot, context, clientEnvironment, commandMode, watchmanFreshInstanceAction, initTimestamp, args);
} catch (IOException e) {
if (e.getMessage().startsWith("No space left on device")) {
(new Console(Verbosity.STANDARD_INFORMATION, stdOut, stdErr, new Ansi(AnsiEnvironmentChecking.environmentSupportsAnsiEscapes(platform, clientEnvironment)))).printBuildFailure(e.getMessage());
} else {
LOG.error(e);
}
} catch (HumanReadableException e) {
Console console = new Console(Verbosity.STANDARD_INFORMATION, stdOut, stdErr, new Ansi(AnsiEnvironmentChecking.environmentSupportsAnsiEscapes(platform, clientEnvironment)));
console.printBuildFailure(e.getHumanReadableErrorMessage());
} catch (InterruptionFailedException e) {
// Command could not be interrupted.
if (context.isPresent()) {
// Exit process to halt command execution.
context.get().getNGServer().shutdown(true);
}
} catch (BuckIsDyingException e) {
LOG.warn(e, "Fallout because buck was already dying");
} catch (Throwable t) {
LOG.error(t, "Uncaught exception at top level");
} finally {
LOG.debug("Done.");
LogConfig.flushLogs();
// Exit explicitly so that non-daemon threads (of which we use many) don't
// keep the VM alive.
System.exit(exitCode);
}
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class MissingSymbolsHandler method createListener.
/**
* Instantiate a MissingSymbolsHandler and wrap it in a listener that calls it on the appropriate
* events. This is done as part of the global listener setup in Main, and it's the entry point
* into most of the dependency autodetection code.
*/
public static BuckEventListener createListener(ProjectFilesystem projectFilesystem, ImmutableSet<Description<?>> descriptions, BuckConfig config, BuckEventBus buckEventBus, Console console, JavacOptions javacOptions, ImmutableMap<String, String> environment) {
final MissingSymbolsHandler missingSymbolsHandler = create(projectFilesystem, descriptions, config, buckEventBus, console, javacOptions, environment);
final Multimap<BuildId, MissingSymbolEvent> missingSymbolEvents = HashMultimap.create();
BuckEventListener missingSymbolsListener = new BuckEventListener() {
@Override
public void outputTrace(BuildId buildId) {
// If we put {@link #printNeededDependencies} here, it's output won't be visible in buckd.
// Instead, we listen for BuildEvent.Finished, below.
}
@Subscribe
public void onMissingSymbol(MissingSymbolEvent event) {
missingSymbolEvents.put(event.getBuildId(), event);
}
@Subscribe
public void onBuildFinished(BuildEvent.Finished event) {
// Shortcircuit if there aren't any failures.
if (missingSymbolEvents.get(event.getBuildId()).isEmpty()) {
return;
}
try {
missingSymbolsHandler.printNeededDependencies(missingSymbolEvents.get(event.getBuildId()));
} catch (InterruptedException e) {
LOG.debug(e, "Missing symbols handler did not complete in time.");
} catch (RuntimeException e) {
if (e.getCause() instanceof ClosedByInterruptException) {
LOG.debug(e.getCause(), "Missing symbols handler did not complete in time.");
} else {
throw e;
}
}
missingSymbolEvents.removeAll(event.getBuildId());
}
};
return missingSymbolsListener;
}
Aggregations