Search in sources :

Example 21 with FakeClock

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")));
}
Also used : FakeWatchmanClient(com.facebook.buck.io.FakeWatchmanClient) FakeClock(com.facebook.buck.timing.FakeClock) EasyMock.anyObject(org.easymock.EasyMock.anyObject) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Example 22 with FakeClock

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());
}
Also used : FakeClock(com.facebook.buck.timing.FakeClock) EasyMock.anyObject(org.easymock.EasyMock.anyObject) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) WatchEvent(java.nio.file.WatchEvent) Test(org.junit.Test)

Example 23 with FakeClock

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");
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeClock(com.facebook.buck.timing.FakeClock) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Test(org.junit.Test)

Example 24 with FakeClock

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()));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeClock(com.facebook.buck.timing.FakeClock) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) TraceAttributes(com.facebook.buck.util.trace.BuildTraces.TraceAttributes) Test(org.junit.Test)

Example 25 with FakeClock

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)));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeClock(com.facebook.buck.timing.FakeClock) Subscribe(com.google.common.eventbus.Subscribe) BuckEvent(com.facebook.buck.event.BuckEvent) AbstractBuckEvent(com.facebook.buck.event.AbstractBuckEvent) BuildId(com.facebook.buck.model.BuildId) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Before(org.junit.Before)

Aggregations

FakeClock (com.facebook.buck.timing.FakeClock)54 Test (org.junit.Test)48 BuckEventBus (com.facebook.buck.event.BuckEventBus)36 EventBus (com.google.common.eventbus.EventBus)19 EasyMock.anyObject (org.easymock.EasyMock.anyObject)17 WatchEvent (java.nio.file.WatchEvent)13 BuildId (com.facebook.buck.model.BuildId)12 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 ProjectBuildFileParser (com.facebook.buck.json.ProjectBuildFileParser)8 Path (java.nio.file.Path)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)6 Subscribe (com.google.common.eventbus.Subscribe)6 ArrayList (java.util.ArrayList)6 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)5 SettableFakeClock (com.facebook.buck.timing.SettableFakeClock)5 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)4 FakeExecutor (com.facebook.buck.testutil.FakeExecutor)4 BuckEvent (com.facebook.buck.event.BuckEvent)3 WatchmanStatusEvent (com.facebook.buck.event.WatchmanStatusEvent)2