Search in sources :

Example 1 with InjectedStat

use of com.google.devtools.build.lib.actions.cache.InjectedStat in project bazel by bazelbuild.

the class TreeArtifactBuildTest method testDigestInjection.

// This is more a smoke test than anything, because it turns out that:
// 1) there is no easy way to turn fast digests on/off for these test cases, and
// 2) injectDigest() doesn't really complain if you inject bad digests or digests
// for nonexistent files. Instead some weird error shows up down the line.
// In fact, there are no tests for injectDigest anywhere in the codebase.
// So all we're really testing here is that injectDigest() doesn't throw a weird exception.
// TODO(bazel-team): write real tests for injectDigest, here and elsewhere.
@Test
public void testDigestInjection() throws Exception {
    TreeArtifactTestAction action = new TreeArtifactTestAction(outOne) {

        @Override
        public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException {
            try {
                writeFile(outOneFileOne, "one");
                writeFile(outOneFileTwo, "two");
                MetadataHandler md = actionExecutionContext.getMetadataHandler();
                FileStatus stat = outOneFileOne.getPath().stat(Symlinks.NOFOLLOW);
                md.injectDigest(outOneFileOne, new InjectedStat(stat.getLastModifiedTime(), stat.getSize(), stat.getNodeId()), Hashing.md5().hashString("one", Charset.forName("UTF-8")).asBytes());
                stat = outOneFileTwo.getPath().stat(Symlinks.NOFOLLOW);
                md.injectDigest(outOneFileTwo, new InjectedStat(stat.getLastModifiedTime(), stat.getSize(), stat.getNodeId()), Hashing.md5().hashString("two", Charset.forName("UTF-8")).asBytes());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    registerAction(action);
    buildArtifact(action.getSoleOutput());
}
Also used : FileStatus(com.google.devtools.build.lib.vfs.FileStatus) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) InjectedStat(com.google.devtools.build.lib.actions.cache.InjectedStat) MetadataHandler(com.google.devtools.build.lib.actions.cache.MetadataHandler) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)1 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)1 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)1 InjectedStat (com.google.devtools.build.lib.actions.cache.InjectedStat)1 MetadataHandler (com.google.devtools.build.lib.actions.cache.MetadataHandler)1 FileStatus (com.google.devtools.build.lib.vfs.FileStatus)1 IOException (java.io.IOException)1 Test (org.junit.Test)1