Search in sources :

Example 1 with PulsarSinkContext

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));
}
Also used : PulsarSinkContext(org.apache.flink.connector.pulsar.sink.writer.context.PulsarSinkContext) SinkConfiguration(org.apache.flink.connector.pulsar.sink.config.SinkConfiguration) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with PulsarSinkContext

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));
}
Also used : PulsarSinkContext(org.apache.flink.connector.pulsar.sink.writer.context.PulsarSinkContext) SinkConfiguration(org.apache.flink.connector.pulsar.sink.config.SinkConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with PulsarSinkContext

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));
}
Also used : PulsarSinkContext(org.apache.flink.connector.pulsar.sink.writer.context.PulsarSinkContext) SinkConfiguration(org.apache.flink.connector.pulsar.sink.config.SinkConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

SinkConfiguration (org.apache.flink.connector.pulsar.sink.config.SinkConfiguration)3 PulsarSinkContext (org.apache.flink.connector.pulsar.sink.writer.context.PulsarSinkContext)3 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1