diff options
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/buildeventstream/transports')
4 files changed, 35 insertions, 32 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java index 51951e4f8a..1b85701a9b 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.buildeventstream.transports; import static com.google.common.truth.Truth.assertThat; +import static com.google.devtools.build.lib.buildeventstream.BuildEventArtifactUploader.LOCAL_FILES_UPLOADER; import static org.mockito.Mockito.when; import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer; @@ -25,7 +26,6 @@ import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildStarted; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.Progress; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.TargetComplete; -import com.google.devtools.build.lib.buildeventstream.PathConverter; import com.google.devtools.common.options.Options; import java.io.File; import java.io.FileInputStream; @@ -43,7 +43,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -/** Tests {@link BinaryFormatFileTransport}. **/ +/** Tests {@link BinaryFormatFileTransport}. */ @RunWith(JUnit4.class) public class BinaryFormatFileTransportTest { private final BuildEventProtocolOptions defaultOpts = @@ -53,7 +53,6 @@ public class BinaryFormatFileTransportTest { @Mock public BuildEvent buildEvent; - @Mock public PathConverter pathConverter; @Mock public ArtifactGroupNamer artifactGroupNamer; @Before @@ -76,7 +75,8 @@ public class BinaryFormatFileTransportTest { .build(); when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); BinaryFormatFileTransport transport = - new BinaryFormatFileTransport(output.getAbsolutePath(), defaultOpts, pathConverter); + new BinaryFormatFileTransport( + output.getAbsolutePath(), defaultOpts, LOCAL_FILES_UPLOADER, (e) -> {}); transport.sendBuildEvent(buildEvent, artifactGroupNamer); BuildEventStreamProtos.BuildEvent progress = @@ -113,7 +113,7 @@ public class BinaryFormatFileTransportTest { .build(); when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); BinaryFormatFileTransport transport = - new BinaryFormatFileTransport(path, defaultOpts, pathConverter); + new BinaryFormatFileTransport(path, defaultOpts, LOCAL_FILES_UPLOADER, (e) -> {}); transport.sendBuildEvent(buildEvent, artifactGroupNamer); transport.close().get(); @@ -134,7 +134,8 @@ public class BinaryFormatFileTransportTest { when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); BinaryFormatFileTransport transport = - new BinaryFormatFileTransport(output.getAbsolutePath(), defaultOpts, pathConverter); + new BinaryFormatFileTransport( + output.getAbsolutePath(), defaultOpts, LOCAL_FILES_UPLOADER, (e) -> {}); // Close the stream. transport.out.close(); @@ -161,7 +162,8 @@ public class BinaryFormatFileTransportTest { when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); BinaryFormatFileTransport transport = - new BinaryFormatFileTransport(output.getAbsolutePath(), defaultOpts, pathConverter); + new BinaryFormatFileTransport( + output.getAbsolutePath(), defaultOpts, LOCAL_FILES_UPLOADER, (e) -> {}); transport.sendBuildEvent(buildEvent, artifactGroupNamer); Future<Void> closeFuture = transport.close(); diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java index e5d5133cca..5494684b3f 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java @@ -22,6 +22,7 @@ import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer; import com.google.devtools.build.lib.buildeventstream.BuildEvent; +import com.google.devtools.build.lib.buildeventstream.BuildEventArtifactUploaderMap; import com.google.devtools.build.lib.buildeventstream.BuildEventContext; import com.google.devtools.build.lib.buildeventstream.BuildEventProtocolOptions; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; @@ -31,7 +32,7 @@ import com.google.devtools.build.lib.buildeventstream.PathConverter; import com.google.devtools.common.options.Options; import java.io.File; import java.io.IOException; -import java.util.concurrent.Future; +import java.util.concurrent.ExecutionException; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -44,7 +45,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -/** Tests {@link BuildEventTransportFactory}. **/ +/** Tests {@link BuildEventTransportFactory}. */ @RunWith(JUnit4.class) public class BuildEventTransportFactoryTest { @@ -85,14 +86,18 @@ public class BuildEventTransportFactoryTest { Mockito.validateMockitoUsage(); } + private BuildEventArtifactUploaderMap localFilesOnly() { + return new BuildEventArtifactUploaderMap.Builder().build(); + } + @Test - public void testCreatesTextFormatFileTransport() throws IOException { + public void testCreatesTextFormatFileTransport() throws Exception { File textFile = tmp.newFile(); when(options.getBuildEventTextFile()).thenReturn(textFile.getAbsolutePath()); - when(options.getBuildEventTextFilePathConversion()).thenReturn(true); when(options.getBuildEventBinaryFile()).thenReturn(""); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions(options, protocolOpts, pathConverter); + BuildEventTransportFactory.createFromOptions( + options, protocolOpts, localFilesOnly(), (e) -> {}); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(TextFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -100,13 +105,13 @@ public class BuildEventTransportFactoryTest { } @Test - public void testCreatesBinaryFormatFileTransport() throws IOException { + public void testCreatesBinaryFormatFileTransport() throws Exception { File binaryFile = tmp.newFile(); when(options.getBuildEventTextFile()).thenReturn(""); when(options.getBuildEventBinaryFile()).thenReturn(binaryFile.getAbsolutePath()); - when(options.getBuildEventBinaryFilePathConversion()).thenReturn(true); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions(options, protocolOpts, pathConverter); + BuildEventTransportFactory.createFromOptions( + options, protocolOpts, localFilesOnly(), (e) -> {}); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(BinaryFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -114,15 +119,14 @@ public class BuildEventTransportFactoryTest { } @Test - public void testCreatesAllTransports() throws IOException { + public void testCreatesAllTransports() throws Exception { File textFile = tmp.newFile(); File binaryFile = tmp.newFile(); when(options.getBuildEventTextFile()).thenReturn(textFile.getAbsolutePath()); when(options.getBuildEventBinaryFile()).thenReturn(binaryFile.getAbsolutePath()); - when(options.getBuildEventBinaryFilePathConversion()).thenReturn(true); - when(options.getBuildEventTextFilePathConversion()).thenReturn(true); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions(options, protocolOpts, pathConverter); + BuildEventTransportFactory.createFromOptions( + options, protocolOpts, localFilesOnly(), (e) -> {}); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(TextFormatFileTransport.class, BinaryFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -134,23 +138,16 @@ public class BuildEventTransportFactoryTest { public void testCreatesNoTransports() throws IOException { when(options.getBuildEventTextFile()).thenReturn(""); ImmutableSet<BuildEventTransport> transports = - BuildEventTransportFactory.createFromOptions(options, protocolOpts, pathConverter); + BuildEventTransportFactory.createFromOptions( + options, protocolOpts, localFilesOnly(), (e) -> {}); assertThat(transports).isEmpty(); } - @Test - public void testPathToUriString() { - // See https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/ - assertThat(BuildEventTransportFactory.pathToUriString("C:/Temp/Foo Bar.txt")) - .isEqualTo("file:///C:/Temp/Foo%20Bar.txt"); - } - private void sendEventsAndClose(BuildEvent event, Iterable<BuildEventTransport> transports) - throws IOException{ + throws InterruptedException, ExecutionException { for (BuildEventTransport transport : transports) { transport.sendBuildEvent(event, artifactGroupNamer); - @SuppressWarnings({"unused", "nullness"}) - Future<?> possiblyIgnoredError = transport.close(); + transport.close().get(); } } } diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransportTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransportTest.java index e667a7d787..656f87c289 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransportTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/JsonFormatFileTransportTest.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.buildeventstream.transports; import static com.google.common.truth.Truth.assertThat; +import static com.google.devtools.build.lib.buildeventstream.BuildEventArtifactUploader.LOCAL_FILES_UPLOADER; import static org.mockito.Mockito.when; import com.google.devtools.build.lib.buildeventstream.ArtifactGroupNamer; @@ -76,7 +77,8 @@ public class JsonFormatFileTransportTest { .build(); when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); JsonFormatFileTransport transport = - new JsonFormatFileTransport(output.getAbsolutePath(), defaultOpts, pathConverter); + new JsonFormatFileTransport( + output.getAbsolutePath(), defaultOpts, LOCAL_FILES_UPLOADER, (e) -> {}); transport.sendBuildEvent(buildEvent, artifactGroupNamer); transport.close().get(); diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java index c3ad19d0d6..df84539c3a 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.buildeventstream.transports; import static com.google.common.truth.Truth.assertThat; +import static com.google.devtools.build.lib.buildeventstream.BuildEventArtifactUploader.LOCAL_FILES_UPLOADER; import static org.mockito.Mockito.when; import com.google.common.base.Joiner; @@ -77,7 +78,8 @@ public class TextFormatFileTransportTest { .build(); when(buildEvent.asStreamProto(Matchers.<BuildEventContext>any())).thenReturn(started); TextFormatFileTransport transport = - new TextFormatFileTransport(output.getAbsolutePath(), defaultOpts, pathConverter); + new TextFormatFileTransport( + output.getAbsolutePath(), defaultOpts, LOCAL_FILES_UPLOADER, (e) -> {}); transport.sendBuildEvent(buildEvent, artifactGroupNamer); BuildEventStreamProtos.BuildEvent progress = |