use of org.apache.flink.connector.pulsar.sink.writer.context.PulsarSinkContext 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.writer.context.PulsarSinkContext 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.writer.context.PulsarSinkContext 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));
}
Aggregations