Search in sources :

Example 1 with EventKind

use of com.google.devtools.build.lib.events.EventKind in project bazel by bazelbuild.

the class ParallelBuilderTest method testProgressReporting.

@Test
public void testProgressReporting() throws Exception {
    // Build three artifacts in 3 separate actions (baz depends on bar and bar
    // depends on foo.  Make sure progress is reported at the beginning of all
    // three actions.
    List<Artifact> sourceFiles = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        sourceFiles.add(createInputFile("file" + i));
    }
    Artifact foo = createDerivedArtifact("foo");
    Artifact bar = createDerivedArtifact("bar");
    Artifact baz = createDerivedArtifact("baz");
    bar.getPath().delete();
    baz.getPath().delete();
    final List<String> messages = new ArrayList<>();
    EventHandler handler = new EventHandler() {

        @Override
        public void handle(Event event) {
            EventKind k = event.getKind();
            if (k == EventKind.START || k == EventKind.FINISH) {
                // Remove the tmpDir as this is user specific and the assert would
                // fail below.
                messages.add(event.getMessage().replaceFirst(TestUtils.tmpDir(), "") + " " + event.getKind());
            }
        }
    };
    reporter.addHandler(handler);
    reporter.addHandler(new PrintingEventHandler(EventKind.ALL_EVENTS));
    registerAction(new TestAction(TestAction.NO_EFFECT, sourceFiles, asSet(foo)));
    registerAction(new TestAction(TestAction.NO_EFFECT, asSet(foo), asSet(bar)));
    registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(baz)));
    buildArtifacts(baz);
    // Check that the percentages increase non-linearly, because foo has 10 input files
    List<String> expectedMessages = Lists.newArrayList("Test foo START", "Test foo FINISH", "Test bar START", "Test bar FINISH", "Test baz START", "Test baz FINISH");
    assertThat(messages).containsAllIn(expectedMessages);
    // Now do an incremental rebuild of bar and baz,
    // and check the incremental progress percentages.
    messages.clear();
    bar.getPath().delete();
    baz.getPath().delete();
    // This uses a new builder instance so that we refetch timestamps from
    // (in-memory) file system, rather than using cached entries.
    buildArtifacts(baz);
    expectedMessages = Lists.newArrayList("Test bar START", "Test bar FINISH", "Test baz START", "Test baz FINISH");
    assertThat(messages).containsAllIn(expectedMessages);
}
Also used : EventKind(com.google.devtools.build.lib.events.EventKind) ArrayList(java.util.ArrayList) EventHandler(com.google.devtools.build.lib.events.EventHandler) PrintingEventHandler(com.google.devtools.build.lib.events.PrintingEventHandler) ActionExecutedEvent(com.google.devtools.build.lib.actions.ActionExecutedEvent) Event(com.google.devtools.build.lib.events.Event) Artifact(com.google.devtools.build.lib.actions.Artifact) PrintingEventHandler(com.google.devtools.build.lib.events.PrintingEventHandler) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Aggregations

ActionExecutedEvent (com.google.devtools.build.lib.actions.ActionExecutedEvent)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 TestAction (com.google.devtools.build.lib.actions.util.TestAction)1 Event (com.google.devtools.build.lib.events.Event)1 EventHandler (com.google.devtools.build.lib.events.EventHandler)1 EventKind (com.google.devtools.build.lib.events.EventKind)1 PrintingEventHandler (com.google.devtools.build.lib.events.PrintingEventHandler)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1