Search in sources :

Example 36 with FakeClock

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

Example 37 with FakeClock

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);
}
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) Test(org.junit.Test)

Example 38 with FakeClock

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

Example 39 with FakeClock

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());
}
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 40 with FakeClock

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());
}
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)

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