Skip to content

Commit

Permalink
Properly close Glue metastore in tests
Browse files Browse the repository at this point in the history
Fix thread leak during tests' execution.
  • Loading branch information
findepi committed May 13, 2024
1 parent b6a92df commit 1c6c7ef
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.trino.plugin.deltalake.metastore.TestingDeltaLakeMetastoreModule;
import io.trino.plugin.hive.TestingHivePlugin;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.testing.AbstractTestQueryFramework;
import io.trino.testing.DistributedQueryRunner;
import io.trino.testing.QueryRunner;
Expand Down Expand Up @@ -175,6 +176,9 @@ public void cleanup()
{
if (metastore != null) {
metastore.dropDatabase(SCHEMA, false);
if (metastore instanceof GlueHiveMetastore glueMetastore) {
glueMetastore.shutdown();
}
deleteRecursively(dataDirectory, ALLOW_INSECURE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.google.common.collect.ImmutableMap;
import io.trino.Session;
import io.trino.plugin.hive.TestingHivePlugin;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.testing.DistributedQueryRunner;
import io.trino.testing.QueryRunner;
import org.junit.jupiter.api.AfterAll;
Expand All @@ -40,7 +40,7 @@ public class TestDeltaLakeSharedGlueMetastoreWithTableRedirections
extends BaseDeltaLakeSharedMetastoreWithTableRedirectionsTest
{
private Path dataDirectory;
private HiveMetastore glueMetastore;
private GlueHiveMetastore glueMetastore;

@Override
protected QueryRunner createQueryRunner()
Expand Down Expand Up @@ -84,6 +84,7 @@ public void cleanup()
{
// Data is on the local disk and will be deleted by the deleteOnExit hook
glueMetastore.dropDatabase(schema, false);
glueMetastore.shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ public void tearDown()
{
// Data is on the local disk and will be deleted by query runner cleanup
metastore.dropDatabase(schema, false);
metastore.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void cleanup()
{
if (metastore != null) {
metastore.dropDatabase(SCHEMA, false);
metastore.shutdown();
deleteRecursively(dataDirectory, ALLOW_INSECURE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ public void tearDown()
{
// Data is on the local disk and will be deleted by query runner cleanup
metastore.dropDatabase(schema, false);
metastore.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package io.trino.plugin.deltalake.metastore.glue;

import io.trino.plugin.deltalake.DeltaLakeQueryRunner;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.testing.AbstractTestQueryFramework;
import io.trino.testing.QueryRunner;
import io.trino.testing.sql.TestTable;
Expand All @@ -39,7 +39,7 @@
public class TestDeltaLakeViewsGlueMetastore
extends AbstractTestQueryFramework
{
private HiveMetastore metastore;
private GlueHiveMetastore metastore;
private String schema;

@Override
Expand All @@ -62,6 +62,7 @@ public void cleanup()
throws IOException
{
metastore.dropDatabase(schema, false);
metastore.shutdown();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import io.trino.Session;
import io.trino.plugin.base.util.UncheckedCloseable;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.spi.connector.SchemaNotFoundException;
import io.trino.testing.AbstractTestQueryFramework;
import org.intellij.lang.annotations.Language;
Expand Down Expand Up @@ -54,7 +54,7 @@ public abstract class BaseS3AndGlueMetastoreTest
protected final String bucketName;
protected final String schemaName = "test_glue_s3_" + randomNameSuffix();

protected HiveMetastore metastore;
protected GlueHiveMetastore metastore;
protected S3Client s3;

protected BaseS3AndGlueMetastoreTest(String partitionByKeyword, String locationKeyword, String bucketName)
Expand All @@ -75,6 +75,7 @@ public void tearDown()
{
if (metastore != null) {
metastore.dropDatabase(schemaName, true);
metastore.shutdown();
metastore = null;
}
if (s3 != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public void cleanup()
{
if (metastore != null) {
metastore.dropDatabase(SCHEMA, false);
metastore.shutdown();
deleteRecursively(dataDirectory, ALLOW_INSECURE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.trino.plugin.hive.metastore;

import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import org.junit.jupiter.api.AfterAll;

import java.io.IOException;
Expand All @@ -27,7 +28,7 @@ final class TestGlueHiveMetastore
extends AbstractTestHiveMetastore
{
private final Path tempDir;
private final HiveMetastore metastore;
private final GlueHiveMetastore metastore;

TestGlueHiveMetastore()
throws IOException
Expand All @@ -40,6 +41,7 @@ final class TestGlueHiveMetastore
void tearDown()
throws IOException
{
metastore.shutdown();
deleteRecursively(tempDir, ALLOW_INSECURE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import io.trino.Session;
import io.trino.execution.Failure;
import io.trino.plugin.hive.metastore.Database;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.plugin.iceberg.TestingIcebergPlugin;
import io.trino.spi.security.PrincipalType;
import io.trino.testing.AbstractTestQueryFramework;
Expand Down Expand Up @@ -59,7 +59,7 @@ public class TestIcebergGlueTableOperationsInsertFailure

private final String schemaName = "test_iceberg_glue_" + randomNameSuffix();

private HiveMetastore glueHiveMetastore;
private GlueHiveMetastore glueHiveMetastore;

@Override
protected QueryRunner createQueryRunner()
Expand Down Expand Up @@ -111,6 +111,7 @@ public void cleanup()
if (glueHiveMetastore != null) {
// Data is on the local disk and will be deleted by the deleteOnExit hook
glueHiveMetastore.dropDatabase(schemaName, false);
glueHiveMetastore.shutdown();
}
}
catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import io.airlift.log.Logger;
import io.trino.Session;
import io.trino.plugin.hive.TestingHivePlugin;
import io.trino.plugin.hive.metastore.HiveMetastore;
import io.trino.plugin.hive.metastore.glue.GlueHiveMetastore;
import io.trino.plugin.iceberg.BaseSharedMetastoreTest;
import io.trino.plugin.iceberg.IcebergPlugin;
import io.trino.plugin.tpch.TpchPlugin;
Expand Down Expand Up @@ -55,7 +55,7 @@ public class TestSharedGlueMetastore
private static final String HIVE_CATALOG = "hive";

private Path dataDirectory;
private HiveMetastore glueMetastore;
private GlueHiveMetastore glueMetastore;

@Override
protected QueryRunner createQueryRunner()
Expand Down Expand Up @@ -115,6 +115,7 @@ public void cleanup()
if (glueMetastore != null) {
// Data is on the local disk and will be deleted by the deleteOnExit hook
glueMetastore.dropDatabase(schema, false);
glueMetastore.shutdown();
}
}
catch (Exception e) {
Expand Down

0 comments on commit 1c6c7ef

Please sign in to comment.