Search in sources :

Example 6 with FakeClock

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

the class ChromeTraceBuildListenerTest method canCompressTraces.

@Test
public void canCompressTraces() 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, true);
    listener.outputTrace(invocationInfo.getBuildId());
    Path tracePath = Paths.get(EXPECTED_DIR + "build.2014-09-02.16-55-51.BUILD_ID.trace.gz");
    assertTrue(projectFilesystem.exists(tracePath));
    BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(projectFilesystem.newFileInputStream(tracePath))));
    List<?> elements = new Gson().fromJson(reader, List.class);
    assertThat(elements, notNullValue());
}
Also used : Path(java.nio.file.Path) GZIPInputStream(java.util.zip.GZIPInputStream) InputStreamReader(java.io.InputStreamReader) FakeClock(com.facebook.buck.timing.FakeClock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) BufferedReader(java.io.BufferedReader) Gson(com.google.gson.Gson) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 7 with FakeClock

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

the class ParsingJavaPackageFinderTest method setUp.

@Before
public void setUp() throws IOException {
    matchPath = Paths.get("case1/org/test/package1/Match.java");
    mismatchPath = Paths.get("case1/org/test/package2/Mismatch.java");
    placeholderPath = Paths.get("case3/com/test/placeholder");
    fakeProjectFilesystem = new FakeProjectFilesystem(new FakeClock(0), Paths.get(".").toAbsolutePath(), ImmutableSet.of(matchPath, mismatchPath, placeholderPath));
    fakeProjectFilesystem.writeContentsToPath("package org.test.package1; \n class Match {} \n", matchPath);
    fakeProjectFilesystem.writeContentsToPath("package org.test.\nhaha; \n class Mismatch {} \n", mismatchPath);
    dummyPackageFinder = new JavaPackageFinder() {

        @Override
        public Path findJavaPackageFolder(Path pathRelativeToProjectRoot) {
            return Paths.get("dummy");
        }

        @Override
        public String findJavaPackage(Path pathRelativeToProjectRoot) {
            return "dummy";
        }

        @Override
        public String findJavaPackage(BuildTarget buildTarget) {
            return "dummy";
        }
    };
    javaFileParser = JavaFileParser.createJavaFileParser(JavaCompilationConstants.DEFAULT_JAVAC_OPTIONS);
}
Also used : Path(java.nio.file.Path) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeClock(com.facebook.buck.timing.FakeClock) BuildTarget(com.facebook.buck.model.BuildTarget) Before(org.junit.Before)

Example 8 with FakeClock

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

the class PythonBuckConfigTest method testPathToPexExecuterUsesConfigSetting.

@Test
public void testPathToPexExecuterUsesConfigSetting() throws IOException {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    Path projectDir = Files.createTempDirectory("project");
    Path pexExecuter = Paths.get("pex-exectuter");
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem(new FakeClock(0), projectDir, ImmutableSet.of(pexExecuter));
    Files.createFile(projectFilesystem.resolve(pexExecuter));
    assertTrue("Should be able to set file executable", projectFilesystem.resolve(pexExecuter).toFile().setExecutable(true));
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("path_to_pex_executer", pexExecuter.toString()))).setFilesystem(projectFilesystem).build(), new ExecutableFinder());
    assertThat(config.getPexExecutor(resolver).get().getCommandPrefix(pathResolver), Matchers.contains(pexExecuter.toString()));
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeClock(com.facebook.buck.timing.FakeClock) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 9 with FakeClock

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

the class ProjectBuildFileParserTest method whenSubprocessReturnsWarningThenConsoleEventPublished.

@Test
public void whenSubprocessReturnsWarningThenConsoleEventPublished() throws IOException, BuildFileParseException, InterruptedException {
    // This test depends on unix utilities that don't exist on Windows.
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    TestProjectBuildFileParserFactory buildFileParserFactory = new TestProjectBuildFileParserFactory(cell.getRoot(), cell.getKnownBuildRuleTypes());
    BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
    final List<ConsoleEvent> consoleEvents = new ArrayList<>();
    final List<WatchmanDiagnosticEvent> watchmanDiagnosticEvents = new ArrayList<>();
    class EventListener {

        @Subscribe
        public void on(ConsoleEvent consoleEvent) {
            consoleEvents.add(consoleEvent);
        }

        @Subscribe
        public void on(WatchmanDiagnosticEvent event) {
            watchmanDiagnosticEvents.add(event);
        }
    }
    EventListener eventListener = new EventListener();
    buckEventBus.register(eventListener);
    try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsSuccessWithWarning(buckEventBus, "This is a warning", "parser")) {
        buildFileParser.initIfNeeded();
        buildFileParser.getAllRulesAndMetaRules(Paths.get("foo"));
    }
    assertThat(consoleEvents, Matchers.contains(Matchers.hasToString("Warning raised by BUCK file parser: This is a warning")));
    assertThat("Should not receive any watchman diagnostic events", watchmanDiagnosticEvents, Matchers.empty());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeClock(com.facebook.buck.timing.FakeClock) WatchmanDiagnosticEvent(com.facebook.buck.io.WatchmanDiagnosticEvent) ProjectBuildFileParser(com.facebook.buck.json.ProjectBuildFileParser) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with FakeClock

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

the class ProjectBuildFileParserTest method whenSubprocessPrintsWarningToStderrThenConsoleEventPublished.

@Test
public void whenSubprocessPrintsWarningToStderrThenConsoleEventPublished() throws IOException, BuildFileParseException, InterruptedException {
    // This test depends on unix utilities that don't exist on Windows.
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    TestProjectBuildFileParserFactory buildFileParserFactory = new TestProjectBuildFileParserFactory(cell.getRoot(), cell.getKnownBuildRuleTypes());
    BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
    final List<ConsoleEvent> consoleEvents = new ArrayList<>();
    class EventListener {

        @Subscribe
        public void onConsoleEvent(ConsoleEvent consoleEvent) {
            consoleEvents.add(consoleEvent);
        }
    }
    EventListener eventListener = new EventListener();
    buckEventBus.register(eventListener);
    try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsSuccessAndPrintsToStderr(buckEventBus)) {
        buildFileParser.initIfNeeded();
        buildFileParser.getAllRulesAndMetaRules(Paths.get("foo"));
    }
    assertThat(consoleEvents, Matchers.contains(Matchers.hasToString("Warning raised by BUCK file parser: Don't Panic!")));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeClock(com.facebook.buck.timing.FakeClock) ProjectBuildFileParser(com.facebook.buck.json.ProjectBuildFileParser) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) ArrayList(java.util.ArrayList) 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