Search in sources :

Example 71 with BuckEventBus

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());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Parser(com.facebook.buck.parser.Parser) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell) ParserConfig(com.facebook.buck.parser.ParserConfig) PerBuildState(com.facebook.buck.parser.PerBuildState) Before(org.junit.Before)

Example 72 with BuckEventBus

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());
}
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 73 with BuckEventBus

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));
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) Subscribe(com.google.common.eventbus.Subscribe) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) BuckEvent(com.facebook.buck.event.BuckEvent) Test(org.junit.Test)

Example 74 with BuckEventBus

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);
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) WatchmanStatusEvent(com.facebook.buck.event.WatchmanStatusEvent) FakeClock(com.facebook.buck.timing.FakeClock) EasyMock.anyObject(org.easymock.EasyMock.anyObject) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) Subscribe(com.google.common.eventbus.Subscribe) BuckEvent(com.facebook.buck.event.BuckEvent) Test(org.junit.Test)

Example 75 with BuckEventBus

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());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeClock(com.facebook.buck.timing.FakeClock) Test(org.junit.Test)

Aggregations

BuckEventBus (com.facebook.buck.event.BuckEventBus)75 Test (org.junit.Test)58 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)25 BuildId (com.facebook.buck.model.BuildId)21 Clock (com.facebook.buck.timing.Clock)21 FakeClock (com.facebook.buck.timing.FakeClock)20 BuildTarget (com.facebook.buck.model.BuildTarget)19 TestConsole (com.facebook.buck.testutil.TestConsole)16 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)15 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)15 Path (java.nio.file.Path)13 IOException (java.io.IOException)12 BuildEvent (com.facebook.buck.rules.BuildEvent)11 ParseEvent (com.facebook.buck.parser.ParseEvent)10 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)10 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)10 RuleKey (com.facebook.buck.rules.RuleKey)10 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)10 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)10 ActionGraphEvent (com.facebook.buck.event.ActionGraphEvent)9