Search in sources :

Example 6 with SinkConfiguration

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));
}
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 7 with SinkConfiguration

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));
}
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 8 with SinkConfiguration

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);
}
Also used : SinkConfiguration(org.apache.flink.connector.pulsar.sink.config.SinkConfiguration) Configuration(org.apache.flink.configuration.Configuration) SinkConfiguration(org.apache.flink.connector.pulsar.sink.config.SinkConfiguration)

Example 9 with SinkConfiguration

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);
}
Also used : SinkConfiguration(org.apache.flink.connector.pulsar.sink.config.SinkConfiguration) Configuration(org.apache.flink.configuration.Configuration) SinkConfiguration(org.apache.flink.connector.pulsar.sink.config.SinkConfiguration)

Example 10 with SinkConfiguration

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);
}
Also used : PulsarCommittable(org.apache.flink.connector.pulsar.sink.committer.PulsarCommittable) TopicMetadataListener(org.apache.flink.connector.pulsar.sink.writer.topic.TopicMetadataListener) SinkConfiguration(org.apache.flink.connector.pulsar.sink.config.SinkConfiguration) RoundRobinTopicRouter(org.apache.flink.connector.pulsar.sink.writer.router.RoundRobinTopicRouter) TransactionCoordinatorClient(org.apache.pulsar.client.api.transaction.TransactionCoordinatorClient) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SinkConfiguration (org.apache.flink.connector.pulsar.sink.config.SinkConfiguration)17 Test (org.junit.jupiter.api.Test)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 EnumSource (org.junit.jupiter.params.provider.EnumSource)6 PulsarSinkContext (org.apache.flink.connector.pulsar.sink.writer.context.PulsarSinkContext)5 Configuration (org.apache.flink.configuration.Configuration)4 TestProcessingTimeService (org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService)4 PulsarCommittable (org.apache.flink.connector.pulsar.sink.committer.PulsarCommittable)3 TopicMetadataListener (org.apache.flink.connector.pulsar.sink.writer.topic.TopicMetadataListener)2 TransactionCoordinatorClient (org.apache.pulsar.client.api.transaction.TransactionCoordinatorClient)2 DeliveryGuarantee (org.apache.flink.connector.base.DeliveryGuarantee)1 RoundRobinTopicRouter (org.apache.flink.connector.pulsar.sink.writer.router.RoundRobinTopicRouter)1 PulsarSchemaWrapper (org.apache.flink.connector.pulsar.sink.writer.serializer.PulsarSchemaWrapper)1 TxnID (org.apache.pulsar.client.api.transaction.TxnID)1 Hash (org.apache.pulsar.client.impl.Hash)1