diff options
author | lpino <lpino@google.com> | 2018-06-21 08:35:40 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-21 08:37:10 -0700 |
commit | 2b945323d2b4cf7dfdf988b9b04c4fb75e416206 (patch) | |
tree | 37e5ba0b1e7277d6f386aa7f3853bbc2d7840c4e /src | |
parent | cbd6f462f4dc8cbd305828abd7e5cd7152b266e0 (diff) |
Fix NoSuchElementException when BuildEventArtifactUploaderMap has no elements.
When there are no uploaders in BuildEventArtifactUploaderMap then we should use the BuildEventArtifactUploader.LOCAL_FILES_UPLOADER as a fallback. Added some unit tests as regression tests for the underlying issue.
PiperOrigin-RevId: 201529578
Diffstat (limited to 'src')
3 files changed, 66 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploaderMap.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploaderMap.java index 8987def882..e9f611ab9a 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploaderMap.java +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploaderMap.java @@ -30,7 +30,7 @@ public class BuildEventArtifactUploaderMap { } public BuildEventArtifactUploader select(@Nullable String name) { - if (name == null) { + if (name == null && !uploaders.values().isEmpty()) { // TODO(b/110235226): We currently choose the strategy with alphabetically first strategy, // which happens to be backwards-compatible; we need to set // experimental_build_event_upload_strategy to appropriate default values instead, and then diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/BUILD b/src/test/java/com/google/devtools/build/lib/buildeventstream/BUILD index 586bdff2c0..a23d3dd3ff 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/BUILD +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/BUILD @@ -17,6 +17,7 @@ java_test( runtime_deps = ["//src/test/java/com/google/devtools/build/lib:test_runner"], deps = [ "//src/main/java/com/google/devtools/build/lib/buildeventstream", + "//src/main/java/com/google/devtools/build/lib/vfs", "//third_party:guava", "//third_party:junit4", "//third_party:mockito", diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploaderMapTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploaderMapTest.java new file mode 100644 index 0000000000..095c42dbda --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/BuildEventArtifactUploaderMapTest.java @@ -0,0 +1,64 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.buildeventstream; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.devtools.build.lib.vfs.Path; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for {@link BuildEventArtifactUploaderMap}. */ +@RunWith(JUnit4.class) +public final class BuildEventArtifactUploaderMapTest { + private BuildEventArtifactUploaderMap uploader; + private BuildEventArtifactUploader noConversionUploader; + + @Before + public void setUp() { + noConversionUploader = + new BuildEventArtifactUploader() { + @Override + public PathConverter upload(Set<Path> files) { + return PathConverter.NO_CONVERSION; + } + }; + uploader = + new BuildEventArtifactUploaderMap.Builder() + .add("a", BuildEventArtifactUploader.LOCAL_FILES_UPLOADER) + .add("b", noConversionUploader) + .build(); + } + + @Test + public void testEmptyUploaders() throws Exception { + BuildEventArtifactUploaderMap emptyUploader = + new BuildEventArtifactUploaderMap.Builder().build(); + assertThat(emptyUploader.select(null)) + .isEqualTo(BuildEventArtifactUploader.LOCAL_FILES_UPLOADER); + } + + @Test + public void testAlphabeticalOrder() throws Exception { + assertThat(uploader.select(null)).isEqualTo(BuildEventArtifactUploader.LOCAL_FILES_UPLOADER); + } + + @Test + public void testSelectByName() throws Exception { + assertThat(uploader.select("b")).isEqualTo(noConversionUploader); + } +} |