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