use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class BuckQueryEnvironmentTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "query_command", tmp);
workspace.setUp();
Cell cell = new TestCellBuilder().setFilesystem(new ProjectFilesystem(workspace.getDestPath())).build();
TestConsole console = new TestConsole();
DefaultTypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
Parser parser = new Parser(new BroadcastEventListener(), cell.getBuckConfig().getView(ParserConfig.class), typeCoercerFactory, new ConstructorArgMarshaller(typeCoercerFactory));
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
parserState = new PerBuildState(parser, eventBus, executor, cell, /* enableProfiling */
false, SpeculativeParsing.of(true), /* ignoreBuckAutodepsFiles */
false);
TargetPatternEvaluator targetPatternEvaluator = new TargetPatternEvaluator(cell, FakeBuckConfig.builder().build(), parser, eventBus, /* enableProfiling */
false);
OwnersReport.Builder ownersReportBuilder = OwnersReport.builder(cell, parser, eventBus, console);
buckQueryEnvironment = BuckQueryEnvironment.from(cell, ownersReportBuilder, parserState, targetPatternEvaluator);
cellRoot = workspace.getDestPath();
executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
use of com.facebook.buck.event.BuckEventBus 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.event.BuckEventBus in project buck by facebook.
the class PerfStatsTrackingTest method probingMemoryPostsToTheEventBus.
@Test
public void probingMemoryPostsToTheEventBus() throws Exception {
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
final BlockingQueue<BuckEvent> events = new LinkedBlockingQueue<>();
eventBus.register(new Object() {
@Subscribe
public void event(BuckEvent event) {
events.add(event);
}
});
try (PerfStatsTrackingForTest perfStatsTracking = new PerfStatsTrackingForTest(eventBus, FakeInvocationInfoFactory.create())) {
perfStatsTracking.runOneIteration();
// The BuckEventBus runs on a separate thread, give it a moment to push the event.
BuckEvent event = events.poll(100, TimeUnit.MILLISECONDS);
assertThat(event, Matchers.notNullValue());
assertThat(event, Matchers.instanceOf(PerfStatsTracking.MemoryPerfStatsEvent.class));
PerfStatsTracking.MemoryPerfStatsEvent memoryEvent = (PerfStatsTracking.MemoryPerfStatsEvent) event;
assertThat(memoryEvent.getTotalMemoryBytes(), Matchers.greaterThan(0L));
assertThat(memoryEvent.getCurrentMemoryBytesUsageByPool().size(), Matchers.greaterThan(0));
}
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class WatchmanWatcherTest method whenWatchmanReportsZeroFilesChangedThenPostEvent.
@Test
public void whenWatchmanReportsZeroFilesChangedThenPostEvent() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of());
WatchmanWatcher watcher = createWatcher(new EventBus("watchman test"), watchmanOutput);
final Set<BuckEvent> events = Sets.newHashSet();
BuckEventBus bus = BuckEventBusFactory.newInstance(new FakeClock(0));
bus.register(new Object() {
@Subscribe
public void listen(WatchmanStatusEvent event) {
events.add(event);
}
});
watcher.postEvents(bus, WatchmanWatcher.FreshInstanceAction.POST_OVERFLOW_EVENT);
boolean zeroFilesChangedSeen = false;
System.err.println(String.format("Events: %d", events.size()));
for (BuckEvent event : events) {
zeroFilesChangedSeen |= event.getEventName().equals("WatchmanZeroFileChanges");
}
assertTrue(zeroFilesChangedSeen);
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class MiniAaptTest method testProcessFileNamesInDirectory.
@Test
public void testProcessFileNamesInDirectory() throws IOException, ResourceParseException {
filesystem.touch(Paths.get("res/drawable/icon.png"));
filesystem.touch(Paths.get("res/drawable/another_icon.png.orig"));
filesystem.touch(Paths.get("res/drawable-ldpi/nine_patch.9.png"));
filesystem.touch(Paths.get("res/drawable-ldpi/.DS_Store"));
filesystem.touch(Paths.get("res/transition-v19/some_transition.xml"));
filesystem.writeContentsToPath("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<resources>" + "<bool name=\"v\">false</bool>" + "</resources>", Paths.get("res/values/value.xml~"));
MiniAapt aapt = new MiniAapt(resolver, filesystem, new FakeSourcePath(filesystem, "res"), Paths.get("R.txt"), ImmutableSet.of());
aapt.processFileNamesInDirectory(filesystem, Paths.get("res/drawable"));
aapt.processFileNamesInDirectory(filesystem, Paths.get("res/drawable-ldpi"));
aapt.processFileNamesInDirectory(filesystem, Paths.get("res/transition-v19"));
aapt.processValues(filesystem, new BuckEventBus(new FakeClock(0), new BuildId("")), Paths.get("res/values"));
assertEquals(ImmutableSet.<RDotTxtEntry>of(new FakeRDotTxtEntry(IdType.INT, RType.DRAWABLE, "icon"), new FakeRDotTxtEntry(IdType.INT, RType.DRAWABLE, "nine_patch"), new FakeRDotTxtEntry(IdType.INT, RType.TRANSITION, "some_transition")), aapt.getResourceCollector().getResources());
}
Aggregations