use of org.apache.kafka.streams.KafkaStreams.State.ERROR in project kafka by apache.
the class KStreamRepartitionIntegrationTest method shouldThrowAnExceptionWhenNumberOfPartitionsOfRepartitionOperationDoNotMatchSourceTopicWhenJoining.
@Test
public void shouldThrowAnExceptionWhenNumberOfPartitionsOfRepartitionOperationDoNotMatchSourceTopicWhenJoining() throws InterruptedException {
final int topicBNumberOfPartitions = 6;
final String inputTopicRepartitionName = "join-repartition-test";
final AtomicReference<Throwable> expectedThrowable = new AtomicReference<>();
final int inputTopicRepartitionedNumOfPartitions = 2;
CLUSTER.createTopic(topicB, topicBNumberOfPartitions, 1);
final StreamsBuilder builder = new StreamsBuilder();
final Repartitioned<Integer, String> inputTopicRepartitioned = Repartitioned.<Integer, String>as(inputTopicRepartitionName).withNumberOfPartitions(inputTopicRepartitionedNumOfPartitions);
final KStream<Integer, String> topicBStream = builder.stream(topicB, Consumed.with(Serdes.Integer(), Serdes.String()));
builder.stream(inputTopic, Consumed.with(Serdes.Integer(), Serdes.String())).repartition(inputTopicRepartitioned).join(topicBStream, (value1, value2) -> value2, JoinWindows.of(Duration.ofSeconds(10))).to(outputTopic);
builder.build(streamsConfiguration);
startStreams(builder, REBALANCING, ERROR, (t, e) -> expectedThrowable.set(e));
final String expectedMsg = String.format("Number of partitions [%s] of repartition topic [%s] " + "doesn't match number of partitions [%s] of the source topic.", inputTopicRepartitionedNumOfPartitions, toRepartitionTopicName(inputTopicRepartitionName), topicBNumberOfPartitions);
assertNotNull(expectedThrowable.get());
assertTrue(expectedThrowable.get().getMessage().contains(expectedMsg));
}
Aggregations