Skip to content

Commit

Permalink
DBZ-3943 Add ConfigDef unit tests to verify all Debezium Field instan…
Browse files Browse the repository at this point in the history
…ces have a proper documentation/description set;

Also adding missing descriptions.
  • Loading branch information
rk3rn3r authored Sep 9, 2021
1 parent 6f1577a commit b92e5c5
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,11 @@ public static SnapshotMode parse(String value, String defaultValue) {
.withWidth(Width.LONG)
.withImportance(Importance.MEDIUM)
.withValidation(MongoDbConnectorConfig::validateFieldRenamesList)
.withDescription("");
.withDescription("A comma-separated list of the fully-qualified replacements of fields that" +
" should be used to rename fields in change event message values. Fully-qualified replacements" +
" for fields are of the form databaseName.collectionName.fieldName.nestedFieldName:newNestedFieldName," +
" where databaseName and collectionName may contain the wildcard (*) which matches any characters," +
" the colon character (:) is used to determine rename mapping of field.");

public static final Field SNAPSHOT_MODE = Field.create("snapshot.mode")
.withDisplayName("Snapshot mode")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.connector.mongodb;

import io.debezium.config.ConfigDefinitionMetadataTest;

public class MongoDbConnectorConfigDefTest extends ConfigDefinitionMetadataTest {

public MongoDbConnectorConfigDefTest() {
super(new MongoDbConnector());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.connector.mongodb;

import io.debezium.config.TransformationConfigDefinitionMetadataTest;
import io.debezium.connector.mongodb.transforms.ExtractNewDocumentState;

public class MongoDbTransformationConfigDefTest extends TransformationConfigDefinitionMetadataTest {

public MongoDbTransformationConfigDefTest() {
super(new ExtractNewDocumentState<>());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.connector.mysql;

import io.debezium.config.ConfigDefinitionMetadataTest;

public class MySqlConnectorConfigDefTest extends ConfigDefinitionMetadataTest {

public MySqlConnectorConfigDefTest() {
super(new MySqlConnector());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,13 @@ public class OracleConnectorConfig extends HistorizedRelationalDatabaseConnector
public static final Field LOG_MINING_BUFFER_TYPE = Field.create("log.mining.buffer.type")
.withDisplayName("Controls which buffer type implementation to be used")
.withEnum(LogMiningBufferType.class, LogMiningBufferType.MEMORY)
.withImportance(Importance.LOW);
.withImportance(Importance.LOW)
.withDescription("The buffer type controls how the connector manages buffering transaction data." + System.lineSeparator() +
System.lineSeparator() +
"memory - Uses the JVM process' heap to buffer all transaction data." + System.lineSeparator() +
System.lineSeparator() +
"infinispan - This option uses an embedded Infinispan cache to buffer transaction data and persist it to disk." +
" Use the log.mining.buffer.location property to define the location for storing cache files.");

public static final Field LOG_MINING_BUFFER_LOCATION = Field.create("log.mining.buffer.location")
.withDisplayName("Location where Infinispan stores buffer caches")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.connector.oracle;

import io.debezium.config.ConfigDefinitionMetadataTest;

public class OracleConnectorConfigDefTest extends ConfigDefinitionMetadataTest {

public OracleConnectorConfigDefTest() {
super(new OracleConnector());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.connector.postgresql;

import io.debezium.config.ConfigDefinitionMetadataTest;

public class PostgresConnectorConfigDefTest extends ConfigDefinitionMetadataTest {

public PostgresConnectorConfigDefTest() {
super(new PostgresConnector());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.connector.sqlserver;

import io.debezium.config.ConfigDefinitionMetadataTest;

public class SqlServerConnectorConfigDefTest extends ConfigDefinitionMetadataTest {

public SqlServerConnectorConfigDefTest() {
super(new SqlServerConnector());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ public static DeleteHandling parse(String value, String defaultValue) {
+ "rewrite - __deleted field is added to records.");

public static final Field ROUTE_BY_FIELD = Field.create("route.by.field")
.withDisplayName("The column which determines how the events will be routed, the value will replace the topic name.")
.withDisplayName("Route by field name")
.withType(ConfigDef.Type.STRING)
.withWidth(ConfigDef.Width.LONG)
.withImportance(ConfigDef.Importance.LOW)
.withDescription("The column which determines how the events will be routed, the value will replace the topic name.")
.withDefault("");

public static final Field ADD_FIELDS_PREFIX = Field.create("add.fields.prefix")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.config;

import static org.fest.assertions.Assertions.assertThat;

import java.util.Map.Entry;

import org.apache.kafka.common.config.ConfigDef;
import org.apache.kafka.common.config.ConfigDef.ConfigKey;
import org.apache.kafka.connect.source.SourceConnector;
import org.junit.Test;

/**
* Applies basic checks of completeness for the connector-specific configuration metadata.
*/
public abstract class ConfigDefinitionMetadataTest {

private final ConfigDef config;

protected ConfigDefinitionMetadataTest(SourceConnector connector) {
this.config = connector.config();
}

@Test
public void allFieldsShouldHaveDescription() {
for (Entry<String, ConfigKey> configKey : config.configKeys().entrySet()) {
assertThat(configKey.getValue().documentation)
.describedAs("Description of config key \"" + configKey.getKey() + "\"")
.isNotNull()
.isNotEmpty();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.config;

import io.debezium.transforms.ByLogicalTableRouter;
import io.debezium.transforms.ExtractNewRecordState;
import io.debezium.transforms.outbox.EventRouter;
import io.debezium.transforms.tracing.ActivateTracingSpan;

/**
* Applies basic checks of completeness of the SMT-specific configuration metadata for the Debezium core SMTs.
*/
public class CoreTransformationConfigDefinitionMetadataTest extends TransformationConfigDefinitionMetadataTest {

public CoreTransformationConfigDefinitionMetadataTest() {
super(
new ByLogicalTableRouter<>(),
new ExtractNewRecordState<>(),
new EventRouter<>(),
new ActivateTracingSpan<>());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.config;

import static org.fest.assertions.Assertions.assertThat;

import java.util.Collections;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.kafka.common.config.ConfigDef.ConfigKey;
import org.apache.kafka.connect.transforms.Transformation;
import org.junit.Test;

/**
* Applies basic checks of completeness for the SMT-specific configuration metadata.
*/
public abstract class TransformationConfigDefinitionMetadataTest {

private final Set<Transformation<?>> transforms;

public TransformationConfigDefinitionMetadataTest(Transformation<?>... transforms) {
Set<Transformation<?>> tmp = new HashSet<>();
Collections.addAll(tmp, transforms);
this.transforms = Collections.unmodifiableSet(tmp);
}

@Test
public void allFieldsShouldHaveDescription() {
for (Transformation<?> transformation : transforms) {
for (Entry<String, ConfigKey> configKey : transformation.config().configKeys().entrySet()) {
assertThat(configKey.getValue().documentation)
.describedAs("Description of config key \"" + configKey.getKey() + "\" of transform class " + transformation.getClass().getName())
.isNotNull()
.isNotEmpty();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Debezium Authors.
*
* Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package io.debezium.transforms;

import io.debezium.config.TransformationConfigDefinitionMetadataTest;

public class ScriptingTransformationConfigDefTest extends TransformationConfigDefinitionMetadataTest {

public ScriptingTransformationConfigDefTest() {
super(new Filter<>(), new ContentBasedRouter<>());
}
}

0 comments on commit b92e5c5

Please sign in to comment.