Search in sources :

Example 1 with CassandraSourceConnectorConfig

use of com.datastax.oss.cdc.CassandraSourceConnectorConfig in project cdc-apache-cassandra by datastax.

the class CassandraSource method open.

@Override
public void open(Map<String, Object> config, SourceContext sourceContext) {
    try {
        this.sourceContext = sourceContext;
        this.config = new CassandraSourceConnectorConfig(ConfigUtil.flatString(config));
        this.buffer = new ArrayBlockingQueue<>(this.config.getBatchSize());
        if (!Strings.isNullOrEmpty(this.config.getColumnsRegexp()) && !".*".equals(this.config.getColumnsRegexp())) {
            this.columnPattern = Optional.of(Pattern.compile(this.config.getColumnsRegexp()));
        }
        Preconditions.checkArgument(this.config.getEventsTopic() != null, "Events topic not set");
        this.dirtyTopicName = this.config.getEventsTopic();
        ConsumerBuilder<KeyValue<GenericRecord, MutationValue>> consumerBuilder = sourceContext.newConsumerBuilder(eventsSchema).consumerName("CDC Consumer").topic(dirtyTopicName).subscriptionName(this.config.getEventsSubscriptionName()).subscriptionType(SubscriptionType.valueOf(this.config.getEventsSubscriptionType())).subscriptionMode(SubscriptionMode.Durable).subscriptionInitialPosition(SubscriptionInitialPosition.Earliest);
        if (SubscriptionType.Key_Shared.equals(SubscriptionType.valueOf(this.config.getEventsSubscriptionType()))) {
            consumerBuilder.keySharedPolicy(KeySharedPolicy.autoSplitHashRange());
        }
        this.consumer = consumerBuilder.subscribe();
        this.mutationCache = new MutationCache<>(this.config.getCacheMaxDigests(), this.config.getCacheMaxCapacity(), Duration.ofMillis(this.config.getCacheExpireAfterMs()));
        log.info("Starting source connector topic={} subscription={} query.executors={}", dirtyTopicName, this.config.getEventsSubscriptionName(), this.config.getQueryExecutors());
    } catch (Throwable err) {
        log.error("Cannot open the connector:", err);
        throw new RuntimeException(err);
    }
}
Also used : CassandraSourceConnectorConfig(com.datastax.oss.cdc.CassandraSourceConnectorConfig) KeyValue(org.apache.pulsar.common.schema.KeyValue)

Example 2 with CassandraSourceConnectorConfig

use of com.datastax.oss.cdc.CassandraSourceConnectorConfig in project cdc-apache-cassandra by datastax.

the class CassandraSourceConnectorConfigTest method should_handle_dc_with_contactPoints_driver_prefix.

@Test
void should_handle_dc_with_contactPoints_driver_prefix() {
    Map<String, String> props = ImmutableMap.<String, String>builder().putAll(requiredSettings()).put(CONTACT_POINTS_OPT, "127.0.0.1, 127.0.1.1").put(LOCAL_DC_DRIVER_SETTING, "local").build();
    CassandraSourceConnectorConfig d = new CassandraSourceConnectorConfig(props);
    assertThat(d.getContactPoints()).containsExactly("127.0.0.1", "127.0.1.1");
    assertThat(d.getLocalDc().get()).isEqualTo("local");
}
Also used : CassandraSourceConnectorConfig(com.datastax.oss.cdc.CassandraSourceConnectorConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with CassandraSourceConnectorConfig

use of com.datastax.oss.cdc.CassandraSourceConnectorConfig in project cdc-apache-cassandra by datastax.

the class CassandraSourceConnectorConfigTest method should_error_empty_dc_with_contactPoints.

@Test
void should_error_empty_dc_with_contactPoints() {
    Map<String, String> props = ImmutableMap.<String, String>builder().putAll(requiredSettings()).put(CONTACT_POINTS_OPT, "127.0.0.1").put(DC_OPT, "").build();
    assertThatThrownBy(() -> new CassandraSourceConnectorConfig(props)).isInstanceOf(ConfigException.class).hasMessageContaining(String.format("When contact points is provided, %s must also be specified", DC_OPT));
}
Also used : CassandraSourceConnectorConfig(com.datastax.oss.cdc.CassandraSourceConnectorConfig) ConfigException(com.datastax.oss.common.sink.ConfigException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with CassandraSourceConnectorConfig

use of com.datastax.oss.cdc.CassandraSourceConnectorConfig in project cdc-apache-cassandra by datastax.

the class CassandraSourceConnectorConfigTest method should_handle_dc_with_contactPoints.

@Test
void should_handle_dc_with_contactPoints() {
    Map<String, String> props = ImmutableMap.<String, String>builder().putAll(requiredSettings()).put(CONTACT_POINTS_OPT, "127.0.0.1, 127.0.1.1").put(DC_OPT, "local").build();
    CassandraSourceConnectorConfig d = new CassandraSourceConnectorConfig(props);
    assertThat(d.getContactPoints()).containsExactly("127.0.0.1", "127.0.1.1");
    assertThat(d.getLocalDc().get()).isEqualTo("local");
}
Also used : CassandraSourceConnectorConfig(com.datastax.oss.cdc.CassandraSourceConnectorConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with CassandraSourceConnectorConfig

use of com.datastax.oss.cdc.CassandraSourceConnectorConfig in project cdc-apache-cassandra by datastax.

the class CassandraSourceConnectorConfigTest method should_handle_instance_name.

@Test
void should_handle_instance_name() {
    Map<String, String> props = ImmutableMap.<String, String>builder().putAll(requiredSettings()).put(SinkUtil.NAME_OPT, "myinst").build();
    CassandraSourceConnectorConfig d = new CassandraSourceConnectorConfig(props);
    assertThat(d.getInstanceName()).isEqualTo("myinst");
}
Also used : CassandraSourceConnectorConfig(com.datastax.oss.cdc.CassandraSourceConnectorConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CassandraSourceConnectorConfig (com.datastax.oss.cdc.CassandraSourceConnectorConfig)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 Test (org.junit.jupiter.api.Test)22 ConfigException (com.datastax.oss.common.sink.ConfigException)13 MethodSource (org.junit.jupiter.params.provider.MethodSource)5 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)1 File (java.io.File)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1 KeyValue (org.apache.pulsar.common.schema.KeyValue)1