From 68aa410229cb36ceedc910c803a0aff2db6d027f Mon Sep 17 00:00:00 2001 From: ulfjack Date: Fri, 15 Jun 2018 01:40:02 -0700 Subject: Add a mechanism for build event protocol events to upload files This should be a no-op, mostly replacing PathConverter with BuildEventArtifactUploader, since none of the implementations perform any upload yet. PiperOrigin-RevId: 200685325 --- .../transports/BuildEventTransportFactoryTest.java | 43 ++++++++++------------ 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java') 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 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 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 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 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 transports) - throws IOException{ + throws InterruptedException, ExecutionException { for (BuildEventTransport transport : transports) { transport.sendBuildEvent(event, artifactGroupNamer); - @SuppressWarnings({"unused", "nullness"}) - Future possiblyIgnoredError = transport.close(); + transport.close().get(); } } } -- cgit v1.2.3