jihoonson closed pull request #6070: Use JUnit TemporaryFolder rule instead of system temp folder URL: https://github.com/apache/incubator-druid/pull/6070
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/codestyle/druid-forbidden-apis.txt b/codestyle/druid-forbidden-apis.txt index 7f56d9abe26..c7bd111c574 100644 --- a/codestyle/druid-forbidden-apis.txt +++ b/codestyle/druid-forbidden-apis.txt @@ -3,4 +3,5 @@ com.google.common.collect.Maps#newConcurrentMap() @ Create java.util.concurrent. com.google.common.util.concurrent.Futures#transform(com.google.common.util.concurrent.ListenableFuture, com.google.common.util.concurrent.AsyncFunction) @ Use io.druid.java.util.common.concurrent.ListenableFutures#transformAsync com.google.common.collect.Iterators#emptyIterator() @ Use java.util.Collections#emptyIterator() com.google.common.base.Charsets @ Use java.nio.charset.StandardCharsets instead -java.io.File#toURL() @ Use java.io.File#toURI() and java.net.URI#toURL() instead \ No newline at end of file +java.io.File#toURL() @ Use java.io.File#toURI() and java.net.URI#toURL() instead +org.apache.commons.io.FileUtils#getTempDirectory() @ Use org.junit.rules.TemporaryFolder for tests instead \ No newline at end of file diff --git a/pom.xml b/pom.xml index 96f26be0bdd..bb414e76417 100644 --- a/pom.xml +++ b/pom.xml @@ -910,6 +910,7 @@ <artifactId>forbiddenapis</artifactId> <version>2.3</version> <configuration> + <failOnUnresolvableSignatures>false</failOnUnresolvableSignatures> <bundledSignatures> <!-- This will automatically choose the right diff --git a/processing/src/test/java/io/druid/segment/data/CompressedColumnarIntsSerializerTest.java b/processing/src/test/java/io/druid/segment/data/CompressedColumnarIntsSerializerTest.java index 0d8fe55ba2e..c990305ba4d 100644 --- a/processing/src/test/java/io/druid/segment/data/CompressedColumnarIntsSerializerTest.java +++ b/processing/src/test/java/io/druid/segment/data/CompressedColumnarIntsSerializerTest.java @@ -32,11 +32,12 @@ import io.druid.segment.writeout.SegmentWriteOutMedium; import io.druid.segment.writeout.WriteOutBytes; import it.unimi.dsi.fastutil.ints.IntArrayList; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -61,6 +62,9 @@ private final Random rand = new Random(0); private int[] vals; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + public CompressedColumnarIntsSerializerTest( CompressionStrategy compressionStrategy, ByteOrder byteOrder @@ -112,7 +116,7 @@ private void generateVals(final int totalSize, final int maxValue) private void checkSerializedSizeAndData(int chunkFactor) throws Exception { - FileSmoosher smoosher = new FileSmoosher(FileUtils.getTempDirectory()); + FileSmoosher smoosher = new FileSmoosher(temporaryFolder.newFolder()); CompressedColumnarIntsSerializer writer = new CompressedColumnarIntsSerializer( segmentWriteOutMedium, "test", chunkFactor, byteOrder, compressionStrategy diff --git a/processing/src/test/java/io/druid/segment/data/CompressedVSizeColumnarIntsSerializerTest.java b/processing/src/test/java/io/druid/segment/data/CompressedVSizeColumnarIntsSerializerTest.java index e32ee3593b7..5aa011dc636 100644 --- a/processing/src/test/java/io/druid/segment/data/CompressedVSizeColumnarIntsSerializerTest.java +++ b/processing/src/test/java/io/druid/segment/data/CompressedVSizeColumnarIntsSerializerTest.java @@ -32,11 +32,12 @@ import io.druid.segment.writeout.SegmentWriteOutMedium; import io.druid.segment.writeout.WriteOutBytes; import it.unimi.dsi.fastutil.ints.IntArrayList; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -58,6 +59,10 @@ private final ByteOrder byteOrder; private final Random rand = new Random(0); private int[] vals; + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + public CompressedVSizeColumnarIntsSerializerTest( CompressionStrategy compressionStrategy, ByteOrder byteOrder @@ -109,7 +114,7 @@ private void generateVals(final int totalSize, final int maxValue) private void checkSerializedSizeAndData(int chunkSize) throws Exception { - FileSmoosher smoosher = new FileSmoosher(FileUtils.getTempDirectory()); + FileSmoosher smoosher = new FileSmoosher(temporaryFolder.newFolder()); CompressedVSizeColumnarIntsSerializer writer = new CompressedVSizeColumnarIntsSerializer( segmentWriteOutMedium, @@ -181,7 +186,7 @@ public void testEmpty() throws Exception private void checkV2SerializedSizeAndData(int chunkSize) throws Exception { - File tmpDirectory = FileUtils.getTempDirectory(); + File tmpDirectory = temporaryFolder.newFolder(); FileSmoosher smoosher = new FileSmoosher(tmpDirectory); GenericIndexedWriter genericIndexed = GenericIndexedWriter.ofCompressedByteBuffers( diff --git a/processing/src/test/java/io/druid/segment/data/V3CompressedVSizeColumnarMultiIntsSerializerTest.java b/processing/src/test/java/io/druid/segment/data/V3CompressedVSizeColumnarMultiIntsSerializerTest.java index 1a1996adce5..2775567d750 100644 --- a/processing/src/test/java/io/druid/segment/data/V3CompressedVSizeColumnarMultiIntsSerializerTest.java +++ b/processing/src/test/java/io/druid/segment/data/V3CompressedVSizeColumnarMultiIntsSerializerTest.java @@ -33,10 +33,11 @@ import io.druid.segment.writeout.OffHeapMemorySegmentWriteOutMedium; import io.druid.segment.writeout.SegmentWriteOutMedium; import io.druid.segment.writeout.WriteOutBytes; -import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -67,6 +68,9 @@ private final Random rand = new Random(0); private List<int[]> vals; + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + public V3CompressedVSizeColumnarMultiIntsSerializerTest( CompressionStrategy compressionStrategy, ByteOrder byteOrder @@ -111,7 +115,7 @@ private void generateVals(final int totalSize, final int maxValue) private void checkSerializedSizeAndData(int offsetChunkFactor, int valueChunkFactor) throws Exception { - FileSmoosher smoosher = new FileSmoosher(FileUtils.getTempDirectory()); + FileSmoosher smoosher = new FileSmoosher(temporaryFolder.newFolder()); try (SegmentWriteOutMedium segmentWriteOutMedium = new OffHeapMemorySegmentWriteOutMedium()) { int maxValue = vals.size() > 0 ? getMaxValue(vals) : 0; diff --git a/processing/src/test/java/io/druid/segment/serde/LargeColumnSupportedComplexColumnSerializerTest.java b/processing/src/test/java/io/druid/segment/serde/LargeColumnSupportedComplexColumnSerializerTest.java index 29f2a06195d..e2529758910 100644 --- a/processing/src/test/java/io/druid/segment/serde/LargeColumnSupportedComplexColumnSerializerTest.java +++ b/processing/src/test/java/io/druid/segment/serde/LargeColumnSupportedComplexColumnSerializerTest.java @@ -34,9 +34,10 @@ import io.druid.segment.column.ValueType; import io.druid.segment.writeout.OffHeapMemorySegmentWriteOutMedium; import io.druid.segment.writeout.SegmentWriteOutMedium; -import org.apache.commons.io.FileUtils; import org.junit.Assert; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; import javax.annotation.Nullable; import java.io.File; @@ -47,6 +48,9 @@ private final HashFunction fn = Hashing.murmur3_128(); + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @Test public void testSanity() throws IOException { @@ -63,7 +67,7 @@ public void testSanity() throws IOException for (int columnSize : columnSizes) { for (int aCase : cases) { - File tmpFile = FileUtils.getTempDirectory(); + File tmpFile = temporaryFolder.newFolder(); HyperLogLogCollector baseCollector = HyperLogLogCollector.makeLatestCollector(); try (SegmentWriteOutMedium segmentWriteOutMedium = new OffHeapMemorySegmentWriteOutMedium(); FileSmoosher v9Smoosher = new FileSmoosher(tmpFile)) { ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org