Skip to content

Commit

Permalink
Replace deprecated Guava method createTempDir
Browse files Browse the repository at this point in the history
  • Loading branch information
joshthoward authored and martint committed Jan 19, 2022
1 parent 12a6b5f commit 7a88b18
Show file tree
Hide file tree
Showing 25 changed files with 193 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -47,7 +48,6 @@
import java.util.Random;
import java.util.concurrent.TimeUnit;

import static com.google.common.io.Files.createTempDir;
import static com.google.common.io.MoreFiles.deleteRecursively;
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
import static io.trino.jmh.Benchmarks.benchmark;
Expand All @@ -68,6 +68,7 @@
import static io.trino.spi.type.TinyintType.TINYINT;
import static io.trino.spi.type.VarcharType.VARCHAR;
import static io.trino.type.InternalTypeManager.TESTING_TYPE_MANAGER;
import static java.nio.file.Files.createTempDirectory;
import static java.nio.file.Files.readAllBytes;
import static java.util.UUID.randomUUID;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
Expand Down Expand Up @@ -343,7 +344,7 @@ public abstract static class BenchmarkData
{
protected final Random random = new Random(0);
private List<Type> types;
private File temporaryDirectory;
private Path temporaryDirectory;
private File orcFile;
private OrcDataSource dataSource;

Expand All @@ -354,8 +355,8 @@ public void setup(List<Type> types, Iterator<Page> pages)
throws Exception
{
this.types = types;
temporaryDirectory = createTempDir();
orcFile = new File(temporaryDirectory, randomUUID().toString());
temporaryDirectory = createTempDirectory(null);
orcFile = temporaryDirectory.resolve(randomUUID().toString()).toFile();
OrcTester.writeOrcPages(orcFile, CompressionKind.valueOf(compression), types, pages, new OrcWriterStats());

dataSource = new MemoryOrcDataSource(new OrcDataSourceId(orcFile.getPath()), Slices.wrappedBuffer(readAllBytes(orcFile.toPath())));
Expand All @@ -365,8 +366,8 @@ public void setup(Type type, Iterator<?> values)
throws Exception
{
this.types = ImmutableList.of(type);
temporaryDirectory = createTempDir();
orcFile = new File(temporaryDirectory, randomUUID().toString());
temporaryDirectory = createTempDirectory(null);
orcFile = temporaryDirectory.resolve(randomUUID().toString()).toFile();
writeOrcColumnTrino(orcFile, NONE, type, values, new OrcWriterStats());

dataSource = new MemoryOrcDataSource(new OrcDataSourceId(orcFile.getPath()), Slices.wrappedBuffer(readAllBytes(orcFile.toPath())));
Expand All @@ -376,7 +377,7 @@ public void setup(Type type, Iterator<?> values)
public void tearDown()
throws IOException
{
deleteRecursively(temporaryDirectory.toPath(), ALLOW_INSECURE);
deleteRecursively(temporaryDirectory, ALLOW_INSECURE);
}

OrcRecordReader createRecordReader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import static com.google.common.io.Files.createTempDir;
import static com.google.common.io.MoreFiles.deleteRecursively;
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
import static io.trino.jmh.Benchmarks.benchmark;
Expand All @@ -51,6 +51,7 @@
import static io.trino.orc.OrcTester.writeOrcColumnHive;
import static io.trino.orc.metadata.CompressionKind.NONE;
import static io.trino.spi.type.DecimalType.createDecimalType;
import static java.nio.file.Files.createTempDirectory;
import static java.util.UUID.randomUUID;

@SuppressWarnings("MethodMayBeStatic")
Expand Down Expand Up @@ -88,15 +89,15 @@ public void testReadDecimal()
@State(Scope.Thread)
public static class BenchmarkData
{
private File temporary;
private Path temporary;
private File dataPath;

@Setup
public void setup()
throws Exception
{
temporary = createTempDir();
dataPath = new File(temporary, randomUUID().toString());
temporary = createTempDirectory(null);
dataPath = temporary.resolve(randomUUID().toString()).toFile();

writeOrcColumnHive(dataPath, ORC_12, NONE, DECIMAL_TYPE, createDecimalValues().iterator());
}
Expand All @@ -105,7 +106,7 @@ public void setup()
public void tearDown()
throws IOException
{
deleteRecursively(temporary.toPath(), ALLOW_INSECURE);
deleteRecursively(temporary, ALLOW_INSECURE);
}

private OrcRecordReader createRecordReader()
Expand Down
12 changes: 7 additions & 5 deletions lib/trino-orc/src/test/java/io/trino/orc/TempFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

import static com.google.common.io.Files.createTempDir;
import static com.google.common.io.MoreFiles.deleteRecursively;
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
import static java.nio.file.Files.createTempDirectory;

class TempFile
implements Closeable
{
private final File tempDir;
private final Path tempDir;
private final File file;

public TempFile()
throws IOException
{
tempDir = createTempDir();
file = new File(tempDir, "data.orc");
tempDir = createTempDirectory(null);
file = tempDir.resolve("data.orc").toFile();
}

public File getFile()
Expand All @@ -43,6 +45,6 @@ public void close()
throws IOException
{
// hadoop creates crc files that must be deleted also, so just delete the whole directory
deleteRecursively(tempDir.toPath(), ALLOW_INSECURE);
deleteRecursively(tempDir, ALLOW_INSECURE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class TestStructColumnReader

@BeforeMethod
public void setUp()
throws IOException
{
tempFile = new TempFile();
}
Expand Down
11 changes: 6 additions & 5 deletions lib/trino-rcfile/src/test/java/io/trino/rcfile/RcFileTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
import static com.google.common.base.Functions.constant;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Iterators.advance;
import static com.google.common.io.Files.createTempDir;
import static com.google.common.io.MoreFiles.deleteRecursively;
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
import static io.airlift.slice.SizeOf.SIZE_OF_INT;
Expand Down Expand Up @@ -149,6 +148,7 @@
import static io.trino.type.DateTimes.MICROSECONDS_PER_MILLISECOND;
import static io.trino.type.InternalTypeManager.TESTING_TYPE_MANAGER;
import static java.lang.Math.toIntExact;
import static java.nio.file.Files.createTempDirectory;
import static java.util.Collections.nCopies;
import static java.util.stream.Collectors.toList;
import static org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.META_TABLE_COLUMNS;
Expand Down Expand Up @@ -1092,13 +1092,14 @@ private static Properties createTableProperties(String name, String type)
private static class TempFile
implements Closeable
{
private final File tempDir;
private final java.nio.file.Path tempDir;
private final File file;

private TempFile()
throws IOException
{
tempDir = createTempDir();
file = new File(tempDir, "data.rcfile");
tempDir = createTempDirectory(null);
file = tempDir.resolve("data.rcfile").toFile();
}

public File getFile()
Expand All @@ -1111,7 +1112,7 @@ public void close()
throws IOException
{
// hadoop creates crc files that must be deleted also, so just delete the whole directory
deleteRecursively(tempDir.toPath(), ALLOW_INSECURE);
deleteRecursively(tempDir, ALLOW_INSECURE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import java.nio.file.Files;
import java.nio.file.Path;

import static com.google.common.io.Files.createTempDir;
import static com.google.common.io.Resources.toByteArray;
import static io.trino.plugin.atop.AtopErrorCode.ATOP_READ_TIMEOUT;
import static io.trino.plugin.atop.LocalAtopQueryRunner.createQueryRunner;
import static io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy;
import static java.nio.file.Files.createTempDirectory;

public class TestAtopHang
{
Expand All @@ -39,8 +39,8 @@ public class TestAtopHang
public void setUp()
throws Exception
{
File tempPath = createTempDir();
copyExecutable("hanging_atop.sh", tempPath);
Path tempPath = createTempDirectory(null);
copyExecutable("hanging_atop.sh", tempPath.toFile());
queryRunner = createQueryRunner(ImmutableMap.of("atop.executable-path", tempPath + "/hanging_atop.sh", "atop.executable-read-timeout", "1s"), AtopProcessFactory.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.TimeoutException;

import static com.datastax.driver.core.ProtocolVersion.V3;
import static com.google.common.io.Files.createTempDir;
import static com.google.common.io.Files.write;
import static com.google.common.io.Resources.getResource;
import static java.lang.String.format;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.Files.createDirectory;
import static java.nio.file.Files.createTempDirectory;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
Expand Down Expand Up @@ -103,18 +103,17 @@ private static String prepareCassandraYaml()
{
String original = Resources.toString(getResource("cu-cassandra.yaml"), UTF_8);

File tempDirFile = createTempDir();
tempDirFile.deleteOnExit();
Path tmpDirPath = tempDirFile.toPath();
Path tmpDirPath = createTempDirectory(null);
Path dataDir = tmpDirPath.resolve("data");
Files.createDirectory(dataDir);
createDirectory(dataDir);

String modified = original.replaceAll("\\$\\{data_directory\\}", dataDir.toAbsolutePath().toString());

Path yamlLocation = tmpDirPath.resolve("cu-cassandra.yaml");
write(modified, yamlLocation.toFile(), UTF_8);
File yamlFile = tmpDirPath.resolve("cu-cassandra.yaml").toFile();
yamlFile.deleteOnExit();
write(modified, yamlFile, UTF_8);

return yamlLocation.toAbsolutePath().toString();
return yamlFile.getAbsolutePath();
}

public CassandraSession getSession()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import java.nio.file.Path;
import java.util.Map;

import static com.google.common.io.Files.createTempDir;
import static com.google.common.io.MoreFiles.deleteRecursively;
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.Files.createTempDirectory;
import static org.testcontainers.utility.MountableFile.forHostPath;

public class ElasticsearchServer
Expand All @@ -48,7 +48,7 @@ public ElasticsearchServer(Network network, String image, Map<String, String> co
container.withNetwork(network);
container.withNetworkAliases("elasticsearch-server");

configurationPath = createTempDir().toPath();
configurationPath = createTempDirectory(null);
for (Map.Entry<String, String> entry : configurationFiles.entrySet()) {
String name = entry.getKey();
String contents = entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

import static com.google.common.collect.Lists.cartesianProduct;
import static com.google.common.io.Files.createTempDir;
import static com.google.common.io.MoreFiles.deleteRecursively;
import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE;
import static io.trino.plugin.hive.authentication.HiveIdentity.none;
import static io.trino.spi.security.SelectedRole.Type.ROLE;
import static io.trino.testing.TestingSession.testSessionBuilder;
import static java.nio.file.Files.createTempDirectory;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@Test(singleThreaded = true)
Expand All @@ -52,7 +52,7 @@ public class TestCachingHiveMetastoreWithQueryRunner
private static final Session ALICE = getTestSession(new Identity.Builder(ALICE_NAME).build());

private DistributedQueryRunner queryRunner;
private File temporaryMetastoreDirectory;
private Path temporaryMetastoreDirectory;

@BeforeMethod
public void createQueryRunner()
Expand All @@ -63,10 +63,10 @@ public void createQueryRunner()
.setNodeCount(1)
.build();
queryRunner.installPlugin(new HivePlugin());
temporaryMetastoreDirectory = createTempDir();
temporaryMetastoreDirectory = createTempDirectory(null);
queryRunner.createCatalog(CATALOG, "hive", ImmutableMap.of(
"hive.metastore", "file",
"hive.metastore.catalog.dir", temporaryMetastoreDirectory.toURI().toString(),
"hive.metastore.catalog.dir", temporaryMetastoreDirectory.toUri().toString(),
"hive.security", "sql-standard",
"hive.metastore-cache-ttl", "60m",
"hive.metastore-refresh-interval", "10m"));
Expand All @@ -79,7 +79,7 @@ public void cleanUp()
throws IOException
{
queryRunner.close();
deleteRecursively(temporaryMetastoreDirectory.toPath(), ALLOW_INSECURE);
deleteRecursively(temporaryMetastoreDirectory, ALLOW_INSECURE);
}

private static Session getTestSession(Identity identity)
Expand Down Expand Up @@ -123,7 +123,7 @@ public void testFlushHiveMetastoreCacheProcedureCallable()
queryRunner.execute("SELECT initial FROM cached");

// Rename column name in Metastore outside Trino
FileHiveMetastore fileHiveMetastore = FileHiveMetastore.createTestingFileHiveMetastore(temporaryMetastoreDirectory);
FileHiveMetastore fileHiveMetastore = FileHiveMetastore.createTestingFileHiveMetastore(temporaryMetastoreDirectory.toFile());
fileHiveMetastore.renameColumn(none(), "test", "cached", "initial", "renamed");

String renamedColumnQuery = "SELECT renamed FROM cached";
Expand Down
Loading

0 comments on commit 7a88b18

Please sign in to comment.