Search in sources :

Example 1 with FakeRuleKeyFactory

use of com.facebook.buck.rules.keys.FakeRuleKeyFactory 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"));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Clock(com.facebook.buck.timing.Clock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) UUID(java.util.UUID) StepEvent(com.facebook.buck.step.StepEvent) FakeRuleKeyFactory(com.facebook.buck.rules.keys.FakeRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildEvent(com.facebook.buck.rules.BuildEvent) ParseEvent(com.facebook.buck.parser.ParseEvent) BuildRuleEvent(com.facebook.buck.rules.BuildRuleEvent) Test(org.junit.Test)

Example 2 with FakeRuleKeyFactory

use of com.facebook.buck.rules.keys.FakeRuleKeyFactory in project buck by facebook.

the class BuildThreadStateRendererTest method createRuleBeginningEventOptional.

private static Optional<? extends BuildRuleEvent.BeginningBuildRuleEvent> createRuleBeginningEventOptional(long threadId, long timeMs, long durationMs, BuildRule rule) {
    BuildRuleDurationTracker durationTracker = new BuildRuleDurationTracker();
    durationTracker.setDuration(rule, new ClockDuration(durationMs, 0, 0));
    RuleKey ruleKey = new RuleKey(HashCode.fromString("aa"));
    return Optional.of(TestEventConfigurator.configureTestEventAtTime(BuildRuleEvent.resumed(rule, durationTracker, new FakeRuleKeyFactory(ImmutableMap.of(rule.getBuildTarget(), ruleKey))), timeMs, TimeUnit.MILLISECONDS, threadId));
}
Also used : FakeRuleKeyFactory(com.facebook.buck.rules.keys.FakeRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) ClockDuration(com.facebook.buck.timing.ClockDuration) BuildRuleDurationTracker(com.facebook.buck.rules.BuildRuleDurationTracker)

Aggregations

RuleKey (com.facebook.buck.rules.RuleKey)2 FakeRuleKeyFactory (com.facebook.buck.rules.keys.FakeRuleKeyFactory)2 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 ParseEvent (com.facebook.buck.parser.ParseEvent)1 BuildEvent (com.facebook.buck.rules.BuildEvent)1 BuildRuleDurationTracker (com.facebook.buck.rules.BuildRuleDurationTracker)1 BuildRuleEvent (com.facebook.buck.rules.BuildRuleEvent)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)1 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)1 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 StepEvent (com.facebook.buck.step.StepEvent)1 Clock (com.facebook.buck.timing.Clock)1 ClockDuration (com.facebook.buck.timing.ClockDuration)1 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)1 UUID (java.util.UUID)1 Test (org.junit.Test)1