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