This is an automated email from the ASF dual-hosted git repository.
mimaison pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new 5785796f985 MINOR: Add a few test cases to clients (#14211)
5785796f985 is described below
commit 5785796f985aa294c12e670da221d086a7fa887c
Author: Maros Orsak <[email protected]>
AuthorDate: Fri Aug 25 11:31:21 2023 +0200
MINOR: Add a few test cases to clients (#14211)
Reviewers: Mickael Maison <[email protected]>
---
.../kafka/clients/producer/KafkaProducerTest.java | 26 ++++++++++++++++++++++
.../producer/internals/BuiltInPartitionerTest.java | 8 +++++++
2 files changed, 34 insertions(+)
diff --git
a/clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java
b/clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java
index 8360bf2b9ff..1610c208f1a 100644
---
a/clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java
+++
b/clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java
@@ -118,6 +118,7 @@ import java.util.stream.Stream;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonMap;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -493,6 +494,12 @@ public class KafkaProducerTest {
Properties producerProps = new Properties();
producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,
"localhost:9000");
assertThrows(ConfigException.class, () -> new
KafkaProducer(producerProps));
+
+ final Map<String, Object> configs = new HashMap<>();
+ configs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
+
+ // Invalid value null for configuration key.serializer: must be
non-null.
+ assertThrows(ConfigException.class, () -> new KafkaProducer<String,
String>(configs));
}
@Test
@@ -2399,4 +2406,23 @@ public class KafkaProducerTest {
}
}
+ @Test
+ void testDeliveryTimeoutAndLingerMsConfig() {
+ final Map<String, Object> configs = new HashMap<>();
+ configs.put(ProducerConfig.CLIENT_ID_CONFIG,
"testDeliveryTimeoutAndLingerMsConfig");
+ configs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
+ configs.put(ProducerConfig.DELIVERY_TIMEOUT_MS_CONFIG, 1000);
+ configs.put(ProducerConfig.LINGER_MS_CONFIG, 1000);
+ configs.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, 1);
+
+ // delivery.timeout.ms should be equal to or larger than linger.ms +
request.timeout.ms
+ assertThrows(KafkaException.class, () -> new KafkaProducer<>(configs,
new StringSerializer(), new StringSerializer()));
+
+ configs.put(ProducerConfig.DELIVERY_TIMEOUT_MS_CONFIG, 1000);
+ configs.put(ProducerConfig.LINGER_MS_CONFIG, 999);
+ configs.put(ProducerConfig.REQUEST_TIMEOUT_MS_CONFIG, 1);
+
+ assertDoesNotThrow(() -> new KafkaProducer<>(configs, new
StringSerializer(), new StringSerializer()));
+ }
+
}
diff --git
a/clients/src/test/java/org/apache/kafka/clients/producer/internals/BuiltInPartitionerTest.java
b/clients/src/test/java/org/apache/kafka/clients/producer/internals/BuiltInPartitionerTest.java
index 734aedc483a..69546aaa6ed 100644
---
a/clients/src/test/java/org/apache/kafka/clients/producer/internals/BuiltInPartitionerTest.java
+++
b/clients/src/test/java/org/apache/kafka/clients/producer/internals/BuiltInPartitionerTest.java
@@ -29,8 +29,10 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import static java.util.Arrays.asList;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class BuiltInPartitionerTest {
@@ -195,4 +197,10 @@ public class BuiltInPartitionerTest {
"Partition " + i + " was chosen " + frequencies[i] + " times");
}
}
+
+ @Test
+ void testStickyBatchSizeMoreThatZero() {
+ assertThrows(IllegalArgumentException.class, () -> new
BuiltInPartitioner(logContext, TOPIC_A, 0));
+ assertDoesNotThrow(() -> new BuiltInPartitioner(logContext, TOPIC_A,
1));
+ }
}