use of org.apache.flink.connector.pulsar.sink.config.SinkConfiguration in project flink by apache.
the class KeyHashTopicRouterTest method routeOnlyOnePartition.
@ParameterizedTest
@EnumSource(MessageKeyHash.class)
void routeOnlyOnePartition(MessageKeyHash keyHash) {
SinkConfiguration configuration = sinkConfiguration(keyHash);
List<String> topics = singletonList(randomAlphanumeric(10));
KeyHashTopicRouter<String> router1 = new KeyHashTopicRouter<>(configuration);
String topic1 = router1.route(randomAlphanumeric(10), randomAlphanumeric(10), topics, mock(PulsarSinkContext.class));
assertEquals(topic1, topics.get(0));
KeyHashTopicRouter<String> router2 = new KeyHashTopicRouter<>(configuration);
String topic2 = router2.route(randomAlphanumeric(10), null, topics, mock(PulsarSinkContext.class));
assertEquals(topic2, topics.get(0));
}
use of org.apache.flink.connector.pulsar.sink.config.SinkConfiguration in project flink by apache.
the class KeyHashTopicRouterTest method routeWithEmptyPartition.
@ParameterizedTest
@EnumSource(MessageKeyHash.class)
void routeWithEmptyPartition(MessageKeyHash keyHash) {
SinkConfiguration configuration = sinkConfiguration(keyHash);
KeyHashTopicRouter<String> router = new KeyHashTopicRouter<>(configuration);
String message = randomAlphanumeric(10);
String key = randomAlphanumeric(10);
List<String> emptyTopics = emptyList();
PulsarSinkContext sinkContext = mock(PulsarSinkContext.class);
assertThrows(IllegalArgumentException.class, () -> router.route(message, key, emptyTopics, sinkContext));
}
use of org.apache.flink.connector.pulsar.sink.config.SinkConfiguration in project flink by apache.
the class KeyHashTopicRouterTest method sinkConfiguration.
private SinkConfiguration sinkConfiguration(MessageKeyHash hash) {
Configuration configuration = new Configuration();
configuration.set(PULSAR_MESSAGE_KEY_HASH, hash);
return new SinkConfiguration(configuration);
}
use of org.apache.flink.connector.pulsar.sink.config.SinkConfiguration in project flink by apache.
the class RoundRobinTopicRouterTest method sinkConfiguration.
private SinkConfiguration sinkConfiguration(int switchSize) {
Configuration configuration = new Configuration();
configuration.set(PULSAR_BATCHING_MAX_MESSAGES, switchSize);
return new SinkConfiguration(configuration);
}
use of org.apache.flink.connector.pulsar.sink.config.SinkConfiguration in project flink by apache.
the class PulsarWriterTest method writeMessageWithoutGuarantee.
@ParameterizedTest
@EnumSource(value = DeliveryGuarantee.class, names = { "AT_LEAST_ONCE", "NONE" })
void writeMessageWithoutGuarantee(DeliveryGuarantee guarantee) throws Exception {
String topic = randomAlphabetic(10);
operator().createTopic(topic, 8);
SinkConfiguration configuration = sinkConfiguration(guarantee);
PulsarSerializationSchema<String> schema = pulsarSchema(STRING);
TopicMetadataListener listener = new TopicMetadataListener(singletonList(topic));
RoundRobinTopicRouter<String> router = new RoundRobinTopicRouter<>(configuration);
FixedMessageDelayer<String> delayer = MessageDelayer.never();
MockInitContext initContext = new MockInitContext();
PulsarWriter<String> writer = new PulsarWriter<>(configuration, schema, listener, router, delayer, initContext);
writer.flush(false);
writer.prepareCommit();
writer.flush(false);
writer.prepareCommit();
String message = randomAlphabetic(10);
writer.write(message, CONTEXT);
writer.flush(false);
Collection<PulsarCommittable> committables = writer.prepareCommit();
if (guarantee != EXACTLY_ONCE) {
assertThat(committables).isEmpty();
} else {
assertThat(committables).hasSize(1);
PulsarCommittable committable = committables.stream().findFirst().orElseThrow(IllegalArgumentException::new);
TransactionCoordinatorClient coordinatorClient = operator().coordinatorClient();
coordinatorClient.commit(committable.getTxnID());
}
String consumedMessage = operator().receiveMessage(topic, STRING).getValue();
assertEquals(consumedMessage, message);
}
Aggregations