sebastienviale commented on code in PR #22725:
URL: https://github.com/apache/kafka/pull/22725#discussion_r3614480169
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriverBuilder.java:
##########
@@ -75,14 +83,43 @@ public TopologyTestDriverBuilder
withInitialWallClockTime(final Instant initialW
}
/**
- * Build the driver: construct it and apply all declared topic partition
counts.
+ * Declare the number of partitions for an input, output, or internal
repartition topic.
+ *
+ * @param topicName the topic to declare
+ * @param partitions the number of partitions (must be at least 1)
+ * @return this builder
+ * @throws IllegalArgumentException if {@code partitions} is less than 1,
or the topic was already
+ * declared with a different count
+ */
+ public TopologyTestDriverBuilder declareTopic(final String topicName,
final int partitions) {
+ Objects.requireNonNull(topicName, "topicName cannot be null");
+ if (partitions < 1) {
+ throw new IllegalArgumentException(
+ "Partition count must be at least 1 (topic='" + topicName +
"', partitions=" + partitions + ").");
+ }
+ final Integer existing = declaredTopics.putIfAbsent(topicName,
partitions);
+ if (existing != null && existing != partitions) {
+ throw new IllegalArgumentException(
Review Comment:
Good point. I agree that our current behavior is a bit inconsistent. I think
allowing the last declaration to win is a reasonable approach.
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriverBuilder.java:
##########
@@ -75,14 +83,43 @@ public TopologyTestDriverBuilder
withInitialWallClockTime(final Instant initialW
}
/**
- * Build the driver: construct it and apply all declared topic partition
counts.
+ * Declare the number of partitions for an input, output, or internal
repartition topic.
+ *
+ * @param topicName the topic to declare
+ * @param partitions the number of partitions (must be at least 1)
+ * @return this builder
+ * @throws IllegalArgumentException if {@code partitions} is less than 1,
or the topic was already
+ * declared with a different count
+ */
+ public TopologyTestDriverBuilder declareTopic(final String topicName,
final int partitions) {
+ Objects.requireNonNull(topicName, "topicName cannot be null");
+ if (partitions < 1) {
+ throw new IllegalArgumentException(
+ "Partition count must be at least 1 (topic='" + topicName +
"', partitions=" + partitions + ").");
+ }
+ final Integer existing = declaredTopics.putIfAbsent(topicName,
partitions);
+ if (existing != null && existing != partitions) {
+ throw new IllegalArgumentException(
+ "Topic '" + topicName + "' was already declared with " +
existing
+ + " partitions; cannot redeclare with " + partitions +
".");
+ }
+ return this;
+ }
+
+ /**
+ * Build the driver: construct it, declare all topics, and—when at least
one declared topic has more
+ * than one partition—create the multi-partition task graph.
*
* @return a ready-to-use {@link TopologyTestDriver}
*/
public TopologyTestDriver build() {
- return new TopologyTestDriver(
+ final TopologyTestDriver driver = new TopologyTestDriver(
topology.internalTopologyBuilder,
config,
initialWallClockTime.map(Instant::toEpochMilli).orElseGet(System::currentTimeMillis));
- }
+ declaredTopics.forEach(driver::declareTopic);
+ if (declaredTopics.values().stream().anyMatch(count -> count > 1)) {
+ driver.activateMultiPartitionMode();
+ }
+ return driver;}
Review Comment:
done
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriverBuilder.java:
##########
@@ -75,14 +83,43 @@ public TopologyTestDriverBuilder
withInitialWallClockTime(final Instant initialW
}
/**
- * Build the driver: construct it and apply all declared topic partition
counts.
+ * Declare the number of partitions for an input, output, or internal
repartition topic.
+ *
+ * @param topicName the topic to declare
+ * @param partitions the number of partitions (must be at least 1)
+ * @return this builder
+ * @throws IllegalArgumentException if {@code partitions} is less than 1,
or the topic was already
+ * declared with a different count
+ */
+ public TopologyTestDriverBuilder declareTopic(final String topicName,
final int partitions) {
+ Objects.requireNonNull(topicName, "topicName cannot be null");
+ if (partitions < 1) {
+ throw new IllegalArgumentException(
+ "Partition count must be at least 1 (topic='" + topicName +
"', partitions=" + partitions + ").");
+ }
+ final Integer existing = declaredTopics.putIfAbsent(topicName,
partitions);
+ if (existing != null && existing != partitions) {
+ throw new IllegalArgumentException(
+ "Topic '" + topicName + "' was already declared with " +
existing
+ + " partitions; cannot redeclare with " + partitions +
".");
+ }
+ return this;
+ }
+
+ /**
+ * Build the driver: construct it, declare all topics, and—when at least
one declared topic has more
+ * than one partition—create the multi-partition task graph.
Review Comment:
done
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriverBuilder.java:
##########
@@ -75,14 +83,43 @@ public TopologyTestDriverBuilder
withInitialWallClockTime(final Instant initialW
}
/**
- * Build the driver: construct it and apply all declared topic partition
counts.
+ * Declare the number of partitions for an input, output, or internal
repartition topic.
+ *
+ * @param topicName the topic to declare
+ * @param partitions the number of partitions (must be at least 1)
+ * @return this builder
+ * @throws IllegalArgumentException if {@code partitions} is less than 1,
or the topic was already
+ * declared with a different count
+ */
+ public TopologyTestDriverBuilder declareTopic(final String topicName,
final int partitions) {
+ Objects.requireNonNull(topicName, "topicName cannot be null");
+ if (partitions < 1) {
+ throw new IllegalArgumentException(
+ "Partition count must be at least 1 (topic='" + topicName +
"', partitions=" + partitions + ").");
+ }
+ final Integer existing = declaredTopics.putIfAbsent(topicName,
partitions);
+ if (existing != null && existing != partitions) {
+ throw new IllegalArgumentException(
+ "Topic '" + topicName + "' was already declared with " +
existing
+ + " partitions; cannot redeclare with " + partitions +
".");
+ }
+ return this;
+ }
+
+ /**
+ * Build the driver: construct it, declare all topics, and—when at least
one declared topic has more
Review Comment:
done
##########
streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriverBuilder.java:
##########
@@ -41,6 +48,7 @@ public class TopologyTestDriverBuilder {
private final Topology topology;
private Properties config = new Properties();
private Optional<Instant> initialWallClockTime = Optional.empty();
+ private final Map<String, Integer> declaredTopics = new LinkedHashMap<>();
Review Comment:
not really, replaced by HashMap
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]