use of org.apache.flink.connector.pulsar.sink.config.SinkConfiguration in project flink by apache.
the class PulsarWriterTest method sinkConfiguration.
private SinkConfiguration sinkConfiguration(DeliveryGuarantee deliveryGuarantee) {
Configuration configuration = operator().sinkConfig(deliveryGuarantee);
configuration.set(PULSAR_WRITE_SCHEMA_EVOLUTION, true);
return new SinkConfiguration(configuration);
}
use of org.apache.flink.connector.pulsar.sink.config.SinkConfiguration in project flink by apache.
the class KeyHashTopicRouterTest method routeMessageByMessageKey.
@ParameterizedTest
@EnumSource(MessageKeyHash.class)
void routeMessageByMessageKey(MessageKeyHash keyHash) {
SinkConfiguration configuration = sinkConfiguration(keyHash);
String messageKey = randomAlphanumeric(10);
KeyHashTopicRouter<String> router = new KeyHashTopicRouter<>(configuration);
List<String> topics = Stream.generate(() -> randomAlphanumeric(10)).distinct().limit(10).collect(toList());
Hash hash = keyHash.getHash();
int index = signSafeMod(hash.makeHash(messageKey), topics.size());
String desiredTopic = topics.get(index);
String message = randomAlphanumeric(10);
String topic = router.route(message, messageKey, topics, mock(PulsarSinkContext.class));
assertEquals(topic, desiredTopic);
}
use of org.apache.flink.connector.pulsar.sink.config.SinkConfiguration in project flink by apache.
the class RoundRobinTopicRouterTest method routeMessageByEmptyTopics.
@Test
void routeMessageByEmptyTopics() {
SinkConfiguration configuration = sinkConfiguration(10);
RoundRobinTopicRouter<String> router = new RoundRobinTopicRouter<>(configuration);
String message = randomAlphabetic(10);
List<String> partitions = emptyList();
PulsarSinkContext context = mock(PulsarSinkContext.class);
assertThrows(IllegalArgumentException.class, () -> router.route(message, null, partitions, context));
}
use of org.apache.flink.connector.pulsar.sink.config.SinkConfiguration in project flink by apache.
the class RoundRobinTopicRouterTest method routeMessagesInRoundRobin.
@Test
void routeMessagesInRoundRobin() {
int batchSize = ThreadLocalRandom.current().nextInt(20) + 1;
SinkConfiguration configuration = sinkConfiguration(batchSize);
RoundRobinTopicRouter<String> router = new RoundRobinTopicRouter<>(configuration);
List<String> topics = ImmutableList.of("topic1", "topic2");
PulsarSinkContext context = mock(PulsarSinkContext.class);
for (int i = 0; i < batchSize; i++) {
String message = randomAlphabetic(10);
String topic = router.route(message, null, topics, context);
assertEquals(topic, topics.get(0));
}
for (int i = 0; i < batchSize; i++) {
String message = randomAlphabetic(10);
String topic = router.route(message, null, topics, context);
assertEquals(topic, topics.get(1));
}
String message = randomAlphabetic(10);
String topic = router.route(message, null, topics, context);
assertEquals(topic, topics.get(0));
}
use of org.apache.flink.connector.pulsar.sink.config.SinkConfiguration in project flink by apache.
the class TopicProducerRegisterTest method createMessageBuilderForSendingMessage.
@ParameterizedTest
@EnumSource(DeliveryGuarantee.class)
void createMessageBuilderForSendingMessage(DeliveryGuarantee deliveryGuarantee) throws IOException {
String topic = randomAlphabetic(10);
operator().createTopic(topic, 8);
SinkConfiguration configuration = sinkConfiguration(deliveryGuarantee);
TopicProducerRegister register = new TopicProducerRegister(configuration);
String message = randomAlphabetic(10);
register.createMessageBuilder(topic, Schema.STRING).value(message).send();
if (deliveryGuarantee == EXACTLY_ONCE) {
List<PulsarCommittable> committables = register.prepareCommit();
for (PulsarCommittable committable : committables) {
TxnID txnID = committable.getTxnID();
TransactionCoordinatorClient coordinatorClient = operator().coordinatorClient();
coordinatorClient.commit(txnID);
}
}
Message<String> receiveMessage = operator().receiveMessage(topic, Schema.STRING);
assertEquals(receiveMessage.getValue(), message);
}
Aggregations