use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class WatchmanWatcherTest method watcherOverflowUpdatesClockId.
@Test
public void watcherOverflowUpdatesClockId() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.<String, Object>of("clock", "c:1:0", "is_fresh_instance", true);
final Set<WatchEvent<?>> events = Sets.newHashSet();
EventBus eventBus = new EventBus("watchman test");
eventBus.register(new Object() {
@Subscribe
public void listen(WatchEvent<?> event) {
events.add(event);
}
});
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:1:0")));
boolean overflowSeen = false;
for (WatchEvent<?> event : events) {
overflowSeen |= event.kind().equals(StandardWatchEventKinds.OVERFLOW);
}
assertTrue(overflowSeen);
}
use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class WatchmanWatcherTest method whenFilesListIsEmptyThenNoEventsAreGenerated.
@Test
public void whenFilesListIsEmptyThenNoEventsAreGenerated() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("version", "2.9.2", "clock", "c:1386170113:26390:5:50273", "is_fresh_instance", false, "files", ImmutableList.of());
EventBus eventBus = createStrictMock(EventBus.class);
replay(eventBus);
WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
verify(eventBus);
}
use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class AutoSparseIntegrationTest method testMaterialize.
@Test
public void testMaterialize() throws IOException {
ProjectFilesystemDelegate delegate = createDelegate(repoPath, true, ImmutableList.of("subdir"));
// Touch various files, these should be part of the profile
delegate.exists(repoPath.resolve("file1"));
delegate.exists(repoPath.resolve("file2"));
// Only directly include the file, not the parent dir
delegate.exists(repoPath.resolve("subdir/file_in_subdir"));
// Only include the parent directory, not the file
delegate.exists(repoPath.resolve("not_hidden_subdir/file_in_subdir_not_hidden"));
delegate.ensureConcreteFilesExist(BuckEventBusFactory.newInstance(new FakeClock(0)));
List<String> lines = Files.readAllLines(repoPath.resolve(".hg/sparse"), Charset.forName(System.getProperty("file.encoding", "UTF-8")));
List<String> expected = ImmutableList.of("%include sparse_profile", "[include]", "file1", "file2", "not_hidden_subdir", "subdir/file_in_subdir", "[exclude]", // sparse always writes a newline at the end
"");
Assert.assertEquals(expected, lines);
}
use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class BuildTracesTest method testGetTraceAttributesForJsonWithoutCommandArgs.
@Test
public void testGetTraceAttributesForJsonWithoutCommandArgs() throws IOException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem(new FakeClock(TimeUnit.MILLISECONDS.toNanos(2000L)));
projectFilesystem.writeContentsToPath("[" + "{" + "\"cat\":\"buck\"," + "\"ph\":\"B\"," + "\"pid\":0," + "\"tid\":1," + "\"ts\":5621911884918" + "}" + "]", projectFilesystem.getBuckPaths().getTraceDir().resolve("build.c.trace"));
BuildTraces helper = new BuildTraces(projectFilesystem);
TraceAttributes traceAttributes = helper.getTraceAttributesFor("c");
assertEquals("BuildTraces should not be able to extract the command because there is no " + "command_args attribute.", Optional.empty(), traceAttributes.getCommand());
assertEquals(2000L, traceAttributes.getLastModifiedTime());
}
use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class BuildTracesTest method testGetTraceAttributesForJsonWithoutName.
@Test
public void testGetTraceAttributesForJsonWithoutName() throws IOException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem(new FakeClock(TimeUnit.MILLISECONDS.toNanos(2000L)));
projectFilesystem.writeContentsToPath("[" + "{" + "\"cat\":\"buck\"," + "\"ph\":\"B\"," + "\"pid\":0," + "\"tid\":1," + "\"ts\":5621911884918," + "\"args\":{\"command_args\":\"buck\"}" + "}" + "]", projectFilesystem.getBuckPaths().getTraceDir().resolve("build.b.trace"));
BuildTraces helper = new BuildTraces(projectFilesystem);
TraceAttributes traceAttributes = helper.getTraceAttributesFor("b");
assertEquals("BuildTraces should not be able to extract the command because there is no name " + "attribute.", Optional.empty(), traceAttributes.getCommand());
assertEquals(2000L, traceAttributes.getLastModifiedTime());
}
Aggregations