aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google
diff options
context:
space:
mode:
authorGravatar George Gensure <ggensure@uber.com>2018-07-23 02:57:03 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-23 02:58:03 -0700
commitc8dfabbe9c4dc5fc45b19ceacef4582a8a0e0f47 (patch)
tree43e5c323240ba6d26be6f572b92d4c8cf582975d /src/test/java/com/google
parent49212c43c1aef61319d69760ca79151636988b68 (diff)
Suppress RepositoryCache IOException on download
With invalid contents in the repository cache, silence the IOException on RepositoryCache::get and re-download an artifact when attempting to short-circuit that operation. The repository cache can easily get into this state when a build is interrupted while downloading into the non- atomic repository cache destination. Possible solution to #5390 Closes #5392. PiperOrigin-RevId: 205634761
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r--src/test/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunctionTest.java35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunctionTest.java
index 8b90c612df..9cc82dc27b 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/MavenJarFunctionTest.java
@@ -16,18 +16,22 @@ package com.google.devtools.build.lib.bazel.repository;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import com.google.common.eventbus.EventBus;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache;
+import com.google.devtools.build.lib.events.EventHandler;
+import com.google.devtools.build.lib.events.ExtendedEventHandler;
+import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.packages.Rule;
-
import com.google.devtools.build.lib.rules.repository.WorkspaceAttributeMapper;
+import java.io.IOException;
import org.apache.maven.settings.Server;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mockito;
-import java.io.IOException;
/**
* Tests for {@link MavenJarFunction}.
@@ -37,6 +41,9 @@ import java.io.IOException;
public class MavenJarFunctionTest extends BuildViewTestCase {
private static final MavenServerValue TEST_SERVER = new MavenServerValue(
"server", "http://example.com", new Server(), new byte[]{});
+ private final EventHandler eventHandler = mock(EventHandler.class);
+ private final ExtendedEventHandler extendedEventHandler =
+ new Reporter(new EventBus(), eventHandler);
@Test
public void testInvalidSha1() throws Exception {
@@ -49,7 +56,11 @@ public class MavenJarFunctionTest extends BuildViewTestCase {
MavenDownloader downloader = new MavenDownloader(Mockito.mock(RepositoryCache.class));
try {
downloader.download(
- "foo", WorkspaceAttributeMapper.of(rule), scratch.dir("/whatever"), TEST_SERVER);
+ "foo",
+ WorkspaceAttributeMapper.of(rule),
+ scratch.dir("/whatever"),
+ TEST_SERVER,
+ extendedEventHandler);
fail("Invalid sha1 should have thrown.");
} catch (IOException expected) {
assertThat(expected.getMessage()).contains("Invalid SHA-1 for maven_jar foo");
@@ -68,7 +79,11 @@ public class MavenJarFunctionTest extends BuildViewTestCase {
MavenDownloader downloader = new MavenDownloader(Mockito.mock(RepositoryCache.class));
try {
downloader.download(
- "foo", WorkspaceAttributeMapper.of(rule), scratch.dir("/whatever"), TEST_SERVER);
+ "foo",
+ WorkspaceAttributeMapper.of(rule),
+ scratch.dir("/whatever"),
+ TEST_SERVER,
+ extendedEventHandler);
fail("Expected failure to fetch artifact because of nonexistent server and not due to "
+ "the existence of a valid SHA");
} catch (IOException expected) {
@@ -86,7 +101,11 @@ public class MavenJarFunctionTest extends BuildViewTestCase {
MavenDownloader downloader = new MavenDownloader(Mockito.mock(RepositoryCache.class));
try {
downloader.download(
- "foo", WorkspaceAttributeMapper.of(rule), scratch.dir("/whatever"), TEST_SERVER);
+ "foo",
+ WorkspaceAttributeMapper.of(rule),
+ scratch.dir("/whatever"),
+ TEST_SERVER,
+ extendedEventHandler);
fail("Expected failure to fetch artifact because of nonexistent server and not due to "
+ "lack of SHA.");
} catch (IOException expected) {
@@ -106,7 +125,11 @@ public class MavenJarFunctionTest extends BuildViewTestCase {
MavenDownloader downloader = new MavenDownloader(cache);
try {
downloader.download(
- "foo", WorkspaceAttributeMapper.of(rule), scratch.dir("/whatever"), TEST_SERVER);
+ "foo",
+ WorkspaceAttributeMapper.of(rule),
+ scratch.dir("/whatever"),
+ TEST_SERVER,
+ extendedEventHandler);
fail("Expected failure to fetch artifact because of nonexistent server.");
} catch (IOException expected) {
assertThat(expected.getMessage()).contains("Failed to fetch Maven dependency:");