Search in sources :

Example 1 with ControlSource

use of org.apache.flink.connector.pulsar.testutils.function.ControlSource in project flink by apache.

the class PulsarSinkITCase method writeRecordsToPulsar.

@ParameterizedTest
@EnumSource(DeliveryGuarantee.class)
void writeRecordsToPulsar(DeliveryGuarantee guarantee) throws Exception {
    // A random topic with partition 1.
    String topic = randomAlphabetic(8);
    operator().createTopic(topic, 4);
    int counts = ThreadLocalRandom.current().nextInt(100, 200);
    ControlSource source = new ControlSource(sharedObjects, operator(), topic, guarantee, counts, Duration.ofMinutes(5));
    PulsarSink<String> sink = PulsarSink.builder().setServiceUrl(operator().serviceUrl()).setAdminUrl(operator().adminUrl()).setDeliveryGuarantee(guarantee).setTopics(topic).setSerializationSchema(flinkSchema(new SimpleStringSchema())).build();
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(PARALLELISM);
    env.enableCheckpointing(100L);
    env.addSource(source).sinkTo(sink);
    env.execute();
    List<String> expectedRecords = source.getExpectedRecords();
    List<String> consumedRecords = source.getConsumedRecords();
    assertThat(consumedRecords).hasSameSizeAs(expectedRecords).containsExactlyInAnyOrderElementsOf(expectedRecords);
}
Also used : ControlSource(org.apache.flink.connector.pulsar.testutils.function.ControlSource) SimpleStringSchema(org.apache.flink.api.common.serialization.SimpleStringSchema) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

SimpleStringSchema (org.apache.flink.api.common.serialization.SimpleStringSchema)1 ControlSource (org.apache.flink.connector.pulsar.testutils.function.ControlSource)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1