kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mj...@apache.org
Subject [kafka] branch trunk updated: KAFKA-9334: Added more unit tests for Materialized class (#7871)
Date Tue, 31 Dec 2019 20:30:21 GMT
This is an automated email from the ASF dual-hosted git repository.

mjsax 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 65d9776  KAFKA-9334: Added more unit tests for Materialized class (#7871)
65d9776 is described below

commit 65d97762abdc089a57dfb57a6f4d42910f8900dc
Author: sainath batthala <sainathbatthala@gmail.com>
AuthorDate: Wed Jan 1 01:59:40 2020 +0530

    KAFKA-9334: Added more unit tests for Materialized class (#7871)
    
    Reviewer: Matthias J. Sax <matthias@confluent.io>
---
 .../kafka/streams/kstream/MaterializedTest.java    | 61 +++++++++++++++++++---
 1 file changed, 53 insertions(+), 8 deletions(-)

diff --git a/streams/src/test/java/org/apache/kafka/streams/kstream/MaterializedTest.java
b/streams/src/test/java/org/apache/kafka/streams/kstream/MaterializedTest.java
index 8434e0f..2630f35 100644
--- a/streams/src/test/java/org/apache/kafka/streams/kstream/MaterializedTest.java
+++ b/streams/src/test/java/org/apache/kafka/streams/kstream/MaterializedTest.java
@@ -23,6 +23,12 @@ import org.apache.kafka.streams.state.SessionBytesStoreSupplier;
 import org.apache.kafka.streams.state.WindowBytesStoreSupplier;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+
 public class MaterializedTest {
 
     @Test
@@ -32,23 +38,62 @@ public class MaterializedTest {
         Materialized.as("valid_name");
     }
 
-    @Test(expected = TopologyException.class)
+    @Test
     public void shouldNotAllowInvalidTopicNames() {
-        Materialized.as("not:valid");
+        final String invalidName = "not:valid";
+        final TopologyException e = assertThrows(TopologyException.class,
+            () -> Materialized.as(invalidName));
+
+        assertEquals(e.getMessage(), "Invalid topology: Name \"" + invalidName +
+            "\" is illegal, it contains a character other than " + "ASCII alphanumerics,
'.', '_' and '-'");
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void shouldThrowNullPointerIfWindowBytesStoreSupplierIsNull() {
-        Materialized.as((WindowBytesStoreSupplier) null);
+        final NullPointerException e = assertThrows(NullPointerException.class,
+            () -> Materialized.as((WindowBytesStoreSupplier) null));
+
+        assertEquals(e.getMessage(), "supplier can't be null");
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void shouldThrowNullPointerIfKeyValueBytesStoreSupplierIsNull() {
-        Materialized.as((KeyValueBytesStoreSupplier) null);
+        final NullPointerException e = assertThrows(NullPointerException.class,
+            () -> Materialized.as((KeyValueBytesStoreSupplier) null));
+
+        assertEquals(e.getMessage(), "supplier can't be null");
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void shouldThrowNullPointerIfSessionBytesStoreSupplierIsNull() {
-        Materialized.as((SessionBytesStoreSupplier) null);
+        final NullPointerException e = assertThrows(NullPointerException.class,
+            () -> Materialized.as((SessionBytesStoreSupplier) null));
+
+        assertEquals(e.getMessage(), "supplier can't be null");
+    }
+
+    @Test
+    public void shouldThrowIllegalArgumentExceptionIfRetentionIsNegative() {
+        final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+            () -> Materialized.as("valid-name").withRetention(Duration.of(-1, ChronoUnit.DAYS)));
+
+        assertEquals(e.getMessage(), "Retention must not be negative.");
+    }
+
+    @Test
+    public void shouldThrowTopologyExceptionIfStoreNameExceedsMaxAllowedLength() {
+        final StringBuffer invalidStoreNameBuffer = new StringBuffer();
+        final int maxNameLength = 249;
+
+        for (int i = 0; i < maxNameLength + 1; i++) {
+            invalidStoreNameBuffer.append('a');
+        }
+
+        final String invalidStoreName = invalidStoreNameBuffer.toString();
+
+        final TopologyException e = assertThrows(TopologyException.class,
+            () -> Materialized.as(invalidStoreName));
+        assertEquals(e.getMessage(), "Invalid topology: Name is illegal, it can't be longer
than " + maxNameLength +
+                " characters, name: " + invalidStoreName);
     }
 }
\ No newline at end of file


Mime
View raw message