Search in sources :

Example 36 with Configuration

use of io.debezium.config.Configuration in project debezium by debezium.

the class MongoDbConnectorIT method shouldFailToValidateInvalidConfiguration.

@Test
public void shouldFailToValidateInvalidConfiguration() {
    Configuration config = Configuration.create().build();
    MongoDbConnector connector = new MongoDbConnector();
    Config result = connector.validate(config.asMap());
    assertConfigurationErrors(result, MongoDbConnectorConfig.HOSTS, 1);
    assertConfigurationErrors(result, MongoDbConnectorConfig.LOGICAL_NAME, 1);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.USER);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.PASSWORD);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.AUTO_DISCOVER_MEMBERS);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.DATABASE_WHITELIST);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.DATABASE_BLACKLIST);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.COLLECTION_WHITELIST);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.COLLECTION_BLACKLIST);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.MAX_COPY_THREADS);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.MAX_QUEUE_SIZE);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.MAX_BATCH_SIZE);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.POLL_INTERVAL_MS);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.CONNECT_BACKOFF_INITIAL_DELAY_MS);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.CONNECT_BACKOFF_MAX_DELAY_MS);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.MAX_FAILED_CONNECTIONS);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.SSL_ENABLED);
    assertNoConfigurationErrors(result, MongoDbConnectorConfig.SSL_ALLOW_INVALID_HOSTNAMES);
    assertNoConfigurationErrors(result, CommonConnectorConfig.TOMBSTONES_ON_DELETE);
}
Also used : Configuration(io.debezium.config.Configuration) Config(org.apache.kafka.common.config.Config) CommonConnectorConfig(io.debezium.config.CommonConnectorConfig) Test(org.junit.Test) AbstractConnectorTest(io.debezium.embedded.AbstractConnectorTest)

Example 37 with Configuration

use of io.debezium.config.Configuration in project debezium by debezium.

the class AbstractConnectorTest method initializeConnectorTestFramework.

@Before
public final void initializeConnectorTestFramework() {
    LoggingContext.forConnector(getClass().getSimpleName(), "", "test");
    keyJsonConverter = new JsonConverter();
    valueJsonConverter = new JsonConverter();
    keyJsonDeserializer = new JsonDeserializer();
    valueJsonDeserializer = new JsonDeserializer();
    Configuration converterConfig = Configuration.create().build();
    Configuration deserializerConfig = Configuration.create().build();
    keyJsonConverter.configure(converterConfig.asMap(), true);
    valueJsonConverter.configure(converterConfig.asMap(), false);
    keyJsonDeserializer.configure(deserializerConfig.asMap(), true);
    valueJsonDeserializer.configure(deserializerConfig.asMap(), false);
    resetBeforeEachTest();
    consumedLines = new ArrayBlockingQueue<>(getMaximumEnqueuedRecordCount());
    Testing.Files.delete(OFFSET_STORE_PATH);
    OFFSET_STORE_PATH.getParent().toFile().mkdirs();
}
Also used : Configuration(io.debezium.config.Configuration) JsonConverter(org.apache.kafka.connect.json.JsonConverter) JsonDeserializer(org.apache.kafka.connect.json.JsonDeserializer) Before(org.junit.Before)

Example 38 with Configuration

use of io.debezium.config.Configuration in project debezium by debezium.

the class AbstractConnectorTest method start.

/**
 * Start the connector using the supplied connector configuration.
 *
 * @param connectorClass the connector class; may not be null
 * @param connectorConfig the configuration for the connector; may not be null
 * @param isStopRecord the function that will be called to determine if the connector should be stopped before processing
 *            this record; may be null if not needed
 * @param callback the function that will be called when the engine fails to start the connector or when the connector
 *            stops running after completing successfully or due to an error; may be null
 */
protected void start(Class<? extends SourceConnector> connectorClass, Configuration connectorConfig, CompletionCallback callback, Predicate<SourceRecord> isStopRecord) {
    Configuration config = Configuration.copy(connectorConfig).with(EmbeddedEngine.ENGINE_NAME, "testing-connector").with(EmbeddedEngine.CONNECTOR_CLASS, connectorClass.getName()).with(StandaloneConfig.OFFSET_STORAGE_FILE_FILENAME_CONFIG, OFFSET_STORE_PATH).with(EmbeddedEngine.OFFSET_FLUSH_INTERVAL_MS, 0).build();
    latch = new CountDownLatch(1);
    CompletionCallback wrapperCallback = (success, msg, error) -> {
        try {
            if (callback != null)
                callback.handle(success, msg, error);
        } finally {
            if (!success) {
                // we only unblock if there was an error; in all other cases we're unblocking when a task has been started
                latch.countDown();
            }
        }
        Testing.debug("Stopped connector");
    };
    ConnectorCallback connectorCallback = new ConnectorCallback() {

        @Override
        public void taskStarted() {
            // if this is called, it means a task has been started successfully so we can continue
            latch.countDown();
        }
    };
    // Create the connector ...
    engine = EmbeddedEngine.create().using(config).notifying((record) -> {
        if (isStopRecord != null && isStopRecord.test(record)) {
            logger.error("Stopping connector after record as requested");
            throw new ConnectException("Stopping connector after record as requested");
        }
        try {
            consumedLines.put(record);
        } catch (InterruptedException e) {
            Thread.interrupted();
        }
    }).using(this.getClass().getClassLoader()).using(wrapperCallback).using(connectorCallback).build();
    // Submit the connector for asynchronous execution ...
    assertThat(executor).isNull();
    executor = Executors.newFixedThreadPool(1);
    executor.execute(() -> {
        LoggingContext.forConnector(getClass().getSimpleName(), "", "engine");
        engine.run();
    });
    try {
        if (!latch.await(10, TimeUnit.SECONDS)) {
            // maybe it takes more time to start up, so just log a warning and continue
            logger.warn("The connector did not finish starting its task(s) or complete in the expected amount of time");
        }
    } catch (InterruptedException e) {
        if (Thread.interrupted()) {
            fail("Interrupted while waiting for engine startup");
        }
    }
}
Also used : WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) FileOffsetBackingStore(org.apache.kafka.connect.storage.FileOffsetBackingStore) Arrays(java.util.Arrays) BooleanConsumer(io.debezium.function.BooleanConsumer) LoggerFactory(org.slf4j.LoggerFactory) Schema(org.apache.kafka.connect.data.Schema) BigDecimal(java.math.BigDecimal) LoggingContext(io.debezium.util.LoggingContext) JsonDeserializer(org.apache.kafka.connect.json.JsonDeserializer) SourceConnector(org.apache.kafka.connect.source.SourceConnector) Assertions.assertThat(org.fest.assertions.Assertions.assertThat) Map(java.util.Map) Converter(org.apache.kafka.connect.storage.Converter) After(org.junit.After) Assert.fail(org.junit.Assert.fail) SkipTestRule(io.debezium.junit.SkipTestRule) Path(java.nio.file.Path) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) ConfigValue(org.apache.kafka.common.config.ConfigValue) SourceRecord(org.apache.kafka.connect.source.SourceRecord) Executors(java.util.concurrent.Executors) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CountDownLatch(java.util.concurrent.CountDownLatch) HistoryRecord(io.debezium.relational.history.HistoryRecord) List(java.util.List) EmbeddedConfig(io.debezium.embedded.EmbeddedEngine.EmbeddedConfig) JsonConverter(org.apache.kafka.connect.json.JsonConverter) Delta(org.fest.assertions.Delta) SchemaUtil(io.debezium.data.SchemaUtil) OffsetStorageReaderImpl(org.apache.kafka.connect.storage.OffsetStorageReaderImpl) TestRule(org.junit.rules.TestRule) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Config(org.apache.kafka.common.config.Config) StandaloneConfig(org.apache.kafka.connect.runtime.standalone.StandaloneConfig) LinkedList(java.util.LinkedList) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) Logger(org.slf4j.Logger) Field(org.apache.kafka.connect.data.Field) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Configuration(io.debezium.config.Configuration) CompletionCallback(io.debezium.embedded.EmbeddedEngine.CompletionCallback) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) Testing(io.debezium.util.Testing) Struct(org.apache.kafka.connect.data.Struct) ConnectException(org.apache.kafka.connect.errors.ConnectException) VerifyRecord(io.debezium.data.VerifyRecord) Collections(java.util.Collections) ConnectorCallback(io.debezium.embedded.EmbeddedEngine.ConnectorCallback) Configuration(io.debezium.config.Configuration) ConnectorCallback(io.debezium.embedded.EmbeddedEngine.ConnectorCallback) CompletionCallback(io.debezium.embedded.EmbeddedEngine.CompletionCallback) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Aggregations

Configuration (io.debezium.config.Configuration)38 Test (org.junit.Test)21 AbstractConnectorTest (io.debezium.embedded.AbstractConnectorTest)16 Config (org.apache.kafka.common.config.Config)15 CommonConnectorConfig (io.debezium.config.CommonConnectorConfig)10 FixFor (io.debezium.doc.FixFor)6 ConnectException (org.apache.kafka.connect.errors.ConnectException)6 ConfigValue (org.apache.kafka.common.config.ConfigValue)5 HashMap (java.util.HashMap)4 JsonConverter (org.apache.kafka.connect.json.JsonConverter)4 SQLException (java.sql.SQLException)3 Map (java.util.Map)3 Field (io.debezium.config.Field)2 SchemaUtil (io.debezium.data.SchemaUtil)2 VerifyRecord (io.debezium.data.VerifyRecord)2 CompletionCallback (io.debezium.embedded.EmbeddedEngine.CompletionCallback)2 EmbeddedConfig (io.debezium.embedded.EmbeddedEngine.EmbeddedConfig)2 JdbcConnection (io.debezium.jdbc.JdbcConnection)2 KafkaProducer (org.apache.kafka.clients.producer.KafkaProducer)2 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)2