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