Search in sources :

Example 26 with IncrementingFakeClock

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());
}
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) Test(org.junit.Test)

Example 27 with IncrementingFakeClock

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"));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ConsoleTestUtils.postStoreFinished(com.facebook.buck.event.listener.ConsoleTestUtils.postStoreFinished) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Clock(com.facebook.buck.timing.Clock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Test(org.junit.Test)

Example 28 with IncrementingFakeClock

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"));
}
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 29 with IncrementingFakeClock

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));
}
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 30 with IncrementingFakeClock

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);
}
Also used : Iterables(com.google.common.collect.Iterables) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) Step(com.facebook.buck.step.Step) Assume.assumeFalse(org.junit.Assume.assumeFalse) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) RichStream(com.facebook.buck.util.RichStream) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) ArrayList(java.util.ArrayList) Assert.assertThat(org.junit.Assert.assertThat) KeystoreBuilder(com.facebook.buck.jvm.java.KeystoreBuilder) ExecutionContext(com.facebook.buck.step.ExecutionContext) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ImmutableList(com.google.common.collect.ImmutableList) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Suppliers(com.google.common.base.Suppliers) ActionGraphCache(com.facebook.buck.rules.ActionGraphCache) MoreCollectors(com.facebook.buck.util.MoreCollectors) Before(org.junit.Before) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) TargetGraph(com.facebook.buck.rules.TargetGraph) TargetNode(com.facebook.buck.rules.TargetNode) Platform(com.facebook.buck.util.environment.Platform) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) BuildTarget(com.facebook.buck.model.BuildTarget) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) Matcher(org.hamcrest.Matcher) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Optional(java.util.Optional) Assert.assertEquals(org.junit.Assert.assertEquals) KeystoreDescription(com.facebook.buck.jvm.java.KeystoreDescription) Joiner(com.google.common.base.Joiner) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) ImmutableList(com.google.common.collect.ImmutableList) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)

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