Skip to content

Commit

Permalink
[apache#1361] test(postgres-jdbc) support multi pg version in IT (apa…
Browse files Browse the repository at this point in the history
…che#1693)

### What changes were proposed in this pull request?
Use separate classes representing various PG versions.
junit5 doesn't support class-level ParameterizedTest. so use a separate
class.

### Why are the changes needed?
Test compatibility with various versions of PG.

Fix: apache#1361 

### Does this PR introduce _any_ user-facing change?
no

### How was this patch tested?
existing IT
  • Loading branch information
FANNG1 authored Jan 25, 2024
1 parent 8b753fd commit 93e2af0
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void startup() throws IOException {
.withPassword("root");
mySQLContainer.start();
postgreSQLContainer =
new PostgreSQLContainer<>(CatalogPostgreSqlIT.POSTGRES_IMAGE)
new PostgreSQLContainer<>(CatalogPostgreSqlIT.DEFAULT_POSTGRES_IMAGE)
.withDatabaseName(TEST_DB_NAME)
.withUsername("root")
.withPassword("root");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,40 +49,43 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.testcontainers.containers.PostgreSQLContainer;

@Tag("gravitino-docker-it")
@TestInstance(Lifecycle.PER_CLASS)
public class CatalogPostgreSqlIT extends AbstractIT {
public static String metalakeName = GravitinoITUtils.genRandomName("postgresql_it_metalake");
public static String catalogName = GravitinoITUtils.genRandomName("postgresql_it_catalog");
public static String schemaName = GravitinoITUtils.genRandomName("postgresql_it_schema");
public static String tableName = GravitinoITUtils.genRandomName("postgresql_it_table");
public static String alertTableName = "alert_table_name";
public static String table_comment = "table_comment";

public static String schema_comment = "schema_comment";

public static String POSTGRESQL_COL_NAME1 = "postgresql_col_name1";
public static String POSTGRESQL_COL_NAME2 = "postgresql_col_name2";
public static String POSTGRESQL_COL_NAME3 = "postgresql_col_name3";
public static final String DEFAULT_POSTGRES_IMAGE = "postgres:13";
public static final String DOWNLOAD_JDBC_DRIVER_URL =
"https://jdbc.postgresql.org/download/postgresql-42.7.0.jar";
private static final String provider = "jdbc-postgresql";

private static GravitinoMetaLake metalake;
public String metalakeName = GravitinoITUtils.genRandomName("postgresql_it_metalake");
public String catalogName = GravitinoITUtils.genRandomName("postgresql_it_catalog");
public String schemaName = GravitinoITUtils.genRandomName("postgresql_it_schema");
public String tableName = GravitinoITUtils.genRandomName("postgresql_it_table");
public String alertTableName = "alert_table_name";
public String table_comment = "table_comment";
public String schema_comment = "schema_comment";
public String POSTGRESQL_COL_NAME1 = "postgresql_col_name1";
public String POSTGRESQL_COL_NAME2 = "postgresql_col_name2";
public String POSTGRESQL_COL_NAME3 = "postgresql_col_name3";
private final String provider = "jdbc-postgresql";

private static Catalog catalog;
private GravitinoMetaLake metalake;

private static PostgreSqlService postgreSqlService;
private Catalog catalog;

private static PostgreSQLContainer<?> POSTGRESQL_CONTAINER;
private PostgreSqlService postgreSqlService;

protected static final String TEST_DB_NAME = GravitinoITUtils.genRandomName("test_db");
private PostgreSQLContainer<?> POSTGRESQL_CONTAINER;

public static final String POSTGRES_IMAGE = "postgres:13";
protected final String TEST_DB_NAME = GravitinoITUtils.genRandomName("test_db");

protected String postgreImageName = DEFAULT_POSTGRES_IMAGE;

@BeforeAll
public static void startup() throws IOException {
public void startup() throws IOException {

if (!ITUtils.EMBEDDED_TEST_MODE.equals(testMode)) {
String gravitinoHome = System.getenv("GRAVITINO_HOME");
Expand All @@ -91,7 +94,7 @@ public static void startup() throws IOException {
}

POSTGRESQL_CONTAINER =
new PostgreSQLContainer<>(POSTGRES_IMAGE)
new PostgreSQLContainer<>(postgreImageName)
.withDatabaseName(TEST_DB_NAME)
.withUsername("root")
.withPassword("root");
Expand All @@ -103,7 +106,7 @@ public static void startup() throws IOException {
}

@AfterAll
public static void stop() {
public void stop() {
clearTableAndSchema();
client.dropMetalake(NameIdentifier.of(metalakeName));
postgreSqlService.close();
Expand All @@ -116,7 +119,7 @@ private void resetSchema() {
createSchema();
}

private static void clearTableAndSchema() {
private void clearTableAndSchema() {
NameIdentifier[] nameIdentifiers =
catalog.asTableCatalog().listTables(Namespace.of(metalakeName, catalogName, schemaName));
for (NameIdentifier nameIdentifier : nameIdentifiers) {
Expand All @@ -125,7 +128,7 @@ private static void clearTableAndSchema() {
catalog.asSchemas().dropSchema(NameIdentifier.of(metalakeName, catalogName, schemaName), false);
}

private static void createMetalake() {
private void createMetalake() {
GravitinoMetaLake[] gravitinoMetaLakes = client.listMetalakes();
Assertions.assertEquals(0, gravitinoMetaLakes.length);

Expand All @@ -137,7 +140,7 @@ private static void createMetalake() {
metalake = loadMetalake;
}

private static void createCatalog() {
private void createCatalog() {
Map<String, String> catalogProperties = Maps.newHashMap();

try {
Expand Down Expand Up @@ -166,7 +169,7 @@ private static void createCatalog() {
catalog = loadCatalog;
}

private static void createSchema() {
private void createSchema() {
NameIdentifier ident = NameIdentifier.of(metalakeName, catalogName, schemaName);

Schema createdSchema =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/

package com.datastrato.gravitino.integration.test.catalog.jdbc.postgresql;

import org.junit.jupiter.api.Tag;

@Tag("gravitino-docker-it")
public class CatalogPostgreSqlVersion12IT extends CatalogPostgreSqlIT {
public CatalogPostgreSqlVersion12IT() {
postgreImageName = "postgres:12";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/

package com.datastrato.gravitino.integration.test.catalog.jdbc.postgresql;

import org.junit.jupiter.api.Tag;

@Tag("gravitino-docker-it")
public class CatalogPostgreSqlVersion14IT extends CatalogPostgreSqlIT {
public CatalogPostgreSqlVersion14IT() {
postgreImageName = "postgres:14";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/

package com.datastrato.gravitino.integration.test.catalog.jdbc.postgresql;

import org.junit.jupiter.api.Tag;

@Tag("gravitino-docker-it")
public class CatalogPostgreSqlVersion15IT extends CatalogPostgreSqlIT {
public CatalogPostgreSqlVersion15IT() {
postgreImageName = "postgres:15";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2024 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/

package com.datastrato.gravitino.integration.test.catalog.jdbc.postgresql;

import org.junit.jupiter.api.Tag;

@Tag("gravitino-docker-it")
public class CatalogPostgreSqlVersion16IT extends CatalogPostgreSqlIT {
public CatalogPostgreSqlVersion16IT() {
postgreImageName = "postgres:16";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TestPostgreSqlAbstractIT extends TestJdbcAbstractIT {
@BeforeAll
public static void startup() {
CONTAINER =
new PostgreSQLContainer<>(CatalogPostgreSqlIT.POSTGRES_IMAGE)
new PostgreSQLContainer<>(CatalogPostgreSqlIT.DEFAULT_POSTGRES_IMAGE)
.withDatabaseName(TEST_DB_NAME)
.withUsername("root")
.withPassword("root");
Expand Down

0 comments on commit 93e2af0

Please sign in to comment.