use of com.facebook.buck.timing.FakeClock 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.timing.FakeClock in project buck by facebook.
the class WatchmanWatcherTest method whenMultipleFilesThenMultipleEventsGenerated.
@Test
public void whenMultipleFilesThenMultipleEventsGenerated() throws IOException, InterruptedException {
ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(ImmutableMap.<String, Object>of("name", "foo/bar/baz"), ImmutableMap.<String, Object>of("name", "foo/bar/boz")));
EventBus eventBus = createStrictMock(EventBus.class);
Capture<WatchEvent<Path>> firstEvent = newCapture();
Capture<WatchEvent<Path>> secondEvent = newCapture();
eventBus.post(capture(firstEvent));
eventBus.post(capture(secondEvent));
replay(eventBus);
WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
verify(eventBus);
assertEquals("Path should match watchman output.", MorePaths.pathWithPlatformSeparators("foo/bar/baz"), firstEvent.getValue().context().toString());
assertEquals("Path should match watchman output.", MorePaths.pathWithPlatformSeparators("foo/bar/boz"), secondEvent.getValue().context().toString());
}
use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class BuildTracesTest method testInputsForTracesThrowsWhenEmpty.
@Test(expected = HumanReadableException.class)
public void testInputsForTracesThrowsWhenEmpty() throws IOException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem(new FakeClock(TimeUnit.MILLISECONDS.toNanos(2000L)));
projectFilesystem.mkdirs(projectFilesystem.getBuckPaths().getTraceDir());
BuildTraces helper = new BuildTraces(projectFilesystem);
helper.getInputsForTraces("nonexistent");
}
use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class BuildTracesTest method testGetTraceAttributesForId.
@Test
public void testGetTraceAttributesForId() throws IOException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem(new FakeClock(TimeUnit.MILLISECONDS.toNanos(1000L)));
projectFilesystem.writeContentsToPath("[\n" + " {\n" + " \"cat\": \"buck\",\n" + " \"pid\": 0,\n" + " \"ts\": 0,\n" + " \"ph\": \"M\",\n" + " \"args\": {\n" + " \"name\": \"buck\"\n" + " },\n" + " \"name\": \"process_name\",\n" + " \"tid\": 0\n" + " },\n" + " {\n" + " \"cat\": \"buck\",\n" + " \"name\": \"build\",\n" + " \"ph\": \"B\",\n" + " \"pid\": 0,\n" + " \"tid\": 1,\n" + " \"ts\": 5621911884918,\n" + " \"args\": {\n" + " \"command_args\": \"buck\"\n" + " }\n" + " }\n" + "]", projectFilesystem.getBuckPaths().getTraceDir().resolve("build.a.trace"));
BuildTraces helper = new BuildTraces(projectFilesystem);
TraceAttributes traceAttributes = helper.getTraceAttributesFor("a");
assertEquals("BuildTraces should be able to extract the command.", Optional.of("buck build buck"), traceAttributes.getCommand());
assertEquals(1000L, traceAttributes.getLastModifiedTime());
// We cannot verify the contents of getFormattedDateTime() because they may vary depending on
// timezone and locale.
assertNotNull(Strings.emptyToNull(traceAttributes.getFormattedDateTime()));
}
use of com.facebook.buck.timing.FakeClock 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)));
}
Aggregations