use of com.facebook.buck.io.FakeWatchmanClient in project buck by facebook.
the class BuildFileSpecTest method findWithWatchmanSucceeds.
@Test
public void findWithWatchmanSucceeds() throws IOException, InterruptedException {
Path watchRoot = Paths.get(".").toAbsolutePath().normalize();
FakeProjectFilesystem filesystem = new FakeProjectFilesystem(watchRoot.resolve("project-name"));
Path buildFile = Paths.get("a", "BUCK");
BuildFileSpec recursiveSpec = BuildFileSpec.fromRecursivePath(buildFile.getParent(), filesystem.getRootPath());
ImmutableSet<Path> expectedBuildFiles = ImmutableSet.of(filesystem.resolve(buildFile));
FakeWatchmanClient fakeWatchmanClient = new FakeWatchmanClient(0, ImmutableMap.of(ImmutableList.of("query", watchRoot.toString(), ImmutableMap.of("relative_root", "project-name", "sync_timeout", 0, "path", ImmutableList.of("a"), "fields", ImmutableList.of("name"), "expression", ImmutableList.of("allof", "exists", ImmutableList.of("name", "BUCK"), ImmutableList.of("type", "f")))), ImmutableMap.of("files", ImmutableList.of("a/BUCK"))));
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setWatchman(new Watchman(ImmutableMap.of(filesystem.getRootPath(), ProjectWatch.of(watchRoot.toString(), Optional.of("project-name"))), ImmutableSet.of(Watchman.Capability.SUPPORTS_PROJECT_WATCH, Watchman.Capability.DIRNAME, Watchman.Capability.WILDMATCH_GLOB), ImmutableMap.of(), Optional.of(Paths.get(".watchman-sock")), Optional.of(fakeWatchmanClient))).build();
ImmutableSet<Path> actualBuildFiles = recursiveSpec.findBuildFiles(cell, ParserConfig.BuildFileSearchMethod.WATCHMAN);
assertEquals(expectedBuildFiles, actualBuildFiles);
}
use of com.facebook.buck.io.FakeWatchmanClient in project buck by facebook.
the class BuildFileSpecTest method findWithWatchmanFallsBackToFilesystemOnTimeout.
@Test
public void findWithWatchmanFallsBackToFilesystemOnTimeout() throws IOException, InterruptedException {
Path watchRoot = Paths.get(".").toAbsolutePath().normalize();
FakeProjectFilesystem filesystem = new FakeProjectFilesystem(watchRoot.resolve("project-name"));
Path buildFile = Paths.get("a", "BUCK");
filesystem.mkdirs(buildFile.getParent());
filesystem.touch(buildFile);
Path nestedBuildFile = Paths.get("a", "b", "BUCK");
filesystem.mkdirs(nestedBuildFile.getParent());
filesystem.touch(nestedBuildFile);
BuildFileSpec recursiveSpec = BuildFileSpec.fromRecursivePath(buildFile.getParent(), filesystem.getRootPath());
FakeWatchmanClient timingOutWatchmanClient = new FakeWatchmanClient(// Pretend the query takes a very very long time.
TimeUnit.SECONDS.toNanos(Long.MAX_VALUE), ImmutableMap.of(ImmutableList.of("query", watchRoot.toString(), ImmutableMap.of("relative_root", "project-name", "sync_timeout", 0, "path", ImmutableList.of("a"), "fields", ImmutableList.of("name"), "expression", ImmutableList.of("allof", "exists", ImmutableList.of("name", "BUCK"), ImmutableList.of("type", "f")))), ImmutableMap.of("files", ImmutableList.of("a/BUCK", "a/b/BUCK"))));
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setWatchman(new Watchman(ImmutableMap.of(filesystem.getRootPath(), ProjectWatch.of(watchRoot.toString(), Optional.of("project-name"))), ImmutableSet.of(Watchman.Capability.SUPPORTS_PROJECT_WATCH, Watchman.Capability.DIRNAME, Watchman.Capability.WILDMATCH_GLOB), ImmutableMap.of(), Optional.of(Paths.get(".watchman-sock")), Optional.of(timingOutWatchmanClient))).build();
ImmutableSet<Path> expectedBuildFiles = ImmutableSet.of(filesystem.resolve(buildFile), filesystem.resolve(nestedBuildFile));
ImmutableSet<Path> actualBuildFiles = recursiveSpec.findBuildFiles(cell, ParserConfig.BuildFileSearchMethod.WATCHMAN);
assertEquals(expectedBuildFiles, actualBuildFiles);
}
use of com.facebook.buck.io.FakeWatchmanClient 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);
}
use of com.facebook.buck.io.FakeWatchmanClient in project buck by facebook.
the class WatchmanWatcherTest method watcherInsertsAndUpdatesClockId.
@Test
public void watcherInsertsAndUpdatesClockId() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.<String, Object>of("clock", "c:0:1", "files", ImmutableList.of());
EventBus eventBus = new EventBus("watchman test");
WatchmanWatcher watcher = createWatcher(eventBus, new FakeWatchmanClient(0, /* queryElapsedTimeNanos */
ImmutableMap.of(FAKE_CLOCK_QUERY, watchmanOutput)), 10000, /* timeout */
"c:0:0");
assertThat(watcher.getWatchmanQuery(FAKE_ROOT), hasItem(hasEntry("since", "c:0:0")));
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.POST_OVERFLOW_EVENT);
assertThat(watcher.getWatchmanQuery(FAKE_ROOT), hasItem(hasEntry("since", "c:0:1")));
}
use of com.facebook.buck.io.FakeWatchmanClient in project buck by facebook.
the class BuildFileSpecTest method findWithWatchmanThrowsOnFailure.
@Test
public void findWithWatchmanThrowsOnFailure() throws IOException, InterruptedException {
Path watchRoot = Paths.get(".").toAbsolutePath().normalize();
FakeProjectFilesystem filesystem = new FakeProjectFilesystem(watchRoot.resolve("project-name"));
Path buildFile = Paths.get("a", "BUCK");
BuildFileSpec recursiveSpec = BuildFileSpec.fromRecursivePath(buildFile.getParent(), filesystem.getRootPath());
FakeWatchmanClient fakeWatchmanClient = new FakeWatchmanClient(0, ImmutableMap.of(ImmutableList.of("query", watchRoot.toString(), ImmutableMap.of("relative_root", "project-name", "sync_timeout", 0, "path", ImmutableList.of("a"), "fields", ImmutableList.of("name"), "expression", ImmutableList.of("allof", "exists", ImmutableList.of("name", "BUCK"), ImmutableList.of("type", "f")))), ImmutableMap.of("files", ImmutableList.of("a/BUCK"))), new IOException("Whoopsie!"));
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setWatchman(new Watchman(ImmutableMap.of(filesystem.getRootPath(), ProjectWatch.of(watchRoot.toString(), Optional.of("project-name"))), ImmutableSet.of(Watchman.Capability.SUPPORTS_PROJECT_WATCH, Watchman.Capability.DIRNAME, Watchman.Capability.WILDMATCH_GLOB), ImmutableMap.of(), Optional.of(Paths.get(".watchman-sock")), Optional.of(fakeWatchmanClient))).build();
thrown.expect(IOException.class);
thrown.expectMessage("Whoopsie!");
recursiveSpec.findBuildFiles(cell, ParserConfig.BuildFileSearchMethod.WATCHMAN);
}
Aggregations