Search in sources :

Example 56 with BuckEventBus

use of com.facebook.buck.event.BuckEventBus in project buck by facebook.

the class ArtifactCachesTest method testCreateBoth.

@Test
public void testCreateBoth() throws Exception {
    ArtifactCacheBuckConfig cacheConfig = ArtifactCacheBuckConfigTest.createFromText("[cache]", "mode = dir, http");
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
    ArtifactCache artifactCache = new ArtifactCaches(cacheConfig, buckEventBus, projectFilesystem, Optional.empty(), MoreExecutors.newDirectExecutorService(), Optional.empty()).newInstance();
    assertThat(stripDecorators(artifactCache), Matchers.instanceOf(MultiArtifactCache.class));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Test(org.junit.Test)

Example 57 with BuckEventBus

use of com.facebook.buck.event.BuckEventBus in project buck by facebook.

the class DistBuildStateTest method createDefaultCodec.

public static DistBuildTargetGraphCodec createDefaultCodec(final Cell cell, final Optional<Parser> parser) {
    // NOPMD confused by lambda
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    Function<? super TargetNode<?, ?>, ? extends Map<String, Object>> nodeToRawNode;
    if (parser.isPresent()) {
        nodeToRawNode = (Function<TargetNode<?, ?>, Map<String, Object>>) input -> {
            try {
                return parser.get().getRawTargetNode(eventBus, cell.getCell(input.getBuildTarget()), false, MoreExecutors.listeningDecorator(MoreExecutors.newDirectExecutorService()), input);
            } catch (BuildFileParseException e) {
                throw new RuntimeException(e);
            }
        };
    } else {
        nodeToRawNode = Functions.constant(ImmutableMap.<String, Object>of());
    }
    DistBuildTypeCoercerFactory typeCoercerFactory = new DistBuildTypeCoercerFactory(objectMapper);
    ParserTargetNodeFactory<TargetNode<?, ?>> parserTargetNodeFactory = DefaultParserTargetNodeFactory.createForDistributedBuild(new ConstructorArgMarshaller(typeCoercerFactory), new TargetNodeFactory(typeCoercerFactory));
    return new DistBuildTargetGraphCodec(objectMapper, parserTargetNodeFactory, nodeToRawNode, ImmutableSet.of());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) ActionGraph(com.facebook.buck.rules.ActionGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ObjectMappers(com.facebook.buck.util.ObjectMappers) TestDataHelper(com.facebook.buck.testutil.integration.TestDataHelper) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) Assert.assertThat(org.junit.Assert.assertThat) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuckConfig(com.facebook.buck.cli.BuckConfig) TargetNodeFactory(com.facebook.buck.rules.TargetNodeFactory) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) Cell(com.facebook.buck.rules.Cell) Path(java.nio.file.Path) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Platform(com.facebook.buck.util.environment.Platform) DefaultParserTargetNodeFactory(com.facebook.buck.parser.DefaultParserTargetNodeFactory) DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) BuildTarget(com.facebook.buck.model.BuildTarget) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) KnownBuildRuleTypesFactory(com.facebook.buck.rules.KnownBuildRuleTypesFactory) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) BuckEventBus(com.facebook.buck.event.BuckEventBus) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) Config(com.facebook.buck.config.Config) TemporaryPaths(com.facebook.buck.testutil.integration.TemporaryPaths) BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) Lists(com.google.common.collect.Lists) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) ParserConfig(com.facebook.buck.parser.ParserConfig) ImmutableList(com.google.common.collect.ImmutableList) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ExpectedException(org.junit.rules.ExpectedException) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Functions(com.google.common.base.Functions) Parser(com.facebook.buck.parser.Parser) TargetNode(com.facebook.buck.rules.TargetNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) Architecture(com.facebook.buck.util.environment.Architecture) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) ConfigBuilder(com.facebook.buck.config.ConfigBuilder) ParserTargetNodeFactory(com.facebook.buck.parser.ParserTargetNodeFactory) Rule(org.junit.Rule) TestConsole(com.facebook.buck.testutil.TestConsole) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Preconditions(com.google.common.base.Preconditions) Assert.assertEquals(org.junit.Assert.assertEquals) TargetNode(com.facebook.buck.rules.TargetNode) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) TargetNodeFactory(com.facebook.buck.rules.TargetNodeFactory) DefaultParserTargetNodeFactory(com.facebook.buck.parser.DefaultParserTargetNodeFactory) ParserTargetNodeFactory(com.facebook.buck.parser.ParserTargetNodeFactory) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 58 with BuckEventBus

use of com.facebook.buck.event.BuckEventBus in project buck by facebook.

the class SimpleConsoleEventBusListenerTest method testBuildTimeDoesNotDisplayNegativeOffset.

@Test
public void testBuildTimeDoesNotDisplayNegativeOffset() {
    Clock fakeClock = new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1));
    BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock);
    TestConsole console = new TestConsole();
    BuildTarget fakeTarget = BuildTargetFactory.newInstance("//banana:stand");
    ImmutableSet<BuildTarget> buildTargets = ImmutableSet.of(fakeTarget);
    Iterable<String> buildArgs = Iterables.transform(buildTargets, Object::toString);
    SimpleConsoleEventBusListener listener = new SimpleConsoleEventBusListener(console, fakeClock, TestResultSummaryVerbosity.of(false, false), Locale.US, logPath, new DefaultExecutionEnvironment(ImmutableMap.copyOf(System.getenv()), System.getProperties()));
    eventBus.register(listener);
    // Do a full parse and action graph cycle before the build event starts
    // This sequencing occurs when running `buck project`
    ParseEvent.Started parseStarted = ParseEvent.started(buildTargets);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(parseStarted, 100L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ParseEvent.finished(parseStarted, Optional.empty()), 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    String expectedOutput = "[-] PARSING BUCK FILES...FINISHED 0.2s\n";
    assertOutput(expectedOutput, console);
    ActionGraphEvent.Started actionGraphStarted = ActionGraphEvent.started();
    eventBus.postWithoutConfiguring(configureTestEventAtTime(actionGraphStarted, 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ActionGraphEvent.finished(actionGraphStarted), 500L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    BuildEvent.Started buildEventStarted = BuildEvent.started(buildArgs);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(buildEventStarted, 500L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildEvent.finished(buildEventStarted, 0), 600L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    expectedOutput += "[-] BUILDING...FINISHED 0.1s\n";
    assertOutput(expectedOutput, console);
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) DefaultExecutionEnvironment(com.facebook.buck.util.environment.DefaultExecutionEnvironment) ActionGraphEvent(com.facebook.buck.event.ActionGraphEvent) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Clock(com.facebook.buck.timing.Clock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) BuildTarget(com.facebook.buck.model.BuildTarget) BuildEvent(com.facebook.buck.rules.BuildEvent) ParseEvent(com.facebook.buck.parser.ParseEvent) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 59 with BuckEventBus

use of com.facebook.buck.event.BuckEventBus in project buck by facebook.

the class SuperConsoleEventBusListenerTest method testSimpleBuild.

@Test
public void testSimpleBuild() {
    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");
    BuildTarget cachedTarget = BuildTargetFactory.newInstance("//chicken:dance");
    ImmutableSet<BuildTarget> buildTargets = ImmutableSet.of(fakeTarget, cachedTarget);
    Iterable<String> buildArgs = Iterables.transform(buildTargets, Object::toString);
    FakeBuildRule fakeRule = new FakeBuildRule(fakeTarget, pathResolver, ImmutableSortedSet.of());
    FakeBuildRule cachedRule = new FakeBuildRule(cachedTarget, pathResolver, ImmutableSortedSet.of());
    ProjectBuildFileParseEvents.Started parseEventStarted = new ProjectBuildFileParseEvents.Started();
    eventBus.postWithoutConfiguring(configureTestEventAtTime(parseEventStarted, 0L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 0L, ImmutableList.of("[+] PARSING BUCK FILES...0.0s"));
    validateConsole(listener, 100L, ImmutableList.of("[+] PARSING BUCK FILES...0.1s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(new ProjectBuildFileParseEvents.Finished(parseEventStarted), 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 200L, ImmutableList.of("[-] PARSING BUCK FILES...FINISHED 0.2s"));
    BuildEvent.Started buildEventStarted = BuildEvent.started(buildArgs);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(buildEventStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    ParseEvent.Started parseStarted = ParseEvent.started(buildTargets);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(parseStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 300L, ImmutableList.of("[+] PROCESSING BUCK FILES...0.1s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ParseEvent.finished(parseStarted, Optional.empty()), 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    ActionGraphEvent.Started actionGraphStarted = ActionGraphEvent.started();
    eventBus.postWithoutConfiguring(configureTestEventAtTime(actionGraphStarted, 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ActionGraphEvent.finished(actionGraphStarted), 400L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String parsingLine = "[-] PROCESSING BUCK FILES...FINISHED 0.2s";
    validateConsole(listener, 540L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.1s"));
    BuildRuleEvent.Started started = BuildRuleEvent.started(fakeRule, durationTracker);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(started, 600L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 700L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.3s", " |=> //banana:stand...  0.1s (checking_cache)"));
    BuildRuleCacheEvent.CacheStepStarted cacheStepStarted = BuildRuleCacheEvent.started(fakeRule, BuildRuleCacheEvent.CacheStepType.INPUT_BASED);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(cacheStepStarted, 701L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 701L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.3s", " |=> //banana:stand...  0.1s (running checking_cache_input_based[0.0s])"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleCacheEvent.finished(cacheStepStarted), 702L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 702L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.3s", " |=> //banana:stand...  0.1s (checking_cache)"));
    ArtifactCompressionEvent.Started compressStarted = ArtifactCompressionEvent.started(ArtifactCompressionEvent.Operation.COMPRESS, ImmutableSet.of());
    eventBus.postWithoutConfiguring(configureTestEventAtTime(compressStarted, 703L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 703L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.3s", " |=> //banana:stand...  0.1s (running artifact_compress[0.0s])"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ArtifactCompressionEvent.finished(compressStarted), 704L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 705L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.3s", " |=> //banana:stand...  0.1s (checking_cache)"));
    DirArtifactCacheEvent.DirArtifactCacheEventFactory dirArtifactCacheEventFactory = new DirArtifactCacheEvent.DirArtifactCacheEventFactory();
    ArtifactCacheEvent.Started dirFetchStarted = dirArtifactCacheEventFactory.newFetchStartedEvent(ImmutableSet.of());
    eventBus.postWithoutConfiguring(configureTestEventAtTime(dirFetchStarted, 740L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 741L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.3s", " |=> //banana:stand...  0.1s (running dir_artifact_fetch[0.0s])"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(dirArtifactCacheEventFactory.newFetchFinishedEvent(dirFetchStarted, CacheResult.hit("dir")), 742L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 800L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.4s", " |=> //banana:stand...  0.2s (checking_cache)"));
    String stepShortName = "doing_something";
    String stepDescription = "working hard";
    UUID stepUuid = UUID.randomUUID();
    StepEvent.Started stepEventStarted = StepEvent.started(stepShortName, stepDescription, stepUuid);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(stepEventStarted, 800L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 900L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.5s", " |=> //banana:stand...  0.3s (running doing_something[0.1s])"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(StepEvent.finished(stepEventStarted, 0), 900L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleEvent.finished(started, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()), 1000L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 1000L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.6s", " |=> IDLE"));
    BuildRuleEvent.Started startedCached = BuildRuleEvent.started(cachedRule, durationTracker);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(startedCached, 1010L, TimeUnit.MILLISECONDS, /* threadId */
    2L));
    validateConsole(listener, 1100L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.7s", " |=> IDLE", " |=> //chicken:dance...  0.1s (checking_cache)"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleEvent.finished(startedCached, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()), 1120L, TimeUnit.MILLISECONDS, /* threadId */
    2L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildEvent.finished(buildEventStarted, 0), 1234L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String buildingLine = "[-] BUILDING...FINISHED 0.8s";
    validateConsole(listener, 1300L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ConsoleEvent.severe(SEVERE_MESSAGE), 1500L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsoleWithLogLines(listener, 1600L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine), ImmutableList.of(SEVERE_MESSAGE));
    InstallEvent.Started installEventStarted = InstallEvent.started(fakeTarget);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(installEventStarted, 2500L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3000L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] INSTALLING...0.5s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(InstallEvent.finished(installEventStarted, true, Optional.empty(), Optional.empty()), 4000L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String installingFinished = "[-] INSTALLING...FINISHED 1.5s";
    validateConsole(listener, 5000L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, installingFinished));
    HttpArtifactCacheEvent.Scheduled storeScheduledOne = postStoreScheduled(eventBus, 0L, TARGET_ONE, 6000L);
    HttpArtifactCacheEvent.Scheduled storeScheduledTwo = postStoreScheduled(eventBus, 0L, TARGET_TWO, 6010L);
    HttpArtifactCacheEvent.Scheduled storeScheduledThree = postStoreScheduled(eventBus, 0L, TARGET_THREE, 6020L);
    validateConsole(listener, 6021L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, installingFinished, "[+] HTTP CACHE UPLOAD...0.00 B (0 COMPLETE/0 FAILED/0 UPLOADING/3 PENDING)"));
    HttpArtifactCacheEvent.Started storeStartedOne = postStoreStarted(eventBus, 0, 6025L, storeScheduledOne);
    validateConsole(listener, 7000, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, installingFinished, "[+] HTTP CACHE UPLOAD...0.00 B (0 COMPLETE/0 FAILED/1 UPLOADING/2 PENDING)"));
    long artifactSizeOne = SizeUnit.KILOBYTES.toBytes(1.5);
    postStoreFinished(eventBus, 0, artifactSizeOne, 7020L, true, storeStartedOne);
    validateConsole(listener, 7020, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, installingFinished, "[+] HTTP CACHE UPLOAD...1.50 KB (1 COMPLETE/0 FAILED/0 UPLOADING/2 PENDING)"));
    HttpArtifactCacheEvent.Started storeStartedTwo = postStoreStarted(eventBus, 0, 7030L, storeScheduledTwo);
    long artifactSizeTwo = SizeUnit.KILOBYTES.toBytes(1.6);
    postStoreFinished(eventBus, 0, artifactSizeTwo, 7030L, false, storeStartedTwo);
    validateConsole(listener, 7040, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, installingFinished, "[+] HTTP CACHE UPLOAD...1.50 KB (1 COMPLETE/1 FAILED/0 UPLOADING/1 PENDING)"));
    HttpArtifactCacheEvent.Started storeStartedThree = postStoreStarted(eventBus, 0, 7040L, storeScheduledThree);
    long artifactSizeThree = SizeUnit.KILOBYTES.toBytes(0.6);
    postStoreFinished(eventBus, 0, artifactSizeThree, 7040L, true, storeStartedThree);
    validateConsole(listener, 7040, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, installingFinished, "[+] HTTP CACHE UPLOAD...2.10 KB (2 COMPLETE/1 FAILED/0 UPLOADING/0 PENDING)"));
    listener.render();
    TestConsole console = (TestConsole) listener.console;
    String beforeStderrWrite = console.getTextWrittenToStdErr();
    console.getStdErr().print("ROFLCOPTER");
    listener.render();
    assertEquals("After stderr is written to by someone other than SuperConsole, rendering " + "should be a noop.", beforeStderrWrite + "ROFLCOPTER", console.getTextWrittenToStdErr());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ConsoleTestUtils.postStoreStarted(com.facebook.buck.event.listener.ConsoleTestUtils.postStoreStarted) ProjectBuildFileParseEvents(com.facebook.buck.json.ProjectBuildFileParseEvents) 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) ConsoleTestUtils.postStoreFinished(com.facebook.buck.event.listener.ConsoleTestUtils.postStoreFinished) StepEvent(com.facebook.buck.step.StepEvent) RuleKey(com.facebook.buck.rules.RuleKey) DirArtifactCacheEvent(com.facebook.buck.artifact_cache.DirArtifactCacheEvent) ActionGraphEvent(com.facebook.buck.event.ActionGraphEvent) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) ArtifactCompressionEvent(com.facebook.buck.event.ArtifactCompressionEvent) InstallEvent(com.facebook.buck.event.InstallEvent) DirArtifactCacheEvent(com.facebook.buck.artifact_cache.DirArtifactCacheEvent) ArtifactCacheEvent(com.facebook.buck.artifact_cache.ArtifactCacheEvent) HttpArtifactCacheEvent(com.facebook.buck.artifact_cache.HttpArtifactCacheEvent) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildEvent(com.facebook.buck.rules.BuildEvent) ParseEvent(com.facebook.buck.parser.ParseEvent) BuildRuleEvent(com.facebook.buck.rules.BuildRuleEvent) HttpArtifactCacheEvent(com.facebook.buck.artifact_cache.HttpArtifactCacheEvent) TestConsole(com.facebook.buck.testutil.TestConsole) BuildRuleCacheEvent(com.facebook.buck.rules.BuildRuleCacheEvent) Test(org.junit.Test)

Example 60 with BuckEventBus

use of com.facebook.buck.event.BuckEventBus in project buck by facebook.

the class SuperConsoleEventBusListenerTest method testSimpleBuildWithProgress.

@Test
public void testSimpleBuildWithProgress() throws IOException {
    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");
    BuildTarget cachedTarget = BuildTargetFactory.newInstance("//chicken:dance");
    ImmutableSet<BuildTarget> buildTargets = ImmutableSet.of(fakeTarget, cachedTarget);
    Iterable<String> buildArgs = Iterables.transform(buildTargets, Object::toString);
    FakeBuildRule fakeRule = new FakeBuildRule(fakeTarget, pathResolver, ImmutableSortedSet.of());
    FakeBuildRule cachedRule = new FakeBuildRule(cachedTarget, pathResolver, ImmutableSortedSet.of());
    ProgressEstimator e = new ProgressEstimator(getStorageForTest(), eventBus, ObjectMappers.newDefaultInstance());
    listener.setProgressEstimator(e);
    eventBus.register(listener);
    BuildEvent.RuleCountCalculated ruleCountCalculated = BuildEvent.ruleCountCalculated(ImmutableSet.of(), 10);
    eventBus.post(ruleCountCalculated);
    BuildEvent.Started buildEventStarted = BuildEvent.started(buildArgs);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(buildEventStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    ParseEvent.Started parseStarted = ParseEvent.started(buildTargets);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(parseStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 300L, ImmutableList.of("[+] PROCESSING BUCK FILES...0.1s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ParseEvent.finished(parseStarted, Optional.empty()), 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    ActionGraphEvent.Started actionGraphStarted = ActionGraphEvent.started();
    eventBus.postWithoutConfiguring(configureTestEventAtTime(actionGraphStarted, 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ActionGraphEvent.finished(actionGraphStarted), 400L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String parsingLine = "[-] PROCESSING BUCK FILES...FINISHED 0.2s";
    validateConsole(listener, 540L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.1s" + " [0%] (0/10 JOBS, 0 UPDATED, " + "0 [0.0%] CACHE MISS)"));
    BuildRuleEvent.Started started = BuildRuleEvent.started(fakeRule, durationTracker);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(started, 600L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 800L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.4s" + " [0%] (0/10 JOBS, 0 UPDATED, " + "0 [0.0%] CACHE MISS)", " |=> //banana:stand...  0.2s (checking_cache)"));
    String stepShortName = "doing_something";
    String stepDescription = "working hard";
    UUID stepUuid = UUID.randomUUID();
    StepEvent.Started stepEventStarted = StepEvent.started(stepShortName, stepDescription, stepUuid);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(stepEventStarted, 800L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 900L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.5s" + " [0%] (0/10 JOBS, 0 UPDATED, " + "0 [0.0%] CACHE MISS)", " |=> //banana:stand...  0.3s (running doing_something[0.1s])"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(StepEvent.finished(stepEventStarted, 0), 900L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleEvent.finished(started, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()), 1000L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 1000L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.6s [10%] (1/10 JOBS, 1 UPDATED, 1 [10.0%] CACHE MISS)", " |=> IDLE"));
    BuildRuleEvent.Started startedCached = BuildRuleEvent.started(cachedRule, durationTracker);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(startedCached, 1010L, TimeUnit.MILLISECONDS, /* threadId */
    2L));
    validateConsole(listener, 1100L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.7s [10%] (1/10 JOBS, 1 UPDATED, 1 [10.0%] CACHE MISS)", " |=> IDLE", " |=> //chicken:dance...  0.1s (checking_cache)"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleEvent.finished(startedCached, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()), 1120L, TimeUnit.MILLISECONDS, /* threadId */
    2L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildEvent.finished(buildEventStarted, 0), 1234L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String buildingLine = "[-] BUILDING...FINISHED 0.8s" + " [100%] (2/10 JOBS, 2 UPDATED, 2 [20.0%] CACHE MISS)";
    validateConsole(listener, 1300L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine));
}
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) RuleKey(com.facebook.buck.rules.RuleKey) ActionGraphEvent(com.facebook.buck.event.ActionGraphEvent) 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)

Aggregations

BuckEventBus (com.facebook.buck.event.BuckEventBus)75 Test (org.junit.Test)58 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)25 BuildId (com.facebook.buck.model.BuildId)21 Clock (com.facebook.buck.timing.Clock)21 FakeClock (com.facebook.buck.timing.FakeClock)20 BuildTarget (com.facebook.buck.model.BuildTarget)19 TestConsole (com.facebook.buck.testutil.TestConsole)16 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)15 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)15 Path (java.nio.file.Path)13 IOException (java.io.IOException)12 BuildEvent (com.facebook.buck.rules.BuildEvent)11 ParseEvent (com.facebook.buck.parser.ParseEvent)10 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)10 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)10 RuleKey (com.facebook.buck.rules.RuleKey)10 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)10 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)10 ActionGraphEvent (com.facebook.buck.event.ActionGraphEvent)9