Search in sources :

Example 66 with Cell

use of com.facebook.buck.rules.Cell in project buck by facebook.

the class ProjectBuildFileParserPoolTest method assertHowManyParserInstancesAreCreated.

private void assertHowManyParserInstancesAreCreated(ListeningExecutorService executorService, final int maxParsers, int numRequests, int expectedCreateCount) throws Exception {
    final AtomicInteger createCount = new AtomicInteger(0);
    Cell cell = EasyMock.createMock(Cell.class);
    final CountDownLatch createParserLatch = new CountDownLatch(expectedCreateCount);
    try (ProjectBuildFileParserPool parserPool = new ProjectBuildFileParserPool(maxParsers, input -> {
        createCount.incrementAndGet();
        return createMockParser(() -> {
            createParserLatch.countDown();
            boolean didntTimeout = false;
            try {
                didntTimeout = createParserLatch.await(1, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                Throwables.throwIfUnchecked(e);
                throw new RuntimeException(e);
            }
            assertThat(didntTimeout, Matchers.equalTo(true));
            return ImmutableList.of();
        });
    })) {
        Futures.allAsList(scheduleWork(cell, parserPool, executorService, numRequests)).get();
        assertThat(createCount.get(), Matchers.equalTo(expectedCreateCount));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CountDownLatch(java.util.concurrent.CountDownLatch) Cell(com.facebook.buck.rules.Cell)

Example 67 with Cell

use of com.facebook.buck.rules.Cell in project buck by facebook.

the class ParserTest method whenAllRulesAreRequestedWithDifferingCellsThenRulesAreParsedOnce.

@Test
public void whenAllRulesAreRequestedWithDifferingCellsThenRulesAreParsedOnce() throws BuildFileParseException, BuildTargetException, IOException, InterruptedException {
    filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
    assertEquals("Should have parsed once.", 1, counter.calls);
    Path newTempDir = Files.createTempDirectory("junit-temp-path").toRealPath();
    Files.createFile(newTempDir.resolve("bar.py"));
    ProjectFilesystem newFilesystem = new ProjectFilesystem(newTempDir);
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(newFilesystem).setSections(ImmutableMap.of(ParserConfig.BUILDFILE_SECTION_NAME, ImmutableMap.of(ParserConfig.INCLUDES_PROPERTY_NAME, "//bar.py"))).build();
    Cell cell = new TestCellBuilder().setFilesystem(newFilesystem).setBuckConfig(config).build();
    filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
    assertEquals("Should not have invalidated cache.", 1, counter.calls);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 68 with Cell

use of com.facebook.buck.rules.Cell in project buck by facebook.

the class ParserTest method whenNotifiedOfContainedFileAddCachedAncestorsAreInvalidatedWithoutBoundaryChecks.

@Test
public void whenNotifiedOfContainedFileAddCachedAncestorsAreInvalidatedWithoutBoundaryChecks() throws Exception {
    BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections("[buildfile]", "includes = //java/com/facebook/defaultIncludeFile", "[project]", "check_package_boundary = false", "temp_files = ''").build();
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
    Path testAncestorBuildFile = tempDir.newFile("java/BUCK").toRealPath();
    Files.write(testAncestorBuildFile, "java_library(name = 'root')\n".getBytes(UTF_8));
    // Call parseBuildFile to populate the cache.
    getRawTargetNodes(parser, eventBus, cell, false, executorService, testAncestorBuildFile);
    // Process event.
    WatchEvent<Path> event = createPathEvent(Paths.get("java/com/facebook/SomeClass.java"), StandardWatchEventKinds.ENTRY_CREATE);
    parser.onFileSystemChange(event);
    // Call parseBuildFile to request cached rules.
    getRawTargetNodes(parser, eventBus, cell, false, executorService, testAncestorBuildFile);
    // Test that the second parseBuildFile call repopulated the cache.
    assertEquals("Should have invalidated cache.", 2, counter.calls);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 69 with Cell

use of com.facebook.buck.rules.Cell in project buck by facebook.

the class ParsePipelineTest method missingBuildFileRaw.

@Test
public void missingBuildFileRaw() throws Exception {
    try (Fixture fixture = createMultiThreadedFixture("parse_rule_with_bad_dependency")) {
        Cell cell = fixture.getCell();
        expectedException.expect(BuildFileParseException.class);
        expectedException.expectMessage(stringContainsInOrder("Parse error for build file", "No such file or directory"));
        fixture.getRawNodeParsePipeline().getAllNodes(cell, cell.getFilesystem().resolve("no/such/file/BUCK"));
    }
}
Also used : Cell(com.facebook.buck.rules.Cell) Test(org.junit.Test)

Example 70 with Cell

use of com.facebook.buck.rules.Cell in project buck by facebook.

the class BuildFileSpecTest method recursiveVsNonRecursive.

@Test
public void recursiveVsNonRecursive() throws IOException, InterruptedException {
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    Path buildFile = Paths.get("a", "BUCK");
    filesystem.mkdirs(buildFile.getParent());
    filesystem.touch(buildFile);
    Path nestedBuildFile = Paths.get("a", "b", "BUCK");
    filesystem.mkdirs(nestedBuildFile.getParent());
    filesystem.touch(nestedBuildFile);
    // Test a non-recursive spec.
    BuildFileSpec nonRecursiveSpec = BuildFileSpec.fromPath(buildFile.getParent(), filesystem.getRootPath());
    ImmutableSet<Path> expectedBuildFiles = ImmutableSet.of(filesystem.resolve(buildFile));
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
    ImmutableSet<Path> actualBuildFiles = nonRecursiveSpec.findBuildFiles(cell, ParserConfig.BuildFileSearchMethod.FILESYSTEM_CRAWL);
    assertEquals(expectedBuildFiles, actualBuildFiles);
    // Test a recursive spec.
    BuildFileSpec recursiveSpec = BuildFileSpec.fromRecursivePath(buildFile.getParent(), filesystem.getRootPath());
    expectedBuildFiles = ImmutableSet.of(filesystem.resolve(buildFile), filesystem.resolve(nestedBuildFile));
    actualBuildFiles = recursiveSpec.findBuildFiles(cell, ParserConfig.BuildFileSearchMethod.FILESYSTEM_CRAWL);
    assertEquals(expectedBuildFiles, actualBuildFiles);
}
Also used : Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Aggregations

Cell (com.facebook.buck.rules.Cell)87 Test (org.junit.Test)57 Path (java.nio.file.Path)46 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)41 BuildTarget (com.facebook.buck.model.BuildTarget)25 BuckConfig (com.facebook.buck.cli.BuckConfig)24 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)22 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)15 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)14 ImmutableSet (com.google.common.collect.ImmutableSet)14 BuckEventBus (com.facebook.buck.event.BuckEventBus)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)11 ParserConfig (com.facebook.buck.parser.ParserConfig)11 IOException (java.io.IOException)11 Map (java.util.Map)11 TargetNode (com.facebook.buck.rules.TargetNode)10 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)10 ImmutableList (com.google.common.collect.ImmutableList)10