Search in sources :

Example 41 with BuckEventBus

use of com.facebook.buck.event.BuckEventBus in project buck by facebook.

the class WatchmanWatcherTest method whenWatchmanProducesAWarningThenDiagnosticEventGenerated.

@Test
public void whenWatchmanProducesAWarningThenDiagnosticEventGenerated() throws IOException, InterruptedException {
    String message = "Find me!";
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(), "warning", message);
    Capture<WatchmanDiagnosticEvent> eventCapture = newCapture();
    EventBus eventBus = new EventBus("watchman test");
    BuckEventBus buckEventBus = createStrictMock(BuckEventBus.class);
    buckEventBus.post(capture(eventCapture));
    replay(buckEventBus);
    WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
    watcher.postEvents(buckEventBus, WatchmanWatcher.FreshInstanceAction.NONE);
    verify(buckEventBus);
    assertThat(eventCapture.getValue().getDiagnostic().getMessage(), Matchers.containsString(message));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) WatchmanDiagnosticEvent(com.facebook.buck.io.WatchmanDiagnosticEvent) EasyMock.anyObject(org.easymock.EasyMock.anyObject) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Example 42 with BuckEventBus

use of com.facebook.buck.event.BuckEventBus in project buck by facebook.

the class UnskippedRulesTrackerTest method setUp.

@Before
public void setUp() {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    sourcePathResolver = new SourcePathResolver(ruleFinder);
    ListeningExecutorService executor = listeningDecorator(MostExecutors.newMultiThreadExecutor("UnskippedRulesTracker", 7));
    RuleDepsCache depsCache = new RuleDepsCache(executor, resolver);
    unskippedRulesTracker = new UnskippedRulesTracker(depsCache, resolver, executor);
    eventBus = new BuckEventBus(new FakeClock(1), new BuildId());
    eventBus.register(new Object() {

        @Subscribe
        public void onUnskippedRuleCountUpdated(BuckEvent event) {
            events.add(event);
        }
    });
    ruleH = resolver.addToIndex(createRule("//:h"));
    ruleG = resolver.addToIndex(createRule("//:g"));
    ruleF = resolver.addToIndex(createRule("//:f"));
    ruleE = resolver.addToIndex(createRule("//:e", ImmutableSet.of(ruleG, ruleH)));
    ruleD = resolver.addToIndex(createRule("//:d", ImmutableSet.of(ruleG), ImmutableSet.of(ruleF)));
    ruleC = resolver.addToIndex(createRule("//:c", ImmutableSet.of(ruleD, ruleE)));
    ruleB = resolver.addToIndex(createRule("//:b", ImmutableSet.of(), ImmutableSet.of(ruleD)));
    ruleA = resolver.addToIndex(createRule("//:a", ImmutableSet.of(ruleD)));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeClock(com.facebook.buck.timing.FakeClock) Subscribe(com.google.common.eventbus.Subscribe) BuckEvent(com.facebook.buck.event.BuckEvent) AbstractBuckEvent(com.facebook.buck.event.AbstractBuckEvent) BuildId(com.facebook.buck.model.BuildId) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Before(org.junit.Before)

Example 43 with BuckEventBus

use of com.facebook.buck.event.BuckEventBus in project buck by facebook.

the class TargetGraphHashingTest method twoNodeIndependentRootsTargetGraphHasExpectedHashes.

@Test
public void twoNodeIndependentRootsTargetGraphHasExpectedHashes() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
    TargetNode<?, ?> nodeA = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//foo:lib"), HashCode.fromLong(64738), ImmutableSet.of(Paths.get("foo/FooLib.java")));
    TargetNode<?, ?> nodeB = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//bar:lib"), HashCode.fromLong(49152), ImmutableSet.of(Paths.get("bar/BarLib.java")));
    TargetGraph targetGraphA = TargetGraphFactory.newInstance(nodeA);
    TargetGraph targetGraphB = TargetGraphFactory.newInstance(nodeB);
    TargetGraph commonTargetGraph = TargetGraphFactory.newInstance(nodeA, nodeB);
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef"), projectFilesystem.resolve("bar/BarLib.java"), HashCode.fromString("123456")));
    Map<BuildTarget, HashCode> resultsA = new TargetGraphHashing(eventBus, targetGraphA, fileHashCache, ImmutableList.of(nodeA)).hashTargetGraph();
    Map<BuildTarget, HashCode> resultsB = new TargetGraphHashing(eventBus, targetGraphB, fileHashCache, ImmutableList.of(nodeB)).hashTargetGraph();
    Map<BuildTarget, HashCode> commonResults = new TargetGraphHashing(eventBus, commonTargetGraph, fileHashCache, ImmutableList.of(nodeA, nodeB)).hashTargetGraph();
    assertThat(resultsA, aMapWithSize(1));
    assertThat(resultsA, hasKey(nodeA.getBuildTarget()));
    assertThat(resultsB, aMapWithSize(1));
    assertThat(resultsB, hasKey(nodeB.getBuildTarget()));
    assertThat(commonResults, aMapWithSize(2));
    assertThat(commonResults, hasKey(nodeA.getBuildTarget()));
    assertThat(commonResults, hasKey(nodeB.getBuildTarget()));
    assertThat(resultsA.get(nodeA.getBuildTarget()), equalTo(commonResults.get(nodeA.getBuildTarget())));
    assertThat(resultsB.get(nodeB.getBuildTarget()), equalTo(commonResults.get(nodeB.getBuildTarget())));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) HashCode(com.google.common.hash.HashCode) BuildId(com.facebook.buck.model.BuildId) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Test(org.junit.Test)

Example 44 with BuckEventBus

use of com.facebook.buck.event.BuckEventBus in project buck by facebook.

the class TargetGraphHashingTest method emptyTargetGraphHasEmptyHashes.

@Test
public void emptyTargetGraphHasEmptyHashes() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
    BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
    TargetGraph targetGraph = TargetGraphFactory.newInstance();
    assertThat(new TargetGraphHashing(eventBus, targetGraph, new NullFileHashCache(), ImmutableList.of()).hashTargetGraph().entrySet(), empty());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Test(org.junit.Test)

Example 45 with BuckEventBus

use of com.facebook.buck.event.BuckEventBus in project buck by facebook.

the class WatchmanWatcherIntegrationTest method createWatchmanWatcher.

// Create a watcher for the given ignore paths, clearing the initial overflow event before
// returning it.
private WatchmanWatcher createWatchmanWatcher(PathOrGlobMatcher... ignorePaths) throws IOException, InterruptedException {
    WatchmanWatcher watcher = new WatchmanWatcher(ImmutableMap.of(tmp.getRoot(), ProjectWatch.of(tmp.getRoot().toString(), Optional.empty())), eventBus, ImmutableSet.copyOf(ignorePaths), watchman, ImmutableMap.of(tmp.getRoot(), new WatchmanCursor(new StringBuilder("n:buckd").append(UUID.randomUUID()).toString())));
    // Clear out the initial overflow event.
    watcher.postEvents(new BuckEventBus(new FakeClock(0), new BuildId()), WatchmanWatcher.FreshInstanceAction.NONE);
    watchmanEventCollector.clear();
    return watcher;
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeClock(com.facebook.buck.timing.FakeClock) WatchmanCursor(com.facebook.buck.io.WatchmanCursor)

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