use of com.facebook.buck.timing.IncrementingFakeClock in project buck by facebook.
the class SuperConsoleEventBusListenerTest method debugConsoleEventShouldNotPrintLogLineToConsole.
@Test
public void debugConsoleEventShouldNotPrintLogLineToConsole() {
Clock fakeClock = new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1));
BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock);
SuperConsoleEventBusListener listener = createSuperConsole(fakeClock, eventBus);
eventBus.postWithoutConfiguring(configureTestEventAtTime(ConsoleEvent.fine("I'll get you Bluths - Hel-loh"), 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 0L, ImmutableList.of());
}
use of com.facebook.buck.timing.IncrementingFakeClock in project buck by facebook.
the class SuperConsoleEventBusListenerTest method testPostingEventBeforeAnyLines.
@Test
public void testPostingEventBeforeAnyLines() {
Clock fakeClock = new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1));
BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock);
SuperConsoleEventBusListener listener = createSuperConsole(fakeClock, eventBus);
eventBus.post(ConsoleEvent.info("Hello world!"));
validateConsoleWithLogLines(listener, 0L, ImmutableList.of(), ImmutableList.of("Hello world!"));
eventBus.postWithoutConfiguring(configureTestEventAtTime(ProjectGenerationEvent.started(), 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
validateConsole(listener, 0L, ImmutableList.of("[+] GENERATING PROJECT...0.0s"));
eventBus.postWithoutConfiguring(configureTestEventAtTime(new ProjectGenerationEvent.Finished(), 0L, TimeUnit.MILLISECONDS, 0L));
validateConsole(listener, 0L, ImmutableList.of("[-] GENERATING PROJECT...FINISHED 0.0s"));
}
use of com.facebook.buck.timing.IncrementingFakeClock in project buck by facebook.
the class SuperConsoleEventBusListenerTest method testBuildRuleSuspendResumeEvents.
@Test
public void testBuildRuleSuspendResumeEvents() {
Clock fakeClock = new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1));
BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock);
SuperConsoleEventBusListener listener = createSuperConsole(fakeClock, eventBus);
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
BuildTarget fakeTarget = BuildTargetFactory.newInstance("//banana:stand");
ImmutableSet<BuildTarget> buildTargets = ImmutableSet.of(fakeTarget);
Iterable<String> buildArgs = Iterables.transform(buildTargets, Object::toString);
FakeBuildRule fakeRule = new FakeBuildRule(fakeTarget, pathResolver, ImmutableSortedSet.of());
String stepShortName = "doing_something";
String stepDescription = "working hard";
UUID stepUuid = UUID.randomUUID();
FakeRuleKeyFactory ruleKeyFactory = new FakeRuleKeyFactory(ImmutableMap.of(fakeTarget, new RuleKey("aaaa")));
// Start the build.
BuildEvent.Started buildEventStarted = BuildEvent.started(buildArgs);
eventBus.postWithoutConfiguring(configureTestEventAtTime(buildEventStarted, 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Start and stop parsing.
String parsingLine = "[-] PROCESSING BUCK FILES...FINISHED 0.0s";
ParseEvent.Started parseStarted = ParseEvent.started(buildTargets);
eventBus.postWithoutConfiguring(configureTestEventAtTime(parseStarted, 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
eventBus.postWithoutConfiguring(configureTestEventAtTime(ParseEvent.finished(parseStarted, Optional.empty()), 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
eventBus.postWithoutConfiguring(configureTestEventAtTime(ActionGraphEvent.finished(ActionGraphEvent.started()), 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Start the rule.
BuildRuleEvent.Started started = BuildRuleEvent.started(fakeRule, durationTracker);
eventBus.postWithoutConfiguring(configureTestEventAtTime(started, 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Post events that run a step for 100ms.
StepEvent.Started stepEventStarted = StepEvent.started(stepShortName, stepDescription, stepUuid);
eventBus.postWithoutConfiguring(configureTestEventAtTime(stepEventStarted, 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
eventBus.postWithoutConfiguring(configureTestEventAtTime(StepEvent.finished(stepEventStarted, /* exitCode */
0), 100L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Suspend the rule.
BuildRuleEvent.Suspended suspended = BuildRuleEvent.suspended(started, ruleKeyFactory);
eventBus.postWithoutConfiguring(configureTestEventAtTime(suspended, 100L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Verify that the rule isn't printed now that it's suspended.
validateConsole(listener, 200L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.2s", " |=> IDLE"));
// Resume the rule.
BuildRuleEvent.Resumed resumed = BuildRuleEvent.resumed(fakeRule, durationTracker, ruleKeyFactory);
eventBus.postWithoutConfiguring(configureTestEventAtTime(resumed, 300L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Verify that we print "checking local..." now that we've resumed, and that we're accounting
// for previous running time.
validateConsole(listener, 300L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.3s", " |=> //banana:stand... 0.1s (checking_cache)"));
// Post events that run another step.
StepEvent.Started step2EventStarted = StepEvent.started(stepShortName, stepDescription, stepUuid);
eventBus.postWithoutConfiguring(configureTestEventAtTime(step2EventStarted, 400L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Verify the current console now accounts for the step.
validateConsole(listener, 500L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.5s", " |=> //banana:stand... 0.3s (running doing_something[0.1s])"));
// Finish the step and rule.
eventBus.postWithoutConfiguring(configureTestEventAtTime(StepEvent.finished(step2EventStarted, /* exitCode */
0), 600L, TimeUnit.MILLISECONDS, /* threadId */
0L));
eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleEvent.finished(resumed, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()), 600L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Verify that the rule isn't printed now that it's finally finished..
validateConsole(listener, 700L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.7s", " |=> IDLE"));
}
use of com.facebook.buck.timing.IncrementingFakeClock in project buck by facebook.
the class TouchStepTest method testFileLastModifiedTimeUpdated.
@Test
public void testFileLastModifiedTimeUpdated() throws IOException, InterruptedException {
Path path = Paths.get("somefile");
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem(new IncrementingFakeClock(TimeUnit.MILLISECONDS.toNanos(1)), tmp.getRoot(), ImmutableSet.of(path));
long lastModifiedTime = projectFilesystem.getLastModifiedTime(path);
TouchStep touchStep = new TouchStep(projectFilesystem, path);
ExecutionContext executionContext = TestExecutionContext.newInstance();
touchStep.execute(executionContext);
assertTrue(projectFilesystem.exists(path));
assertTrue(lastModifiedTime < projectFilesystem.getLastModifiedTime(path));
}
use of com.facebook.buck.timing.IncrementingFakeClock in project buck by facebook.
the class DuplicateResourcesTest method getAaptStepShellCommand.
private ImmutableList<String> getAaptStepShellCommand(TargetNode<AndroidBinaryDescription.Arg, AndroidBinaryDescription> binary) {
TargetGraph targetGraph = TargetGraphFactory.newInstance(binary, mainRes, directDepRes, transitiveDepRes, transitiveDepLib, bottomDepRes, library, keystore);
ActionGraphAndResolver actionGraphAndResolver = ActionGraphCache.getFreshActionGraph(BuckEventBusFactory.newInstance(new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1))), new DefaultTargetNodeToBuildRuleTransformer(), targetGraph);
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(actionGraphAndResolver.getResolver()));
ImmutableSet<ImmutableList<Step>> ruleSteps = RichStream.from(actionGraphAndResolver.getActionGraph().getNodes()).filter(AaptPackageResources.class).filter(r -> androidBinaryTarget.getUnflavoredBuildTarget().equals(r.getBuildTarget().getUnflavoredBuildTarget())).map(b -> b.getBuildSteps(FakeBuildContext.withSourcePathResolver(pathResolver), new FakeBuildableContext())).map(steps -> steps.stream().filter(step -> step instanceof AaptStep).collect(MoreCollectors.toImmutableList())).filter(steps -> !steps.isEmpty()).collect(MoreCollectors.toImmutableSet());
assertEquals(1, ruleSteps.size());
assertEquals(1, Iterables.getOnlyElement(ruleSteps).size());
AaptStep step = (AaptStep) Iterables.getOnlyElement(Iterables.getOnlyElement(ruleSteps));
AndroidDirectoryResolver androidDirectoryResolver = new FakeAndroidDirectoryResolver(Optional.of(filesystem.getPath("/android-sdk")), Optional.of(filesystem.getPath("/android-build-tools")), Optional.empty(), Optional.empty());
AndroidPlatformTarget androidPlatformTarget = AndroidPlatformTarget.createFromDefaultDirectoryStructure("", androidDirectoryResolver, "", ImmutableSet.of(), Optional.empty());
ExecutionContext context = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatformTarget)).build();
return step.getShellCommand(context);
}
Aggregations