Skip to content

Commit

Permalink
Use JUnit TemporaryFolder rule instead of system temp folder (#6070)
Browse files Browse the repository at this point in the history
* Use JUnit TemporaryFolder rule instead of system tmp folder

* Allow to forbid apis which present not in all mvn modules
  • Loading branch information
yuppie-flu authored and jihoonson committed Aug 16, 2018
1 parent 5726692 commit 62e5800
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
3 changes: 2 additions & 1 deletion codestyle/druid-forbidden-apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@
<artifactId>forbiddenapis</artifactId>
<version>2.3</version>
<configuration>
<failOnUnresolvableSignatures>false</failOnUnresolvableSignatures>
<bundledSignatures>
<!--
This will automatically choose the right
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -61,6 +62,9 @@ public class CompressedColumnarIntsSerializerTest
private final Random rand = new Random(0);
private int[] vals;

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

public CompressedColumnarIntsSerializerTest(
CompressionStrategy compressionStrategy,
ByteOrder byteOrder
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -58,6 +59,10 @@ public class CompressedVSizeColumnarIntsSerializerTest
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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -67,6 +68,9 @@ public class V3CompressedVSizeColumnarMultiIntsSerializerTest
private final Random rand = new Random(0);
private List<int[]> vals;

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

public V3CompressedVSizeColumnarMultiIntsSerializerTest(
CompressionStrategy compressionStrategy,
ByteOrder byteOrder
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,6 +48,9 @@ public class LargeColumnSupportedComplexColumnSerializerTest

private final HashFunction fn = Hashing.murmur3_128();

@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();

@Test
public void testSanity() throws IOException
{
Expand All @@ -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)) {
Expand Down

0 comments on commit 62e5800

Please sign in to comment.