Search in sources :

Example 26 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class WatchmanWatcherIntegrationTest method createWatchmanWatcher.

// Create a watcher for the given ignore paths, clearing the initial overflow event before
// returning it.
private WatchmanWatcher createWatchmanWatcher(PathOrGlobMatcher... ignorePaths) throws IOException, InterruptedException {
    WatchmanWatcher watcher = new WatchmanWatcher(ImmutableMap.of(tmp.getRoot(), ProjectWatch.of(tmp.getRoot().toString(), Optional.empty())), eventBus, ImmutableSet.copyOf(ignorePaths), watchman, ImmutableMap.of(tmp.getRoot(), new WatchmanCursor(new StringBuilder("n:buckd").append(UUID.randomUUID()).toString())));
    // Clear out the initial overflow event.
    watcher.postEvents(new BuckEventBus(new FakeClock(0), new BuildId()), WatchmanWatcher.FreshInstanceAction.NONE);
    watchmanEventCollector.clear();
    return watcher;
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeClock(com.facebook.buck.timing.FakeClock) WatchmanCursor(com.facebook.buck.io.WatchmanCursor)

Example 27 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class WatchmanWatcherTest method whenWatchmanProducesAWarningThenWarningAddedToCache.

@Test
public void whenWatchmanProducesAWarningThenWarningAddedToCache() throws IOException, InterruptedException {
    String message = "I'm a warning!";
    ImmutableMap<String, Object> watchmanOutput = ImmutableMap.of("files", ImmutableList.of(), "warning", message);
    EventBus eventBus = new EventBus("watchman test");
    WatchmanWatcher watcher = createWatcher(eventBus, watchmanOutput);
    Set<WatchmanDiagnostic> diagnostics = new HashSet<>();
    BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
    buckEventBus.register(new WatchmanDiagnosticEventListener(buckEventBus, diagnostics));
    watcher.postEvents(buckEventBus, WatchmanWatcher.FreshInstanceAction.NONE);
    assertThat(diagnostics, hasItem(WatchmanDiagnostic.of(WatchmanDiagnostic.Level.WARNING, message)));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeClock(com.facebook.buck.timing.FakeClock) WatchmanDiagnostic(com.facebook.buck.io.WatchmanDiagnostic) EasyMock.anyObject(org.easymock.EasyMock.anyObject) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) WatchmanDiagnosticEventListener(com.facebook.buck.io.WatchmanDiagnosticEventListener) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 28 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class CounterRegistryImplTest method closingRegistryBeforeTimerFiresFlushesCounters.

@Test
public void closingRegistryBeforeTimerFiresFlushesCounters() throws IOException {
    BuckEventBus fakeEventBus = new BuckEventBus(new FakeClock(0), false, new BuildId("12345"), 1000);
    SnapshotEventListener listener = new SnapshotEventListener();
    fakeEventBus.register(listener);
    FakeExecutor fakeExecutor = new FakeExecutor();
    try (CounterRegistryImpl registry = new CounterRegistryImpl(fakeExecutor, fakeEventBus)) {
        IntegerCounter counter = registry.newIntegerCounter(CATEGORY, NAME, TAGS);
        counter.inc(42);
        assertThat("No events should be flushed before timer fires", listener.snapshotEvents, empty());
    }
    // We explicitly do not call fakeExecutor.drain() here, because we want to simulate what
    // happens when the registry is closed before the executor fires.
    assertThat("One snapshot event should be flushed when registry closed before timer fires", listener.snapshotEvents, hasSize(1));
    assertThat("Expected snapshot should be flushed when registry closed before timer fires", listener.snapshotEvents.get(0).getSnapshots(), hasItem(CounterSnapshot.builder().setCategory(CATEGORY).setTags(TAGS).putValues(NAME, 42).build()));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeExecutor(com.facebook.buck.testutil.FakeExecutor) FakeClock(com.facebook.buck.timing.FakeClock) Test(org.junit.Test)

Example 29 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class ChromeTraceBuildListenerTest method outputFileUsesCurrentTime.

@Test
public void outputFileUsesCurrentTime() throws IOException {
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmpDir.getRoot().toPath());
    ChromeTraceBuildListener listener = new ChromeTraceBuildListener(projectFilesystem, invocationInfo, new FakeClock(TIMESTAMP_NANOS), ObjectMappers.newDefaultInstance(), Locale.US, TimeZone.getTimeZone("America/Los_Angeles"), /* tracesToKeep */
    1, false);
    listener.outputTrace(invocationInfo.getBuildId());
    assertTrue(projectFilesystem.exists(Paths.get(EXPECTED_DIR + "build.2014-09-02.16-55-51.BUILD_ID.trace")));
}
Also used : FakeClock(com.facebook.buck.timing.FakeClock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 30 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class ChromeTraceBuildListenerTest method testOutputFailed.

@Test
public void testOutputFailed() throws IOException {
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmpDir.getRoot().toPath());
    assumeTrue("Can make the root directory read-only", tmpDir.getRoot().setReadOnly());
    try {
        ChromeTraceBuildListener listener = new ChromeTraceBuildListener(projectFilesystem, invocationInfo, new FakeClock(TIMESTAMP_NANOS), ObjectMappers.newDefaultInstance(), Locale.US, TimeZone.getTimeZone("America/Los_Angeles"), /* tracesToKeep */
        3, false);
        listener.outputTrace(invocationInfo.getBuildId());
        fail("Expected an exception.");
    } catch (HumanReadableException e) {
        assertEquals("Unable to write trace file: java.nio.file.AccessDeniedException: " + projectFilesystem.resolve(projectFilesystem.getBuckPaths().getBuckOut()), e.getMessage());
    } finally {
        tmpDir.getRoot().setWritable(true);
    }
}
Also used : FakeClock(com.facebook.buck.timing.FakeClock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) HumanReadableException(com.facebook.buck.util.HumanReadableException) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) 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