use of com.facebook.buck.model.BuildId in project buck by facebook.
the class AbstractInvocationInfo method parseLogLine.
public static Optional<ParsedLog> parseLogLine(String line) {
Matcher matcher = LOG_MSG_PATTERN.matcher(line);
if (matcher.find()) {
BuildId buildId = new BuildId(matcher.group("buildid"));
String args = matcher.group("args");
return Optional.of(new ParsedLog(buildId, args));
}
return Optional.empty();
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class BuildIdSamplerTest method testIsUniformish.
@Test
public void testIsUniformish() {
final int iterations = 5000;
final float fudge = 0.01f;
final int bucketCount = 10;
List<Pair<BuildIdSampler, AtomicInteger>> buckets = new ArrayList<>();
for (int i = 1; i <= bucketCount; ++i) {
buckets.add(new Pair<BuildIdSampler, AtomicInteger>(new BuildIdSampler(SampleRate.of(((float) i) / bucketCount)), new AtomicInteger(0)));
}
Random random = new Random(0);
for (int i = 0; i < iterations; ++i) {
UUID uuid = new UUID(random.nextLong(), random.nextLong());
BuildId buildId = new BuildId(uuid.toString());
for (Pair<BuildIdSampler, AtomicInteger> entry : buckets) {
if (entry.getFirst().apply(buildId)) {
entry.getSecond().incrementAndGet();
break;
}
}
}
for (Pair<BuildIdSampler, AtomicInteger> bucketPair : buckets) {
float bucketSize = ((float) bucketPair.getSecond().get()) / iterations;
assertThat(bucketSize, Matchers.allOf(Matchers.greaterThan(0.1f - fudge), Matchers.lessThan(0.1f + fudge)));
}
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class DaemonIntegrationTest method createRunnableCommand.
private Runnable createRunnableCommand(final int expectedExitCode, final String... args) {
return () -> {
try {
Main main = new Main(new CapturingPrintStream(), new CapturingPrintStream(), new ByteArrayInputStream("".getBytes("UTF-8")));
int exitCode = main.runMainWithExitCode(new BuildId(), tmp.getRoot(), Optional.of(new TestContext()), ImmutableMap.copyOf(System.getenv()), CommandMode.TEST, WatchmanWatcher.FreshInstanceAction.NONE, System.nanoTime(), args);
assertEquals("Unexpected exit code.", expectedExitCode, exitCode);
} catch (IOException e) {
fail("Should not throw exception.");
Throwables.throwIfUnchecked(e);
} catch (InterruptedException e) {
fail("Should not throw exception.");
Thread.currentThread().interrupt();
}
};
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class BuildInfoRecorderIntegrationTest method testPerformUploadToArtifactCache.
@Test
public void testPerformUploadToArtifactCache() throws IOException, InterruptedException {
BuildInfoRecorder buildInfoRecorder = createBuildInfoRecorder(new FakeProjectFilesystem() {
@Override
public void createZip(Collection<Path> pathsToIncludeInZip, Path out) throws IOException {
// For this test, nothing really cares about the content, so just write out the name.
writeBytesToPath(out.toString().getBytes(), out);
}
});
Path cacheDir = Files.createTempDirectory("root");
ArtifactCache artifactCache = TestArtifactCaches.createDirCacheForTest(cacheDir, Paths.get("cache"));
buildInfoRecorder.performUploadToArtifactCache(ImmutableSet.of(new RuleKey(RULE_KEY)), artifactCache, new BuckEventBus(new DefaultClock(), new BuildId()));
assertTrue(cacheDir.resolve(DirArtifactCacheTestUtil.getPathForRuleKey(artifactCache, new RuleKey(RULE_KEY), Optional.empty())).toFile().exists());
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class OfflineScribeLoggerTest method sendStoredLogs.
@Test
public void sendStoredLogs() throws Exception {
final ImmutableList<String> blacklistCategories = ImmutableList.of();
final int maxScribeOfflineLogsKB = 2;
final ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
final Path logDir = filesystem.getBuckPaths().getOfflineLogDir();
final ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
final String[] ids = { "test1", "test2", "test3" };
final String[] uniqueCategories = { "cat1", "cat2" };
final String[] categories = { uniqueCategories[0], uniqueCategories[1], uniqueCategories[0] };
final String testCategory = "test_category";
final String line = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
final List<Pair<String, Iterable<String>>> sentData = new ArrayList<>();
final ScribeLogger succeeddingLogger = new ScribeLogger() {
@Override
public ListenableFuture<Void> log(String category, Iterable<String> lines) {
if (!category.equals(testCategory)) {
sentData.add(new Pair<>(category, lines));
}
return Futures.immediateFuture(null);
}
@Override
public void close() throws IOException {
}
};
// Create 3 dummy logfiles - each will have 3 categories x 4 lines ~ 0.9KB. Hence, when reading
// and sending the logger should stop after 2 of those 3 files (we set the limit to 2KB).
filesystem.mkdirs(logDir);
for (String id : ids) {
File log = filesystem.resolve(logDir.resolve(LOGFILE_PREFIX + id + LOGFILE_SUFFIX)).toFile();
BufferedOutputStream logFileStoreStream = new BufferedOutputStream(new FileOutputStream(log));
for (String category : categories) {
byte[] scribeData = objectMapper.writeValueAsString(ScribeData.builder().setCategory(category).setLines(ImmutableList.of(line, line, line, line)).build()).getBytes(Charsets.UTF_8);
logFileStoreStream.write(scribeData);
}
logFileStoreStream.close();
}
// Get the logger and trigger sending with dummy succeeding log().
OfflineScribeLogger offlineLogger = new OfflineScribeLogger(succeeddingLogger, blacklistCategories, maxScribeOfflineLogsKB, filesystem, objectMapper, BuckEventBusFactory.newInstance(), new BuildId("sendingLogger"));
offlineLogger.log(testCategory, ImmutableList.of("line1", "line2"));
offlineLogger.close();
//Check read&sent data is as expected - for first category we expect clustered 8 lines from 2x4.
assertEquals(4, sentData.size());
final String[] expectedCategories = ObjectArrays.concat(uniqueCategories, uniqueCategories, String.class);
final String[] seenCategories = new String[sentData.size()];
for (int i = 0; i < sentData.size(); i++) {
seenCategories[i] = sentData.get(i).getFirst();
int expectedCount = (sentData.get(i).getFirst().equals(uniqueCategories[0])) ? 8 : 4;
assertThat(sentData.get(i).getSecond(), Matchers.allOf(everyItem(equalTo(line)), IsIterableWithSize.<String>iterableWithSize(expectedCount)));
}
assertThat(seenCategories, arrayContainingInAnyOrder(expectedCategories));
// Check that oldest log was not removed (due to exceeding the byte limit when reading&sending).
ImmutableSortedSet<Path> logs = filesystem.getMtimeSortedMatchingDirectoryContents(logDir, LOGFILE_PATTERN);
Path notRemovedLog = filesystem.resolve(logDir.resolve(LOGFILE_PREFIX + ids[0] + LOGFILE_SUFFIX));
assertThat(logs, Matchers.allOf(hasItem(notRemovedLog), IsIterableWithSize.<Path>iterableWithSize(1)));
}
Aggregations