Search in sources :

Example 16 with IncrementingFakeClock

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

the class TargetGraphHashingTest method hashChangesForDependentNodeWhenDepsChange.

@Test
public void hashChangesForDependentNodeWhenDepsChange() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
    BuildTarget nodeTarget = BuildTargetFactory.newInstance("//foo:lib");
    BuildTarget depTarget = BuildTargetFactory.newInstance("//dep:lib");
    TargetGraph targetGraphA = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(64738));
    TargetGraph targetGraphB = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(84552));
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef"), projectFilesystem.resolve("dep/DepLib.java"), HashCode.fromString("123456")));
    Map<BuildTarget, HashCode> resultA = new TargetGraphHashing(eventBus, targetGraphA, fileHashCache, ImmutableList.of(targetGraphA.get(nodeTarget))).hashTargetGraph();
    Map<BuildTarget, HashCode> resultB = new TargetGraphHashing(eventBus, targetGraphB, fileHashCache, ImmutableList.of(targetGraphB.get(nodeTarget))).hashTargetGraph();
    assertThat(resultA, aMapWithSize(2));
    assertThat(resultA, hasKey(nodeTarget));
    assertThat(resultA, hasKey(depTarget));
    assertThat(resultB, aMapWithSize(2));
    assertThat(resultB, hasKey(nodeTarget));
    assertThat(resultB, hasKey(depTarget));
    assertThat(resultA.get(nodeTarget), not(equalTo(resultB.get(nodeTarget))));
    assertThat(resultA.get(depTarget), not(equalTo(resultB.get(depTarget))));
}
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 17 with IncrementingFakeClock

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

the class DefaultRuleKeyCacheTest method testLoadTime.

@Test
public void testLoadTime() {
    Clock clock = new IncrementingFakeClock();
    DefaultRuleKeyCache<Void> cache = new DefaultRuleKeyCache<>(clock);
    TestRule rule = new TestRule();
    RuleKeyInput input = RuleKeyInput.of(FILESYSTEM, FILESYSTEM.getPath("input"));
    cache.get(rule, r -> new RuleKeyResult<>(null, ImmutableList.of(), ImmutableList.of(input)));
    cache.invalidateInputs(ImmutableList.of(input));
    assertThat(cache.getStats().totalLoadTime(), Matchers.equalTo(1L));
}
Also used : IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Clock(com.facebook.buck.timing.Clock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Test(org.junit.Test)

Example 18 with IncrementingFakeClock

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

the class TouchStepTest method testFileGetsCreated.

@Test
public void testFileGetsCreated() throws IOException, InterruptedException {
    Path path = Paths.get("somefile");
    assertFalse(path.toFile().exists());
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem(new IncrementingFakeClock(TimeUnit.MILLISECONDS.toNanos(1)), tmp.getRoot(), ImmutableSet.of());
    TouchStep touchStep = new TouchStep(projectFilesystem, path);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    touchStep.execute(executionContext);
    assertTrue(projectFilesystem.exists(path));
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 19 with IncrementingFakeClock

use of com.facebook.buck.timing.IncrementingFakeClock 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 20 with IncrementingFakeClock

use of com.facebook.buck.timing.IncrementingFakeClock 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)

Aggregations

IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)30 Test (org.junit.Test)29 BuckEventBus (com.facebook.buck.event.BuckEventBus)25 Clock (com.facebook.buck.timing.Clock)20 BuildTarget (com.facebook.buck.model.BuildTarget)15 BuildEvent (com.facebook.buck.rules.BuildEvent)11 ActionGraphEvent (com.facebook.buck.event.ActionGraphEvent)10 ParseEvent (com.facebook.buck.parser.ParseEvent)10 ConsoleTestUtils.postStoreFinished (com.facebook.buck.event.listener.ConsoleTestUtils.postStoreFinished)9 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)9 RuleKey (com.facebook.buck.rules.RuleKey)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)9 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)9 BuildRuleEvent (com.facebook.buck.rules.BuildRuleEvent)8 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)8 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)8 BuildId (com.facebook.buck.model.BuildId)7 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)7 UUID (java.util.UUID)7 StepEvent (com.facebook.buck.step.StepEvent)6