From 6ac0faa1ec81c434eec80239d75ab27309ac09bc Mon Sep 17 00:00:00 2001 From: Vincent Guilpain Date: Wed, 1 Nov 2023 22:31:23 +0100 Subject: [PATCH] Create namespace metadata when importing table --- .../JdbcAdminImportTableIntegrationTest.java | 6 + .../jdbc/JdbcAdminImportTestUtils.java | 22 +- ...JdbcSchemaLoaderImportIntegrationTest.java | 12 +- ...actionAdminImportTableIntegrationTest.java | 60 ----- .../main/java/com/scalar/db/api/Admin.java | 4 +- .../CheckedDistributedStorageAdmin.java | 5 +- .../com/scalar/db/service/AdminService.java | 5 +- .../db/storage/cassandra/CassandraAdmin.java | 2 +- .../scalar/db/storage/cosmos/CosmosAdmin.java | 2 +- .../scalar/db/storage/dynamo/DynamoAdmin.java | 2 +- .../com/scalar/db/storage/jdbc/JdbcAdmin.java | 16 +- .../multistorage/MultiStorageAdmin.java | 5 +- .../com/scalar/db/storage/rpc/GrpcAdmin.java | 2 +- .../consensuscommit/ConsensusCommitAdmin.java | 8 +- .../jdbc/JdbcTransactionAdmin.java | 5 +- .../transaction/rpc/GrpcTransactionAdmin.java | 2 +- .../cassandra/CassandraAdminTestBase.java | 3 +- .../storage/cosmos/CosmosAdminTestBase.java | 3 +- .../storage/dynamo/DynamoAdminTestBase.java | 3 +- .../db/storage/jdbc/JdbcAdminTestBase.java | 240 ++++++++++++++++-- .../scalar/db/storage/rpc/GrpcAdminTest.java | 2 +- .../ConsensusCommitAdminTestBase.java | 10 +- .../jdbc/JdbcTransactionAdminTest.java | 4 +- .../rpc/GrpcTransactionAdminTest.java | 2 +- ...geAdminImportTableIntegrationTestBase.java | 19 +- ...onAdminImportTableIntegrationTestBase.java | 19 +- ...SchemaLoaderImportIntegrationTestBase.java | 3 - .../db/schemaloader/SchemaOperator.java | 5 +- .../db/schemaloader/SchemaOperatorTest.java | 4 +- 29 files changed, 317 insertions(+), 158 deletions(-) delete mode 100644 core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdminImportTableIntegrationTest.java diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTableIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTableIntegrationTest.java index d554b48843..398170f041 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTableIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTableIntegrationTest.java @@ -22,6 +22,12 @@ protected Properties getProperties(String testName) { return JdbcEnv.getProperties(testName); } + @Override + protected void afterAll() throws Exception { + super.afterAll(); + testUtils.close(); + } + @Override protected Map createExistingDatabaseWithAllDataTypes() throws SQLException { diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTestUtils.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTestUtils.java index e2ee220b15..9e5788aa3c 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTestUtils.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTestUtils.java @@ -107,18 +107,20 @@ public class JdbcAdminImportTestUtils { "geometry", "geography"); - private final JdbcConfig config; private final RdbEngineStrategy rdbEngine; private final int majorVersion; + private final BasicDataSource dataSource; public JdbcAdminImportTestUtils(Properties properties) { - config = new JdbcConfig(new DatabaseConfig(properties)); + JdbcConfig config = new JdbcConfig(new DatabaseConfig(properties)); rdbEngine = RdbEngineFactory.create(config); + dataSource = JdbcUtils.initDataSourceForAdmin(config, rdbEngine); majorVersion = getMajorVersion(); } public Map createExistingDatabaseWithAllDataTypes(String namespace) throws SQLException { + execute(rdbEngine.createSchemaSqls(namespace)); if (rdbEngine instanceof RdbEngineMysql) { return createExistingMysqlDatabaseWithAllDataTypes(namespace); } else if (rdbEngine instanceof RdbEnginePostgresql) { @@ -138,15 +140,13 @@ public void dropTable(String namespace, String table) throws SQLException { } public void execute(String sql) throws SQLException { - try (BasicDataSource dataSource = JdbcUtils.initDataSourceForAdmin(config, rdbEngine); - Connection connection = dataSource.getConnection()) { + try (Connection connection = dataSource.getConnection()) { JdbcAdmin.execute(connection, sql); } } public void execute(String[] sql) throws SQLException { - try (BasicDataSource dataSource = JdbcUtils.initDataSourceForAdmin(config, rdbEngine); - Connection connection = dataSource.getConnection()) { + try (Connection connection = dataSource.getConnection()) { JdbcAdmin.execute(connection, sql); } } @@ -539,8 +539,7 @@ private Map executeCreateTableSql( } private boolean isMariaDB() { - try (BasicDataSource dataSource = JdbcUtils.initDataSourceForAdmin(config, rdbEngine); - Connection connection = dataSource.getConnection()) { + try (Connection connection = dataSource.getConnection()) { String version = connection.getMetaData().getDatabaseProductVersion(); return version.contains("MariaDB"); } catch (SQLException e) { @@ -549,11 +548,14 @@ private boolean isMariaDB() { } private int getMajorVersion() { - try (BasicDataSource dataSource = JdbcUtils.initDataSourceForAdmin(config, rdbEngine); - Connection connection = dataSource.getConnection()) { + try (Connection connection = dataSource.getConnection()) { return connection.getMetaData().getDatabaseMajorVersion(); } catch (SQLException e) { throw new RuntimeException("Get database major version failed"); } } + + public void close() throws SQLException { + dataSource.close(); + } } diff --git a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcSchemaLoaderImportIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcSchemaLoaderImportIntegrationTest.java index 518cd53add..ffbe1b273a 100644 --- a/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcSchemaLoaderImportIntegrationTest.java +++ b/core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcSchemaLoaderImportIntegrationTest.java @@ -2,7 +2,6 @@ import com.scalar.db.config.DatabaseConfig; import com.scalar.db.schemaloader.SchemaLoaderImportIntegrationTestBase; -import com.scalar.db.util.AdminTestUtils; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.util.Properties; import org.junit.jupiter.api.Test; @@ -23,11 +22,6 @@ protected Properties getProperties(String testName) { return properties; } - @Override - protected AdminTestUtils getAdminTestUtils(String testName) { - return new JdbcAdminTestUtils(getProperties(testName)); - } - @SuppressFBWarnings("SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE") @Override protected void createImportableTable(String namespace, String table) throws Exception { @@ -70,6 +64,12 @@ public void importTables_ImportableTablesGiven_ShouldImportProperly() throws Exc super.importTables_ImportableTablesGiven_ShouldImportProperly(); } + @Override + public void afterAll() throws Exception { + super.afterAll(); + testUtils.close(); + } + @SuppressWarnings("unused") private boolean isSqlite() { return JdbcEnv.isSqlite(); diff --git a/core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdminImportTableIntegrationTest.java b/core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdminImportTableIntegrationTest.java deleted file mode 100644 index b892917f63..0000000000 --- a/core/src/integration-test/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdminImportTableIntegrationTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.scalar.db.transaction.jdbc; - -import com.scalar.db.api.DistributedTransactionAdminImportTableIntegrationTestBase; -import com.scalar.db.api.TableMetadata; -import com.scalar.db.config.DatabaseConfig; -import com.scalar.db.exception.storage.ExecutionException; -import com.scalar.db.storage.jdbc.JdbcAdminImportTestUtils; -import com.scalar.db.storage.jdbc.JdbcEnv; -import java.sql.SQLException; -import java.util.Map; -import java.util.Properties; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledIf; -import org.junit.jupiter.api.condition.EnabledIf; - -public class JdbcTransactionAdminImportTableIntegrationTest - extends DistributedTransactionAdminImportTableIntegrationTestBase { - - private JdbcAdminImportTestUtils testUtils; - - @Override - protected Properties getProperties(String testName) { - Properties properties = new Properties(); - properties.putAll(JdbcEnv.getProperties(testName)); - properties.setProperty(DatabaseConfig.TRANSACTION_MANAGER, "jdbc"); - testUtils = new JdbcAdminImportTestUtils(properties); - return properties; - } - - @Override - protected Map createExistingDatabaseWithAllDataTypes() - throws SQLException { - return testUtils.createExistingDatabaseWithAllDataTypes(getNamespace()); - } - - @Override - protected void dropNonImportableTable(String table) throws SQLException { - testUtils.dropTable(getNamespace(), table); - } - - @SuppressWarnings("unused") - private boolean isSqlite() { - return JdbcEnv.isSqlite(); - } - - @Test - @Override - @DisabledIf("isSqlite") - public void importTable_ShouldWorkProperly() throws Exception { - super.importTable_ShouldWorkProperly(); - } - - @Test - @Override - @EnabledIf("isSqlite") - public void importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationException() - throws ExecutionException { - super.importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationException(); - } -} diff --git a/core/src/main/java/com/scalar/db/api/Admin.java b/core/src/main/java/com/scalar/db/api/Admin.java index 1c4ca77348..ee7f0d3eed 100644 --- a/core/src/main/java/com/scalar/db/api/Admin.java +++ b/core/src/main/java/com/scalar/db/api/Admin.java @@ -418,11 +418,13 @@ void addNewColumnToTable(String namespace, String table, String columnName, Data * * @param namespace an existing namespace * @param table an existing table + * @param options options to import * @throws IllegalArgumentException if the table is already managed by ScalarDB, if the target * table does not exist, or if the table does not meet the requirement of ScalarDB table * @throws ExecutionException if the operation fails */ - void importTable(String namespace, String table) throws ExecutionException; + void importTable(String namespace, String table, Map options) + throws ExecutionException; /** * Returns the names of the existing namespaces created through Scalar DB. diff --git a/core/src/main/java/com/scalar/db/common/CheckedDistributedStorageAdmin.java b/core/src/main/java/com/scalar/db/common/CheckedDistributedStorageAdmin.java index 3ba284cd4e..45e8dc98af 100644 --- a/core/src/main/java/com/scalar/db/common/CheckedDistributedStorageAdmin.java +++ b/core/src/main/java/com/scalar/db/common/CheckedDistributedStorageAdmin.java @@ -298,7 +298,8 @@ public TableMetadata getImportTableMetadata(String namespace, String table) } @Override - public void importTable(String namespace, String table) throws ExecutionException { + public void importTable(String namespace, String table, Map options) + throws ExecutionException { TableMetadata tableMetadata = getTableMetadata(namespace, table); if (tableMetadata != null) { throw new IllegalArgumentException( @@ -306,7 +307,7 @@ public void importTable(String namespace, String table) throws ExecutionExceptio } try { - admin.importTable(namespace, table); + admin.importTable(namespace, table, options); } catch (ExecutionException e) { throw new ExecutionException( "Importing the table failed: " + ScalarDbUtils.getFullTableName(namespace, table), e); diff --git a/core/src/main/java/com/scalar/db/service/AdminService.java b/core/src/main/java/com/scalar/db/service/AdminService.java index e34b598619..46bf250049 100644 --- a/core/src/main/java/com/scalar/db/service/AdminService.java +++ b/core/src/main/java/com/scalar/db/service/AdminService.java @@ -107,8 +107,9 @@ public void addRawColumnToTable( } @Override - public void importTable(String namespace, String table) throws ExecutionException { - admin.importTable(namespace, table); + public void importTable(String namespace, String table, Map options) + throws ExecutionException { + admin.importTable(namespace, table, options); } @Override diff --git a/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java b/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java index f954c69204..071b0abfa9 100644 --- a/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/cassandra/CassandraAdmin.java @@ -277,7 +277,7 @@ public void addRawColumnToTable( } @Override - public void importTable(String namespace, String table) { + public void importTable(String namespace, String table, Map options) { throw new UnsupportedOperationException( "Import-related functionality is not supported in Cassandra"); } diff --git a/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java b/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java index ebbfacc2a2..00a10fb2d2 100644 --- a/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/cosmos/CosmosAdmin.java @@ -622,7 +622,7 @@ public void addRawColumnToTable( } @Override - public void importTable(String namespace, String table) { + public void importTable(String namespace, String table, Map options) { throw new UnsupportedOperationException( "Import-related functionality is not supported in Cosmos DB"); } diff --git a/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java b/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java index a11a4c741d..d802e86d89 100644 --- a/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/dynamo/DynamoAdmin.java @@ -1328,7 +1328,7 @@ public void addRawColumnToTable( } @Override - public void importTable(String namespace, String table) { + public void importTable(String namespace, String table, Map options) { throw new UnsupportedOperationException( "Import-related functionality is not supported in DynamoDB"); } diff --git a/core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java b/core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java index 2adc80b505..19b5bbb2f4 100644 --- a/core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/jdbc/JdbcAdmin.java @@ -543,9 +543,12 @@ public TableMetadata getImportTableMetadata(String namespace, String table) } @Override - public void importTable(String namespace, String table) throws ExecutionException { + public void importTable(String namespace, String table, Map options) + throws ExecutionException { try (Connection connection = dataSource.getConnection()) { TableMetadata tableMetadata = getImportTableMetadata(namespace, table); + createNamespacesTableIfNotExists(connection); + upsertIntoNamespacesTable(connection, namespace); addTableMetadata(connection, namespace, table, tableMetadata, true, false); } catch (SQLException | ExecutionException e) { throw new ExecutionException( @@ -763,7 +766,7 @@ public void repairNamespace(String namespace, Map options) try (Connection connection = dataSource.getConnection()) { createSchemaIfNotExists(connection, namespace); createNamespacesTableIfNotExists(connection); - upsertIntoNamespaceTable(connection, namespace); + upsertIntoNamespacesTable(connection, namespace); } catch (SQLException e) { throw new ExecutionException(String.format("Repairing the %s schema failed", namespace), e); } @@ -942,7 +945,8 @@ public Set getNamespaceNames() throws ExecutionException { } } - private void createNamespacesTableIfNotExists(Connection connection) throws ExecutionException { + @VisibleForTesting + void createNamespacesTableIfNotExists(Connection connection) throws ExecutionException { try { createSchemaIfNotExists(connection, metadataSchema); String createTableStatement = @@ -972,8 +976,8 @@ private void insertIntoNamespacesTable(Connection connection, String namespaceNa } } - private void upsertIntoNamespaceTable(Connection connection, String namespace) - throws SQLException { + @VisibleForTesting + void upsertIntoNamespacesTable(Connection connection, String namespace) throws SQLException { try { insertIntoNamespacesTable(connection, namespace); } catch (SQLException e) { @@ -1042,7 +1046,7 @@ private void importNamespaceNamesOfExistingTables(Connection connection) namespaceOfExistingTables.add(namespaceName); } for (String namespace : namespaceOfExistingTables) { - upsertIntoNamespaceTable(connection, namespace); + upsertIntoNamespacesTable(connection, namespace); } } catch (SQLException e) { throw new ExecutionException("Importing the namespace names of existing tables failed", e); diff --git a/core/src/main/java/com/scalar/db/storage/multistorage/MultiStorageAdmin.java b/core/src/main/java/com/scalar/db/storage/multistorage/MultiStorageAdmin.java index c6ad2f39c6..3196bce219 100644 --- a/core/src/main/java/com/scalar/db/storage/multistorage/MultiStorageAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/multistorage/MultiStorageAdmin.java @@ -209,8 +209,9 @@ public void addRawColumnToTable( } @Override - public void importTable(String namespace, String table) throws ExecutionException { - getAdmin(namespace, table).importTable(namespace, table); + public void importTable(String namespace, String table, Map options) + throws ExecutionException { + getAdmin(namespace, table).importTable(namespace, table, options); } @Override diff --git a/core/src/main/java/com/scalar/db/storage/rpc/GrpcAdmin.java b/core/src/main/java/com/scalar/db/storage/rpc/GrpcAdmin.java index 52b16dc627..e2fb0d73c9 100644 --- a/core/src/main/java/com/scalar/db/storage/rpc/GrpcAdmin.java +++ b/core/src/main/java/com/scalar/db/storage/rpc/GrpcAdmin.java @@ -340,7 +340,7 @@ public void addRawColumnToTable( } @Override - public void importTable(String namespace, String table) { + public void importTable(String namespace, String table, Map options) { throw new UnsupportedOperationException( "Import-related functionality is not supported in ScalarDB Server"); } diff --git a/core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitAdmin.java b/core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitAdmin.java index 1d8be18ca4..31b3d67b81 100644 --- a/core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitAdmin.java +++ b/core/src/main/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitAdmin.java @@ -6,7 +6,6 @@ import static com.scalar.db.transaction.consensuscommit.ConsensusCommitUtils.removeTransactionMetaColumns; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableMap; import com.google.inject.Inject; import com.scalar.db.api.DistributedStorageAdmin; import com.scalar.db.api.DistributedTransactionAdmin; @@ -208,7 +207,8 @@ public Set getNamespaceNames() throws ExecutionException { } @Override - public void importTable(String namespace, String table) throws ExecutionException { + public void importTable(String namespace, String table, Map options) + throws ExecutionException { TableMetadata tableMetadata = getTableMetadata(namespace, table); if (tableMetadata != null) { throw new IllegalArgumentException( @@ -231,8 +231,8 @@ public void importTable(String namespace, String table) throws ExecutionExceptio } // add ScalarDB metadata - admin.repairTable( - namespace, table, buildTransactionTableMetadata(tableMetadata), ImmutableMap.of()); + admin.repairNamespace(namespace, options); + admin.repairTable(namespace, table, buildTransactionTableMetadata(tableMetadata), options); } @Override diff --git a/core/src/main/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdmin.java b/core/src/main/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdmin.java index 7b7aba0ef3..081c8ebc3f 100644 --- a/core/src/main/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdmin.java +++ b/core/src/main/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdmin.java @@ -86,8 +86,9 @@ public boolean namespaceExists(String namespace) throws ExecutionException { } @Override - public void importTable(String namespace, String table) throws ExecutionException { - jdbcAdmin.importTable(namespace, table); + public void importTable(String namespace, String table, Map options) + throws ExecutionException { + jdbcAdmin.importTable(namespace, table, options); } @Override diff --git a/core/src/main/java/com/scalar/db/transaction/rpc/GrpcTransactionAdmin.java b/core/src/main/java/com/scalar/db/transaction/rpc/GrpcTransactionAdmin.java index 9f45e35ad3..e839d4fca9 100644 --- a/core/src/main/java/com/scalar/db/transaction/rpc/GrpcTransactionAdmin.java +++ b/core/src/main/java/com/scalar/db/transaction/rpc/GrpcTransactionAdmin.java @@ -395,7 +395,7 @@ public void addNewColumnToTable( } @Override - public void importTable(String namespace, String table) { + public void importTable(String namespace, String table, Map options) { throw new UnsupportedOperationException( "Import-related functionality is not supported in ScalarDB Server"); } diff --git a/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTestBase.java b/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTestBase.java index 3a7fa22c9a..9bc42eb74a 100644 --- a/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTestBase.java +++ b/core/src/test/java/com/scalar/db/storage/cassandra/CassandraAdminTestBase.java @@ -831,7 +831,8 @@ public void unsupportedOperations_ShouldThrowUnsupportedException() { Throwable thrown2 = catchThrowable( () -> cassandraAdmin.addRawColumnToTable(namespace, table, column, DataType.INT)); - Throwable thrown3 = catchThrowable(() -> cassandraAdmin.importTable(namespace, table)); + Throwable thrown3 = + catchThrowable(() -> cassandraAdmin.importTable(namespace, table, Collections.emptyMap())); // Assert assertThat(thrown1).isInstanceOf(UnsupportedOperationException.class); diff --git a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTestBase.java b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTestBase.java index 3f0f6da424..8f60929751 100644 --- a/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTestBase.java +++ b/core/src/test/java/com/scalar/db/storage/cosmos/CosmosAdminTestBase.java @@ -987,7 +987,8 @@ public void unsupportedOperations_ShouldThrowUnsupportedException() { Throwable thrown1 = catchThrowable(() -> admin.getImportTableMetadata(namespace, table)); Throwable thrown2 = catchThrowable(() -> admin.addRawColumnToTable(namespace, table, column, DataType.INT)); - Throwable thrown3 = catchThrowable(() -> admin.importTable(namespace, table)); + Throwable thrown3 = + catchThrowable(() -> admin.importTable(namespace, table, Collections.emptyMap())); // Assert assertThat(thrown1).isInstanceOf(UnsupportedOperationException.class); diff --git a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java index a53e571709..58de5439d2 100644 --- a/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java +++ b/core/src/test/java/com/scalar/db/storage/dynamo/DynamoAdminTestBase.java @@ -1526,7 +1526,8 @@ public void unsupportedOperations_ShouldThrowUnsupportedException() { Throwable thrown1 = catchThrowable(() -> admin.getImportTableMetadata(NAMESPACE, TABLE)); Throwable thrown2 = catchThrowable(() -> admin.addRawColumnToTable(NAMESPACE, TABLE, "c1", DataType.INT)); - Throwable thrown3 = catchThrowable(() -> admin.importTable(NAMESPACE, TABLE)); + Throwable thrown3 = + catchThrowable(() -> admin.importTable(NAMESPACE, TABLE, Collections.emptyMap())); // Assert assertThat(thrown1).isInstanceOf(UnsupportedOperationException.class); diff --git a/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTestBase.java b/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTestBase.java index 0193236338..f22725f9fd 100644 --- a/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTestBase.java +++ b/core/src/test/java/com/scalar/db/storage/jdbc/JdbcAdminTestBase.java @@ -10,9 +10,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.catchThrowable; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.description; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mockStatic; import static org.mockito.Mockito.spy; @@ -2720,38 +2724,24 @@ private void addRawColumnToTable_WithNonExistingTableForX_ShouldThrowIllegalArgu public void importTable_ForXBesidesSqlite_ShouldWorkProperly(RdbEngine rdbEngine) throws SQLException, ExecutionException { // Arrange - DatabaseMetaData metadata = mock(DatabaseMetaData.class); - ResultSet primaryKeyResults = mock(ResultSet.class); - ResultSet columnResults = mock(ResultSet.class); - when(dataSource.getConnection()).thenReturn(connection); - when(connection.getMetaData()).thenReturn(metadata); - when(primaryKeyResults.next()).thenReturn(true).thenReturn(false); - when(primaryKeyResults.getString(JDBC_COL_COLUMN_NAME)).thenReturn(COLUMN_1); - when(columnResults.next()).thenReturn(true).thenReturn(false); - when(columnResults.getString(JDBC_COL_COLUMN_NAME)).thenReturn(COLUMN_1); - when(columnResults.getInt(JDBC_COL_DATA_TYPE)).thenReturn(Types.VARCHAR); - when(columnResults.getString(JDBC_COL_TYPE_NAME)).thenReturn("VARCHAR"); - when(columnResults.getInt(JDBC_COL_COLUMN_SIZE)).thenReturn(0); - when(columnResults.getInt(JDBC_COL_DECIMAL_DIGITS)).thenReturn(0); - when(metadata.getPrimaryKeys(null, NAMESPACE, TABLE)).thenReturn(primaryKeyResults); - when(metadata.getColumns(null, NAMESPACE, TABLE, "%")).thenReturn(columnResults); - Statement checkTableExistsStatement = mock(Statement.class); - when(connection.createStatement()).thenReturn(checkTableExistsStatement); + JdbcAdmin adminSpy = spy(createJdbcAdminFor(rdbEngine)); when(dataSource.getConnection()).thenReturn(connection); - TableMetadata importedTableMetadata = - TableMetadata.newBuilder() - .addPartitionKey(COLUMN_1) - .addColumn(COLUMN_1, DataType.TEXT) - .build(); - JdbcAdmin adminSpy = spy(createJdbcAdminFor(rdbEngine)); + TableMetadata importedTableMetadata = mock(TableMetadata.class); + doReturn(importedTableMetadata).when(adminSpy).getImportTableMetadata(anyString(), anyString()); + doNothing().when(adminSpy).createNamespacesTableIfNotExists(connection); + doNothing().when(adminSpy).upsertIntoNamespacesTable(any(), anyString()); + doNothing() + .when(adminSpy) + .addTableMetadata(any(), anyString(), anyString(), any(), anyBoolean(), anyBoolean()); // Act - adminSpy.importTable(NAMESPACE, TABLE); + adminSpy.importTable(NAMESPACE, TABLE, Collections.emptyMap()); // Assert verify(adminSpy).getImportTableMetadata(NAMESPACE, TABLE); - verify(checkTableExistsStatement).execute(prepareSqlForTableCheck(rdbEngine, NAMESPACE, TABLE)); + verify(adminSpy).createNamespacesTableIfNotExists(connection); + verify(adminSpy).upsertIntoNamespacesTable(connection, NAMESPACE); verify(adminSpy) .addTableMetadata(connection, NAMESPACE, TABLE, importedTableMetadata, true, false); } @@ -2762,7 +2752,8 @@ public void importTable_ForSQLite_ShouldThrowUnsupportedOperationException() { JdbcAdmin admin = createJdbcAdminFor(RdbEngine.SQLITE); // Act - Throwable thrown = catchThrowable(() -> admin.importTable(NAMESPACE, TABLE)); + Throwable thrown = + catchThrowable(() -> admin.importTable(NAMESPACE, TABLE, Collections.emptyMap())); // Assert assertThat(thrown).isInstanceOf(UnsupportedOperationException.class); @@ -3043,6 +3034,203 @@ private List prepareMockStatements(int count) { return statements; } + @ParameterizedTest + @EnumSource(value = RdbEngine.class) + public void upsertIntoNamespacesTable_ForNonExistingNamespace_ShouldInsertNamespacesMetadata( + RdbEngine rdbEngine) throws SQLException { + // Arrange + PreparedStatement insertStatement = mock(PreparedStatement.class); + when(connection.prepareStatement(anyString())).thenReturn(insertStatement); + JdbcAdmin admin = createJdbcAdminFor(rdbEngine); + + // Act + admin.upsertIntoNamespacesTable(connection, NAMESPACE); + + // Assert + RdbEngineStrategy rdbEngineStrategy = getRdbEngineStrategy(rdbEngine); + verify(connection) + .prepareStatement( + "INSERT INTO " + + rdbEngineStrategy.encloseFullTableName( + metadataSchemaName, JdbcAdmin.NAMESPACES_TABLE) + + " VALUES (?)"); + verify(insertStatement).setString(1, NAMESPACE); + verify(insertStatement).execute(); + } + + @ParameterizedTest + @EnumSource(value = RdbEngine.class) + public void upsertIntoNamespacesTable_ForExistingNamespace_ShouldNotThrowException( + RdbEngine rdbEngine) throws SQLException { + // Arrange + PreparedStatement insertStatement = mock(PreparedStatement.class); + when(connection.prepareStatement(anyString())).thenReturn(insertStatement); + doThrow(prepareDuplicatedKeyException(rdbEngine)).when(insertStatement).execute(); + JdbcAdmin admin = createJdbcAdminFor(rdbEngine); + + // Act + admin.upsertIntoNamespacesTable(connection, NAMESPACE); + + // Assert + RdbEngineStrategy rdbEngineStrategy = getRdbEngineStrategy(rdbEngine); + verify(connection) + .prepareStatement( + "INSERT INTO " + + rdbEngineStrategy.encloseFullTableName( + metadataSchemaName, JdbcAdmin.NAMESPACES_TABLE) + + " VALUES (?)"); + verify(insertStatement).setString(1, NAMESPACE); + verify(insertStatement).execute(); + } + + @Test + public void + createNamespaceTableIfNotExists_forMysql_shouldCreateNamespaceIfNotExistsAndUpsertMetadata() + throws ExecutionException, SQLException { + createNamespaceTableIfNotExists_forX_shouldCreateMetadataSchemaAndNamespacesTableIfNotExists( + RdbEngine.MYSQL, + "CREATE SCHEMA IF NOT EXISTS `" + + metadataSchemaName + + "` character set utf8 COLLATE utf8_bin", + "CREATE TABLE IF NOT EXISTS `" + + metadataSchemaName + + "`.`namespaces`(`namespace_name` VARCHAR(128), PRIMARY KEY (`namespace_name`))"); + } + + @Test + public void + createNamespaceTableIfNotExists_forOracle_shouldCreateNamespaceIfNotExistsAndUpsertMetadata() + throws ExecutionException, SQLException { + createNamespaceTableIfNotExists_forX_shouldCreateMetadataSchemaAndNamespacesTableIfNotExists( + RdbEngine.ORACLE, + "CREATE USER \"" + metadataSchemaName + "\" IDENTIFIED BY \"oracle\"", + "ALTER USER \"" + metadataSchemaName + "\" quota unlimited on USERS", + "CREATE TABLE \"" + + metadataSchemaName + + "\".\"namespaces\"(\"namespace_name\" VARCHAR2(128), PRIMARY KEY (\"namespace_name\"))"); + } + + @Test + public void + createNamespaceTableIfNotExists_forPosgresql_shouldCreateNamespaceIfNotExistsAndUpsertMetadata() + throws ExecutionException, SQLException { + createNamespaceTableIfNotExists_forX_shouldCreateMetadataSchemaAndNamespacesTableIfNotExists( + RdbEngine.POSTGRESQL, + "CREATE SCHEMA IF NOT EXISTS \"" + metadataSchemaName + "\"", + "CREATE TABLE IF NOT EXISTS \"" + + metadataSchemaName + + "\".\"namespaces\"(\"namespace_name\" VARCHAR(128), PRIMARY KEY (\"namespace_name\"))"); + } + + @Test + public void + createNamespaceTableIfNotExists_forSqlServer_shouldCreateNamespaceIfNotExistsAndUpsertMetadata() + throws ExecutionException, SQLException { + createNamespaceTableIfNotExists_forX_shouldCreateMetadataSchemaAndNamespacesTableIfNotExists( + RdbEngine.SQL_SERVER, + "CREATE SCHEMA [" + metadataSchemaName + "]", + "CREATE TABLE [" + + metadataSchemaName + + "].[namespaces]([namespace_name] VARCHAR(128), PRIMARY KEY ([namespace_name]))"); + } + + @Test + public void + createNamespaceTableIfNotExists_forSqlite_shouldCreateNamespaceIfNotExistsAndUpsertMetadata() + throws ExecutionException, SQLException { + createNamespaceTableIfNotExists_forX_shouldCreateMetadataSchemaAndNamespacesTableIfNotExists( + RdbEngine.SQLITE, + "CREATE TABLE IF NOT EXISTS \"" + + metadataSchemaName + + "$namespaces\"(\"namespace_name\" TEXT, PRIMARY KEY (\"namespace_name\"))"); + } + + public void + createNamespaceTableIfNotExists_forX_shouldCreateMetadataSchemaAndNamespacesTableIfNotExists( + RdbEngine rdbEngine, String... expectedSqlStatements) + throws SQLException, ExecutionException { + // Arrange + JdbcAdmin admin = createJdbcAdminFor(rdbEngine); + List mockedStatements = new ArrayList<>(); + + for (int i = 0; i < expectedSqlStatements.length; i++) { + mockedStatements.add(mock(Statement.class)); + } + when(connection.createStatement()) + .thenReturn( + mockedStatements.get(0), + mockedStatements.subList(1, mockedStatements.size()).toArray(new Statement[0])); + when(dataSource.getConnection()).thenReturn(connection); + + // Act + admin.createNamespacesTableIfNotExists(connection); + + // Assert + for (int i = 0; i < expectedSqlStatements.length; i++) { + verify(mockedStatements.get(i)).execute(expectedSqlStatements[i]); + } + } + + private SQLException prepareDuplicatedKeyException(RdbEngine rdbEngine) { + SQLException duplicateKeyException; + switch (rdbEngine) { + case SQL_SERVER: + case MYSQL: + case ORACLE: + duplicateKeyException = mock(SQLException.class); + when(duplicateKeyException.getSQLState()).thenReturn("23000"); + break; + case POSTGRESQL: + duplicateKeyException = mock(SQLException.class); + when(duplicateKeyException.getSQLState()).thenReturn("23505"); + break; + case SQLITE: + SQLiteException sqLiteException = mock(SQLiteException.class); + when(sqLiteException.getResultCode()) + .thenReturn(SQLiteErrorCode.SQLITE_CONSTRAINT_PRIMARYKEY); + duplicateKeyException = sqLiteException; + break; + default: + throw new AssertionError("Unsupported rdbEngine " + rdbEngine); + } + return duplicateKeyException; + } + + @ParameterizedTest + @EnumSource(value = RdbEngine.class) + public void upsertIntoNamespacesTable_ForNonDuplicatedKeyException_ShouldThrowSqlException( + RdbEngine rdbEngine) throws SQLException { + // Arrange + PreparedStatement insertStatement = mock(PreparedStatement.class); + when(connection.prepareStatement(anyString())).thenReturn(insertStatement); + SQLException anySqlException; + if (rdbEngine == RdbEngine.SQLITE) { + SQLiteException sqLiteException = mock(SQLiteException.class); + when(sqLiteException.getResultCode()).thenReturn(SQLiteErrorCode.SQLITE_IOERR); + anySqlException = sqLiteException; + } else { + anySqlException = mock(SQLException.class); + when(anySqlException.getSQLState()).thenReturn("foo"); + } + doThrow(anySqlException).when(insertStatement).execute(); + JdbcAdmin admin = createJdbcAdminFor(rdbEngine); + + // Act + assertThatThrownBy(() -> admin.upsertIntoNamespacesTable(connection, NAMESPACE)) + .isEqualTo(anySqlException); + + // Assert + RdbEngineStrategy rdbEngineStrategy = getRdbEngineStrategy(rdbEngine); + verify(connection) + .prepareStatement( + "INSERT INTO " + + rdbEngineStrategy.encloseFullTableName( + metadataSchemaName, JdbcAdmin.NAMESPACES_TABLE) + + " VALUES (?)"); + verify(insertStatement).setString(1, NAMESPACE); + verify(insertStatement).execute(); + } + // Utility class used to mock ResultSet for a "select * from" query on the metadata table static class SelectAllFromMetadataTableResultSetMocker implements org.mockito.stubbing.Answer { diff --git a/core/src/test/java/com/scalar/db/storage/rpc/GrpcAdminTest.java b/core/src/test/java/com/scalar/db/storage/rpc/GrpcAdminTest.java index 405d98a609..618b4897e5 100644 --- a/core/src/test/java/com/scalar/db/storage/rpc/GrpcAdminTest.java +++ b/core/src/test/java/com/scalar/db/storage/rpc/GrpcAdminTest.java @@ -345,7 +345,7 @@ public void unsupportedOperations_ShouldThrowUnsupportedException() { .isInstanceOf(UnsupportedOperationException.class); assertThatThrownBy(() -> admin.addRawColumnToTable(namespace, table, column, DataType.INT)) .isInstanceOf(UnsupportedOperationException.class); - assertThatThrownBy(() -> admin.importTable(namespace, table)) + assertThatThrownBy(() -> admin.importTable(namespace, table, Collections.emptyMap())) .isInstanceOf(UnsupportedOperationException.class); assertThatThrownBy(() -> admin.getNamespaceNames()) .isInstanceOf(UnsupportedOperationException.class); diff --git a/core/src/test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitAdminTestBase.java b/core/src/test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitAdminTestBase.java index c524013865..ee0fcdae69 100644 --- a/core/src/test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitAdminTestBase.java +++ b/core/src/test/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitAdminTestBase.java @@ -1,5 +1,6 @@ package com.scalar.db.transaction.consensuscommit; +import static com.scalar.db.transaction.consensuscommit.ConsensusCommitUtils.buildTransactionTableMetadata; import static com.scalar.db.transaction.consensuscommit.ConsensusCommitUtils.getBeforeImageColumnName; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -595,6 +596,7 @@ public void addNewColumnToTable_ShouldCallJdbcAdminProperly() throws ExecutionEx @Test public void importTable_ShouldCallStorageAdminProperly() throws ExecutionException { // Arrange + Map options = ImmutableMap.of("foo", "bar"); String primaryKeyColumn = "pk"; String column = "col"; TableMetadata metadata = @@ -610,7 +612,7 @@ public void importTable_ShouldCallStorageAdminProperly() throws ExecutionExcepti .addRawColumnToTable(anyString(), anyString(), anyString(), any(DataType.class)); // Act - admin.importTable(NAMESPACE, TABLE); + admin.importTable(NAMESPACE, TABLE, options); // Assert verify(distributedStorageAdmin).getTableMetadata(NAMESPACE, TABLE); @@ -625,6 +627,9 @@ public void importTable_ShouldCallStorageAdminProperly() throws ExecutionExcepti NAMESPACE, TABLE, getBeforeImageColumnName(column, metadata), DataType.INT); verify(distributedStorageAdmin, never()) .addRawColumnToTable(NAMESPACE, TABLE, primaryKeyColumn, DataType.INT); + verify(distributedStorageAdmin).repairNamespace(NAMESPACE, options); + verify(distributedStorageAdmin) + .repairTable(NAMESPACE, TABLE, buildTransactionTableMetadata(metadata), options); } @Test @@ -653,7 +658,8 @@ public void importTable_WithTableAlreadyExists_ShouldThrowIllegalArgumentExcepti when(distributedStorageAdmin.getTableMetadata(NAMESPACE, TABLE)).thenReturn(metadata); // Act - Throwable thrown = catchThrowable(() -> admin.importTable(NAMESPACE, TABLE)); + Throwable thrown = + catchThrowable(() -> admin.importTable(NAMESPACE, TABLE, Collections.emptyMap())); // Assert assertThat(thrown).isInstanceOf(IllegalArgumentException.class); diff --git a/core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdminTest.java b/core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdminTest.java index 1d320eeb14..02bbca7226 100644 --- a/core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdminTest.java +++ b/core/src/test/java/com/scalar/db/transaction/jdbc/JdbcTransactionAdminTest.java @@ -235,10 +235,10 @@ public void importTable_ShouldCallJdbcAdminProperly() throws ExecutionException String table = "tbl"; // Act - admin.importTable(namespace, table); + admin.importTable(namespace, table, Collections.emptyMap()); // Assert - verify(jdbcAdmin).importTable(namespace, table); + verify(jdbcAdmin).importTable(namespace, table, Collections.emptyMap()); } @Test diff --git a/core/src/test/java/com/scalar/db/transaction/rpc/GrpcTransactionAdminTest.java b/core/src/test/java/com/scalar/db/transaction/rpc/GrpcTransactionAdminTest.java index e46f701ce1..b7b74dce0b 100644 --- a/core/src/test/java/com/scalar/db/transaction/rpc/GrpcTransactionAdminTest.java +++ b/core/src/test/java/com/scalar/db/transaction/rpc/GrpcTransactionAdminTest.java @@ -420,7 +420,7 @@ public void unsupportedOperations_ShouldThrowUnsupportedException() { String table = "tbl"; // Act Assert - assertThatThrownBy(() -> admin.importTable(namespace, table)) + assertThatThrownBy(() -> admin.importTable(namespace, table, Collections.emptyMap())) .isInstanceOf(UnsupportedOperationException.class); assertThatThrownBy(() -> admin.getNamespaceNames()) .isInstanceOf(UnsupportedOperationException.class); diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminImportTableIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminImportTableIntegrationTestBase.java index 8218c93125..77794e1cb2 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminImportTableIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedStorageAdminImportTableIntegrationTestBase.java @@ -53,6 +53,10 @@ private void dropTable() throws Exception { admin.dropTable(getNamespace(), table); } } + if (!admin.namespaceExists(getNamespace())) { + // Create metadata to be able to delete the namespace using the Admin + admin.repairNamespace(getNamespace(), getCreationOptions()); + } admin.dropNamespace(getNamespace()); } @@ -79,7 +83,6 @@ protected abstract Map createExistingDatabaseWithAllDataT @Test public void importTable_ShouldWorkProperly() throws Exception { // Arrange - admin.repairNamespace(getNamespace(), getCreationOptions()); tables.putAll(createExistingDatabaseWithAllDataTypes()); // Act Assert @@ -98,20 +101,19 @@ public void importTable_ShouldWorkProperly() throws Exception { @Test public void importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationException() throws ExecutionException { - // Arrange - admin.repairNamespace(getNamespace(), getCreationOptions()); - // Act Assert - assertThatThrownBy(() -> admin.importTable(getNamespace(), "unsupported_db")) + assertThatThrownBy( + () -> admin.importTable(getNamespace(), "unsupported_db", Collections.emptyMap())) .isInstanceOf(UnsupportedOperationException.class); } private void importTable_ForImportableTable_ShouldImportProperly( String table, TableMetadata metadata) throws ExecutionException { // Act - admin.importTable(getNamespace(), table); + admin.importTable(getNamespace(), table, Collections.emptyMap()); // Assert + assertThat(admin.namespaceExists(getNamespace())).isTrue(); assertThat(admin.tableExists(getNamespace(), table)).isTrue(); assertThat(admin.getTableMetadata(getNamespace(), table)).isEqualTo(metadata); } @@ -119,14 +121,15 @@ private void importTable_ForImportableTable_ShouldImportProperly( private void importTable_ForNonImportableTable_ShouldThrowIllegalArgumentException(String table) { // Act Assert assertThatThrownBy( - () -> admin.importTable(getNamespace(), table), + () -> admin.importTable(getNamespace(), table, Collections.emptyMap()), "non-importable data type test failed: " + table) .isInstanceOf(IllegalArgumentException.class); } private void importTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() { // Act Assert - assertThatThrownBy(() -> admin.importTable(getNamespace(), "non-existing-table")) + assertThatThrownBy( + () -> admin.importTable(getNamespace(), "non-existing-table", Collections.emptyMap())) .isInstanceOf(IllegalArgumentException.class); } } diff --git a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminImportTableIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminImportTableIntegrationTestBase.java index c6b059c527..9789c5aafb 100644 --- a/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminImportTableIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/api/DistributedTransactionAdminImportTableIntegrationTestBase.java @@ -53,6 +53,10 @@ private void dropTable() throws Exception { admin.dropTable(getNamespace(), table); } } + if (!admin.namespaceExists(getNamespace())) { + // Create metadata to be able to delete the namespace using the Admin + admin.repairNamespace(getNamespace(), getCreationOptions()); + } admin.dropNamespace(getNamespace()); } @@ -79,7 +83,6 @@ protected abstract Map createExistingDatabaseWithAllDataT @Test public void importTable_ShouldWorkProperly() throws Exception { // Arrange - admin.createNamespace(getNamespace(), getCreationOptions()); tables.putAll(createExistingDatabaseWithAllDataTypes()); // Act Assert @@ -98,33 +101,33 @@ public void importTable_ShouldWorkProperly() throws Exception { @Test public void importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationException() throws ExecutionException { - // Arrange - admin.createNamespace(getNamespace(), getCreationOptions()); - // Act Assert - assertThatThrownBy(() -> admin.importTable(getNamespace(), "unsupported_db")) + assertThatThrownBy( + () -> admin.importTable(getNamespace(), "unsupported_db", Collections.emptyMap())) .isInstanceOf(UnsupportedOperationException.class); } private void importTable_ForImportableTable_ShouldImportProperly( String table, TableMetadata metadata) throws ExecutionException { // Act - admin.importTable(getNamespace(), table); + admin.importTable(getNamespace(), table, Collections.emptyMap()); // Assert + assertThat(admin.namespaceExists(getNamespace())).isTrue(); assertThat(admin.tableExists(getNamespace(), table)).isTrue(); assertThat(admin.getTableMetadata(getNamespace(), table)).isEqualTo(metadata); } private void importTable_ForNonImportableTable_ShouldThrowIllegalArgumentException(String table) { // Act Assert - assertThatThrownBy(() -> admin.importTable(getNamespace(), table)) + assertThatThrownBy(() -> admin.importTable(getNamespace(), table, Collections.emptyMap())) .isInstanceOf(IllegalArgumentException.class); } private void importTable_ForNonExistingTable_ShouldThrowIllegalArgumentException() { // Act Assert - assertThatThrownBy(() -> admin.importTable(getNamespace(), "non-existing-table")) + assertThatThrownBy( + () -> admin.importTable(getNamespace(), "non-existing-table", Collections.emptyMap())) .isInstanceOf(IllegalArgumentException.class); } } diff --git a/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderImportIntegrationTestBase.java b/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderImportIntegrationTestBase.java index 20392a40bc..8e4eb4b04f 100644 --- a/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderImportIntegrationTestBase.java +++ b/integration-test/src/main/java/com/scalar/db/schemaloader/SchemaLoaderImportIntegrationTestBase.java @@ -9,7 +9,6 @@ import com.scalar.db.api.DistributedTransactionAdmin; import com.scalar.db.service.StorageFactory; import com.scalar.db.service.TransactionFactory; -import com.scalar.db.util.AdminTestUtils; import java.io.IOException; import java.io.OutputStream; import java.io.Writer; @@ -79,8 +78,6 @@ protected String getNamespace2() { return NAMESPACE_2; } - protected abstract AdminTestUtils getAdminTestUtils(String testName); - protected Map getImportSchemaJsonMap() { return ImmutableMap.of( namespace1 + "." + TABLE_1, diff --git a/schema-loader/src/main/java/com/scalar/db/schemaloader/SchemaOperator.java b/schema-loader/src/main/java/com/scalar/db/schemaloader/SchemaOperator.java index bc2296b641..64f8fa4300 100644 --- a/schema-loader/src/main/java/com/scalar/db/schemaloader/SchemaOperator.java +++ b/schema-loader/src/main/java/com/scalar/db/schemaloader/SchemaOperator.java @@ -13,6 +13,7 @@ import com.scalar.db.service.TransactionFactory; import java.io.IOException; import java.nio.file.Path; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -413,9 +414,9 @@ public void importTables(List tableSchemaList) throws SchemaL String table = tableSchema.getTable(); try { if (tableSchema.isTransactionTable()) { - transactionAdmin.get().importTable(namespace, table); + transactionAdmin.get().importTable(namespace, table, Collections.emptyMap()); } else { - storageAdmin.get().importTable(namespace, table); + storageAdmin.get().importTable(namespace, table, Collections.emptyMap()); } logger.info("Importing the table {} in the namespace {} succeeded", table, namespace); } catch (ExecutionException e) { diff --git a/schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaOperatorTest.java b/schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaOperatorTest.java index 79bc680771..d2136c2ad9 100644 --- a/schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaOperatorTest.java +++ b/schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaOperatorTest.java @@ -517,7 +517,7 @@ public void importTables_WithTransactionTables_ShouldCallProperMethods() throws operator.importTables(tableSchemaList); // Assert - verify(transactionAdmin, times(3)).importTable("ns", "tb"); + verify(transactionAdmin, times(3)).importTable("ns", "tb", Collections.emptyMap()); verifyNoInteractions(storageAdmin); } @@ -534,7 +534,7 @@ public void importTables_WithoutTransactionTables_ShouldCallProperMethods() thro operator.importTables(tableSchemaList); // Assert - verify(storageAdmin, times(3)).importTable("ns", "tb"); + verify(storageAdmin, times(3)).importTable("ns", "tb", Collections.emptyMap()); verifyNoInteractions(transactionAdmin); }