Search in sources :

Example 1 with EmbeddedConfig

use of io.debezium.embedded.EmbeddedEngine.EmbeddedConfig in project debezium by debezium.

the class AbstractConnectorTest method readLastCommittedOffsets.

/**
 * Utility to read the last committed offsets for the specified partitions.
 *
 * @param config the configuration of the engine used to persist the offsets
 * @param partitions the partitions
 * @return the map of partitions to offsets; never null but possibly empty
 */
protected <T> Map<Map<String, T>, Map<String, Object>> readLastCommittedOffsets(Configuration config, Collection<Map<String, T>> partitions) {
    config = config.edit().with(EmbeddedEngine.ENGINE_NAME, "testing-connector").with(StandaloneConfig.OFFSET_STORAGE_FILE_FILENAME_CONFIG, OFFSET_STORE_PATH).with(EmbeddedEngine.OFFSET_FLUSH_INTERVAL_MS, 0).build();
    final String engineName = config.getString(EmbeddedEngine.ENGINE_NAME);
    Converter keyConverter = config.getInstance(EmbeddedEngine.INTERNAL_KEY_CONVERTER_CLASS, Converter.class);
    keyConverter.configure(config.subset(EmbeddedEngine.INTERNAL_KEY_CONVERTER_CLASS.name() + ".", true).asMap(), true);
    Converter valueConverter = config.getInstance(EmbeddedEngine.INTERNAL_VALUE_CONVERTER_CLASS, Converter.class);
    Configuration valueConverterConfig = config;
    if (valueConverter instanceof JsonConverter) {
        // Make sure that the JSON converter is configured to NOT enable schemas ...
        valueConverterConfig = config.edit().with(EmbeddedEngine.INTERNAL_VALUE_CONVERTER_CLASS + ".schemas.enable", false).build();
    }
    valueConverter.configure(valueConverterConfig.subset(EmbeddedEngine.INTERNAL_VALUE_CONVERTER_CLASS.name() + ".", true).asMap(), false);
    // Create the worker config, adding extra fields that are required for validation of a worker config
    // but that are not used within the embedded engine (since the source records are never serialized) ...
    Map<String, String> embeddedConfig = config.asMap(EmbeddedEngine.ALL_FIELDS);
    embeddedConfig.put(WorkerConfig.KEY_CONVERTER_CLASS_CONFIG, JsonConverter.class.getName());
    embeddedConfig.put(WorkerConfig.VALUE_CONVERTER_CLASS_CONFIG, JsonConverter.class.getName());
    WorkerConfig workerConfig = new EmbeddedConfig(embeddedConfig);
    FileOffsetBackingStore offsetStore = new FileOffsetBackingStore();
    offsetStore.configure(workerConfig);
    offsetStore.start();
    try {
        OffsetStorageReaderImpl offsetReader = new OffsetStorageReaderImpl(offsetStore, engineName, keyConverter, valueConverter);
        return offsetReader.offsets(partitions);
    } finally {
        offsetStore.stop();
    }
}
Also used : Configuration(io.debezium.config.Configuration) JsonConverter(org.apache.kafka.connect.json.JsonConverter) Converter(org.apache.kafka.connect.storage.Converter) JsonConverter(org.apache.kafka.connect.json.JsonConverter) WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) FileOffsetBackingStore(org.apache.kafka.connect.storage.FileOffsetBackingStore) EmbeddedConfig(io.debezium.embedded.EmbeddedEngine.EmbeddedConfig) OffsetStorageReaderImpl(org.apache.kafka.connect.storage.OffsetStorageReaderImpl)

Aggregations

Configuration (io.debezium.config.Configuration)1 EmbeddedConfig (io.debezium.embedded.EmbeddedEngine.EmbeddedConfig)1 JsonConverter (org.apache.kafka.connect.json.JsonConverter)1 WorkerConfig (org.apache.kafka.connect.runtime.WorkerConfig)1 Converter (org.apache.kafka.connect.storage.Converter)1 FileOffsetBackingStore (org.apache.kafka.connect.storage.FileOffsetBackingStore)1 OffsetStorageReaderImpl (org.apache.kafka.connect.storage.OffsetStorageReaderImpl)1