Search in sources :

Example 21 with BuildId

use of com.facebook.buck.model.BuildId in project buck by facebook.

the class JUnitStepTest method ensureThatDebugFlagCausesJavaDebugCommandFlagToBeAdded.

@Test
public void ensureThatDebugFlagCausesJavaDebugCommandFlagToBeAdded() {
    String testClass1 = "com.facebook.buck.shell.JUnitCommandTest";
    String testClass2 = "com.facebook.buck.shell.InstrumentCommandTest";
    Set<String> testClassNames = ImmutableSet.of(testClass1, testClass2);
    String vmArg1 = "-Dname1=value1";
    String vmArg2 = "-Dname1=value2";
    ImmutableList<String> vmArgs = ImmutableList.of(vmArg1, vmArg2);
    BuildId pretendBuildId = new BuildId("pretend-build-id");
    String buildIdArg = String.format("-Dcom.facebook.buck.buildId=%s", pretendBuildId);
    Path modulePath = Paths.get("module/submodule");
    String modulePathArg = String.format("-Dcom.facebook.buck.moduleBasePath=%s", modulePath);
    Path directoryForTestResults = Paths.get("buck-out/gen/theresults/");
    Path testRunnerClasspath = Paths.get("build/classes/junit");
    ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    Path classpathFile = filesystem.resolve("foo");
    JUnitJvmArgs args = JUnitJvmArgs.builder().setClasspathFile(classpathFile).setBuildId(pretendBuildId).setBuckModuleBaseSourceCodePath(modulePath).setTestRunnerClasspath(testRunnerClasspath).setDebugEnabled(true).setExtraJvmArgs(vmArgs).setTestType(TestType.JUNIT).setDirectoryForTestResults(directoryForTestResults).addAllTestClasses(testClassNames).build();
    JUnitStep junit = new JUnitStep(filesystem, ImmutableMap.of(), /* testRuleTimeoutMs */
    Optional.empty(), /* testCaseTimeoutMs */
    Optional.empty(), ImmutableMap.of(), new ExternalJavaRuntimeLauncher("/foo/bar/custom/java"), args);
    TestConsole console = new TestConsole(Verbosity.ALL);
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setConsole(console).setDebugEnabled(true).build();
    List<String> observedArgs = junit.getShellCommand(executionContext);
    MoreAsserts.assertListEquals(ImmutableList.of("/foo/bar/custom/java", "-Dbuck.testrunner_classes=" + testRunnerClasspath, buildIdArg, modulePathArg, "-Dapple.awt.UIElement=true", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005", vmArg1, vmArg2, "-verbose", "-classpath", "@" + classpathFile + File.pathSeparator + MorePaths.pathWithPlatformSeparators("build/classes/junit"), FileClassPathRunner.class.getName(), "com.facebook.buck.testrunner.JUnitMain", "--output", directoryForTestResults.toString(), "--default-test-timeout", "0", testClass1, testClass2), observedArgs);
    // TODO(shs96c): Why does the CapturingPrintStream append spaces?
    assertEquals("Debugging. Suspending JVM. Connect a JDWP debugger to port 5005 to proceed.", console.getTextWrittenToStdErr().trim());
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildId(com.facebook.buck.model.BuildId) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 22 with BuildId

use of com.facebook.buck.model.BuildId in project buck by facebook.

the class UnskippedRulesTrackerTest method setUp.

@Before
public void setUp() {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    sourcePathResolver = new SourcePathResolver(ruleFinder);
    ListeningExecutorService executor = listeningDecorator(MostExecutors.newMultiThreadExecutor("UnskippedRulesTracker", 7));
    RuleDepsCache depsCache = new RuleDepsCache(executor, resolver);
    unskippedRulesTracker = new UnskippedRulesTracker(depsCache, resolver, executor);
    eventBus = new BuckEventBus(new FakeClock(1), new BuildId());
    eventBus.register(new Object() {

        @Subscribe
        public void onUnskippedRuleCountUpdated(BuckEvent event) {
            events.add(event);
        }
    });
    ruleH = resolver.addToIndex(createRule("//:h"));
    ruleG = resolver.addToIndex(createRule("//:g"));
    ruleF = resolver.addToIndex(createRule("//:f"));
    ruleE = resolver.addToIndex(createRule("//:e", ImmutableSet.of(ruleG, ruleH)));
    ruleD = resolver.addToIndex(createRule("//:d", ImmutableSet.of(ruleG), ImmutableSet.of(ruleF)));
    ruleC = resolver.addToIndex(createRule("//:c", ImmutableSet.of(ruleD, ruleE)));
    ruleB = resolver.addToIndex(createRule("//:b", ImmutableSet.of(), ImmutableSet.of(ruleD)));
    ruleA = resolver.addToIndex(createRule("//:a", ImmutableSet.of(ruleD)));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeClock(com.facebook.buck.timing.FakeClock) Subscribe(com.google.common.eventbus.Subscribe) BuckEvent(com.facebook.buck.event.BuckEvent) AbstractBuckEvent(com.facebook.buck.event.AbstractBuckEvent) BuildId(com.facebook.buck.model.BuildId) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Before(org.junit.Before)

Example 23 with BuildId

use of com.facebook.buck.model.BuildId in project buck by facebook.

the class TargetGraphHashingTest method twoNodeIndependentRootsTargetGraphHasExpectedHashes.

@Test
public void twoNodeIndependentRootsTargetGraphHasExpectedHashes() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
    TargetNode<?, ?> nodeA = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//foo:lib"), HashCode.fromLong(64738), ImmutableSet.of(Paths.get("foo/FooLib.java")));
    TargetNode<?, ?> nodeB = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//bar:lib"), HashCode.fromLong(49152), ImmutableSet.of(Paths.get("bar/BarLib.java")));
    TargetGraph targetGraphA = TargetGraphFactory.newInstance(nodeA);
    TargetGraph targetGraphB = TargetGraphFactory.newInstance(nodeB);
    TargetGraph commonTargetGraph = TargetGraphFactory.newInstance(nodeA, nodeB);
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef"), projectFilesystem.resolve("bar/BarLib.java"), HashCode.fromString("123456")));
    Map<BuildTarget, HashCode> resultsA = new TargetGraphHashing(eventBus, targetGraphA, fileHashCache, ImmutableList.of(nodeA)).hashTargetGraph();
    Map<BuildTarget, HashCode> resultsB = new TargetGraphHashing(eventBus, targetGraphB, fileHashCache, ImmutableList.of(nodeB)).hashTargetGraph();
    Map<BuildTarget, HashCode> commonResults = new TargetGraphHashing(eventBus, commonTargetGraph, fileHashCache, ImmutableList.of(nodeA, nodeB)).hashTargetGraph();
    assertThat(resultsA, aMapWithSize(1));
    assertThat(resultsA, hasKey(nodeA.getBuildTarget()));
    assertThat(resultsB, aMapWithSize(1));
    assertThat(resultsB, hasKey(nodeB.getBuildTarget()));
    assertThat(commonResults, aMapWithSize(2));
    assertThat(commonResults, hasKey(nodeA.getBuildTarget()));
    assertThat(commonResults, hasKey(nodeB.getBuildTarget()));
    assertThat(resultsA.get(nodeA.getBuildTarget()), equalTo(commonResults.get(nodeA.getBuildTarget())));
    assertThat(resultsB.get(nodeB.getBuildTarget()), equalTo(commonResults.get(nodeB.getBuildTarget())));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) HashCode(com.google.common.hash.HashCode) BuildId(com.facebook.buck.model.BuildId) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Test(org.junit.Test)

Example 24 with BuildId

use of com.facebook.buck.model.BuildId in project buck by facebook.

the class TargetGraphHashingTest method emptyTargetGraphHasEmptyHashes.

@Test
public void emptyTargetGraphHasEmptyHashes() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
    BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
    TargetGraph targetGraph = TargetGraphFactory.newInstance();
    assertThat(new TargetGraphHashing(eventBus, targetGraph, new NullFileHashCache(), ImmutableList.of()).hashTargetGraph().entrySet(), empty());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Test(org.junit.Test)

Example 25 with BuildId

use of com.facebook.buck.model.BuildId in project buck by facebook.

the class FakeBuildEngineTest method buildRuleFutureHasResult.

@Test
public void buildRuleFutureHasResult() throws Exception {
    BuildTarget fakeBuildTarget = BuildTargetFactory.newInstance("//foo:bar");
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    FakeBuildRule fakeBuildRule = new FakeBuildRule(fakeBuildTarget, pathResolver);
    BuildResult fakeBuildResult = BuildResult.success(fakeBuildRule, BUILT_LOCALLY, CacheResult.miss());
    FakeBuildEngine fakeEngine = new FakeBuildEngine(ImmutableMap.of(fakeBuildTarget, fakeBuildResult), ImmutableMap.of(fakeBuildTarget, new RuleKey("00")));
    assertThat(fakeEngine.build(BuildEngineBuildContext.builder().setBuildContext(FakeBuildContext.NOOP_CONTEXT).setArtifactCache(new NoopArtifactCache()).setBuildId(new BuildId()).setObjectMapper(ObjectMappers.newDefaultInstance()).setClock(new DefaultClock()).build(), TestExecutionContext.newInstance(), fakeBuildRule).get(), equalTo(fakeBuildResult));
}
Also used : NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) BuildId(com.facebook.buck.model.BuildId) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultClock(com.facebook.buck.timing.DefaultClock) Test(org.junit.Test)

Aggregations

BuildId (com.facebook.buck.model.BuildId)41 Test (org.junit.Test)25 BuckEventBus (com.facebook.buck.event.BuckEventBus)22 Path (java.nio.file.Path)13 FakeClock (com.facebook.buck.timing.FakeClock)12 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)10 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 IOException (java.io.IOException)8 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)7 BuildTarget (com.facebook.buck.model.BuildTarget)6 Before (org.junit.Before)6 DefaultClock (com.facebook.buck.timing.DefaultClock)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ArtifactCache (com.facebook.buck.artifact_cache.ArtifactCache)4 BuildRuleDurationTracker (com.facebook.buck.rules.BuildRuleDurationTracker)4 Clock (com.facebook.buck.timing.Clock)4 NullFileHashCache (com.facebook.buck.util.cache.NullFileHashCache)4 ImmutableList (com.google.common.collect.ImmutableList)4 RuleKey (com.facebook.buck.rules.RuleKey)3 FakeExecutor (com.facebook.buck.testutil.FakeExecutor)3