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);
}
}
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");
}
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));
}
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");
}
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");
}
Aggregations