Search in sources :

Example 6 with TestAction

use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.

the class ParallelBuilderTest method testReportsActionExecutedEvent.

@Test
public void testReportsActionExecutedEvent() throws Exception {
    Artifact pear = createDerivedArtifact("pear");
    ActionEventRecorder recorder = new ActionEventRecorder();
    EventBus eventBus = new EventBus();
    eventBusRef.set(eventBus);
    eventBus.register(recorder);
    Action action = registerAction(new TestAction(Runnables.doNothing(), emptySet, asSet(pear)));
    buildArtifacts(createBuilder(DEFAULT_NUM_JOBS, true), pear);
    assertThat(recorder.actionExecutedEvents).hasSize(1);
    assertEquals(action, recorder.actionExecutedEvents.get(0).getAction());
}
Also used : Action(com.google.devtools.build.lib.actions.Action) TestAction(com.google.devtools.build.lib.actions.util.TestAction) EventBus(com.google.common.eventbus.EventBus) Artifact(com.google.devtools.build.lib.actions.Artifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Example 7 with TestAction

use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.

the class ParallelBuilderTest method testUpdateCacheError.

@Test
public void testUpdateCacheError() throws Exception {
    FileSystem fs = new InMemoryFileSystem() {

        @Override
        public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
            final FileStatus stat = super.stat(path, followSymlinks);
            if (path.toString().endsWith("/out/foo")) {
                return new FileStatus() {

                    private final FileStatus original = stat;

                    @Override
                    public boolean isSymbolicLink() {
                        return original.isSymbolicLink();
                    }

                    @Override
                    public boolean isFile() {
                        return original.isFile();
                    }

                    @Override
                    public boolean isDirectory() {
                        return original.isDirectory();
                    }

                    @Override
                    public boolean isSpecialFile() {
                        return original.isSpecialFile();
                    }

                    @Override
                    public long getSize() throws IOException {
                        return original.getSize();
                    }

                    @Override
                    public long getNodeId() throws IOException {
                        return original.getNodeId();
                    }

                    @Override
                    public long getLastModifiedTime() throws IOException {
                        throw new IOException();
                    }

                    @Override
                    public long getLastChangeTime() throws IOException {
                        return original.getLastChangeTime();
                    }
                };
            }
            return stat;
        }
    };
    Artifact foo = createDerivedArtifact(fs, "foo");
    registerAction(new TestAction(TestAction.NO_EFFECT, emptySet, ImmutableList.of(foo)));
    reporter.removeHandler(failFastHandler);
    try {
        buildArtifacts(foo);
        fail("Expected to fail");
    } catch (BuildFailedException e) {
        assertContainsEvent("not all outputs were created or valid");
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) FileSystem(com.google.devtools.build.lib.vfs.FileSystem) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) IOException(java.io.IOException) Artifact(com.google.devtools.build.lib.actions.Artifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Example 8 with TestAction

use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.

the class ParallelBuilderTest method testCyclicActionGraph.

@Test
public void testCyclicActionGraph() throws Exception {
    // foo -> [action] -> bar
    // bar -> [action] -> baz
    // baz -> [action] -> foo
    Artifact foo = createDerivedArtifact("foo");
    Artifact bar = createDerivedArtifact("bar");
    Artifact baz = createDerivedArtifact("baz");
    try {
        registerAction(new TestAction(TestAction.NO_EFFECT, asSet(foo), asSet(bar)));
        registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(baz)));
        registerAction(new TestAction(TestAction.NO_EFFECT, asSet(baz), asSet(foo)));
        buildArtifacts(foo);
        fail("Builder failed to detect cyclic action graph");
    } catch (BuildFailedException e) {
        assertEquals(e.getMessage(), CYCLE_MSG);
    }
}
Also used : BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) Artifact(com.google.devtools.build.lib.actions.Artifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Example 9 with TestAction

use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.

the class ParallelBuilderTest method testSelfCyclicActionGraph.

@Test
public void testSelfCyclicActionGraph() throws Exception {
    // foo -> [action] -> foo
    Artifact foo = createDerivedArtifact("foo");
    try {
        registerAction(new TestAction(TestAction.NO_EFFECT, asSet(foo), asSet(foo)));
        buildArtifacts(foo);
        fail("Builder failed to detect cyclic action graph");
    } catch (BuildFailedException e) {
        assertEquals(e.getMessage(), CYCLE_MSG);
    }
}
Also used : BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) Artifact(com.google.devtools.build.lib.actions.Artifact) TestAction(com.google.devtools.build.lib.actions.util.TestAction) Test(org.junit.Test)

Example 10 with TestAction

use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.

the class TimestampBuilderTestCase method createActionCounter.

/**
   * Creates a TestAction from 'inputs' to 'outputs', and a new counter, such
   * that executing the action causes the counter to be incremented.  The
   * counter is returned.
   */
protected Counter createActionCounter(Collection<Artifact> inputs, Collection<Artifact> outputs) {
    Counter counter = new Counter();
    registerAction(new TestAction(counter, inputs, outputs));
    return counter;
}
Also used : TestAction(com.google.devtools.build.lib.actions.util.TestAction)

Aggregations

TestAction (com.google.devtools.build.lib.actions.util.TestAction)20 Artifact (com.google.devtools.build.lib.actions.Artifact)16 Test (org.junit.Test)14 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)10 IOException (java.io.IOException)5 Action (com.google.devtools.build.lib.actions.Action)4 Path (com.google.devtools.build.lib.vfs.Path)4 ActionInputHelper.treeFileArtifact (com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact)3 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)3 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)3 FileSystem (com.google.devtools.build.lib.vfs.FileSystem)3 InMemoryFileSystem (com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem)3 Callable (java.util.concurrent.Callable)3 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)2 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)2 ExternalFileAction (com.google.devtools.build.lib.skyframe.ExternalFilesHelper.ExternalFileAction)2 ModifiedFileSet (com.google.devtools.build.lib.vfs.ModifiedFileSet)2 EventBus (com.google.common.eventbus.EventBus)1 ActionExecutedEvent (com.google.devtools.build.lib.actions.ActionExecutedEvent)1 ActionInputFileCache (com.google.devtools.build.lib.actions.ActionInputFileCache)1