Search in sources :

Example 11 with SinkConfiguration

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

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

Example 13 with SinkConfiguration

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

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

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);
}
Also used : PulsarCommittable(org.apache.flink.connector.pulsar.sink.committer.PulsarCommittable) TxnID(org.apache.pulsar.client.api.transaction.TxnID) SinkConfiguration(org.apache.flink.connector.pulsar.sink.config.SinkConfiguration) 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