use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class TargetGraphHashingTest method hashChangesForDependentNodeWhenDepsChange.
@Test
public void hashChangesForDependentNodeWhenDepsChange() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
BuildTarget nodeTarget = BuildTargetFactory.newInstance("//foo:lib");
BuildTarget depTarget = BuildTargetFactory.newInstance("//dep:lib");
TargetGraph targetGraphA = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(64738));
TargetGraph targetGraphB = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(84552));
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef"), projectFilesystem.resolve("dep/DepLib.java"), HashCode.fromString("123456")));
Map<BuildTarget, HashCode> resultA = new TargetGraphHashing(eventBus, targetGraphA, fileHashCache, ImmutableList.of(targetGraphA.get(nodeTarget))).hashTargetGraph();
Map<BuildTarget, HashCode> resultB = new TargetGraphHashing(eventBus, targetGraphB, fileHashCache, ImmutableList.of(targetGraphB.get(nodeTarget))).hashTargetGraph();
assertThat(resultA, aMapWithSize(2));
assertThat(resultA, hasKey(nodeTarget));
assertThat(resultA, hasKey(depTarget));
assertThat(resultB, aMapWithSize(2));
assertThat(resultB, hasKey(nodeTarget));
assertThat(resultB, hasKey(depTarget));
assertThat(resultA.get(nodeTarget), not(equalTo(resultB.get(nodeTarget))));
assertThat(resultA.get(depTarget), not(equalTo(resultB.get(depTarget))));
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class ProcessTrackerTest method createProcessTracker.
private ProcessTrackerForTest createProcessTracker(final BlockingQueue<ProcessResourceConsumptionEvent> events) {
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
eventBus.register(new Object() {
@Subscribe
public void event(ProcessResourceConsumptionEvent event) {
events.add(event);
}
});
return new ProcessTrackerForTest(eventBus, FakeInvocationInfoFactory.create(), processHelper, processRegistry);
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class WatchmanWatcherIntegrationTest method globMatchesWholeName.
@Test
public void globMatchesWholeName() throws IOException, InterruptedException {
WatchmanWatcher watcher = createWatchmanWatcher(new PathOrGlobMatcher("*.txt"));
// Create a dot-file which should be ignored by the above glob.
Path path = tmp.getRoot().getFileSystem().getPath("foo/bar/hello.txt");
Files.createDirectories(tmp.getRoot().resolve(path).getParent());
Files.write(tmp.getRoot().resolve(path), new byte[0]);
// Verify we still get an event for the created path.
watcher.postEvents(new BuckEventBus(new FakeClock(0), new BuildId()), WatchmanWatcher.FreshInstanceAction.NONE);
ImmutableList<WatchEvent<?>> events = watchmanEventCollector.getEvents();
assertThat(events.size(), Matchers.equalTo(1));
WatchEvent<?> event = events.get(0);
Path eventPath = (Path) event.context();
assertThat(eventPath, Matchers.equalTo(path));
assertSame(event.kind(), StandardWatchEventKinds.ENTRY_CREATE);
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class WatchmanWatcherIntegrationTest method ignoreDotFileInGlob.
@Test
public void ignoreDotFileInGlob() throws IOException, InterruptedException {
WatchmanWatcher watcher = createWatchmanWatcher(new PathOrGlobMatcher("**/*.swp"));
// Create a dot-file which should be ignored by the above glob.
Path path = tmp.getRoot().getFileSystem().getPath("foo/bar/.hello.swp");
Files.createDirectories(tmp.getRoot().resolve(path).getParent());
Files.write(tmp.getRoot().resolve(path), new byte[0]);
// Verify we don't get an event for the path.
watcher.postEvents(new BuckEventBus(new FakeClock(0), new BuildId()), WatchmanWatcher.FreshInstanceAction.NONE);
assertThat(watchmanEventCollector.getEvents(), Matchers.empty());
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class WatchmanWatcherTest method whenWatchmanCellReportsFilesChangedThenPostEvent.
@Test
public void whenWatchmanCellReportsFilesChangedThenPostEvent() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanRootOutput = ImmutableMap.of("files", ImmutableList.of());
ImmutableMap<String, Object> watchmanSecondaryOutput = ImmutableMap.of("files", ImmutableList.of(ImmutableMap.<String, Object>of("name", "foo/bar/baz")));
WatchmanWatcher watcher = new WatchmanWatcher(new EventBus("watchman test"), new FakeWatchmanClient(0, ImmutableMap.of(FAKE_CLOCK_QUERY, watchmanRootOutput, FAKE_SECONDARY_QUERY.toList("c:0:0"), watchmanSecondaryOutput)), 10000, ImmutableMap.of(FAKE_ROOT, FAKE_QUERY, FAKE_SECONDARY_ROOT, FAKE_SECONDARY_QUERY), ImmutableMap.of(FAKE_ROOT, new WatchmanCursor("c:0:0"), FAKE_SECONDARY_ROOT, new WatchmanCursor("c:0:0")));
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) {
System.err.println(String.format("Event: %s", event));
zeroFilesChangedSeen |= event.getEventName().equals("WatchmanZeroFileChanges");
}
assertFalse(zeroFilesChangedSeen);
}
Aggregations