Search in sources :

Example 21 with SettableFakeClock

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

the class BuckEventBusTest method timestampedEventHasSeparateNanosAndMillis.

@Test
public void timestampedEventHasSeparateNanosAndMillis() throws IOException {
    SettableFakeClock fakeClock = new SettableFakeClock(49152, 64738);
    BuckEventBus eb = new BuckEventBus(fakeClock, false, BuckEventBusFactory.BUILD_ID_FOR_TEST, timeoutMillis);
    TestEvent event = new TestEvent();
    eb.post(event);
    eb.close();
    assertEquals(event.getTimestamp(), 49152);
    assertEquals(event.getNanoTime(), 64738);
}
Also used : SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Test(org.junit.Test)

Example 22 with SettableFakeClock

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

the class SimplePerfEventTest method testMinimumTimeScope.

@Test
public void testMinimumTimeScope() throws Exception {
    PerfEventId ignoredEventId = PerfEventId.of("IgnoreMe");
    PerfEventId loggedEventId = PerfEventId.of("LogMe");
    PerfEventId parentId = PerfEventId.of("Parent");
    SimplePerfEventListener listener = new SimplePerfEventListener();
    SettableFakeClock clock = new SettableFakeClock(0L, 0L);
    BuckEventBus eventBus = BuckEventBusFactory.newInstance(clock);
    eventBus.register(listener);
    try (SimplePerfEvent.Scope parent = SimplePerfEvent.scope(eventBus, parentId)) {
        clock.advanceTimeNanos(10L);
        try (SimplePerfEvent.Scope scope = SimplePerfEvent.scopeIgnoringShortEvents(eventBus, ignoredEventId, parent, 1, TimeUnit.SECONDS)) {
            clock.advanceTimeNanos(10L);
        }
        clock.advanceTimeNanos(10L);
        try (SimplePerfEvent.Scope scope = SimplePerfEvent.scopeIgnoringShortEvents(eventBus, loggedEventId, parent, 1, TimeUnit.MILLISECONDS)) {
            clock.advanceTimeNanos(TimeUnit.MILLISECONDS.toNanos(2));
        }
    }
    ImmutableList<SimplePerfEvent> perfEvents = listener.getPerfEvents();
    assertThat(perfEvents, Matchers.hasSize(4));
    assertPerfEvent(perfEvents.get(0), parentId, SimplePerfEvent.Type.STARTED, ImmutableMap.of());
    assertPerfEvent(perfEvents.get(1), loggedEventId, SimplePerfEvent.Type.STARTED, ImmutableMap.of());
    assertPerfEvent(perfEvents.get(2), loggedEventId, SimplePerfEvent.Type.FINISHED, ImmutableMap.of());
    assertPerfEvent(perfEvents.get(3), parentId, SimplePerfEvent.Type.FINISHED, ImmutableMap.of("IgnoreMe_accumulated_count", "1", "IgnoreMe_accumulated_duration_ns", "10"));
}
Also used : SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Test(org.junit.Test)

Example 23 with SettableFakeClock

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

the class FakeProjectFilesystemTest method fileModifiedTimeIsUpdatedOnSubsequentWrite.

@Test
public void fileModifiedTimeIsUpdatedOnSubsequentWrite() throws IOException {
    SettableFakeClock clock = new SettableFakeClock(49152, 0);
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem(clock);
    filesystem.touch(Paths.get("foo"));
    clock.setCurrentTimeMillis(64738);
    filesystem.touch(Paths.get("foo"));
    assertEquals(filesystem.getLastModifiedTime(Paths.get("foo")), 64738);
}
Also used : SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Test(org.junit.Test)

Example 24 with SettableFakeClock

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

the class BuildTracesTest method testSortByLastModified.

@Test
public void testSortByLastModified() throws IOException {
    SettableFakeClock clock = new SettableFakeClock(0L, 0L);
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem(clock);
    clock.setCurrentTimeMillis(1);
    Path traceDir = projectFilesystem.getBuckPaths().getTraceDir();
    projectFilesystem.touch(traceDir.resolve("build.1.trace"));
    clock.setCurrentTimeMillis(4);
    projectFilesystem.touch(traceDir.resolve("build.4.trace"));
    clock.setCurrentTimeMillis(2);
    projectFilesystem.touch(traceDir.resolve("build.2.trace"));
    clock.setCurrentTimeMillis(5);
    projectFilesystem.touch(traceDir.resolve("build.5.trace"));
    clock.setCurrentTimeMillis(3);
    projectFilesystem.touch(traceDir.resolve("build.3.trace"));
    projectFilesystem.touch(traceDir.resolve("build.3b.trace"));
    BuildTraces helper = new BuildTraces(projectFilesystem);
    assertEquals(ImmutableList.of(traceDir.resolve("build.5.trace"), traceDir.resolve("build.4.trace"), traceDir.resolve("build.3b.trace"), traceDir.resolve("build.3.trace"), traceDir.resolve("build.2.trace"), traceDir.resolve("build.1.trace")), helper.listTraceFilesByLastModified());
}
Also used : Path(java.nio.file.Path) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) Test(org.junit.Test)

Aggregations

SettableFakeClock (com.facebook.buck.timing.SettableFakeClock)24 Test (org.junit.Test)21 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 TestConsole (com.facebook.buck.testutil.TestConsole)8 FakeListeningProcessExecutor (com.facebook.buck.util.FakeListeningProcessExecutor)8 Hasher (com.google.common.hash.Hasher)4 Before (org.junit.Before)3 Path (java.nio.file.Path)2 NSString (com.dd.plist.NSString)1 AppleConfig (com.facebook.buck.apple.AppleConfig)1 BuckConfig (com.facebook.buck.cli.BuckConfig)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)1 HalideBuckConfig (com.facebook.buck.halide.HalideBuckConfig)1 ReactNativeBuckConfig (com.facebook.buck.js.ReactNativeBuckConfig)1 TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)1 SwiftBuckConfig (com.facebook.buck.swift.SwiftBuckConfig)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1