From a8fbb31bc4e0101385f7030e7839aeeeca033853 Mon Sep 17 00:00:00 2001 From: Mitsunori Komatsu Date: Wed, 11 Jun 2025 02:37:15 +0000 Subject: [PATCH 1/2] Empty commit [skip ci] From 7bf2f64f0007273c0afdaf4c3feaa890837d9072 Mon Sep 17 00:00:00 2001 From: Mitsunori Komatsu Date: Wed, 11 Jun 2025 11:37:02 +0900 Subject: [PATCH 2/2] Add `--replication-tables` option to the Schema Loader (#2747) --- .../com/scalar/db/api/ReplicationAdmin.java | 18 +- .../com/scalar/db/common/error/CoreError.java | 3 +- schema-loader/build.gradle | 1 + .../scalar/db/schemaloader/SchemaLoader.java | 104 +++- .../db/schemaloader/SchemaOperator.java | 43 ++ .../command/SchemaLoaderCommand.java | 12 +- .../db/schemaloader/SchemaLoaderTest.java | 572 +++++++++++++----- .../db/schemaloader/SchemaOperatorTest.java | 70 +++ .../command/SchemaLoaderCommandTest.java | 107 +++- 9 files changed, 712 insertions(+), 218 deletions(-) diff --git a/core/src/main/java/com/scalar/db/api/ReplicationAdmin.java b/core/src/main/java/com/scalar/db/api/ReplicationAdmin.java index 63916fb898..ce595d8d64 100644 --- a/core/src/main/java/com/scalar/db/api/ReplicationAdmin.java +++ b/core/src/main/java/com/scalar/db/api/ReplicationAdmin.java @@ -2,7 +2,6 @@ import com.scalar.db.common.error.CoreError; import com.scalar.db.exception.storage.ExecutionException; -import java.util.Collections; import java.util.Map; /** An administrative interface for the replication feature. */ @@ -31,10 +30,7 @@ default void createReplicationTables(Map options) throws Executi */ default void createReplicationTables(boolean ifNotExist, Map options) throws ExecutionException { - if (ifNotExist && replicationTablesExist()) { - return; - } - createReplicationTables(options); + throw new UnsupportedOperationException(CoreError.REPLICATION_NOT_ENABLED.buildMessage()); } /** @@ -48,10 +44,7 @@ default void createReplicationTables(boolean ifNotExist, Map opt * @throws ExecutionException if the operation fails */ default void createReplicationTables(boolean ifNotExist) throws ExecutionException { - if (ifNotExist && replicationTablesExist()) { - return; - } - createReplicationTables(Collections.emptyMap()); + throw new UnsupportedOperationException(CoreError.REPLICATION_NOT_ENABLED.buildMessage()); } /** @@ -60,7 +53,7 @@ default void createReplicationTables(boolean ifNotExist) throws ExecutionExcepti * @throws ExecutionException if the operation fails */ default void createReplicationTables() throws ExecutionException { - createReplicationTables(Collections.emptyMap()); + throw new UnsupportedOperationException(CoreError.REPLICATION_NOT_ENABLED.buildMessage()); } /** @@ -83,10 +76,7 @@ default void dropReplicationTables() throws ExecutionException { * @throws ExecutionException if the operation fails */ default void dropReplicationTables(boolean ifExist) throws ExecutionException { - if (ifExist && !replicationTablesExist()) { - return; - } - dropReplicationTables(); + throw new UnsupportedOperationException(CoreError.REPLICATION_NOT_ENABLED.buildMessage()); } /** diff --git a/core/src/main/java/com/scalar/db/common/error/CoreError.java b/core/src/main/java/com/scalar/db/common/error/CoreError.java index f6c02711b5..d58ff52f64 100644 --- a/core/src/main/java/com/scalar/db/common/error/CoreError.java +++ b/core/src/main/java/com/scalar/db/common/error/CoreError.java @@ -861,8 +861,7 @@ public enum CoreError implements ScalarDbError { REPLICATION_NOT_ENABLED( Category.USER_ERROR, "0188", - // TODO: Update the message once the licence type is determined. - "The replication feature is not enabled. To use this feature, you must enable it", + "The replication feature is not enabled. To use this feature, you must enable it. Note that this feature is supported only in the ScalarDB Enterprise edition", "", ""), DATA_LOADER_IMPORT_TARGET_MISSING( diff --git a/schema-loader/build.gradle b/schema-loader/build.gradle index 97523de479..26a2a358b4 100644 --- a/schema-loader/build.gradle +++ b/schema-loader/build.gradle @@ -19,6 +19,7 @@ dependencies { implementation "com.google.code.gson:gson:${gsonVersion}" implementation "info.picocli:picocli:${picocliVersion}" testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}" + testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}" testImplementation "org.assertj:assertj-core:${assertjVersion}" testImplementation "org.mockito:mockito-core:${mockitoVersion}" 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 f87693917f..3347d0b959 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 @@ -97,17 +97,19 @@ private static Object getCommand(String arg) { * @param schemaFilePath path to schema file. * @param options specific options for creating tables. * @param createCoordinatorTables create coordinator tables or not. + * @param createReplicationTables create replication tables or not. * @throws SchemaLoaderException thrown when creating tables fails. */ public static void load( Properties configProperties, @Nullable Path schemaFilePath, Map options, - boolean createCoordinatorTables) + boolean createCoordinatorTables, + boolean createReplicationTables) throws SchemaLoaderException { Either config = new Right<>(configProperties); Either schema = new Left<>(schemaFilePath); - load(config, schema, options, createCoordinatorTables); + load(config, schema, options, createCoordinatorTables, createReplicationTables); } /** @@ -117,17 +119,19 @@ public static void load( * @param schemaFilePath path to schema file. * @param options specific options for creating tables. * @param createCoordinatorTables create coordinator tables or not. + * @param createReplicationTables create replication tables or not. * @throws SchemaLoaderException thrown when creating tables fails. */ public static void load( Path configFilePath, @Nullable Path schemaFilePath, Map options, - boolean createCoordinatorTables) + boolean createCoordinatorTables, + boolean createReplicationTables) throws SchemaLoaderException { Either config = new Left<>(configFilePath); Either schema = new Left<>(schemaFilePath); - load(config, schema, options, createCoordinatorTables); + load(config, schema, options, createCoordinatorTables, createReplicationTables); } /** @@ -137,17 +141,19 @@ public static void load( * @param serializedSchemaJson serialized json string schema. * @param options specific options for creating tables. * @param createCoordinatorTables create coordinator tables or not. + * @param createReplicationTables create replication tables or not. * @throws SchemaLoaderException thrown when creating tables fails. */ public static void load( Properties configProperties, @Nullable String serializedSchemaJson, Map options, - boolean createCoordinatorTables) + boolean createCoordinatorTables, + boolean createReplicationTables) throws SchemaLoaderException { Either config = new Right<>(configProperties); Either schema = new Right<>(serializedSchemaJson); - load(config, schema, options, createCoordinatorTables); + load(config, schema, options, createCoordinatorTables, createReplicationTables); } /** @@ -157,17 +163,19 @@ public static void load( * @param serializedSchemaJson serialized json string schema. * @param options specific options for creating tables. * @param createCoordinatorTables create coordinator tables or not. + * @param createReplicationTables create replication tables or not. * @throws SchemaLoaderException thrown when creating tables fails. */ public static void load( Path configFilePath, @Nullable String serializedSchemaJson, Map options, - boolean createCoordinatorTables) + boolean createCoordinatorTables, + boolean createReplicationTables) throws SchemaLoaderException { Either config = new Left<>(configFilePath); Either schema = new Right<>(serializedSchemaJson); - load(config, schema, options, createCoordinatorTables); + load(config, schema, options, createCoordinatorTables, createReplicationTables); } /** @@ -177,13 +185,15 @@ public static void load( * @param schema schema definition. * @param options specific options for creating tables. * @param createCoordinatorTables create coordinator tables or not. + * @param createReplicationTables create replication tables or not. * @throws SchemaLoaderException thrown when creating tables fails. */ private static void load( Either config, Either schema, Map options, - boolean createCoordinatorTables) + boolean createCoordinatorTables, + boolean createReplicationTables) throws SchemaLoaderException { // Parse the schema List tableSchemaList = getTableSchemaList(schema, options); @@ -194,6 +204,9 @@ private static void load( if (createCoordinatorTables) { operator.createCoordinatorTables(options); } + if (createReplicationTables) { + operator.createReplicationTables(options); + } } } @@ -203,14 +216,18 @@ private static void load( * @param configProperties ScalarDB config properties. * @param schemaFilePath path to schema file. * @param deleteCoordinatorTables delete coordinator tables or not. + * @param deleteReplicationTables delete replication tables or not. * @throws SchemaLoaderException thrown when deleting tables fails. */ public static void unload( - Properties configProperties, @Nullable Path schemaFilePath, boolean deleteCoordinatorTables) + Properties configProperties, + @Nullable Path schemaFilePath, + boolean deleteCoordinatorTables, + boolean deleteReplicationTables) throws SchemaLoaderException { Either config = new Right<>(configProperties); Either schema = new Left<>(schemaFilePath); - unload(config, schema, deleteCoordinatorTables); + unload(config, schema, deleteCoordinatorTables, deleteReplicationTables); } /** @@ -219,14 +236,18 @@ public static void unload( * @param configFilePath path to ScalarDB config file. * @param schemaFilePath path to schema file. * @param deleteCoordinatorTables delete coordinator tables or not. + * @param deleteReplicationTables delete replication tables or not. * @throws SchemaLoaderException thrown when deleting tables fails. */ public static void unload( - Path configFilePath, @Nullable Path schemaFilePath, boolean deleteCoordinatorTables) + Path configFilePath, + @Nullable Path schemaFilePath, + boolean deleteCoordinatorTables, + boolean deleteReplicationTables) throws SchemaLoaderException { Either config = new Left<>(configFilePath); Either schema = new Left<>(schemaFilePath); - unload(config, schema, deleteCoordinatorTables); + unload(config, schema, deleteCoordinatorTables, deleteReplicationTables); } /** @@ -235,16 +256,18 @@ public static void unload( * @param configProperties ScalarDB config properties. * @param serializedSchemaJson serialized json string schema. * @param deleteCoordinatorTables delete coordinator tables or not. + * @param deleteReplicationTables delete replication tables or not. * @throws SchemaLoaderException thrown when deleting tables fails. */ public static void unload( Properties configProperties, @Nullable String serializedSchemaJson, - boolean deleteCoordinatorTables) + boolean deleteCoordinatorTables, + boolean deleteReplicationTables) throws SchemaLoaderException { Either config = new Right<>(configProperties); Either schema = new Right<>(serializedSchemaJson); - unload(config, schema, deleteCoordinatorTables); + unload(config, schema, deleteCoordinatorTables, deleteReplicationTables); } /** @@ -253,14 +276,18 @@ public static void unload( * @param configFilePath path to ScalarDB config file. * @param serializedSchemaJson serialized json string schema. * @param deleteCoordinatorTables delete coordinator tables or not. + * @param deleteReplicationTables delete replication tables or not. * @throws SchemaLoaderException thrown when deleting tables fails. */ public static void unload( - Path configFilePath, @Nullable String serializedSchemaJson, boolean deleteCoordinatorTables) + Path configFilePath, + @Nullable String serializedSchemaJson, + boolean deleteCoordinatorTables, + boolean deleteReplicationTables) throws SchemaLoaderException { Either config = new Left<>(configFilePath); Either schema = new Right<>(serializedSchemaJson); - unload(config, schema, deleteCoordinatorTables); + unload(config, schema, deleteCoordinatorTables, deleteReplicationTables); } /** @@ -269,10 +296,14 @@ public static void unload( * @param config ScalarDB config. * @param schema schema definition. * @param deleteCoordinatorTables delete coordinator tables or not. + * @param deleteReplicationTables delete replication tables or not. * @throws SchemaLoaderException thrown when deleting tables fails. */ private static void unload( - Either config, Either schema, boolean deleteCoordinatorTables) + Either config, + Either schema, + boolean deleteCoordinatorTables, + boolean deleteReplicationTables) throws SchemaLoaderException { // Parse the schema List tableSchemaList = getTableSchemaList(schema, Collections.emptyMap()); @@ -283,6 +314,9 @@ private static void unload( if (deleteCoordinatorTables) { operator.dropCoordinatorTables(); } + if (deleteReplicationTables) { + operator.dropReplicationTables(); + } } } @@ -293,17 +327,19 @@ private static void unload( * @param serializedSchemaJson serialized json string schema. * @param options specific options for repairing tables. * @param repairCoordinatorTable repair coordinator tables or not. + * @param repairReplicationTable repair replication tables or not. * @throws SchemaLoaderException thrown when repairing tables fails. */ public static void repairTables( Properties configProperties, String serializedSchemaJson, Map options, - boolean repairCoordinatorTable) + boolean repairCoordinatorTable, + boolean repairReplicationTable) throws SchemaLoaderException { Either config = new Right<>(configProperties); Either schema = new Right<>(serializedSchemaJson); - repairTables(config, schema, options, repairCoordinatorTable); + repairTables(config, schema, options, repairCoordinatorTable, repairReplicationTable); } /** @@ -313,17 +349,19 @@ public static void repairTables( * @param schemaPath path to the schema file. * @param options specific options for repairing tables. * @param repairCoordinatorTable repair coordinator tables or not. + * @param repairReplicationTable repair replication tables or not. * @throws SchemaLoaderException thrown when repairing tables fails. */ public static void repairTables( Properties configProperties, Path schemaPath, Map options, - boolean repairCoordinatorTable) + boolean repairCoordinatorTable, + boolean repairReplicationTable) throws SchemaLoaderException { Either config = new Right<>(configProperties); Either schema = new Left<>(schemaPath); - repairTables(config, schema, options, repairCoordinatorTable); + repairTables(config, schema, options, repairCoordinatorTable, repairReplicationTable); } /** @@ -333,17 +371,19 @@ public static void repairTables( * @param serializedSchemaJson serialized json string schema. * @param options specific options for repairing tables. * @param repairCoordinatorTable repair coordinator tables or not. + * @param repairReplicationTable repair replication tables or not. * @throws SchemaLoaderException thrown when repairing tables fails. */ public static void repairTables( Path configPath, String serializedSchemaJson, Map options, - boolean repairCoordinatorTable) + boolean repairCoordinatorTable, + boolean repairReplicationTable) throws SchemaLoaderException { Either config = new Left<>(configPath); Either schema = new Right<>(serializedSchemaJson); - repairTables(config, schema, options, repairCoordinatorTable); + repairTables(config, schema, options, repairCoordinatorTable, repairReplicationTable); } /** @@ -353,14 +393,19 @@ public static void repairTables( * @param schemaPath path to the schema file. * @param options specific options for repairing tables. * @param repairCoordinatorTable repair coordinator tables or not. + * @param repairReplicationTable repair replication tables or not. * @throws SchemaLoaderException thrown when repairing tables fails. */ public static void repairTables( - Path configPath, Path schemaPath, Map options, boolean repairCoordinatorTable) + Path configPath, + Path schemaPath, + Map options, + boolean repairCoordinatorTable, + boolean repairReplicationTable) throws SchemaLoaderException { Either config = new Left<>(configPath); Either schema = new Left<>(schemaPath); - repairTables(config, schema, options, repairCoordinatorTable); + repairTables(config, schema, options, repairCoordinatorTable, repairReplicationTable); } /** @@ -370,13 +415,15 @@ public static void repairTables( * @param schema schema. * @param options specific options for repairing tables. * @param repairCoordinatorTable repair coordinator tables or not. + * @param repairReplicationTable repair replication tables or not. * @throws SchemaLoaderException thrown when repairing tables fails. */ private static void repairTables( Either config, Either schema, Map options, - boolean repairCoordinatorTable) + boolean repairCoordinatorTable, + boolean repairReplicationTable) throws SchemaLoaderException { // Parse the schema List tableSchemaList = getTableSchemaList(schema, options); @@ -387,6 +434,9 @@ private static void repairTables( if (repairCoordinatorTable) { operator.repairCoordinatorTables(options); } + if (repairReplicationTable) { + operator.repairReplicationTables(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 69e4ea2d10..4ceaafe88d 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 @@ -243,6 +243,49 @@ public void repairCoordinatorTables(Map options) throws SchemaLo } } + public void createReplicationTables(Map options) throws SchemaLoaderException { + if (replicationTablesExist()) { + logger.warn("The replication tables already exist"); + return; + } + try { + transactionAdmin.get().createReplicationTables(options); + logger.info("Creating the replication tables succeeded"); + } catch (ExecutionException e) { + throw new SchemaLoaderException(e.getMessage(), e); + } + } + + public void dropReplicationTables() throws SchemaLoaderException { + if (!replicationTablesExist()) { + logger.warn("The replication tables don't exist"); + return; + } + try { + transactionAdmin.get().dropReplicationTables(); + logger.info("Deleting the replication tables succeeded"); + } catch (ExecutionException e) { + throw new SchemaLoaderException(e.getMessage(), e); + } + } + + private boolean replicationTablesExist() throws SchemaLoaderException { + try { + return transactionAdmin.get().replicationTablesExist(); + } catch (ExecutionException e) { + throw new SchemaLoaderException(e.getMessage(), e); + } + } + + public void repairReplicationTables(Map options) throws SchemaLoaderException { + try { + transactionAdmin.get().repairReplicationTables(options); + logger.info("Repairing the replication tables succeeded"); + } catch (ExecutionException e) { + throw new SchemaLoaderException(e.getMessage(), e); + } + } + public void alterTables(List tableSchemaList, Map options) throws SchemaLoaderException { for (TableSchema tableSchema : tableSchemaList) { 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 e863190b98..5261bcec32 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 @@ -62,6 +62,12 @@ public class SchemaLoaderCommand implements Callable { defaultValue = "false") private boolean coordinator; + @Option( + names = "--replication-tables", + description = "Create/delete/repair replication tables", + defaultValue = "false") + private boolean replicationTables; + @Option( names = {"-f", "--schema-file"}, description = "Path to the schema json file") @@ -107,7 +113,7 @@ public Integer call() throws Exception { if (mode == null) { createTables(); } else if (mode.deleteTables) { - SchemaLoader.unload(configPath, schemaFile, coordinator); + SchemaLoader.unload(configPath, schemaFile, coordinator, replicationTables); } else if (mode.repairTables) { repairTables(); } else if (mode.alterTables) { @@ -120,7 +126,7 @@ public Integer call() throws Exception { private void createTables() throws SchemaLoaderException { Map options = prepareAllOptions(); - SchemaLoader.load(configPath, schemaFile, options, coordinator); + SchemaLoader.load(configPath, schemaFile, options, coordinator, replicationTables); } private void repairTables() throws SchemaLoaderException { @@ -130,7 +136,7 @@ private void repairTables() throws SchemaLoaderException { .buildMessage()); } Map options = prepareAllOptions(); - SchemaLoader.repairTables(configPath, schemaFile, options, coordinator); + SchemaLoader.repairTables(configPath, schemaFile, options, coordinator, replicationTables); } private void alterTables() throws SchemaLoaderException { 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 a8b86e643f..0764d05eed 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 @@ -17,6 +17,8 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.Mock; import org.mockito.MockedStatic; import org.mockito.MockitoAnnotations; @@ -59,604 +61,854 @@ public void tearDown() throws Exception { closeable.close(); } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigFileAndSchemaFileWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigFileAndSchemaFileWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configFilePath, schemaFilePath, options, true); + SchemaLoader.load(configFilePath, schemaFilePath, options, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).createTables(anyList()); verify(operator).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigFileAndSchemaFileWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigFileAndSchemaFileWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configFilePath, schemaFilePath, options, false); + SchemaLoader.load(configFilePath, schemaFilePath, options, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).createTables(anyList()); verify(operator, never()).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigFileAndNullSchemaFileWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigFileAndNullSchemaFileWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configFilePath, (Path) null, options, true); + SchemaLoader.load(configFilePath, (Path) null, options, true, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).createTables(anyList()); verify(operator).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigFileAndNullSchemaFileWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigFileAndNullSchemaFileWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configFilePath, (Path) null, options, false); + SchemaLoader.load(configFilePath, (Path) null, options, false, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).createTables(anyList()); verify(operator, never()).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigFileAndSerializedSchemaJsonWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigFileAndSerializedSchemaJsonWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configFilePath, SERIALIZED_SCHEMA_JSON, options, true); + SchemaLoader.load(configFilePath, SERIALIZED_SCHEMA_JSON, options, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).createTables(anyList()); verify(operator).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigFileAndSerializedSchemaJsonWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigFileAndSerializedSchemaJsonWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configFilePath, SERIALIZED_SCHEMA_JSON, options, false); + SchemaLoader.load( + configFilePath, SERIALIZED_SCHEMA_JSON, options, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).createTables(anyList()); verify(operator, never()).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigFileAndNullSerializedSchemaJsonWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigFileAndNullSerializedSchemaJsonWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configFilePath, (String) null, options, true); + SchemaLoader.load(configFilePath, (String) null, options, true, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).createTables(anyList()); verify(operator).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigFileAndNullSerializedSchemaJsonWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigFileAndNullSerializedSchemaJsonWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configFilePath, (String) null, options, false); + SchemaLoader.load(configFilePath, (String) null, options, false, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).createTables(anyList()); verify(operator, never()).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigPropertiesAndSchemaFileWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigPropertiesAndSchemaFileWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configProperties, schemaFilePath, options, true); + SchemaLoader.load(configProperties, schemaFilePath, options, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).createTables(anyList()); verify(operator).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigPropertiesAndSchemaFileWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigPropertiesAndSchemaFileWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configProperties, schemaFilePath, options, false); + SchemaLoader.load(configProperties, schemaFilePath, options, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).createTables(anyList()); verify(operator, never()).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigPropertiesAndNullSchemaFileWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigPropertiesAndNullSchemaFileWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configProperties, (Path) null, options, true); + SchemaLoader.load(configProperties, (Path) null, options, true, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).createTables(anyList()); verify(operator).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigPropertiesAndNullSchemaFileWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigPropertiesAndNullSchemaFileWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configProperties, (Path) null, options, false); + SchemaLoader.load(configProperties, (Path) null, options, false, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).createTables(anyList()); verify(operator, never()).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigPropertiesAndSerializedSchemaJsonWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigPropertiesAndSerializedSchemaJsonWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configProperties, SERIALIZED_SCHEMA_JSON, options, true); + SchemaLoader.load( + configProperties, SERIALIZED_SCHEMA_JSON, options, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).createTables(anyList()); verify(operator).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigPropertiesAndSerializedSchemaJsonWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigPropertiesAndSerializedSchemaJsonWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configProperties, SERIALIZED_SCHEMA_JSON, options, false); + SchemaLoader.load( + configProperties, SERIALIZED_SCHEMA_JSON, options, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).createTables(anyList()); verify(operator, never()).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigPropertiesAndNullSerializedSchemaJsonWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigPropertiesAndNullSerializedSchemaJsonWithCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configProperties, (String) null, options, true); + SchemaLoader.load(configProperties, (String) null, options, true, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).createTables(anyList()); verify(operator).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - load_WithConfigPropertiesAndNullSerializedSchemaJsonWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + load_WithConfigPropertiesAndNullSerializedSchemaJsonWithoutCreateCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.load(configProperties, (String) null, options, false); + SchemaLoader.load(configProperties, (String) null, options, false, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).createTables(anyList()); verify(operator, never()).createCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).createReplicationTables(options); + } else { + verify(operator, never()).createReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigFileAndSchemaFileWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigFileAndSchemaFileWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configFilePath, schemaFilePath, true); + SchemaLoader.unload(configFilePath, schemaFilePath, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).deleteTables(anyList()); verify(operator).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigFileAndSchemaFileWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigFileAndSchemaFileWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configFilePath, schemaFilePath, false); + SchemaLoader.unload(configFilePath, schemaFilePath, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).deleteTables(anyList()); verify(operator, never()).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigFileAndNullSchemaFileWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigFileAndNullSchemaFileWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configFilePath, (Path) null, true); + SchemaLoader.unload(configFilePath, (Path) null, true, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).deleteTables(anyList()); verify(operator).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigFileAndNullSchemaFileWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigFileAndNullSchemaFileWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configFilePath, (Path) null, false); + SchemaLoader.unload(configFilePath, (Path) null, false, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).deleteTables(anyList()); verify(operator, never()).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigFileAndSerializedSchemaJsonWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigFileAndSerializedSchemaJsonWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configFilePath, SERIALIZED_SCHEMA_JSON, true); + SchemaLoader.unload(configFilePath, SERIALIZED_SCHEMA_JSON, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).deleteTables(anyList()); verify(operator).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigFileAndSerializedSchemaJsonWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigFileAndSerializedSchemaJsonWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configFilePath, SERIALIZED_SCHEMA_JSON, false); + SchemaLoader.unload(configFilePath, SERIALIZED_SCHEMA_JSON, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).deleteTables(anyList()); verify(operator, never()).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigFileAndNullSerializedSchemaJsonWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigFileAndNullSerializedSchemaJsonWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configFilePath, (String) null, true); + SchemaLoader.unload(configFilePath, (String) null, true, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).deleteTables(anyList()); verify(operator).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigFileAndNullSerializedSchemaJsonWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigFileAndNullSerializedSchemaJsonWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configFilePath, (String) null, false); + SchemaLoader.unload(configFilePath, (String) null, false, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).deleteTables(anyList()); verify(operator, never()).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigPropertiesAndSchemaFileWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigPropertiesAndSchemaFileWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configProperties, schemaFilePath, true); + SchemaLoader.unload(configProperties, schemaFilePath, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).deleteTables(anyList()); verify(operator).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigPropertiesAndSchemaFileWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigPropertiesAndSchemaFileWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configProperties, schemaFilePath, false); + SchemaLoader.unload(configProperties, schemaFilePath, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).deleteTables(anyList()); verify(operator, never()).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigPropertiesAndNullSchemaFileWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigPropertiesAndNullSchemaFileWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configProperties, (Path) null, true); + SchemaLoader.unload(configProperties, (Path) null, true, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).deleteTables(anyList()); verify(operator).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigPropertiesAndNullSchemaFileWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigPropertiesAndNullSchemaFileWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configProperties, (Path) null, false); + SchemaLoader.unload(configProperties, (Path) null, false, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).deleteTables(anyList()); verify(operator, never()).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigPropertiesAndSerializedSchemaJsonWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigPropertiesAndSerializedSchemaJsonWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configProperties, SERIALIZED_SCHEMA_JSON, true); + SchemaLoader.unload(configProperties, SERIALIZED_SCHEMA_JSON, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).deleteTables(anyList()); verify(operator).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigPropertiesAndSerializedSchemaJsonWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigPropertiesAndSerializedSchemaJsonWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configProperties, SERIALIZED_SCHEMA_JSON, false); + SchemaLoader.unload(configProperties, SERIALIZED_SCHEMA_JSON, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).deleteTables(anyList()); verify(operator, never()).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigPropertiesAndNullSerializedSchemaJsonWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigPropertiesAndNullSerializedSchemaJsonWithDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configProperties, (String) null, true); + SchemaLoader.unload(configProperties, (String) null, true, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).deleteTables(anyList()); verify(operator).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - unload_WithConfigPropertiesAndNullSerializedSchemaJsonWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + unload_WithConfigPropertiesAndNullSerializedSchemaJsonWithoutDeleteCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.unload(configProperties, (String) null, false); + SchemaLoader.unload(configProperties, (String) null, false, withReplicationTables); // Assert verify(parser, never()).parse(); verify(operator).deleteTables(anyList()); verify(operator, never()).dropCoordinatorTables(); + if (withReplicationTables) { + verify(operator).dropReplicationTables(); + } else { + verify(operator, never()).dropReplicationTables(); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - repairTable_WithConfigFilePathAndSerializedSchemaAndDoRepairCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + repairTable_WithConfigFilePathAndSerializedSchemaAndDoRepairCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.repairTables(configFilePath, SERIALIZED_SCHEMA_JSON, options, true); + SchemaLoader.repairTables( + configFilePath, SERIALIZED_SCHEMA_JSON, options, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).repairTables(anyList()); verify(operator).repairCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).repairReplicationTables(options); + } else { + verify(operator, never()).repairReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - repairTable_WithConfigFilePathAndSerializedSchemaAndDoNotRepairCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + repairTable_WithConfigFilePathAndSerializedSchemaAndDoNotRepairCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.repairTables(configFilePath, SERIALIZED_SCHEMA_JSON, options, false); + SchemaLoader.repairTables( + configFilePath, SERIALIZED_SCHEMA_JSON, options, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).repairTables(anyList()); verify(operator, never()).repairCoordinatorTables(anyMap()); + if (withReplicationTables) { + verify(operator).repairReplicationTables(options); + } else { + verify(operator, never()).repairReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - repairTable_WithConfigPropertiesAndSerializedSchemaAndDoRepairCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + repairTable_WithConfigPropertiesAndSerializedSchemaAndDoRepairCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.repairTables(configProperties, SERIALIZED_SCHEMA_JSON, options, true); + SchemaLoader.repairTables( + configProperties, SERIALIZED_SCHEMA_JSON, options, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).repairTables(anyList()); verify(operator).repairCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).repairReplicationTables(options); + } else { + verify(operator, never()).repairReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - repairTable_WithConfigPropertiesAndSerializedSchemaAndDoNotRepairCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + repairTable_WithConfigPropertiesAndSerializedSchemaAndDoNotRepairCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.repairTables(configProperties, SERIALIZED_SCHEMA_JSON, options, false); + SchemaLoader.repairTables( + configProperties, SERIALIZED_SCHEMA_JSON, options, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).repairTables(anyList()); verify(operator, never()).repairCoordinatorTables(anyMap()); + if (withReplicationTables) { + verify(operator).repairReplicationTables(options); + } else { + verify(operator, never()).repairReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - repairTable_WithConfigPropertiesAndSchemaFilePathAndDoRepairCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + repairTable_WithConfigPropertiesAndSchemaFilePathAndDoRepairCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.repairTables(configProperties, schemaFilePath, options, true); + SchemaLoader.repairTables( + configProperties, schemaFilePath, options, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).repairTables(anyList()); verify(operator).repairCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).repairReplicationTables(options); + } else { + verify(operator, never()).repairReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - repairTable_WithConfigPropertiesAndSchemaFilePathAndDoNotRepairCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + repairTable_WithConfigPropertiesAndSchemaFilePathAndDoNotRepairCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.repairTables(configProperties, schemaFilePath, options, false); + SchemaLoader.repairTables( + configProperties, schemaFilePath, options, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).repairTables(anyList()); verify(operator, never()).repairCoordinatorTables(anyMap()); + if (withReplicationTables) { + verify(operator).repairReplicationTables(options); + } else { + verify(operator, never()).repairReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - repairTable_WithConfigFilePathAndSchemaFilePathAndDoRepairCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + repairTable_WithConfigFilePathAndSchemaFilePathAndDoRepairCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.repairTables(configFilePath, schemaFilePath, options, true); + SchemaLoader.repairTables(configFilePath, schemaFilePath, options, true, withReplicationTables); // Assert verify(parser).parse(); verify(operator).repairTables(anyList()); verify(operator).repairCoordinatorTables(options); + if (withReplicationTables) { + verify(operator).repairReplicationTables(options); + } else { + verify(operator, never()).repairReplicationTables(options); + } } - @Test + @ParameterizedTest + @ValueSource(booleans = {true, false}) public void - repairTable_WithConfigFilePathAndSchemaFilePathAndDoNotRepairCoordinatorTables_ShouldCallParserAndOperatorProperly() - throws Exception { + repairTable_WithConfigFilePathAndSchemaFilePathAndDoNotRepairCoordinatorTables_ShouldCallParserAndOperatorProperly( + boolean withReplicationTables) throws Exception { // Arrange // Act - SchemaLoader.repairTables(configFilePath, schemaFilePath, options, false); + SchemaLoader.repairTables( + configFilePath, schemaFilePath, options, false, withReplicationTables); // Assert verify(parser).parse(); verify(operator).repairTables(anyList()); verify(operator, never()).repairCoordinatorTables(anyMap()); + if (withReplicationTables) { + verify(operator).repairReplicationTables(options); + } else { + verify(operator, never()).repairReplicationTables(options); + } } @Test 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 1fafa70a57..6e32980ab8 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 @@ -122,6 +122,36 @@ public void createTables_WithNonTransactionTables_ShouldCallProperMethods() thro verify(transactionAdmin, never()).createCoordinatorTables(options); } + @Test + public void + createReplicationTables_IfReplicationTablesNotExist_ShouldCallCreateReplicationTables() + throws Exception { + // Arrange + when(transactionAdmin.replicationTablesExist()).thenReturn(false); + + // Act + operator.createReplicationTables(options); + + // Assert + verify(transactionAdmin).replicationTablesExist(); + verify(transactionAdmin).createReplicationTables(options); + } + + @Test + public void + createReplicationTables_IfReplicationTablesExist_ShouldNotCallCreateReplicationTables() + throws Exception { + // Arrange + when(transactionAdmin.replicationTablesExist()).thenReturn(true); + + // Act + operator.createReplicationTables(options); + + // Assert + verify(transactionAdmin).replicationTablesExist(); + verify(transactionAdmin, never()).createReplicationTables(options); + } + @Test public void deleteTables_WithTableList_ShouldCallProperMethods() throws Exception { // Arrange @@ -196,6 +226,34 @@ public void dropCoordinatorTables_IfCoordinatorTablesNotExist_ShouldCallNotDropC verify(transactionAdmin, never()).dropCoordinatorTables(); } + @Test + public void dropReplicationTables_IfReplicationTablesExist_ShouldCallDropReplicationTables() + throws Exception { + // Arrange + when(transactionAdmin.replicationTablesExist()).thenReturn(true); + + // Act + operator.dropReplicationTables(); + + // Assert + verify(transactionAdmin).replicationTablesExist(); + verify(transactionAdmin).dropReplicationTables(); + } + + @Test + public void dropReplicationTables_IfReplicationTablesNotExist_ShouldCallNotDropReplicationTables() + throws Exception { + // Arrange + when(transactionAdmin.replicationTablesExist()).thenReturn(false); + + // Act + operator.dropReplicationTables(); + + // Assert + verify(transactionAdmin).replicationTablesExist(); + verify(transactionAdmin, never()).dropReplicationTables(); + } + @Test public void repairTables_WithTransactionTables_ShouldCallProperMethods() throws Exception { // Arrange @@ -246,6 +304,18 @@ public void repairCoordinatorTables_ShouldCallProperMethods() throws Exception { verifyNoInteractions(storageAdmin); } + @Test + public void repairReplicationTables_ShouldCallProperMethods() throws Exception { + // Arrange + + // Act + operator.repairReplicationTables(options); + + // Assert + verify(transactionAdmin).repairReplicationTables(options); + verifyNoInteractions(storageAdmin); + } + @Test public void alterTables_WithoutChanges_ShouldDoNothing() throws SchemaLoaderException, ExecutionException { 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 28911a0e1e..a139abe782 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 @@ -85,11 +85,12 @@ public void call_WithProperArgumentsForCreatingTables_ShouldCallLoadProperly() { "--no-backup", "-f", schemaFile, - "--coordinator"); + "--coordinator", + "--replication-tables"); // Assert schemaLoaderMockedStatic.verify( - () -> SchemaLoader.load(Paths.get(configFile), Paths.get(schemaFile), options, true)); + () -> SchemaLoader.load(Paths.get(configFile), Paths.get(schemaFile), options, true, true)); } @Test @@ -121,11 +122,51 @@ public void call_WithProperArgumentsForCreatingTables_ShouldCallLoadProperly() { "--no-scaling", "--no-backup", "-f", - schemaFile); + schemaFile, + "--replication-tables"); + + // Assert + schemaLoaderMockedStatic.verify( + () -> + SchemaLoader.load(Paths.get(configFile), Paths.get(schemaFile), options, false, true)); + } + + @Test + public void + call_WithProperArgumentsForCreatingTablesWithoutReplicationTablesArgument_ShouldCallLoadProperly() { + // Arrange + 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( + "--config", + configFile, + "--replication-strategy", + replicationStrategy, + "--compaction-strategy", + compactionStrategy, + "--replication-factor", + replicationFactor, + "--ru", + ru, + "--no-scaling", + "--no-backup", + "-f", + schemaFile, + "--coordinator"); // Assert schemaLoaderMockedStatic.verify( - () -> SchemaLoader.load(Paths.get(configFile), Paths.get(schemaFile), options, false)); + () -> + SchemaLoader.load(Paths.get(configFile), Paths.get(schemaFile), options, true, false)); } @Test @@ -160,7 +201,7 @@ public void call_WithProperArgumentsForCreatingTables_ShouldCallLoadProperly() { // Assert schemaLoaderMockedStatic.verify( - () -> SchemaLoader.load(Paths.get(configFile), (Path) null, options, true)); + () -> SchemaLoader.load(Paths.get(configFile), (Path) null, options, true, false)); } @Test @@ -170,11 +211,12 @@ public void call_WithProperArgumentsForDeletingTables_ShouldCallUnloadProperly() String configFile = "path_to_config_file"; // Act - commandLine.execute("-f", schemaFile, "-D", "--config", configFile, "--coordinator"); + commandLine.execute( + "-f", schemaFile, "-D", "--config", configFile, "--coordinator", "--replication-tables"); // Assert schemaLoaderMockedStatic.verify( - () -> SchemaLoader.unload(Paths.get(configFile), Paths.get(schemaFile), true)); + () -> SchemaLoader.unload(Paths.get(configFile), Paths.get(schemaFile), true, true)); } @Test @@ -185,11 +227,26 @@ public void call_WithProperArgumentsForDeletingTables_ShouldCallUnloadProperly() String configFile = "path_to_config_file"; // Act - commandLine.execute("-f", schemaFile, "-D", "--config", configFile); + commandLine.execute("-f", schemaFile, "-D", "--config", configFile, "--replication-tables"); // Assert schemaLoaderMockedStatic.verify( - () -> SchemaLoader.unload(Paths.get(configFile), Paths.get(schemaFile), false)); + () -> SchemaLoader.unload(Paths.get(configFile), Paths.get(schemaFile), false, true)); + } + + @Test + public void + call_WithProperArgumentsForDeletingTablesWithoutReplicationTablesArgument_ShouldCallUnloadProperly() { + // Arrange + String schemaFile = "path_to_file"; + String configFile = "path_to_config_file"; + + // Act + commandLine.execute("-f", schemaFile, "-D", "--config", configFile, "--coordinator"); + + // Assert + schemaLoaderMockedStatic.verify( + () -> SchemaLoader.unload(Paths.get(configFile), Paths.get(schemaFile), true, false)); } @Test @@ -207,7 +264,7 @@ public void call_WithProperArgumentsForDeletingTables_ShouldCallUnloadProperly() schemaLoaderMockedStatic.verify( () -> SchemaLoader.repairTables( - Paths.get(configFile), Paths.get(schemaFile), options, false)); + Paths.get(configFile), Paths.get(schemaFile), options, false, false)); } @Test @@ -225,7 +282,33 @@ public void call_WithProperArgumentsForDeletingTables_ShouldCallUnloadProperly() // Assert schemaLoaderMockedStatic.verify( () -> - SchemaLoader.repairTables(Paths.get(configFile), Paths.get(schemaFile), options, true)); + SchemaLoader.repairTables( + Paths.get(configFile), Paths.get(schemaFile), options, true, false)); + } + + @Test + public void + call_WithProperArgumentsForRepairingAllWithReplicationTablesArgument_ShouldCallRepairAllProperly() { + // Arrange + String schemaFile = "path_to_file"; + String configFile = "path_to_config_file"; + Map options = ImmutableMap.of(DynamoAdmin.NO_BACKUP, noBackup.toString()); + + // Act + commandLine.execute( + "-f", + schemaFile, + "--repair-all", + "--config", + configFile, + "--replication-tables", + "--no-backup"); + + // Assert + schemaLoaderMockedStatic.verify( + () -> + SchemaLoader.repairTables( + Paths.get(configFile), Paths.get(schemaFile), options, false, true)); } @Test @@ -253,7 +336,7 @@ public void call_forRepairingTablesWithoutSchemaFile_ShouldThrowIllegalArgumentE // Assert schemaLoaderMockedStatic.verify( - () -> SchemaLoader.unload(Paths.get(configFile), (Path) null, true)); + () -> SchemaLoader.unload(Paths.get(configFile), (Path) null, true, false)); } @Test