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