Search in sources :

Example 36 with BuildId

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();
}
Also used : Matcher(java.util.regex.Matcher) BuildId(com.facebook.buck.model.BuildId)

Example 37 with BuildId

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)));
    }
}
Also used : Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BuildId(com.facebook.buck.model.BuildId) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Pair(com.facebook.buck.model.Pair) Test(org.junit.Test)

Example 38 with BuildId

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();
        }
    };
}
Also used : CapturingPrintStream(com.facebook.buck.util.CapturingPrintStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BuildId(com.facebook.buck.model.BuildId) TestContext(com.facebook.buck.testutil.integration.TestContext) IOException(java.io.IOException)

Example 39 with BuildId

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());
}
Also used : Path(java.nio.file.Path) BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) DefaultClock(com.facebook.buck.timing.DefaultClock) IOException(java.io.IOException) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) Test(org.junit.Test)

Example 40 with BuildId

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)));
}
Also used : Path(java.nio.file.Path) FluentIterable(com.google.common.collect.FluentIterable) ArrayList(java.util.ArrayList) ScribeLogger(com.facebook.buck.util.network.ScribeLogger) FakeFailingScribeLogger(com.facebook.buck.util.network.FakeFailingScribeLogger) BuildId(com.facebook.buck.model.BuildId) FileOutputStream(java.io.FileOutputStream) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Pair(com.facebook.buck.model.Pair) Test(org.junit.Test)

Aggregations

BuildId (com.facebook.buck.model.BuildId)41 Test (org.junit.Test)25 BuckEventBus (com.facebook.buck.event.BuckEventBus)22 Path (java.nio.file.Path)13 FakeClock (com.facebook.buck.timing.FakeClock)12 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)10 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 IOException (java.io.IOException)8 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)7 BuildTarget (com.facebook.buck.model.BuildTarget)6 Before (org.junit.Before)6 DefaultClock (com.facebook.buck.timing.DefaultClock)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ArtifactCache (com.facebook.buck.artifact_cache.ArtifactCache)4 BuildRuleDurationTracker (com.facebook.buck.rules.BuildRuleDurationTracker)4 Clock (com.facebook.buck.timing.Clock)4 NullFileHashCache (com.facebook.buck.util.cache.NullFileHashCache)4 ImmutableList (com.google.common.collect.ImmutableList)4 RuleKey (com.facebook.buck.rules.RuleKey)3 FakeExecutor (com.facebook.buck.testutil.FakeExecutor)3