diff --git a/schema-loader/src/main/java/com/scalar/db/schemaloader/ImportSchemaParser.java b/schema-loader/src/main/java/com/scalar/db/schemaloader/ImportSchemaParser.java index f67f2b8a67..f3524380ce 100644 --- a/schema-loader/src/main/java/com/scalar/db/schemaloader/ImportSchemaParser.java +++ b/schema-loader/src/main/java/com/scalar/db/schemaloader/ImportSchemaParser.java @@ -1,5 +1,6 @@ package com.scalar.db.schemaloader; +import com.google.common.collect.ImmutableMap; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; @@ -16,28 +17,33 @@ @ThreadSafe public class ImportSchemaParser { private final JsonObject schemaJson; + private final Map options; - public ImportSchemaParser(Path jsonFilePath) throws SchemaLoaderException { + public ImportSchemaParser(Path jsonFilePath, Map options) + throws SchemaLoaderException { try (Reader reader = Files.newBufferedReader(jsonFilePath)) { schemaJson = JsonParser.parseReader(reader).getAsJsonObject(); } catch (IOException | JsonParseException e) { throw new SchemaLoaderException("Parsing the schema JSON failed", e); } + this.options = ImmutableMap.copyOf(options); } - public ImportSchemaParser(String serializedSchemaJson) throws SchemaLoaderException { + public ImportSchemaParser(String serializedSchemaJson, Map options) + throws SchemaLoaderException { try { schemaJson = JsonParser.parseString(serializedSchemaJson).getAsJsonObject(); } catch (JsonParseException e) { throw new SchemaLoaderException("Parsing the schema JSON failed", e); } + this.options = ImmutableMap.copyOf(options); } public List parse() throws SchemaLoaderException { List tableSchemaList = new ArrayList<>(); for (Map.Entry entry : schemaJson.entrySet()) { tableSchemaList.add( - new ImportTableSchema(entry.getKey(), entry.getValue().getAsJsonObject())); + new ImportTableSchema(entry.getKey(), entry.getValue().getAsJsonObject(), options)); } return tableSchemaList; } diff --git a/schema-loader/src/main/java/com/scalar/db/schemaloader/ImportTableSchema.java b/schema-loader/src/main/java/com/scalar/db/schemaloader/ImportTableSchema.java index c613e03204..590ec9c601 100644 --- a/schema-loader/src/main/java/com/scalar/db/schemaloader/ImportTableSchema.java +++ b/schema-loader/src/main/java/com/scalar/db/schemaloader/ImportTableSchema.java @@ -1,16 +1,21 @@ package com.scalar.db.schemaloader; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.gson.JsonObject; +import java.util.Map; +import java.util.Set; import javax.annotation.concurrent.Immutable; @Immutable public class ImportTableSchema { - private static final String TRANSACTION = "transaction"; private final String namespace; private final String tableName; private final boolean isTransactionTable; + private final ImmutableMap options; - public ImportTableSchema(String tableFullName, JsonObject tableDefinition) + public ImportTableSchema( + String tableFullName, JsonObject tableDefinition, Map options) throws SchemaLoaderException { String[] fullName = tableFullName.split("\\.", -1); if (fullName.length != 2) { @@ -20,11 +25,30 @@ public ImportTableSchema(String tableFullName, JsonObject tableDefinition) } namespace = fullName[0]; tableName = fullName[1]; - if (tableDefinition.keySet().contains(TRANSACTION)) { - isTransactionTable = tableDefinition.get(TRANSACTION).getAsBoolean(); + if (tableDefinition.keySet().contains(TableSchema.TRANSACTION)) { + isTransactionTable = tableDefinition.get(TableSchema.TRANSACTION).getAsBoolean(); } else { isTransactionTable = true; } + this.options = buildOptions(tableDefinition, options); + } + + private ImmutableMap buildOptions( + JsonObject tableDefinition, Map globalOptions) { + ImmutableMap.Builder optionsBuilder = ImmutableMap.builder(); + optionsBuilder.putAll(globalOptions); + Set keysToIgnore = + ImmutableSet.of( + TableSchema.PARTITION_KEY, + TableSchema.CLUSTERING_KEY, + TableSchema.TRANSACTION, + TableSchema.COLUMNS, + TableSchema.SECONDARY_INDEX); + tableDefinition.entrySet().stream() + .filter(entry -> !keysToIgnore.contains(entry.getKey())) + .forEach(entry -> optionsBuilder.put(entry.getKey(), entry.getValue().getAsString())); + // If an option is defined globally and in the JSON file, the JSON file value is used + return optionsBuilder.buildKeepingLast(); } public String getNamespace() { @@ -38,4 +62,8 @@ public String getTable() { public boolean isTransactionTable() { return isTransactionTable; } + + public Map getOptions() { + return options; + } } diff --git a/schema-loader/src/main/java/com/scalar/db/schemaloader/SchemaLoader.java b/schema-loader/src/main/java/com/scalar/db/schemaloader/SchemaLoader.java index 44331df621..ea4eabdafe 100644 --- a/schema-loader/src/main/java/com/scalar/db/schemaloader/SchemaLoader.java +++ b/schema-loader/src/main/java/com/scalar/db/schemaloader/SchemaLoader.java @@ -514,13 +514,15 @@ private static void alterTables( * * @param configProperties ScalarDB config properties * @param serializedSchemaJson serialized json string schema. + * @param options specific options for importing. * @throws SchemaLoaderException thrown when importing tables fails. */ - public static void importTables(Properties configProperties, String serializedSchemaJson) + public static void importTables( + Properties configProperties, String serializedSchemaJson, Map options) throws SchemaLoaderException { Either config = new Right<>(configProperties); Either schema = new Right<>(serializedSchemaJson); - importTables(config, schema); + importTables(config, schema, options); } /** @@ -528,13 +530,15 @@ public static void importTables(Properties configProperties, String serializedSc * * @param configProperties ScalarDB properties. * @param schemaPath path to the schema file. + * @param options specific options for importing. * @throws SchemaLoaderException thrown when importing tables fails. */ - public static void importTables(Properties configProperties, Path schemaPath) + public static void importTables( + Properties configProperties, Path schemaPath, Map options) throws SchemaLoaderException { Either config = new Right<>(configProperties); Either schema = new Left<>(schemaPath); - importTables(config, schema); + importTables(config, schema, options); } /** @@ -542,13 +546,15 @@ public static void importTables(Properties configProperties, Path schemaPath) * * @param configPath path to the ScalarDB config. * @param serializedSchemaJson serialized json string schema. + * @param options specific options for importing. * @throws SchemaLoaderException thrown when importing tables fails. */ - public static void importTables(Path configPath, String serializedSchemaJson) + public static void importTables( + Path configPath, String serializedSchemaJson, Map options) throws SchemaLoaderException { Either config = new Left<>(configPath); Either schema = new Right<>(serializedSchemaJson); - importTables(config, schema); + importTables(config, schema, options); } /** @@ -556,22 +562,25 @@ public static void importTables(Path configPath, String serializedSchemaJson) * * @param configPath path to the ScalarDB config. * @param schemaPath path to the schema file. + * @param options specific options for importing. * @throws SchemaLoaderException thrown when importing tables fails. */ - public static void importTables(Path configPath, Path schemaPath) throws SchemaLoaderException { + public static void importTables(Path configPath, Path schemaPath, Map options) + throws SchemaLoaderException { Either config = new Left<>(configPath); Either schema = new Left<>(schemaPath); - importTables(config, schema); + importTables(config, schema, options); } - private static void importTables(Either config, Either schema) + private static void importTables( + Either config, Either schema, Map options) throws SchemaLoaderException { // Parse the schema - List tableSchemaList = getImportTableSchemaList(schema); + List tableSchemaList = getImportTableSchemaList(schema, options); // Import tables try (SchemaOperator operator = getSchemaOperator(config)) { - operator.importTables(tableSchemaList); + operator.importTables(tableSchemaList, options); } } @@ -613,25 +622,25 @@ static SchemaParser getSchemaParser(Either schema, Map getImportTableSchemaList(Either schema) - throws SchemaLoaderException { + private static List getImportTableSchemaList( + Either schema, Map options) throws SchemaLoaderException { if ((schema.isLeft() && schema.getLeft() != null) || (schema.isRight() && schema.getRight() != null)) { - ImportSchemaParser schemaParser = getImportSchemaParser(schema); + ImportSchemaParser schemaParser = getImportSchemaParser(schema, options); return schemaParser.parse(); } return Collections.emptyList(); } @VisibleForTesting - static ImportSchemaParser getImportSchemaParser(Either schema) - throws SchemaLoaderException { + static ImportSchemaParser getImportSchemaParser( + Either schema, Map options) throws SchemaLoaderException { assert (schema.isLeft() && schema.getLeft() != null) || (schema.isRight() && schema.getRight() != null); if (schema.isLeft()) { - return new ImportSchemaParser(schema.getLeft()); + return new ImportSchemaParser(schema.getLeft(), options); } else { - return new ImportSchemaParser(schema.getRight()); + return new ImportSchemaParser(schema.getRight(), options); } } } 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 64f8fa4300..e31f4a3f9c 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,7 +13,6 @@ 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; @@ -408,15 +407,16 @@ private void addNewColumnsToTable( } } - public void importTables(List tableSchemaList) throws SchemaLoaderException { + public void importTables(List tableSchemaList, Map options) + throws SchemaLoaderException { for (ImportTableSchema tableSchema : tableSchemaList) { String namespace = tableSchema.getNamespace(); String table = tableSchema.getTable(); try { if (tableSchema.isTransactionTable()) { - transactionAdmin.get().importTable(namespace, table, Collections.emptyMap()); + transactionAdmin.get().importTable(namespace, table, options); } else { - storageAdmin.get().importTable(namespace, table, Collections.emptyMap()); + storageAdmin.get().importTable(namespace, table, options); } logger.info("Importing the table {} in the namespace {} succeeded", table, namespace); } catch (ExecutionException e) { diff --git a/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java b/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java index f058aed051..f2b52b847e 100644 --- a/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java +++ b/schema-loader/src/main/java/com/scalar/db/schemaloader/TableSchema.java @@ -20,11 +20,11 @@ @Immutable public class TableSchema { - private static final String COLUMNS = "columns"; - private static final String TRANSACTION = "transaction"; - private static final String PARTITION_KEY = "partition-key"; - private static final String CLUSTERING_KEY = "clustering-key"; - private static final String SECONDARY_INDEX = "secondary-index"; + static final String COLUMNS = "columns"; + static final String TRANSACTION = "transaction"; + static final String PARTITION_KEY = "partition-key"; + static final String CLUSTERING_KEY = "clustering-key"; + static final String SECONDARY_INDEX = "secondary-index"; private static final ImmutableMap DATA_MAP_TYPE = ImmutableMap.builder() .put("BOOLEAN", DataType.BOOLEAN) diff --git a/schema-loader/src/main/java/com/scalar/db/schemaloader/command/SchemaLoaderCommand.java b/schema-loader/src/main/java/com/scalar/db/schemaloader/command/SchemaLoaderCommand.java index 9897b7b882..28acf730a3 100644 --- a/schema-loader/src/main/java/com/scalar/db/schemaloader/command/SchemaLoaderCommand.java +++ b/schema-loader/src/main/java/com/scalar/db/schemaloader/command/SchemaLoaderCommand.java @@ -151,8 +151,8 @@ private void importTables() throws SchemaLoaderException { "Specifying the '--coordinator' option with the '--import' option is not allowed." + " Create coordinator tables separately"); } - - SchemaLoader.importTables(configPath, schemaFile); + Map options = prepareAllOptions(); + SchemaLoader.importTables(configPath, schemaFile, options); } private Map prepareAllOptions() { diff --git a/schema-loader/src/test/java/com/scalar/db/schemaloader/ImportSchemaParserTest.java b/schema-loader/src/test/java/com/scalar/db/schemaloader/ImportSchemaParserTest.java index b00df1c971..9275e22a2a 100644 --- a/schema-loader/src/test/java/com/scalar/db/schemaloader/ImportSchemaParserTest.java +++ b/schema-loader/src/test/java/com/scalar/db/schemaloader/ImportSchemaParserTest.java @@ -1,8 +1,11 @@ package com.scalar.db.schemaloader; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.entry; +import com.google.common.collect.ImmutableMap; import java.util.List; +import java.util.Map; import org.junit.jupiter.api.Test; public class ImportSchemaParserTest { @@ -11,6 +14,7 @@ public class ImportSchemaParserTest { public void parse_ProperSerializedSchemaJsonAndOptionsGiven_ShouldParseCorrectly() throws SchemaLoaderException { // Arrange + Map globalOptions = ImmutableMap.of("ru", "4000", "replication-factor", "1"); String serializedSchemaJson = "{" + " \"sample_db.sample_table1\": {" @@ -45,7 +49,7 @@ public void parse_ProperSerializedSchemaJsonAndOptionsGiven_ShouldParseCorrectly + " \"compaction-strategy\": \"LCS\"" + " }" + "}"; - ImportSchemaParser parser = new ImportSchemaParser(serializedSchemaJson); + ImportSchemaParser parser = new ImportSchemaParser(serializedSchemaJson, globalOptions); // Act List actual = parser.parse(); @@ -56,13 +60,22 @@ public void parse_ProperSerializedSchemaJsonAndOptionsGiven_ShouldParseCorrectly assertThat(actual.get(0).getNamespace()).isEqualTo("sample_db"); assertThat(actual.get(0).getTable()).isEqualTo("sample_table1"); assertThat(actual.get(0).isTransactionTable()).isTrue(); + assertThat(actual.get(0).getOptions()) + .containsOnly(entry("ru", "4000"), entry("replication-factor", "1")); assertThat(actual.get(1).getNamespace()).isEqualTo("sample_db"); assertThat(actual.get(1).getTable()).isEqualTo("sample_table2"); assertThat(actual.get(1).isTransactionTable()).isFalse(); + assertThat(actual.get(1).getOptions()) + .containsOnly(entry("ru", "4000"), entry("replication-factor", "1")); assertThat(actual.get(2).getNamespace()).isEqualTo("sample_db"); assertThat(actual.get(2).getTable()).isEqualTo("sample_table3"); assertThat(actual.get(2).isTransactionTable()).isTrue(); + assertThat(actual.get(2).getOptions()) + .containsOnly( + entry("ru", "5000"), + entry("compaction-strategy", "LCS"), + entry("replication-factor", "1")); } } diff --git a/schema-loader/src/test/java/com/scalar/db/schemaloader/ImportTableSchemaTest.java b/schema-loader/src/test/java/com/scalar/db/schemaloader/ImportTableSchemaTest.java index 1ad062e9c1..fd366009ac 100644 --- a/schema-loader/src/test/java/com/scalar/db/schemaloader/ImportTableSchemaTest.java +++ b/schema-loader/src/test/java/com/scalar/db/schemaloader/ImportTableSchemaTest.java @@ -1,7 +1,11 @@ package com.scalar.db.schemaloader; +import static org.assertj.core.api.Assertions.entry; + +import com.google.common.collect.ImmutableMap; import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import java.util.Collections; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,12 +28,14 @@ public void constructor_DefinitionWithTransactionTrueGiven_ShouldConstructProper JsonObject tableDefinition = JsonParser.parseString(tableDefinitionJson).getAsJsonObject(); // Act - ImportTableSchema tableSchema = new ImportTableSchema("ns.tbl", tableDefinition); + ImportTableSchema tableSchema = + new ImportTableSchema("ns.tbl", tableDefinition, Collections.emptyMap()); // Assert Assertions.assertThat(tableSchema.getNamespace()).isEqualTo("ns"); Assertions.assertThat(tableSchema.getTable()).isEqualTo("tbl"); Assertions.assertThat(tableSchema.isTransactionTable()).isEqualTo(true); + Assertions.assertThat(tableSchema.getOptions()).isEmpty(); } @Test @@ -39,12 +45,14 @@ public void constructor_DefinitionWithTransactionFalseGiven_ShouldConstructPrope JsonObject tableDefinition = JsonParser.parseString(tableDefinitionJson).getAsJsonObject(); // Act - ImportTableSchema tableSchema = new ImportTableSchema("ns.tbl", tableDefinition); + ImportTableSchema tableSchema = + new ImportTableSchema("ns.tbl", tableDefinition, Collections.emptyMap()); // Assert Assertions.assertThat(tableSchema.getNamespace()).isEqualTo("ns"); Assertions.assertThat(tableSchema.getTable()).isEqualTo("tbl"); Assertions.assertThat(tableSchema.isTransactionTable()).isEqualTo(false); + Assertions.assertThat(tableSchema.getOptions()).isEmpty(); } @Test @@ -53,7 +61,8 @@ public void constructor_WrongFormatTableFullNameGiven_ShouldThrowSchemaLoaderExc String tableFullName = "namespace_and_table_without_dot_separator"; // Act Assert - Assertions.assertThatThrownBy(() -> new ImportTableSchema(tableFullName, tableDefinition)) + Assertions.assertThatThrownBy( + () -> new ImportTableSchema(tableFullName, tableDefinition, Collections.emptyMap())) .isInstanceOf(SchemaLoaderException.class); } @@ -64,11 +73,38 @@ public void constructor_DefinitionWithoutTransactionGiven_ShouldConstructProperT JsonObject tableDefinition = JsonParser.parseString(tableDefinitionJson).getAsJsonObject(); // Act - ImportTableSchema tableSchema = new ImportTableSchema("ns.tbl", tableDefinition); + ImportTableSchema tableSchema = + new ImportTableSchema("ns.tbl", tableDefinition, Collections.emptyMap()); // Assert Assertions.assertThat(tableSchema.getNamespace()).isEqualTo("ns"); Assertions.assertThat(tableSchema.getTable()).isEqualTo("tbl"); Assertions.assertThat(tableSchema.isTransactionTable()).isEqualTo(true); + Assertions.assertThat(tableSchema.getOptions()).isEmpty(); + } + + @Test + public void constructor_DefinitionWithGlobalAndSchemaOptions_ShouldConstructWithProperOptions() + throws SchemaLoaderException { + String tableDefinitionJson = + "{\"partition-key\": \"ignored\", \"columns\": \"ignored\", \"clustering-key\": \"ignored\", \"secondary-index\": \"ignored\",\"transaction\": false, \"opt1\": \"schema-opt1\", \"opt3\": \"schema-opt3\"}"; + JsonObject tableDefinition = JsonParser.parseString(tableDefinitionJson).getAsJsonObject(); + + // Act + ImportTableSchema tableSchema = + new ImportTableSchema( + "ns.tbl", + tableDefinition, + ImmutableMap.of("opt1", "global-opt1", "opt2", "global-opt2")); + + // Assert + Assertions.assertThat(tableSchema.getNamespace()).isEqualTo("ns"); + Assertions.assertThat(tableSchema.getTable()).isEqualTo("tbl"); + Assertions.assertThat(tableSchema.isTransactionTable()).isEqualTo(false); + Assertions.assertThat(tableSchema.getOptions()) + .containsOnly( + entry("opt1", "schema-opt1"), + entry("opt2", "global-opt2"), + entry("opt3", "schema-opt3")); } } diff --git a/schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaLoaderTest.java b/schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaLoaderTest.java index 6ca0ea32ac..bdcaa3be57 100644 --- a/schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaLoaderTest.java +++ b/schema-loader/src/test/java/com/scalar/db/schemaloader/SchemaLoaderTest.java @@ -2,6 +2,7 @@ import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mockStatic; @@ -46,7 +47,7 @@ public void setUp() throws SchemaLoaderException { .when(() -> SchemaLoader.getSchemaParser(any(), anyMap())) .thenReturn(parser); schemaLoaderMockedStatic - .when(() -> SchemaLoader.getImportSchemaParser(any())) + .when(() -> SchemaLoader.getImportSchemaParser(any(), anyMap())) .thenReturn(importSchemaParser); when(parser.parse()).thenReturn(Collections.emptyList()); when(importSchemaParser.parse()).thenReturn(Collections.emptyList()); @@ -727,11 +728,11 @@ public void alterTable_WithConfigPropertiesAndSchemaFilePath_ShouldCallParserAnd // Arrange // Act - SchemaLoader.importTables(configProperties, SERIALIZED_SCHEMA_JSON); + SchemaLoader.importTables(configProperties, SERIALIZED_SCHEMA_JSON, options); // Assert verify(importSchemaParser).parse(); - verify(operator).importTables(anyList()); + verify(operator).importTables(anyList(), eq(options)); } @Test @@ -741,11 +742,11 @@ public void alterTable_WithConfigPropertiesAndSchemaFilePath_ShouldCallParserAnd // Arrange // Act - SchemaLoader.importTables(configFilePath, SERIALIZED_SCHEMA_JSON); + SchemaLoader.importTables(configFilePath, SERIALIZED_SCHEMA_JSON, options); // Assert verify(importSchemaParser).parse(); - verify(operator).importTables(anyList()); + verify(operator).importTables(anyList(), eq(options)); } @Test @@ -755,11 +756,11 @@ public void alterTable_WithConfigPropertiesAndSchemaFilePath_ShouldCallParserAnd // Arrange // Act - SchemaLoader.importTables(configProperties, schemaFilePath); + SchemaLoader.importTables(configProperties, schemaFilePath, options); // Assert verify(importSchemaParser).parse(); - verify(operator).importTables(anyList()); + verify(operator).importTables(anyList(), eq(options)); } @Test @@ -768,10 +769,10 @@ public void importTable_WithConfigFilePathAndSchemaFilePath_ShouldCallParserAndO // Arrange // Act - SchemaLoader.importTables(configFilePath, schemaFilePath); + SchemaLoader.importTables(configFilePath, schemaFilePath, options); // Assert verify(importSchemaParser).parse(); - verify(operator).importTables(anyList()); + verify(operator).importTables(anyList(), eq(options)); } } 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 d2136c2ad9..cc2a3b593b 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 @@ -514,10 +514,10 @@ public void importTables_WithTransactionTables_ShouldCallProperMethods() throws when(importTableSchema.getTable()).thenReturn("tb"); // Act - operator.importTables(tableSchemaList); + operator.importTables(tableSchemaList, options); // Assert - verify(transactionAdmin, times(3)).importTable("ns", "tb", Collections.emptyMap()); + verify(transactionAdmin, times(3)).importTable("ns", "tb", options); verifyNoInteractions(storageAdmin); } @@ -531,10 +531,10 @@ public void importTables_WithoutTransactionTables_ShouldCallProperMethods() thro when(importTableSchema.getTable()).thenReturn("tb"); // Act - operator.importTables(tableSchemaList); + operator.importTables(tableSchemaList, options); // Assert - verify(storageAdmin, times(3)).importTable("ns", "tb", Collections.emptyMap()); + verify(storageAdmin, times(3)).importTable("ns", "tb", options); verifyNoInteractions(transactionAdmin); } diff --git a/schema-loader/src/test/java/com/scalar/db/schemaloader/command/SchemaLoaderCommandTest.java b/schema-loader/src/test/java/com/scalar/db/schemaloader/command/SchemaLoaderCommandTest.java index 288313d22f..1ae2e862f2 100644 --- a/schema-loader/src/test/java/com/scalar/db/schemaloader/command/SchemaLoaderCommandTest.java +++ b/schema-loader/src/test/java/com/scalar/db/schemaloader/command/SchemaLoaderCommandTest.java @@ -352,13 +352,37 @@ public void call_ImportOptionGivenWithProperArguments_ShouldCallImportTablePrope // Arrange String schemaFile = "path_to_file"; String configFile = "path_to_config_file"; + Map options = + ImmutableMap.builder() + .put(CassandraAdmin.REPLICATION_STRATEGY, replicationStrategy) + .put(CassandraAdmin.COMPACTION_STRATEGY, compactionStrategy) + .put(CassandraAdmin.REPLICATION_FACTOR, replicationFactor) + .put(DynamoAdmin.REQUEST_UNIT, ru) + .put(DynamoAdmin.NO_SCALING, noScaling.toString()) + .put(DynamoAdmin.NO_BACKUP, noBackup.toString()) + .build(); // Act - commandLine.execute("-f", schemaFile, "--import", "--config", configFile); + commandLine.execute( + "-f", + schemaFile, + "--import", + "--config", + configFile, + "--replication-strategy", + replicationStrategy, + "--compaction-strategy", + compactionStrategy, + "--replication-factor", + replicationFactor, + "--ru", + ru, + "--no-scaling", + "--no-backup"); // Assert schemaLoaderMockedStatic.verify( - () -> SchemaLoader.importTables(Paths.get(configFile), Paths.get(schemaFile))); + () -> SchemaLoader.importTables(Paths.get(configFile), Paths.get(schemaFile), options)); } @Test