Testing Configuration Loading
Relevant source files
The following files were used as context for generating this wiki page:
- src/test/java/liquibase/ParamsLoaderTest.java
- src/test/resources/testLiquibaseClickhouse.conf
- src/test/resources/testLiquibaseClickhouseBroken.conf
- src/main/java/liquibase/ext/clickhouse/params/ParamsLoader.java
- src/main/java/liquibase/ext/clickhouse/params/ClusterConfig.java
- src/test/java/liquibase/ClickHouseTest.java
Testing configuration loading ensures that the Liquibase ClickHouse extension correctly parses and validates cluster-specific settings required for replicated environments. This process verifies that the system can distinguish between a single-instance setup and a multi-node cluster configuration by loading parameters from external .conf files.
The testing suite specifically targets the ParamsLoader utility to confirm it correctly populates the ClusterConfig data structure or gracefully handles malformed configuration files.
Sources: src/main/java/liquibase/ext/clickhouse/params/ParamsLoader.java, src/test/java/liquibase/ParamsLoaderTest.java
Configuration Architecture
The configuration loading system utilizes the Typesafe Config library to read HOCON-formatted files. It looks for a specific cluster block containing parameters for cluster naming and ZooKeeper paths.
Component Interaction
The following diagram illustrates the flow from a test case through the loader to the final configuration object:
The ParamsLoader acts as a static utility that abstracts the complexity of file I/O and validation, providing a clean ClusterConfig object to the rest of the extension.
Sources: src/main/java/liquibase/ext/clickhouse/params/ParamsLoader.java:79-111, src/test/java/liquibase/ParamsLoaderTest.java:27-40
Validation Logic
The system enforces a strict set of required properties. If any property is missing or if unknown properties are present, the loader logs a severe error and reverts to single-instance mode by returning null.
Required Properties
| Property | Description |
|---|---|
clusterName | The name of the ClickHouse cluster for the ON CLUSTER clause. |
tableZooKeeperPathPrefix | The path in ZooKeeper where replicated table metadata is stored. |
tableReplicaName | The identifier for the specific replica. |
Sources: src/main/java/liquibase/ext/clickhouse/params/ParamsLoader.java:40-42, src/main/java/liquibase/ext/clickhouse/params/ClusterConfig.java:25-50
Failure Handling
When a configuration file is "broken" (e.g., contains typos in key names), the ParamsLoader catches InvalidPropertiesFormatException or ConfigException.Missing.
Implementation Details
Successful Load Example
A valid configuration file must match the expected structure precisely to be accepted by the test suite.
cluster {
clusterName="Cluster1"
tableZooKeeperPathPrefix="Path1"
tableReplicaName="Replica1"
}
Sources: src/test/resources/testLiquibaseClickhouse.conf:1-6
Test Assertions
The ParamsLoaderTest class performs functional validation by asserting the state of the returned ClusterConfig object.
@Test
void loadParams() {
ClusterConfig params = ParamsLoader.getLiquibaseClickhouseProperties("testLiquibaseClickhouse");
assert (params != null);
assert (params.getClusterName().equals("Cluster1"));
assert (params.getTableZooKeeperPathPrefix().equals("Path1"));
assert (params.getTableReplicaName().equals("Replica1"));
}
Sources: src/test/java/liquibase/ParamsLoaderTest.java:30-36
Integration with Liquibase Operations
While ParamsLoaderTest focuses on the unit level, the loaded configuration impacts how SQL is generated across the extension. When properties are found, the extension switches from standard MergeTree engines to ReplicatedMergeTree and appends ON CLUSTER clauses to DDL statements.
Sources: src/main/java/liquibase/ext/clickhouse/params/ParamsLoader.java:99-101, src/test/java/liquibase/ClickHouseTest.java:43-50
Conclusion
Testing configuration loading is critical for ensuring the extension's reliability in distributed ClickHouse environments. By validating the ParamsLoader against both valid and malformed files, the project ensures that cluster-mode features are only activated when a complete and correct configuration is provided, preventing runtime errors during database migrations.