diff --git a/lib/trino-orc/src/test/java/io/trino/orc/BenchmarkColumnReaders.java b/lib/trino-orc/src/test/java/io/trino/orc/BenchmarkColumnReaders.java index bd74ff707dcd..83d84dea6e38 100644 --- a/lib/trino-orc/src/test/java/io/trino/orc/BenchmarkColumnReaders.java +++ b/lib/trino-orc/src/test/java/io/trino/orc/BenchmarkColumnReaders.java @@ -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; @@ -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; @@ -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; @@ -343,7 +344,7 @@ public abstract static class BenchmarkData { protected final Random random = new Random(0); private List types; - private File temporaryDirectory; + private Path temporaryDirectory; private File orcFile; private OrcDataSource dataSource; @@ -354,8 +355,8 @@ public void setup(List types, Iterator 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()))); @@ -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()))); @@ -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() diff --git a/lib/trino-orc/src/test/java/io/trino/orc/BenchmarkOrcDecimalReader.java b/lib/trino-orc/src/test/java/io/trino/orc/BenchmarkOrcDecimalReader.java index ae32cac3faae..b41801a04521 100644 --- a/lib/trino-orc/src/test/java/io/trino/orc/BenchmarkOrcDecimalReader.java +++ b/lib/trino-orc/src/test/java/io/trino/orc/BenchmarkOrcDecimalReader.java @@ -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; @@ -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") @@ -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()); } @@ -105,7 +106,7 @@ public void setup() public void tearDown() throws IOException { - deleteRecursively(temporary.toPath(), ALLOW_INSECURE); + deleteRecursively(temporary, ALLOW_INSECURE); } private OrcRecordReader createRecordReader() diff --git a/lib/trino-orc/src/test/java/io/trino/orc/TempFile.java b/lib/trino-orc/src/test/java/io/trino/orc/TempFile.java index 951c39408473..ec1814f39fe2 100644 --- a/lib/trino-orc/src/test/java/io/trino/orc/TempFile.java +++ b/lib/trino-orc/src/test/java/io/trino/orc/TempFile.java @@ -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() @@ -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); } } diff --git a/lib/trino-orc/src/test/java/io/trino/orc/TestStructColumnReader.java b/lib/trino-orc/src/test/java/io/trino/orc/TestStructColumnReader.java index dd862e553f80..edff0437772c 100644 --- a/lib/trino-orc/src/test/java/io/trino/orc/TestStructColumnReader.java +++ b/lib/trino-orc/src/test/java/io/trino/orc/TestStructColumnReader.java @@ -65,6 +65,7 @@ public class TestStructColumnReader @BeforeMethod public void setUp() + throws IOException { tempFile = new TempFile(); } diff --git a/lib/trino-rcfile/src/test/java/io/trino/rcfile/RcFileTester.java b/lib/trino-rcfile/src/test/java/io/trino/rcfile/RcFileTester.java index 0883ccb085cc..beb20ebf62f4 100644 --- a/lib/trino-rcfile/src/test/java/io/trino/rcfile/RcFileTester.java +++ b/lib/trino-rcfile/src/test/java/io/trino/rcfile/RcFileTester.java @@ -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; @@ -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; @@ -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() @@ -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); } } diff --git a/plugin/trino-atop/src/test/java/io/trino/plugin/atop/TestAtopHang.java b/plugin/trino-atop/src/test/java/io/trino/plugin/atop/TestAtopHang.java index 4266ac032215..028a3ac07283 100644 --- a/plugin/trino-atop/src/test/java/io/trino/plugin/atop/TestAtopHang.java +++ b/plugin/trino-atop/src/test/java/io/trino/plugin/atop/TestAtopHang.java @@ -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 { @@ -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); } diff --git a/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/CassandraServer.java b/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/CassandraServer.java index 97751d88641a..9014e2fa3378 100644 --- a/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/CassandraServer.java +++ b/plugin/trino-cassandra/src/test/java/io/trino/plugin/cassandra/CassandraServer.java @@ -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; @@ -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() diff --git a/plugin/trino-elasticsearch/src/test/java/io/trino/plugin/elasticsearch/ElasticsearchServer.java b/plugin/trino-elasticsearch/src/test/java/io/trino/plugin/elasticsearch/ElasticsearchServer.java index 46a2ee632804..444c1e389a3f 100644 --- a/plugin/trino-elasticsearch/src/test/java/io/trino/plugin/elasticsearch/ElasticsearchServer.java +++ b/plugin/trino-elasticsearch/src/test/java/io/trino/plugin/elasticsearch/ElasticsearchServer.java @@ -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 @@ -48,7 +48,7 @@ public ElasticsearchServer(Network network, String image, Map co container.withNetwork(network); container.withNetworkAliases("elasticsearch-server"); - configurationPath = createTempDir().toPath(); + configurationPath = createTempDirectory(null); for (Map.Entry entry : configurationFiles.entrySet()) { String name = entry.getKey(); String contents = entry.getValue(); diff --git a/plugin/trino-hive-hadoop2/src/test/java/io/trino/plugin/hive/metastore/cache/TestCachingHiveMetastoreWithQueryRunner.java b/plugin/trino-hive-hadoop2/src/test/java/io/trino/plugin/hive/metastore/cache/TestCachingHiveMetastoreWithQueryRunner.java index 1985fd9598cd..e9fef5c01281 100644 --- a/plugin/trino-hive-hadoop2/src/test/java/io/trino/plugin/hive/metastore/cache/TestCachingHiveMetastoreWithQueryRunner.java +++ b/plugin/trino-hive-hadoop2/src/test/java/io/trino/plugin/hive/metastore/cache/TestCachingHiveMetastoreWithQueryRunner.java @@ -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) @@ -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() @@ -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")); @@ -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) @@ -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"; diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveConnectorTest.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveConnectorTest.java index 44de2f5e09ab..b12d8856e709 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveConnectorTest.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveConnectorTest.java @@ -94,7 +94,6 @@ import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Sets.intersection; import static com.google.common.io.Files.asCharSink; -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.FeaturesConfig.JoinDistributionType.BROADCAST; @@ -154,6 +153,7 @@ import static java.lang.String.format; import static java.lang.String.join; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.nio.file.Files.createTempDirectory; import static java.util.Collections.nCopies; import static java.util.Locale.ENGLISH; import static java.util.Objects.requireNonNull; @@ -3810,14 +3810,14 @@ private void testCreateExternalTable( List tableProperties) throws Exception { - File tempDir = createTempDir(); - File dataFile = new File(tempDir, "test.txt"); + java.nio.file.Path tempDir = createTempDirectory(null); + File dataFile = tempDir.resolve("test.txt").toFile(); Files.asCharSink(dataFile, UTF_8).write(fileContents); // Table properties StringJoiner propertiesSql = new StringJoiner(",\n "); propertiesSql.add( - format("external_location = '%s'", new Path(tempDir.toURI().toASCIIString()))); + format("external_location = '%s'", new Path(tempDir.toUri().toASCIIString()))); propertiesSql.add("format = 'TEXTFILE'"); tableProperties.forEach(propertiesSql::add); @@ -3841,7 +3841,7 @@ private void testCreateExternalTable( assertQuery(format("SELECT col1, col2 from %s", tableName), expectedResults); assertUpdate(format("DROP TABLE %s", tableName)); assertFile(dataFile); // file should still exist after drop - deleteRecursively(tempDir.toPath(), ALLOW_INSECURE); + deleteRecursively(tempDir, ALLOW_INSECURE); } @Test @@ -3905,16 +3905,16 @@ public void testCreateExternalTableWithNullFormat() public void testCreateExternalTableWithDataNotAllowed() throws IOException { - File tempDir = createTempDir(); + java.nio.file.Path tempDir = createTempDirectory(null); @Language("SQL") String createTableSql = format("" + "CREATE TABLE test_create_external_with_data_not_allowed " + "WITH (external_location = '%s') AS " + "SELECT * FROM tpch.tiny.nation", - tempDir.toURI().toASCIIString()); + tempDir.toUri().toASCIIString()); assertQueryFails(createTableSql, "Writes to non-managed Hive tables is disabled"); - deleteRecursively(tempDir.toPath(), ALLOW_INSECURE); + deleteRecursively(tempDir, ALLOW_INSECURE); } private void testCreateTableWithHeaderAndFooter(String format) diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveCreateExternalTable.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveCreateExternalTable.java index 6768e03b5845..6ca1d28257b5 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveCreateExternalTable.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveCreateExternalTable.java @@ -21,16 +21,16 @@ import org.intellij.lang.annotations.Language; import org.testng.annotations.Test; -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 io.trino.testing.QueryAssertions.assertEqualsIgnoreOrder; import static io.trino.tpch.TpchTable.CUSTOMER; import static io.trino.tpch.TpchTable.ORDERS; import static java.lang.String.format; +import static java.nio.file.Files.createTempDirectory; import static org.assertj.core.api.Assertions.assertThat; public class TestHiveCreateExternalTable @@ -50,14 +50,14 @@ protected QueryRunner createQueryRunner() public void testCreateExternalTableWithData() throws IOException { - File tempDir = createTempDir(); - File tableLocation = new File(tempDir, "data"); + Path tempDir = createTempDirectory(null); + Path tableLocation = tempDir.resolve("data"); @Language("SQL") String createTableSql = format("" + "CREATE TABLE test_create_external " + "WITH (external_location = '%s') AS " + "SELECT * FROM tpch.tiny.nation", - tableLocation.toURI().toASCIIString()); + tableLocation.toUri().toASCIIString()); assertUpdate(createTableSql, 25); @@ -67,22 +67,23 @@ public void testCreateExternalTableWithData() MaterializedResult result = computeActual("SELECT DISTINCT regexp_replace(\"$path\", '/[^/]*$', '/') FROM test_create_external"); String tablePath = (String) result.getOnlyValue(); - assertThat(tablePath).startsWith(tableLocation.toURI().toString()); + assertThat(tablePath).startsWith(tableLocation.toFile().toURI().toString()); assertUpdate("DROP TABLE test_create_external"); - deleteRecursively(tempDir.toPath(), ALLOW_INSECURE); + deleteRecursively(tempDir, ALLOW_INSECURE); } @Test public void testCreateExternalTableAsWithExistingDirectory() + throws IOException { - File tempDir = createTempDir(); + Path tempDir = createTempDirectory(null); @Language("SQL") String createTableSql = format("" + "CREATE TABLE test_create_external_exists " + "WITH (external_location = '%s') AS " + "SELECT * FROM tpch.tiny.nation", - tempDir.toURI().toASCIIString()); + tempDir.toUri().toASCIIString()); assertQueryFails(createTableSql, "Target directory for table '.*' already exists:.*"); } diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveCreateExternalTableDisabled.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveCreateExternalTableDisabled.java index 7234709c7f39..cc4b9cab0bed 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveCreateExternalTableDisabled.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveCreateExternalTableDisabled.java @@ -20,14 +20,14 @@ import org.intellij.lang.annotations.Language; import org.testng.annotations.Test; -import java.io.File; +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 io.trino.tpch.TpchTable.CUSTOMER; import static io.trino.tpch.TpchTable.ORDERS; import static java.lang.String.format; +import static java.nio.file.Files.createTempDirectory; public class TestHiveCreateExternalTableDisabled extends AbstractTestQueryFramework @@ -48,30 +48,30 @@ protected QueryRunner createQueryRunner() public void testCreateExternalTableWithData() throws Exception { - File tempDir = createTempDir(); + Path tempDir = createTempDirectory(null); @Language("SQL") String createTableSql = format("" + "CREATE TABLE test_create_external " + "WITH (external_location = '%s') AS " + "SELECT * FROM tpch.tiny.nation", - tempDir.toURI().toASCIIString()); + tempDir.toUri().toASCIIString()); assertQueryFails(createTableSql, "Creating non-managed Hive tables is disabled"); - deleteRecursively(tempDir.toPath(), ALLOW_INSECURE); + deleteRecursively(tempDir, ALLOW_INSECURE); } @Test public void testCreateExternalTable() throws Exception { - File tempDir = createTempDir(); + Path tempDir = createTempDirectory(null); @Language("SQL") String createTableSql = format("" + "CREATE TABLE test_create_external (n TINYINT) " + "WITH (external_location = '%s')", - tempDir.toURI().toASCIIString()); + tempDir.toUri().toASCIIString()); assertQueryFails(createTableSql, "Cannot create non-managed Hive table"); - deleteRecursively(tempDir.toPath(), ALLOW_INSECURE); + deleteRecursively(tempDir, ALLOW_INSECURE); } } diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/AbstractTestBackupStore.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/AbstractTestBackupStore.java index 31ee44fb1715..41109864ae9b 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/AbstractTestBackupStore.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/AbstractTestBackupStore.java @@ -17,6 +17,7 @@ import org.testng.annotations.Test; import java.io.File; +import java.nio.file.Path; import java.util.UUID; import static java.nio.charset.StandardCharsets.UTF_8; @@ -28,7 +29,7 @@ public abstract class AbstractTestBackupStore { - protected File temporary; + protected Path temporary; protected T store; @Test @@ -36,7 +37,7 @@ public void testBackupStore() throws Exception { // backup first file - File file1 = new File(temporary, "file1"); + File file1 = temporary.resolve("file1").toFile(); Files.write("hello world", file1, UTF_8); UUID uuid1 = randomUUID(); @@ -45,7 +46,7 @@ public void testBackupStore() assertTrue(store.shardExists(uuid1)); // backup second file - File file2 = new File(temporary, "file2"); + File file2 = temporary.resolve("file2").toFile(); Files.write("bye bye", file2, UTF_8); UUID uuid2 = randomUUID(); @@ -54,12 +55,12 @@ public void testBackupStore() assertTrue(store.shardExists(uuid2)); // verify first file - File restore1 = new File(temporary, "restore1"); + File restore1 = temporary.resolve("restore1").toFile(); store.restoreShard(uuid1, restore1); assertEquals(readAllBytes(file1.toPath()), readAllBytes(restore1.toPath())); // verify second file - File restore2 = new File(temporary, "restore2"); + File restore2 = temporary.resolve("restore2").toFile(); store.restoreShard(uuid2, restore2); assertEquals(readAllBytes(file2.toPath()), readAllBytes(restore2.toPath())); diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestBackupManager.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestBackupManager.java index 5f5a34599bb5..4ebbd0c51dd1 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestBackupManager.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestBackupManager.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -32,12 +33,12 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ThreadLocalRandom; -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.raptor.legacy.RaptorErrorCode.RAPTOR_BACKUP_CORRUPTION; import static io.trino.plugin.raptor.legacy.RaptorErrorCode.RAPTOR_BACKUP_ERROR; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.nio.file.Files.createTempDirectory; import static java.util.Objects.requireNonNull; import static java.util.UUID.randomUUID; import static java.util.concurrent.TimeUnit.SECONDS; @@ -52,21 +53,22 @@ public class TestBackupManager private static final UUID FAILURE_UUID = randomUUID(); private static final UUID CORRUPTION_UUID = randomUUID(); - private File temporary; + private Path temporary; private BackupStore backupStore; private FileStorageService storageService; private BackupManager backupManager; @BeforeMethod public void setup() + throws IOException { - temporary = createTempDir(); + temporary = createTempDirectory(null); - FileBackupStore fileStore = new FileBackupStore(new File(temporary, "backup")); + FileBackupStore fileStore = new FileBackupStore(temporary.resolve("backup").toFile()); fileStore.start(); backupStore = new TestingBackupStore(fileStore); - storageService = new FileStorageService(new File(temporary, "data")); + storageService = new FileStorageService(temporary.resolve("data").toFile()); storageService.start(); backupManager = new BackupManager(Optional.of(backupStore), storageService, 5); @@ -76,7 +78,7 @@ public void setup() public void tearDown() throws Exception { - deleteRecursively(temporary.toPath(), ALLOW_INSECURE); + deleteRecursively(temporary, ALLOW_INSECURE); backupManager.shutdown(); } @@ -90,7 +92,7 @@ public void testSimple() List> futures = new ArrayList<>(); List uuids = new ArrayList<>(5); for (int i = 0; i < 5; i++) { - File file = new File(temporary, "file" + i); + File file = temporary.resolve("file" + i).toFile(); Files.write("hello world", file, UTF_8); uuids.add(randomUUID()); @@ -112,7 +114,7 @@ public void testFailure() assertEmptyStagingDirectory(); assertBackupStats(0, 0, 0); - File file = new File(temporary, "failure"); + File file = temporary.resolve("failure").toFile(); Files.write("hello world", file, UTF_8); assertThatThrownBy(() -> backupManager.submit(FAILURE_UUID, file).get(10, SECONDS)) @@ -133,7 +135,7 @@ public void testCorruption() assertEmptyStagingDirectory(); assertBackupStats(0, 0, 0); - File file = new File(temporary, "corrupt"); + File file = temporary.resolve("corrupt").toFile(); Files.write("hello world", file, UTF_8); assertThatThrownBy(() -> backupManager.submit(CORRUPTION_UUID, file).get(10, SECONDS)) diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestFileBackupStore.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestFileBackupStore.java index 8118aaa4c3f5..b113f9be8dbe 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestFileBackupStore.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestFileBackupStore.java @@ -18,12 +18,13 @@ import org.testng.annotations.Test; import java.io.File; +import java.io.IOException; import java.util.UUID; -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.lang.String.format; +import static java.nio.file.Files.createTempDirectory; import static org.testng.Assert.assertEquals; public class TestFileBackupStore @@ -31,9 +32,10 @@ public class TestFileBackupStore { @BeforeClass public void setup() + throws IOException { - temporary = createTempDir(); - store = new FileBackupStore(new File(temporary, "backup")); + temporary = createTempDirectory(null); + store = new FileBackupStore(temporary.resolve("backup").toFile()); store.start(); } @@ -41,14 +43,14 @@ public void setup() public void tearDown() throws Exception { - deleteRecursively(temporary.toPath(), ALLOW_INSECURE); + deleteRecursively(temporary, ALLOW_INSECURE); } @Test public void testFilePaths() { UUID uuid = UUID.fromString("701e1a79-74f7-4f56-b438-b41e8e7d019d"); - File expected = new File(temporary, format("backup/70/1e/%s.orc", uuid)); + File expected = temporary.resolve("backup").resolve("70").resolve("1e").resolve(format("%s.orc", uuid)).toFile(); assertEquals(store.getBackupFile(uuid), expected); } } diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestHttpBackupStore.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestHttpBackupStore.java index dd1b43cf408a..a83da1315a74 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestHttpBackupStore.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/backup/TestHttpBackupStore.java @@ -38,11 +38,11 @@ import java.util.Map; import java.util.function.Supplier; -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 com.google.inject.util.Modules.override; import static io.airlift.jaxrs.JaxrsBinder.jaxrsBinder; +import static java.nio.file.Files.createTempDirectory; @Test(singleThreaded = true) public class TestHttpBackupStore @@ -52,8 +52,9 @@ public class TestHttpBackupStore @BeforeMethod public void setup() + throws IOException { - temporary = createTempDir(); + temporary = createTempDirectory(null); Map properties = ImmutableMap.builder() .put("backup.http.uri", "http://localhost:8080") @@ -83,7 +84,7 @@ public void setup() public void teardown() throws IOException { - deleteRecursively(temporary.toPath(), ALLOW_INSECURE); + deleteRecursively(temporary, ALLOW_INSECURE); if (lifeCycleManager != null) { lifeCycleManager.stop(); } diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/metadata/TestRaptorSplitManager.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/metadata/TestRaptorSplitManager.java index 478926ec123a..1ceb0f6b459a 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/metadata/TestRaptorSplitManager.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/metadata/TestRaptorSplitManager.java @@ -42,17 +42,16 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.Path; import java.util.List; import java.util.Optional; import java.util.UUID; import static com.google.common.base.Ticker.systemTicker; import static com.google.common.collect.Iterables.getOnlyElement; -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.concurrent.MoreFutures.getFutureValue; @@ -66,6 +65,7 @@ import static io.trino.spi.type.VarcharType.createVarcharType; import static io.trino.testing.TestingConnectorSession.SESSION; import static java.lang.String.format; +import static java.nio.file.Files.createTempDirectory; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.stream.Collectors.toList; import static org.testng.Assert.assertEquals; @@ -80,7 +80,7 @@ public class TestRaptorSplitManager .build(); private Handle dummyHandle; - private File temporary; + private Path temporary; private RaptorMetadata metadata; private RaptorSplitManager raptorSplitManager; private ConnectorTableHandle tableHandle; @@ -94,7 +94,7 @@ public void setup() Jdbi dbi = createTestingJdbi(); dummyHandle = dbi.open(); createTablesWithRetry(dbi); - temporary = createTempDir(); + temporary = createTempDirectory(null); AssignmentLimiter assignmentLimiter = new AssignmentLimiter(ImmutableSet::of, systemTicker(), new MetadataConfig()); shardManager = new DatabaseShardManager(dbi, new DaoSupplier<>(dbi, ShardDao.class), ImmutableSet::of, assignmentLimiter, systemTicker(), new Duration(0, MINUTES)); TestingNodeManager nodeManager = new TestingNodeManager(); @@ -134,7 +134,7 @@ public void teardown() throws IOException { dummyHandle.close(); - deleteRecursively(temporary.toPath(), ALLOW_INSECURE); + deleteRecursively(temporary, ALLOW_INSECURE); } @Test diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/metadata/TestShardCleaner.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/metadata/TestShardCleaner.java index cb38bb4037da..6d77f4cb9a49 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/metadata/TestShardCleaner.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/metadata/TestShardCleaner.java @@ -34,6 +34,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; @@ -41,13 +42,13 @@ import java.util.Set; import java.util.UUID; -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.raptor.legacy.DatabaseTesting.createTestingJdbi; import static io.trino.plugin.raptor.legacy.metadata.SchemaDaoUtil.createTablesWithRetry; import static io.trino.plugin.raptor.legacy.util.UuidUtil.uuidFromBytes; import static io.trino.testing.QueryAssertions.assertEqualsIgnoreOrder; +import static java.nio.file.Files.createTempDirectory; import static java.util.Arrays.asList; import static java.util.UUID.randomUUID; import static java.util.concurrent.TimeUnit.HOURS; @@ -61,7 +62,7 @@ public class TestShardCleaner { private Jdbi dbi; private Handle dummyHandle; - private File temporary; + private Path temporary; private StorageService storageService; private BackupStore backupStore; private TestingTicker ticker; @@ -69,17 +70,18 @@ public class TestShardCleaner @BeforeMethod public void setup() + throws IOException { dbi = createTestingJdbi(); dummyHandle = dbi.open(); createTablesWithRetry(dbi); - temporary = createTempDir(); - File directory = new File(temporary, "data"); + temporary = createTempDirectory(null); + File directory = temporary.resolve("data").toFile(); storageService = new FileStorageService(directory); storageService.start(); - File backupDirectory = new File(temporary, "backup"); + File backupDirectory = temporary.resolve("backup").toFile(); backupStore = new FileBackupStore(backupDirectory); ((FileBackupStore) backupStore).start(); @@ -110,7 +112,7 @@ public void teardown() if (dummyHandle != null) { dummyHandle.close(); } - deleteRecursively(temporary.toPath(), ALLOW_INSECURE); + deleteRecursively(temporary, ALLOW_INSECURE); } @Test @@ -406,7 +408,7 @@ private void createShardBackups(UUID... uuids) throws IOException { for (UUID uuid : uuids) { - File file = new File(temporary, "empty-" + randomUUID()); + File file = temporary.resolve("empty-" + randomUUID()).toFile(); assertTrue(file.createNewFile()); backupStore.backupShard(uuid, file); } diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestFileStorageService.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestFileStorageService.java index 9c1830365783..a3fedd7d949b 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestFileStorageService.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestFileStorageService.java @@ -19,14 +19,16 @@ import org.testng.annotations.Test; import java.io.File; +import java.io.IOException; +import java.nio.file.Path; import java.util.Set; import java.util.UUID; -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.raptor.legacy.storage.FileStorageService.getFileSystemPath; import static java.lang.String.format; +import static java.nio.file.Files.createTempDirectory; import static java.util.UUID.randomUUID; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -37,14 +39,15 @@ @Test(singleThreaded = true) public class TestFileStorageService { - private File temporary; + private Path temporary; private FileStorageService store; @BeforeMethod public void setup() + throws IOException { - temporary = createTempDir(); - store = new FileStorageService(temporary); + temporary = createTempDirectory(null); + store = new FileStorageService(temporary.toFile()); store.start(); } @@ -52,7 +55,7 @@ public void setup() public void tearDown() throws Exception { - deleteRecursively(temporary.toPath(), ALLOW_INSECURE); + deleteRecursively(temporary, ALLOW_INSECURE); } @Test @@ -67,9 +70,9 @@ public void testGetFileSystemPath() public void testFilePaths() { UUID uuid = UUID.fromString("701e1a79-74f7-4f56-b438-b41e8e7d019d"); - File staging = new File(temporary, format("staging/%s.orc", uuid)); - File storage = new File(temporary, format("storage/70/1e/%s.orc", uuid)); - File quarantine = new File(temporary, format("quarantine/%s.orc", uuid)); + File staging = temporary.resolve("staging").resolve(format("%s.orc", uuid)).toFile(); + File storage = temporary.resolve("storage").resolve("70").resolve("1e").resolve(format("%s.orc", uuid)).toFile(); + File quarantine = temporary.resolve("quarantine").resolve(format("%s.orc", uuid)).toFile(); assertEquals(store.getStagingFile(uuid), staging); assertEquals(store.getStorageFile(uuid), storage); assertEquals(store.getQuarantineFile(uuid), quarantine); @@ -79,9 +82,9 @@ public void testFilePaths() public void testStop() throws Exception { - File staging = new File(temporary, "staging"); - File storage = new File(temporary, "storage"); - File quarantine = new File(temporary, "quarantine"); + File staging = temporary.resolve("staging").toFile(); + File storage = temporary.resolve("storage").toFile(); + File quarantine = temporary.resolve("quarantine").toFile(); assertDirectory(staging); assertDirectory(storage); @@ -116,7 +119,7 @@ public void testGetStorageShards() assertTrue(file.createNewFile()); } - File storage = new File(temporary, "storage"); + File storage = temporary.resolve("storage").toFile(); assertTrue(new File(storage, "abc").mkdir()); assertTrue(new File(storage, "ab/cd").mkdirs()); assertTrue(new File(storage, format("ab/cd/%s.junk", randomUUID())).createNewFile()); diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestOrcFileRewriter.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestOrcFileRewriter.java index 8713557dfb08..7e03d1ce9a53 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestOrcFileRewriter.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestOrcFileRewriter.java @@ -32,11 +32,12 @@ import org.testng.annotations.Test; import java.io.File; +import java.io.IOException; import java.math.BigDecimal; +import java.nio.file.Path; import java.util.BitSet; import java.util.List; -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.json.JsonCodec.jsonCodec; @@ -54,6 +55,7 @@ import static io.trino.testing.StructuralTestUtil.mapBlockOf; import static io.trino.testing.StructuralTestUtil.mapBlocksEqual; 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 org.testng.Assert.assertEquals; @@ -66,19 +68,20 @@ public class TestOrcFileRewriter { private static final JsonCodec METADATA_CODEC = jsonCodec(OrcFileMetadata.class); - private File temporary; + private Path temporary; @BeforeClass public void setup() + throws IOException { - temporary = createTempDir(); + temporary = createTempDirectory(null); } @AfterClass(alwaysRun = true) public void tearDown() throws Exception { - deleteRecursively(temporary.toPath(), ALLOW_INSECURE); + deleteRecursively(temporary, ALLOW_INSECURE); } @Test @@ -95,7 +98,7 @@ public void testRewrite() List columnTypes = ImmutableList.of(BIGINT, createVarcharType(20), arrayType, mapType, arrayOfArrayType, decimalType); - File file = new File(temporary, randomUUID().toString()); + File file = temporary.resolve(randomUUID().toString()).toFile(); try (OrcFileWriter writer = new OrcFileWriter(columnIds, columnTypes, file)) { List pages = rowPagesBuilder(columnTypes) .row(123L, "hello", arrayBlockOf(BIGINT, 1, 2), mapBlockOf(createVarcharType(5), BOOLEAN, "k1", true), arrayBlockOf(arrayType, arrayBlockOf(BIGINT, 5)), new BigDecimal("2.3")) @@ -190,7 +193,7 @@ public void testRewrite() rowsToDelete.set(3); rowsToDelete.set(4); - File newFile = new File(temporary, randomUUID().toString()); + File newFile = temporary.resolve(randomUUID().toString()).toFile(); OrcFileInfo info = OrcFileRewriter.rewrite(file, newFile, rowsToDelete); assertEquals(info.getRowCount(), 2); assertEquals(info.getUncompressedSize(), 94); @@ -266,7 +269,7 @@ public void testRewriteWithoutMetadata() List columnIds = ImmutableList.of(3L, 7L); List columnTypes = ImmutableList.of(BIGINT, createVarcharType(20)); - File file = new File(temporary, randomUUID().toString()); + File file = temporary.resolve(randomUUID().toString()).toFile(); try (OrcFileWriter writer = new OrcFileWriter(columnIds, columnTypes, file, false)) { List pages = rowPagesBuilder(columnTypes) .row(123L, "hello") @@ -307,7 +310,7 @@ public void testRewriteWithoutMetadata() BitSet rowsToDelete = new BitSet(5); rowsToDelete.set(1); - File newFile = new File(temporary, randomUUID().toString()); + File newFile = temporary.resolve(randomUUID().toString()).toFile(); OrcFileInfo info = OrcFileRewriter.rewrite(file, newFile, rowsToDelete); assertEquals(info.getRowCount(), 1); assertEquals(info.getUncompressedSize(), 13); @@ -343,7 +346,7 @@ public void testRewriteAllRowsDeleted() List columnIds = ImmutableList.of(3L); List columnTypes = ImmutableList.of(BIGINT); - File file = new File(temporary, randomUUID().toString()); + File file = temporary.resolve(randomUUID().toString()).toFile(); try (OrcFileWriter writer = new OrcFileWriter(columnIds, columnTypes, file)) { writer.appendPages(rowPagesBuilder(columnTypes).row(123L).row(456L).build()); } @@ -352,7 +355,7 @@ public void testRewriteAllRowsDeleted() rowsToDelete.set(0); rowsToDelete.set(1); - File newFile = new File(temporary, randomUUID().toString()); + File newFile = temporary.resolve(randomUUID().toString()).toFile(); OrcFileInfo info = OrcFileRewriter.rewrite(file, newFile, rowsToDelete); assertEquals(info.getRowCount(), 0); assertEquals(info.getUncompressedSize(), 0); @@ -367,14 +370,14 @@ public void testRewriteNoRowsDeleted() List columnIds = ImmutableList.of(3L); List columnTypes = ImmutableList.of(BIGINT); - File file = new File(temporary, randomUUID().toString()); + File file = temporary.resolve(randomUUID().toString()).toFile(); try (OrcFileWriter writer = new OrcFileWriter(columnIds, columnTypes, file)) { writer.appendPages(rowPagesBuilder(columnTypes).row(123L).row(456L).build()); } BitSet rowsToDelete = new BitSet(); - File newFile = new File(temporary, randomUUID().toString()); + File newFile = temporary.resolve(randomUUID().toString()).toFile(); OrcFileInfo info = OrcFileRewriter.rewrite(file, newFile, rowsToDelete); assertEquals(info.getRowCount(), 2); assertEquals(info.getUncompressedSize(), 16); @@ -389,7 +392,7 @@ public void testUncompressedSize() List columnIds = ImmutableList.of(1L, 2L, 3L, 4L, 5L); List columnTypes = ImmutableList.of(BOOLEAN, BIGINT, DOUBLE, createVarcharType(10), VARBINARY); - File file = new File(temporary, randomUUID().toString()); + File file = temporary.resolve(randomUUID().toString()).toFile(); try (OrcFileWriter writer = new OrcFileWriter(columnIds, columnTypes, file)) { List pages = rowPagesBuilder(columnTypes) .row(true, 123L, 98.7, "hello", utf8Slice("abc")) @@ -399,7 +402,7 @@ public void testUncompressedSize() writer.appendPages(pages); } - File newFile = new File(temporary, randomUUID().toString()); + File newFile = temporary.resolve(randomUUID().toString()).toFile(); OrcFileInfo info = OrcFileRewriter.rewrite(file, newFile, new BitSet()); assertEquals(info.getRowCount(), 3); assertEquals(info.getUncompressedSize(), 55); diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestRaptorStorageManager.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestRaptorStorageManager.java index 2e17b05481e6..0c38d010a569 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestRaptorStorageManager.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestRaptorStorageManager.java @@ -55,6 +55,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.Arrays; import java.util.BitSet; import java.util.Collection; @@ -66,7 +67,6 @@ import java.util.concurrent.TimeUnit; import static com.google.common.hash.Hashing.md5; -import static com.google.common.io.Files.createTempDir; import static com.google.common.io.Files.hash; import static com.google.common.io.MoreFiles.deleteRecursively; import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE; @@ -96,6 +96,7 @@ import static io.trino.testing.assertions.Assert.assertEquals; import static io.trino.type.InternalTypeManager.TESTING_TYPE_MANAGER; import static java.lang.String.format; +import static java.nio.file.Files.createTempDirectory; import static org.joda.time.DateTimeZone.UTC; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotEquals; @@ -127,7 +128,7 @@ public class TestRaptorStorageManager private final NodeManager nodeManager = new TestingNodeManager(); private Handle dummyHandle; - private File temporary; + private Path temporary; private StorageService storageService; private ShardRecoveryManager recoveryManager; private FileBackupStore fileBackupStore; @@ -136,13 +137,14 @@ public class TestRaptorStorageManager @BeforeMethod public void setup() + throws IOException { - temporary = createTempDir(); - File directory = new File(temporary, "data"); + temporary = createTempDirectory(null); + File directory = temporary.resolve("data").toFile(); storageService = new FileStorageService(directory); storageService.start(); - File backupDirectory = new File(temporary, "backup"); + File backupDirectory = temporary.resolve("backup").toFile(); fileBackupStore = new FileBackupStore(backupDirectory); fileBackupStore.start(); backupStore = Optional.of(fileBackupStore); @@ -165,7 +167,7 @@ public void tearDown() if (dummyHandle != null) { dummyHandle.close(); } - deleteRecursively(temporary.toPath(), ALLOW_INSECURE); + deleteRecursively(temporary, ALLOW_INSECURE); } @Test @@ -365,7 +367,7 @@ public void testRewriter() public void testWriterRollback() { // verify staging directory is empty - File staging = new File(new File(temporary, "data"), "staging"); + File staging = temporary.resolve("data").resolve("staging").toFile(); assertDirectory(staging); assertEquals(staging.list(), new String[] {}); diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardEjector.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardEjector.java index cfc4b0c7d3d8..8e39982bd67a 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardEjector.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardEjector.java @@ -35,7 +35,9 @@ import org.testng.annotations.Test; import java.io.File; +import java.io.IOException; import java.net.URI; +import java.nio.file.Path; import java.util.List; import java.util.Optional; import java.util.OptionalInt; @@ -43,13 +45,13 @@ import java.util.Set; import java.util.UUID; -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.raptor.legacy.DatabaseTesting.createTestingJdbi; import static io.trino.plugin.raptor.legacy.metadata.SchemaDaoUtil.createTablesWithRetry; import static io.trino.plugin.raptor.legacy.metadata.TestDatabaseShardManager.createShardManager; import static io.trino.spi.type.BigintType.BIGINT; +import static java.nio.file.Files.createTempDirectory; import static java.util.UUID.randomUUID; import static java.util.concurrent.TimeUnit.HOURS; import static java.util.stream.Collectors.toSet; @@ -63,19 +65,20 @@ public class TestShardEjector private Jdbi dbi; private Handle dummyHandle; private ShardManager shardManager; - private File dataDir; + private Path dataDir; private StorageService storageService; @BeforeMethod public void setup() + throws IOException { dbi = createTestingJdbi(); dummyHandle = dbi.open(); createTablesWithRetry(dbi); shardManager = createShardManager(dbi); - dataDir = createTempDir(); - storageService = new FileStorageService(dataDir); + dataDir = createTempDirectory(null); + storageService = new FileStorageService(dataDir.toFile()); storageService.start(); } @@ -87,7 +90,7 @@ public void teardown() dummyHandle.close(); } if (dataDir != null) { - deleteRecursively(dataDir.toPath(), ALLOW_INSECURE); + deleteRecursively(dataDir, ALLOW_INSECURE); } } diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardRecovery.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardRecovery.java index a1f797e08a82..5a4a31b6f692 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardRecovery.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardRecovery.java @@ -28,13 +28,14 @@ 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 java.util.OptionalLong; import java.util.UUID; import static com.google.common.collect.Iterables.getOnlyElement; -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.raptor.legacy.DatabaseTesting.createTestingJdbi; @@ -43,8 +44,9 @@ import static io.trino.plugin.raptor.legacy.metadata.TestDatabaseShardManager.createShardManager; import static io.trino.plugin.raptor.legacy.storage.RaptorStorageManager.xxhash64; import static io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy; -import static java.io.File.createTempFile; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.nio.file.Files.createTempDirectory; +import static java.nio.file.Files.createTempFile; import static java.util.concurrent.TimeUnit.MINUTES; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -58,15 +60,16 @@ public class TestShardRecovery private StorageService storageService; private ShardRecoveryManager recoveryManager; private Handle dummyHandle; - private File temporary; + private Path temporary; private FileBackupStore backupStore; @BeforeMethod public void setup() + throws IOException { - temporary = createTempDir(); - File directory = new File(temporary, "data"); - File backupDirectory = new File(temporary, "backup"); + temporary = createTempDirectory(null); + File directory = temporary.resolve("data").toFile(); + File backupDirectory = temporary.resolve("backup").toFile(); backupStore = new FileBackupStore(backupDirectory); backupStore.start(); storageService = new FileStorageService(directory); @@ -86,7 +89,7 @@ public void tearDown() if (dummyHandle != null) { dummyHandle.close(); } - deleteRecursively(temporary.toPath(), ALLOW_INSECURE); + deleteRecursively(temporary, ALLOW_INSECURE); } @SuppressWarnings("EmptyTryBlock") @@ -96,7 +99,7 @@ public void testShardRecovery() { UUID shardUuid = UUID.randomUUID(); File file = storageService.getStorageFile(shardUuid); - File tempFile = createTempFile("tmp", null, temporary); + File tempFile = createTempFile(temporary, "tmp", null).toFile(); Files.write("test data", tempFile, UTF_8); @@ -119,7 +122,7 @@ public void testShardRecoveryExistingFileSizeMismatch() UUID shardUuid = UUID.randomUUID(); // write data and backup - File tempFile = createTempFile("tmp", null, temporary); + File tempFile = createTempFile(temporary, "tmp", null).toFile(); Files.write("test data", tempFile, UTF_8); backupStore.backupShard(shardUuid, tempFile); @@ -157,7 +160,7 @@ public void testShardRecoveryExistingFileChecksumMismatch() UUID shardUuid = UUID.randomUUID(); // write data and backup - File tempFile = createTempFile("tmp", null, temporary); + File tempFile = createTempFile(temporary, "tmp", null).toFile(); Files.write("test data", tempFile, UTF_8); backupStore.backupShard(shardUuid, tempFile); diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardWriter.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardWriter.java index f5cd1bcf3ac4..62fa5f8ebe64 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardWriter.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/TestShardWriter.java @@ -32,9 +32,10 @@ import org.testng.annotations.Test; import java.io.File; +import java.io.IOException; +import java.nio.file.Path; import java.util.List; -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.json.JsonCodec.jsonCodec; @@ -53,6 +54,7 @@ import static io.trino.testing.StructuralTestUtil.mapBlockOf; import static io.trino.testing.StructuralTestUtil.mapBlocksEqual; import static io.trino.type.InternalTypeManager.TESTING_TYPE_MANAGER; +import static java.nio.file.Files.createTempDirectory; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; @@ -60,21 +62,22 @@ public class TestShardWriter { - private File directory; + private Path directory; private static final JsonCodec METADATA_CODEC = jsonCodec(OrcFileMetadata.class); @BeforeClass public void setup() + throws IOException { - directory = createTempDir(); + directory = createTempDirectory(null); } @AfterClass(alwaysRun = true) public void tearDown() throws Exception { - deleteRecursively(directory.toPath(), ALLOW_INSECURE); + deleteRecursively(directory, ALLOW_INSECURE); } @Test @@ -88,7 +91,7 @@ public void testWriter() TypeSignatureParameter.typeParameter(createVarcharType(10).getTypeSignature()), TypeSignatureParameter.typeParameter(BOOLEAN.getTypeSignature()))); List columnTypes = ImmutableList.of(BIGINT, createVarcharType(10), VARBINARY, DOUBLE, BOOLEAN, arrayType, mapType, arrayOfArrayType); - File file = new File(directory, System.nanoTime() + ".orc"); + File file = directory.resolve(System.nanoTime() + ".orc").toFile(); byte[] bytes1 = octets(0x00, 0xFE, 0xFF); byte[] bytes3 = octets(0x01, 0x02, 0x19, 0x80); diff --git a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/organization/TestShardCompactor.java b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/organization/TestShardCompactor.java index c558c52dd8da..426b551bf4b3 100644 --- a/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/organization/TestShardCompactor.java +++ b/plugin/trino-raptor-legacy/src/test/java/io/trino/plugin/raptor/legacy/storage/organization/TestShardCompactor.java @@ -40,14 +40,13 @@ import org.testng.annotations.BeforeMethod; 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.OptionalInt; import java.util.Set; import java.util.UUID; -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.concurrent.MoreFutures.getFutureValue; @@ -64,6 +63,7 @@ import static io.trino.testing.QueryAssertions.assertEqualsIgnoreOrder; import static io.trino.testing.TestingConnectorSession.SESSION; import static io.trino.testing.assertions.Assert.assertEquals; +import static java.nio.file.Files.createTempDirectory; import static java.util.Collections.nCopies; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toSet; @@ -81,16 +81,17 @@ public class TestShardCompactor private RaptorStorageManager storageManager; private ShardCompactor compactor; - private File temporary; + private Path temporary; private Handle dummyHandle; @BeforeMethod public void setup() + throws IOException { - temporary = createTempDir(); + temporary = createTempDirectory(null); Jdbi dbi = createTestingJdbi(); dummyHandle = dbi.open(); - storageManager = createRaptorStorageManager(dbi, temporary, MAX_SHARD_ROWS); + storageManager = createRaptorStorageManager(dbi, temporary.toFile(), MAX_SHARD_ROWS); compactor = new ShardCompactor(storageManager, READER_OPTIONS, new TypeOperators()); } @@ -101,7 +102,7 @@ public void tearDown() if (dummyHandle != null) { dummyHandle.close(); } - deleteRecursively(temporary.toPath(), ALLOW_INSECURE); + deleteRecursively(temporary, ALLOW_INSECURE); } @Test