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