You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by mj...@apache.org on 2019/10/15 20:02:44 UTC

[kafka] branch 2.4 updated (4755084 -> baff35d)

This is an automated email from the ASF dual-hosted git repository.

mjsax pushed a change to branch 2.4
in repository https://gitbox.apache.org/repos/asf/kafka.git.


    from 4755084  MINOR: remove unused import in QueryableStateIntegrationTest (#7521)
     new 641dfa4  KAFKA-8122: Fix Kafka Streams EOS integration test (#7470)
     new baff35d  MINOR: code and JavaDoc cleanup (#7462)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../integration/AbstractJoinIntegrationTest.java   |  44 +++---
 .../streams/integration/EosIntegrationTest.java    |  28 ++--
 .../org/apache/kafka/test/StreamsTestUtils.java    |  23 +++
 .../org/apache/kafka/streams/TestInputTopic.java   |  37 +++--
 .../org/apache/kafka/streams/TestOutputTopic.java  |  35 +++--
 .../apache/kafka/streams/TopologyTestDriver.java   |  81 ++++------
 .../org/apache/kafka/streams/test/TestRecord.java  |  45 ++----
 .../org/apache/kafka/streams/TestTopicsTest.java   | 172 +++++++++++++--------
 .../kafka/streams/TopologyTestDriverTest.java      | 117 ++++++++------
 .../apache/kafka/streams/test/TestRecordTest.java  |  25 +--
 10 files changed, 339 insertions(+), 268 deletions(-)


[kafka] 02/02: MINOR: code and JavaDoc cleanup (#7462)

Posted by mj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mjsax pushed a commit to branch 2.4
in repository https://gitbox.apache.org/repos/asf/kafka.git

commit baff35d456d0f9f59c55cffc966c2592ff748d41
Author: Matthias J. Sax <ma...@confluent.io>
AuthorDate: Tue Oct 15 11:49:45 2019 -0700

    MINOR: code and JavaDoc cleanup (#7462)
    
    Reviewers: Jukka Karvanen <ju...@jukinimi.com>, Bill Bejeck <bi...@confluent.io>
---
 .../org/apache/kafka/streams/TestInputTopic.java   |  37 +++--
 .../org/apache/kafka/streams/TestOutputTopic.java  |  35 +++--
 .../apache/kafka/streams/TopologyTestDriver.java   |  81 ++++------
 .../org/apache/kafka/streams/test/TestRecord.java  |  45 ++----
 .../org/apache/kafka/streams/TestTopicsTest.java   | 172 +++++++++++++--------
 .../kafka/streams/TopologyTestDriverTest.java      | 117 ++++++++------
 .../apache/kafka/streams/test/TestRecordTest.java  |  25 +--
 7 files changed, 282 insertions(+), 230 deletions(-)

diff --git a/streams/test-utils/src/main/java/org/apache/kafka/streams/TestInputTopic.java b/streams/test-utils/src/main/java/org/apache/kafka/streams/TestInputTopic.java
index 162ce4c..50310aa 100644
--- a/streams/test-utils/src/main/java/org/apache/kafka/streams/TestInputTopic.java
+++ b/streams/test-utils/src/main/java/org/apache/kafka/streams/TestInputTopic.java
@@ -27,11 +27,11 @@ import java.util.StringJoiner;
 
 /**
  * {@code TestInputTopic} is used to pipe records to topic in {@link TopologyTestDriver}.
- * To use {@code TestInputTopic} create a new instance via {@link TopologyTestDriver#createInputTopic(String, Serializer, Serializer)}
- * In actual test code, you can pipe new record values, keys and values or list of {@link KeyValue} pairs
+ * To use {@code TestInputTopic} create a new instance via
+ * {@link TopologyTestDriver#createInputTopic(String, Serializer, Serializer)}.
+ * In actual test code, you can pipe new record values, keys and values or list of {@link KeyValue} pairs.
  * If you have multiple source topics, you need to create a {@code TestInputTopic} for each.
  *
- *
  * <h2>Processing messages</h2>
  * <pre>{@code
  *     private TestInputTopic<Long, String> inputTopic;
@@ -77,13 +77,16 @@ public class TestInputTopic<K, V> {
             throw new IllegalArgumentException("autoAdvance must be positive");
         }
         this.advanceDuration = autoAdvance;
-
     }
 
     /**
-     * Advances the internally tracked event time of this input topic. Each time a record without explicitly defined timestamp is piped, the current topic event time is used as record timestamp.
+     * Advances the internally tracked event time of this input topic.
+     * Each time a record without explicitly defined timestamp is piped,
+     * the current topic event time is used as record timestamp.
      * <p>
-     * Note: advancing the event time on the input topic, does not advance the tracked stream time in {@link TopologyTestDriver} as long as no new input records are piped. Furthermore, it does not advance the wall-clock time of {@link TopologyTestDriver}.
+     * Note: advancing the event time on the input topic, does not advance the tracked stream time in
+     * {@link TopologyTestDriver} as long as no new input records are piped.
+     * Furthermore, it does not advance the wall-clock time of {@link TopologyTestDriver}.
      *
      * @param advance the duration of time to advance
      */
@@ -102,7 +105,7 @@ public class TestInputTopic<K, V> {
 
     /**
      * Send an input record with the given record on the topic and then commit the records.
-     * May auto advance topic time
+     * May auto advance topic time.
      *
      * @param record the record to sent
      */
@@ -114,7 +117,7 @@ public class TestInputTopic<K, V> {
 
     /**
      * Send an input record with the given value on the topic and then commit the records.
-     * May auto advance topic time
+     * May auto advance topic time.
      *
      * @param value the record value
      */
@@ -129,7 +132,8 @@ public class TestInputTopic<K, V> {
      * @param key   the record key
      * @param value the record value
      */
-    public void pipeInput(final K key, final V value) {
+    public void pipeInput(final K key,
+                          final V value) {
         pipeInput(new TestRecord<>(key, value));
     }
 
@@ -142,7 +146,7 @@ public class TestInputTopic<K, V> {
      */
     public void pipeInput(final V value,
                           final Instant timestamp) {
-        pipeInput(new TestRecord<K, V>(null, value, timestamp));
+        pipeInput(new TestRecord<>(null, value, timestamp));
     }
 
     /**
@@ -156,7 +160,7 @@ public class TestInputTopic<K, V> {
     public void pipeInput(final K key,
                           final V value,
                           final long timestampMs) {
-        pipeInput(new TestRecord<K, V>(key, value, null, timestampMs));
+        pipeInput(new TestRecord<>(key, value, null, timestampMs));
     }
 
     /**
@@ -170,7 +174,7 @@ public class TestInputTopic<K, V> {
     public void pipeInput(final K key,
                           final V value,
                           final Instant timestamp) {
-        pipeInput(new TestRecord<K, V>(key, value, timestamp));
+        pipeInput(new TestRecord<>(key, value, timestamp));
     }
 
     /**
@@ -187,7 +191,8 @@ public class TestInputTopic<K, V> {
 
     /**
      * Send input records with the given KeyValue list on the topic then commit each record individually.
-     * The timestamp will be generated based on the constructor provided start time and time will auto advance based on autoAdvance setting.
+     * The timestamp will be generated based on the constructor provided start time and time will auto advance based on
+     * {@link #TestInputTopic(TopologyTestDriver, String, Serializer, Serializer, Instant, Duration) autoAdvance} setting.
      *
      * @param keyValues the {@link List} of {@link KeyValue} records
      */
@@ -199,7 +204,8 @@ public class TestInputTopic<K, V> {
 
     /**
      * Send input records with the given value list on the topic then commit each record individually.
-     * The timestamp will be generated based on the constructor provided start time and time will auto advance based on autoAdvance setting.
+     * The timestamp will be generated based on the constructor provided start time and time will auto advance based on
+     * {@link #TestInputTopic(TopologyTestDriver, String, Serializer, Serializer, Instant, Duration) autoAdvance} setting.
      *
      * @param values the {@link List} of {@link KeyValue} records
      */
@@ -229,7 +235,8 @@ public class TestInputTopic<K, V> {
 
     /**
      * Send input records with the given value list on the topic then commit each record individually.
-     * The timestamp will be generated based on the constructor provided start time and time will auto advance based on autoAdvance setting.
+     * The timestamp will be generated based on the constructor provided start time and time will auto advance based on
+     * {@link #TestInputTopic(TopologyTestDriver, String, Serializer, Serializer, Instant, Duration) autoAdvance} setting.
      *
      * @param values         the {@link List} of values
      * @param startTimestamp the timestamp for the first generated record
diff --git a/streams/test-utils/src/main/java/org/apache/kafka/streams/TestOutputTopic.java b/streams/test-utils/src/main/java/org/apache/kafka/streams/TestOutputTopic.java
index da3629e..4296ce8 100644
--- a/streams/test-utils/src/main/java/org/apache/kafka/streams/TestOutputTopic.java
+++ b/streams/test-utils/src/main/java/org/apache/kafka/streams/TestOutputTopic.java
@@ -28,12 +28,14 @@ import java.util.StringJoiner;
 
 /**
  * {@code TestOutputTopic} is used to read records from a topic in {@link TopologyTestDriver}.
- * To use {@code TestOutputTopic} create a new instance via {@link TopologyTestDriver#createOutputTopic(String, Deserializer, Deserializer)}
+ * To use {@code TestOutputTopic} create a new instance via
+ * {@link TopologyTestDriver#createOutputTopic(String, Deserializer, Deserializer)}.
  * In actual test code, you can read record values, keys, {@link KeyValue} or {@link TestRecord}
  * If you have multiple source topics, you need to create a {@code TestOutputTopic} for each.
  * <p>
  * If you need to test key, value and headers, use {@link #readRecord()} methods.
- * Using {@link #readKeyValue()} you get a {@link KeyValue} pair, and thus, don't get access to the record's timestamp or headers.
+ * Using {@link #readKeyValue()} you get a {@link KeyValue} pair, and thus, don't get access to the record's
+ * timestamp or headers.
  * Similarly using {@link #readValue()} you only get the value of a record.
  *
  * <h2>Processing records</h2>
@@ -69,11 +71,10 @@ public class TestOutputTopic<K, V> {
         this.valueDeserializer = valueDeserializer;
     }
 
-
     /**
      * Read one record from the output topic and return record's value.
      *
-     * @return Next value for output topic
+     * @return Next value for output topic.
      */
     public V readValue() {
         final TestRecord<K, V> record = readRecord();
@@ -83,7 +84,7 @@ public class TestOutputTopic<K, V> {
     /**
      * Read one record from the output topic and return its key and value as pair.
      *
-     * @return Next output as {@link KeyValue}
+     * @return Next output as {@link KeyValue}.
      */
     public KeyValue<K, V> readKeyValue() {
         final TestRecord<K, V> record = readRecord();
@@ -93,7 +94,7 @@ public class TestOutputTopic<K, V> {
     /**
      * Read one Record from output topic.
      *
-     * @return Next output as {@link TestRecord}
+     * @return Next output as {@link TestRecord}.
      */
     public TestRecord<K, V> readRecord() {
         return driver.readRecord(topic, keyDeserializer, valueDeserializer);
@@ -101,10 +102,12 @@ public class TestOutputTopic<K, V> {
 
     /**
      * Read output to List.
-     * This method can be used if the result is considered a stream. If the result is considered a table, the list will
-     * contain all updated, ie, a key might be contained multiple times. If you are only interested in the last table update (ie, the final table state), you can use {@link #readKeyValuesToMap()} instead.
+     * This method can be used if the result is considered a stream.
+     * If the result is considered a table, the list will contain all updated, ie, a key might be contained multiple times.
+     * If you are only interested in the last table update (ie, the final table state),
+     * you can use {@link #readKeyValuesToMap()} instead.
      *
-     * @return List of output
+     * @return List of output.
      */
     public List<TestRecord<K, V>> readRecordsToList() {
         final List<TestRecord<K, V>> output = new LinkedList<>();
@@ -117,13 +120,13 @@ public class TestOutputTopic<K, V> {
 
     /**
      * Read output to map.
-     * This method can be used if the result is considered a table, when
-     * you are only interested in the last table update (ie, the final table state).
+     * This method can be used if the result is considered a table,
+     * when you are only interested in the last table update (ie, the final table state).
      * If the result is considered a stream, you can use {@link #readRecordsToList()} instead.
      * The list will contain all updated, ie, a key might be contained multiple times.
      * If the last update to a key is a delete/tombstone, the key will still be in the map (with null-value).
      *
-     * @return Map of output by key
+     * @return Map of output by key.
      */
     public Map<K, V> readKeyValuesToMap() {
         final Map<K, V> output = new HashMap<>();
@@ -141,7 +144,7 @@ public class TestOutputTopic<K, V> {
     /**
      * Read all KeyValues from topic to List.
      *
-     * @return List of output KeyValues
+     * @return List of output KeyValues.
      */
     public List<KeyValue<K, V>> readKeyValuesToList() {
         final List<KeyValue<K, V>> output = new LinkedList<>();
@@ -156,7 +159,7 @@ public class TestOutputTopic<K, V> {
     /**
      * Read all values from topic to List.
      *
-     * @return List of output values
+     * @return List of output values.
      */
     public List<V> readValuesToList() {
         final List<V> output = new LinkedList<>();
@@ -171,7 +174,7 @@ public class TestOutputTopic<K, V> {
     /**
      * Get size of unread record in the topic queue.
      *
-     * @return size of topic queue
+     * @return size of topic queue.
      */
     public final long getQueueSize() {
         return driver.getQueueSize(topic);
@@ -180,7 +183,7 @@ public class TestOutputTopic<K, V> {
     /**
      * Verify if the topic queue is empty.
      *
-     * @return true if no more record in the topic queue
+     * @return {@code true} if no more record in the topic queue.
      */
     public final boolean isEmpty() {
         return driver.isEmpty(topic);
diff --git a/streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java b/streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java
index 65b3f08..39d40a8 100644
--- a/streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java
+++ b/streams/test-utils/src/main/java/org/apache/kafka/streams/TopologyTestDriver.java
@@ -225,10 +225,9 @@ public class TopologyTestDriver implements Closeable {
      * @param topology the topology to be tested
      * @param config   the configuration for the topology
      */
-    @SuppressWarnings("WeakerAccess")
     public TopologyTestDriver(final Topology topology,
                               final Properties config) {
-        this(topology, config, (Instant) null);
+        this(topology, config, null);
     }
 
     /**
@@ -240,7 +239,6 @@ public class TopologyTestDriver implements Closeable {
      * @param config                 the configuration for the topology
      * @param initialWallClockTimeMs the initial value of internally mocked wall-clock time
      */
-    @SuppressWarnings("WeakerAccess")
     @Deprecated
     public TopologyTestDriver(final Topology topology,
                               final Properties config,
@@ -255,11 +253,13 @@ public class TopologyTestDriver implements Closeable {
      * @param config                 the configuration for the topology
      * @param initialWallClockTime   the initial value of internally mocked wall-clock time
      */
-    @SuppressWarnings("WeakerAccess")
     public TopologyTestDriver(final Topology topology,
                               final Properties config,
                               final Instant initialWallClockTime) {
-        this(topology.internalTopologyBuilder, config, initialWallClockTime == null ? System.currentTimeMillis() : initialWallClockTime.toEpochMilli());
+        this(
+            topology.internalTopologyBuilder,
+            config,
+            initialWallClockTime == null ? System.currentTimeMillis() : initialWallClockTime.toEpochMilli());
     }
 
 
@@ -379,7 +379,12 @@ public class TopologyTestDriver implements Closeable {
                 new LogContext()
             );
             globalStateTask.initialize();
-            globalProcessorContext.setRecordContext(new ProcessorRecordContext(0L, -1L, -1, ProcessorContextImpl.NONEXIST_TOPIC, new RecordHeaders()));
+            globalProcessorContext.setRecordContext(new ProcessorRecordContext(
+                0L,
+                -1L,
+                -1,
+                ProcessorContextImpl.NONEXIST_TOPIC,
+                new RecordHeaders()));
         } else {
             globalStateManager = null;
             globalStateTask = null;
@@ -421,7 +426,6 @@ public class TopologyTestDriver implements Closeable {
      *
      * @return Map of all metrics.
      */
-    @SuppressWarnings("WeakerAccess")
     public Map<MetricName, ? extends Metric> metrics() {
         return Collections.unmodifiableMap(metrics.metrics());
     }
@@ -434,21 +438,28 @@ public class TopologyTestDriver implements Closeable {
      *
      * @param consumerRecord the record to be processed
      */
-    @SuppressWarnings("WeakerAccess")
     @Deprecated
     public void pipeInput(final ConsumerRecord<byte[], byte[]> consumerRecord) {
-        pipeRecord(consumerRecord.topic(), consumerRecord.timestamp(), consumerRecord.key(), consumerRecord.value(), consumerRecord.headers());
+        pipeRecord(
+            consumerRecord.topic(),
+            consumerRecord.timestamp(),
+            consumerRecord.key(),
+            consumerRecord.value(),
+            consumerRecord.headers());
     }
 
     private void pipeRecord(final ProducerRecord<byte[], byte[]> record) {
         pipeRecord(record.topic(), record.timestamp(), record.key(), record.value(), record.headers());
     }
 
-    private void pipeRecord(final String topic, final Long timestamp, final byte[] key, final byte[] value, final Headers headers) {
-        final String topicName = topic;
+    private void pipeRecord(final String topicName,
+                            final Long timestamp,
+                            final byte[] key,
+                            final byte[] value,
+                            final Headers headers) {
 
         if (!internalTopologyBuilder.sourceTopicNames().isEmpty()) {
-            validateSourceTopicNameRegexPattern(topic);
+            validateSourceTopicNameRegexPattern(topicName);
         }
         final TopicPartition topicPartition = getTopicPartition(topicName);
         if (topicPartition != null) {
@@ -543,7 +554,6 @@ public class TopologyTestDriver implements Closeable {
      *
      * @param records a list of records to be processed
      */
-    @SuppressWarnings("WeakerAccess")
     @Deprecated
     public void pipeInput(final List<ConsumerRecord<byte[], byte[]>> records) {
         for (final ConsumerRecord<byte[], byte[]> record : records) {
@@ -560,7 +570,6 @@ public class TopologyTestDriver implements Closeable {
      *
      * @param advanceMs the amount of time to advance wall-clock time in milliseconds
      */
-    @SuppressWarnings("WeakerAccess")
     @Deprecated
     public void advanceWallClockTime(final long advanceMs) {
         advanceWallClockTime(Duration.ofMillis(advanceMs));
@@ -573,7 +582,6 @@ public class TopologyTestDriver implements Closeable {
      *
      * @param advance the amount of time to advance wall-clock time
      */
-    @SuppressWarnings("WeakerAccess")
     public void advanceWallClockTime(final Duration advance) {
         Objects.requireNonNull(advance, "advance cannot be null");
         mockWallClockTime.sleep(advance.toMillis());
@@ -593,7 +601,6 @@ public class TopologyTestDriver implements Closeable {
      * @param topic the name of the topic
      * @return the next record on that topic, or {@code null} if there is no record available
      */
-    @SuppressWarnings("WeakerAccess")
     @Deprecated
     public ProducerRecord<byte[], byte[]> readOutput(final String topic) {
         final Queue<ProducerRecord<byte[], byte[]>> outputRecords = outputRecordsByTopic.get(topic);
@@ -614,7 +621,6 @@ public class TopologyTestDriver implements Closeable {
      * @param valueDeserializer the deserializer for the value type
      * @return the next record on that topic, or {@code null} if there is no record available
      */
-    @SuppressWarnings("WeakerAccess")
     @Deprecated
     public <K, V> ProducerRecord<K, V> readOutput(final String topic,
                                                   final Deserializer<K> keyDeserializer,
@@ -628,8 +634,7 @@ public class TopologyTestDriver implements Closeable {
         return new ProducerRecord<>(record.topic(), record.partition(), record.timestamp(), key, value, record.headers());
     }
 
-
-    private final Queue<ProducerRecord<byte[], byte[]>> getRecordsQueue(final String topicName) {
+    private Queue<ProducerRecord<byte[], byte[]>> getRecordsQueue(final String topicName) {
         final Queue<ProducerRecord<byte[], byte[]>> outputRecords = outputRecordsByTopic.get(topicName);
         if (outputRecords == null) {
             if (!processorTopology.sinkTopics().contains(topicName)) {
@@ -654,7 +659,7 @@ public class TopologyTestDriver implements Closeable {
     public final <K, V> TestInputTopic<K, V> createInputTopic(final String topicName,
                                                               final Serializer<K> keySerializer,
                                                               final Serializer<V> valueSerializer) {
-        return new TestInputTopic<K, V>(this, topicName, keySerializer, valueSerializer, Instant.now(), Duration.ZERO);
+        return new TestInputTopic<>(this, topicName, keySerializer, valueSerializer, Instant.now(), Duration.ZERO);
     }
 
     /**
@@ -675,7 +680,7 @@ public class TopologyTestDriver implements Closeable {
                                                               final Serializer<V> valueSerializer,
                                                               final Instant startTimestamp,
                                                               final Duration autoAdvance) {
-        return new TestInputTopic<K, V>(this, topicName, keySerializer, valueSerializer, startTimestamp, autoAdvance);
+        return new TestInputTopic<>(this, topicName, keySerializer, valueSerializer, startTimestamp, autoAdvance);
     }
 
     /**
@@ -691,10 +696,9 @@ public class TopologyTestDriver implements Closeable {
     public final <K, V> TestOutputTopic<K, V> createOutputTopic(final String topicName,
                                                                 final Deserializer<K> keyDeserializer,
                                                                 final Deserializer<V> valueDeserializer) {
-        return new TestOutputTopic<K, V>(this, topicName, keyDeserializer, valueDeserializer);
+        return new TestOutputTopic<>(this, topicName, keyDeserializer, valueDeserializer);
     }
 
-    @SuppressWarnings("WeakerAccess")
     ProducerRecord<byte[], byte[]> readRecord(final String topic) {
         final Queue<? extends ProducerRecord<byte[], byte[]>> outputRecords = getRecordsQueue(topic);
         if (outputRecords == null) {
@@ -703,10 +707,9 @@ public class TopologyTestDriver implements Closeable {
         return outputRecords.poll();
     }
 
-    @SuppressWarnings("WeakerAccess")
     <K, V> TestRecord<K, V> readRecord(final String topic,
-                                         final Deserializer<K> keyDeserializer,
-                                         final Deserializer<V> valueDeserializer) {
+                                       final Deserializer<K> keyDeserializer,
+                                       final Deserializer<V> valueDeserializer) {
         final Queue<? extends ProducerRecord<byte[], byte[]>> outputRecords = getRecordsQueue(topic);
         if (outputRecords == null) {
             throw new NoSuchElementException("Uninitialized topic: " + topic);
@@ -720,7 +723,6 @@ public class TopologyTestDriver implements Closeable {
         return new TestRecord<>(key, value, record.headers(), record.timestamp());
     }
 
-    @SuppressWarnings("WeakerAccess")
     <K, V> void pipeRecord(final String topic,
                            final TestRecord<K, V> record,
                            final Serializer<K> keySerializer,
@@ -740,12 +742,6 @@ public class TopologyTestDriver implements Closeable {
         pipeRecord(topic, timestamp, serializedKey, serializedValue, record.headers());
     }
 
-    /**
-     * Get size of unread record in the topic queue.
-     *
-     * @param topic
-     * @return size of topic queue
-     */
     final long getQueueSize(final String topic) {
         final Queue<ProducerRecord<byte[], byte[]>> queue = getRecordsQueue(topic);
         if (queue == null) {
@@ -755,17 +751,10 @@ public class TopologyTestDriver implements Closeable {
         return queue.size();
     }
 
-    /**
-     * Verify if the topic queue is empty.
-     *
-     * @param topic
-     * @return true if no more record in the topic queue
-     */
     final boolean isEmpty(final String topic) {
         return getQueueSize(topic) == 0;
     }
 
-
     /**
      * Get all {@link StateStore StateStores} from the topology.
      * The stores can be a "regular" or global stores.
@@ -817,7 +806,6 @@ public class TopologyTestDriver implements Closeable {
      * @see #getTimestampedWindowStore(String)
      * @see #getSessionStore(String)
      */
-    @SuppressWarnings("WeakerAccess")
     public StateStore getStateStore(final String name) throws IllegalArgumentException {
         return getStateStore(name, true);
     }
@@ -892,7 +880,7 @@ public class TopologyTestDriver implements Closeable {
      * @see #getTimestampedWindowStore(String)
      * @see #getSessionStore(String)
      */
-    @SuppressWarnings({"unchecked", "WeakerAccess"})
+    @SuppressWarnings("unchecked")
     public <K, V> KeyValueStore<K, V> getKeyValueStore(final String name) {
         final StateStore store = getStateStore(name, false);
         if (store instanceof TimestampedKeyValueStore) {
@@ -918,7 +906,7 @@ public class TopologyTestDriver implements Closeable {
      * @see #getTimestampedWindowStore(String)
      * @see #getSessionStore(String)
      */
-    @SuppressWarnings({"unchecked", "WeakerAccess"})
+    @SuppressWarnings("unchecked")
     public <K, V> KeyValueStore<K, ValueAndTimestamp<V>> getTimestampedKeyValueStore(final String name) {
         final StateStore store = getStateStore(name, false);
         return store instanceof TimestampedKeyValueStore ? (TimestampedKeyValueStore<K, V>) store : null;
@@ -945,7 +933,7 @@ public class TopologyTestDriver implements Closeable {
      * @see #getTimestampedWindowStore(String)
      * @see #getSessionStore(String)
      */
-    @SuppressWarnings({"unchecked", "WeakerAccess"})
+    @SuppressWarnings("unchecked")
     public <K, V> WindowStore<K, V> getWindowStore(final String name) {
         final StateStore store = getStateStore(name, false);
         if (store instanceof TimestampedWindowStore) {
@@ -971,7 +959,7 @@ public class TopologyTestDriver implements Closeable {
      * @see #getWindowStore(String)
      * @see #getSessionStore(String)
      */
-    @SuppressWarnings({"unchecked", "WeakerAccess"})
+    @SuppressWarnings("unchecked")
     public <K, V> WindowStore<K, ValueAndTimestamp<V>> getTimestampedWindowStore(final String name) {
         final StateStore store = getStateStore(name, false);
         return store instanceof TimestampedWindowStore ? (TimestampedWindowStore<K, V>) store : null;
@@ -993,7 +981,7 @@ public class TopologyTestDriver implements Closeable {
      * @see #getWindowStore(String)
      * @see #getTimestampedWindowStore(String)
      */
-    @SuppressWarnings({"unchecked", "WeakerAccess"})
+    @SuppressWarnings("unchecked")
     public <K, V> SessionStore<K, V> getSessionStore(final String name) {
         final StateStore store = getStateStore(name, false);
         return store instanceof SessionStore ? (SessionStore<K, V>) store : null;
@@ -1002,7 +990,6 @@ public class TopologyTestDriver implements Closeable {
     /**
      * Close the driver, its topology, and all processors.
      */
-    @SuppressWarnings("WeakerAccess")
     public void close() {
         if (task != null) {
             task.close(true, false);
diff --git a/streams/test-utils/src/main/java/org/apache/kafka/streams/test/TestRecord.java b/streams/test-utils/src/main/java/org/apache/kafka/streams/test/TestRecord.java
index a1992ae..63f6921 100644
--- a/streams/test-utils/src/main/java/org/apache/kafka/streams/test/TestRecord.java
+++ b/streams/test-utils/src/main/java/org/apache/kafka/streams/test/TestRecord.java
@@ -38,7 +38,6 @@ public class TestRecord<K, V> {
     private final V value;
     private final Instant recordTime;
 
-
     /**
      * Creates a record.
      *
@@ -54,7 +53,6 @@ public class TestRecord<K, V> {
         this.headers = new RecordHeaders(headers);
     }
 
-
     /**
      * Creates a record.
      * 
@@ -67,7 +65,7 @@ public class TestRecord<K, V> {
         if (timestampMs != null) {
             if (timestampMs < 0) {
                 throw new IllegalArgumentException(
-                        String.format("Invalid timestamp: %d. Timestamp should always be non-negative or null.", timestampMs));
+                    String.format("Invalid timestamp: %d. Timestamp should always be non-negative or null.", timestampMs));
             }
             this.recordTime = Instant.ofEpochMilli(timestampMs);
         } else {
@@ -152,22 +150,21 @@ public class TestRecord<K, V> {
     }
 
     /**
-     * @return The headers
+     * @return The headers.
      */
     public Headers headers() {
         return headers;
     }
 
     /**
-     * @return The key (or null if no key is specified)
+     * @return The key (or {@code null} if no key is specified).
      */
     public K key() {
         return key;
     }
 
-
     /**
-     * @return The value
+     * @return The value.
      */
     public V value() {
         return value;
@@ -181,7 +178,7 @@ public class TestRecord<K, V> {
     }
 
     /**
-     * @return The headers
+     * @return The headers.
      */
     public Headers getHeaders() {
         return headers;
@@ -195,14 +192,14 @@ public class TestRecord<K, V> {
     }
 
     /**
-     * @return The value
+     * @return The value.
      */
     public V getValue() {
         return value;
     }
 
     /**
-     * @return The recordTime as Instant
+     * @return The timestamp.
      */
     public Instant getRecordTime() {
         return recordTime;
@@ -220,31 +217,21 @@ public class TestRecord<K, V> {
 
     @Override
     public boolean equals(final Object o) {
-        if (this == o)
+        if (this == o) {
             return true;
-        else if (!(o instanceof TestRecord))
+        }
+        if (o == null || getClass() != o.getClass()) {
             return false;
-
+        }
         final TestRecord<?, ?> that = (TestRecord<?, ?>) o;
-
-        if (key != null ? !key.equals(that.key) : that.key != null) 
-            return false;
-        else if (headers != null ? !headers.equals(that.headers) : that.headers != null)
-            return false;
-        else if (value != null ? !value.equals(that.value) : that.value != null) 
-            return false;
-        else if (recordTime != null ? !recordTime.equals(that.recordTime) : that.recordTime != null)
-            return false;
-
-        return true;
+        return Objects.equals(headers, that.headers) &&
+            Objects.equals(key, that.key) &&
+            Objects.equals(value, that.value) &&
+            Objects.equals(recordTime, that.recordTime);
     }
 
     @Override
     public int hashCode() {
-        int result = headers != null ? headers.hashCode() : 0;
-        result = 31 * result + (key != null ? key.hashCode() : 0);
-        result = 31 * result + (value != null ? value.hashCode() : 0);
-        result = 31 * result + (recordTime != null ? recordTime.hashCode() : 0);
-        return result;
+        return Objects.hash(headers, key, value, recordTime);
     }
 }
diff --git a/streams/test-utils/src/test/java/org/apache/kafka/streams/TestTopicsTest.java b/streams/test-utils/src/test/java/org/apache/kafka/streams/TestTopicsTest.java
index 3819688..0e22ec9 100644
--- a/streams/test-utils/src/test/java/org/apache/kafka/streams/TestTopicsTest.java
+++ b/streams/test-utils/src/test/java/org/apache/kafka/streams/TestTopicsTest.java
@@ -98,8 +98,10 @@ public class TestTopicsTest {
 
     @Test
     public void testValue() {
-        final TestInputTopic<String, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC, stringSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<String, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, stringSerde.deserializer(), stringSerde.deserializer());
+        final TestInputTopic<String, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC, stringSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<String, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, stringSerde.deserializer(), stringSerde.deserializer());
         //Feed word "Hello" to inputTopic and no kafka key, timestamp is irrelevant in this case
         inputTopic.pipeInput("Hello");
         assertThat(outputTopic.readValue(), equalTo("Hello"));
@@ -109,8 +111,10 @@ public class TestTopicsTest {
 
     @Test
     public void testValueList() {
-        final TestInputTopic<String, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC, stringSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<String, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, stringSerde.deserializer(), stringSerde.deserializer());
+        final TestInputTopic<String, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC, stringSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<String, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, stringSerde.deserializer(), stringSerde.deserializer());
         final List<String> inputList = Arrays.asList("This", "is", "an", "example");
         //Feed list of words to inputTopic and no kafka key, timestamp is irrelevant in this case
         inputTopic.pipeValueList(inputList);
@@ -121,8 +125,10 @@ public class TestTopicsTest {
 
     @Test
     public void testKeyValue() {
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<Long, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<Long, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
         inputTopic.pipeInput(1L, "Hello");
         assertThat(outputTopic.readKeyValue(), equalTo(new KeyValue<>(1L, "Hello")));
         assertThat(outputTopic.isEmpty(), is(true));
@@ -130,8 +136,10 @@ public class TestTopicsTest {
 
     @Test
     public void testKeyValueList() {
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<String, Long> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<String, Long> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
         final List<String> inputList = Arrays.asList("This", "is", "an", "example");
         final List<KeyValue<Long, String>> input = new LinkedList<>();
         final List<KeyValue<String, Long>> expected = new LinkedList<>();
@@ -148,8 +156,10 @@ public class TestTopicsTest {
 
     @Test
     public void testKeyValuesToMap() {
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<String, Long> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<String, Long> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
         final List<String> inputList = Arrays.asList("This", "is", "an", "example");
         final List<KeyValue<Long, String>> input = new LinkedList<>();
         final Map<String, Long> expected = new HashMap<>();
@@ -166,17 +176,21 @@ public class TestTopicsTest {
 
     @Test
     public void testKeyValuesToMapWithNull() {
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<Long, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<Long, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
         inputTopic.pipeInput("value");
-        assertThrows(IllegalStateException.class, () -> outputTopic.readKeyValuesToMap());
+        assertThrows(IllegalStateException.class, outputTopic::readKeyValuesToMap);
     }
 
 
     @Test
     public void testKeyValueListDuration() {
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<String, Long> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<String, Long> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
         final List<String> inputList = Arrays.asList("This", "is", "an", "example");
         final List<KeyValue<Long, String>> input = new LinkedList<>();
         final List<TestRecord<String, Long>> expected = new LinkedList<>();
@@ -196,8 +210,10 @@ public class TestTopicsTest {
 
     @Test
     public void testRecordList() {
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<String, Long> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<String, Long> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
         final List<String> inputList = Arrays.asList("This", "is", "an", "example");
         final List<TestRecord<Long, String>> input = new LinkedList<>();
         final List<TestRecord<String, Long>> expected = new LinkedList<>();
@@ -205,8 +221,8 @@ public class TestTopicsTest {
         Instant recordInstant = testBaseTime;
         Long i = 0L;
         for (final String s : inputList) {
-            input.add(new TestRecord<Long, String>(i, s, recordInstant));
-            expected.add(new TestRecord<String, Long>(s, i, recordInstant));
+            input.add(new TestRecord<>(i, s, recordInstant));
+            expected.add(new TestRecord<>(s, i, recordInstant));
             i++;
             recordInstant = recordInstant.plus(advance);
         }
@@ -218,24 +234,26 @@ public class TestTopicsTest {
     @Test
     public void testTimestamp() {
         long baseTime = 3;
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<Long, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<Long, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
         inputTopic.pipeInput(null, "Hello", baseTime);
-        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<Long, String>(null, "Hello", null, baseTime))));
+        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<>(null, "Hello", null, baseTime))));
 
         inputTopic.pipeInput(2L, "Kafka", ++baseTime);
-        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<Long, String>(2L, "Kafka", null, baseTime))));
+        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<>(2L, "Kafka", null, baseTime))));
 
         inputTopic.pipeInput(2L, "Kafka", testBaseTime);
-        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<Long, String>(2L, "Kafka", testBaseTime))));
+        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<>(2L, "Kafka", testBaseTime))));
 
         final List<String> inputList = Arrays.asList("Advancing", "time");
         //Feed list of words to inputTopic and no kafka key, timestamp advancing from testInstant
         final Duration advance = Duration.ofSeconds(15);
         final Instant recordInstant = testBaseTime.plus(Duration.ofDays(1));
         inputTopic.pipeValueList(inputList, recordInstant, advance);
-        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<Long, String>(null, "Advancing", recordInstant))));
-        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<Long, String>(null, "time", null, recordInstant.plus(advance)))));
+        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<>(null, "Advancing", recordInstant))));
+        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<>(null, "time", null, recordInstant.plus(advance)))));
     }
 
     @Test
@@ -247,50 +265,59 @@ public class TestTopicsTest {
                     new RecordHeader("bar", (byte[]) null),
                     new RecordHeader("\"A\\u00ea\\u00f1\\u00fcC\"", "value".getBytes())
                 });
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<Long, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
-        inputTopic.pipeInput(new TestRecord<Long, String>(1L, "Hello", headers));
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<Long, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
+        inputTopic.pipeInput(new TestRecord<>(1L, "Hello", headers));
         assertThat(outputTopic.readRecord(), allOf(
                 hasProperty("key", equalTo(1L)),
                 hasProperty("value", equalTo("Hello")),
                 hasProperty("headers", equalTo(headers))));
-        inputTopic.pipeInput(new TestRecord<Long, String>(2L, "Kafka", headers, ++baseTime));
-        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<Long, String>(2L, "Kafka", headers, baseTime))));
+        inputTopic.pipeInput(new TestRecord<>(2L, "Kafka", headers, ++baseTime));
+        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<>(2L, "Kafka", headers, baseTime))));
     }
 
     @Test
     public void testStartTimestamp() {
-        final long baseTime = testBaseTime.toEpochMilli();
         final Duration advance = Duration.ofSeconds(2);
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer(), testBaseTime, Duration.ZERO);
-        final TestOutputTopic<Long, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer(), testBaseTime, Duration.ZERO);
+        final TestOutputTopic<Long, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
         inputTopic.pipeInput(1L, "Hello");
-        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<Long, String>(1L, "Hello", testBaseTime))));
+        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<>(1L, "Hello", testBaseTime))));
         inputTopic.pipeInput(2L, "World");
-        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<Long, String>(2L, "World", null, testBaseTime.toEpochMilli()))));
+        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<>(2L, "World", null, testBaseTime.toEpochMilli()))));
         inputTopic.advanceTime(advance);
         inputTopic.pipeInput(3L, "Kafka");
-        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<Long, String>(3L, "Kafka", testBaseTime.plus(advance)))));
+        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<>(3L, "Kafka", testBaseTime.plus(advance)))));
     }
 
     @Test
     public void testTimestampAutoAdvance() {
         final Duration advance = Duration.ofSeconds(2);
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer(), testBaseTime, advance);
-        final TestOutputTopic<Long, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer(), testBaseTime, advance);
+        final TestOutputTopic<Long, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
         inputTopic.pipeInput("Hello");
-        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<Long, String>(null, "Hello", testBaseTime))));
+        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<>(null, "Hello", testBaseTime))));
         inputTopic.pipeInput(2L, "Kafka");
-        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<Long, String>(2L, "Kafka", testBaseTime.plus(advance)))));
+        assertThat(outputTopic.readRecord(), is(equalTo(new TestRecord<>(2L, "Kafka", testBaseTime.plus(advance)))));
     }
 
 
     @Test
     public void testMultipleTopics() {
-        final TestInputTopic<Long, String> inputTopic1 = testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer());
-        final TestInputTopic<Long, String> inputTopic2 = testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<Long, String> outputTopic1 = testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
-        final TestOutputTopic<String, Long> outputTopic2 = testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic1 =
+            testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer());
+        final TestInputTopic<Long, String> inputTopic2 =
+            testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<Long, String> outputTopic1 =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
+        final TestOutputTopic<String, Long> outputTopic2 =
+            testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
         inputTopic1.pipeInput(1L, "Hello");
         assertThat(outputTopic1.readKeyValue(), equalTo(new KeyValue<>(1L, "Hello")));
         assertThat(outputTopic2.readKeyValue(), equalTo(new KeyValue<>("Hello", 1L)));
@@ -305,64 +332,72 @@ public class TestTopicsTest {
 
     @Test
     public void testNonExistingOutputTopic() {
-        final TestOutputTopic<Long, String> outputTopic = testDriver.createOutputTopic("no-exist", longSerde.deserializer(), stringSerde.deserializer());
-        assertThrows("Unknown topic", IllegalArgumentException.class, () -> outputTopic.readRecord());
+        final TestOutputTopic<Long, String> outputTopic =
+            testDriver.createOutputTopic("no-exist", longSerde.deserializer(), stringSerde.deserializer());
+        assertThrows("Unknown topic", IllegalArgumentException.class, outputTopic::readRecord);
     }
 
     @Test
     public void testNonUsedOutputTopic() {
-        final TestOutputTopic<Long, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
-        assertThrows("Uninitialized topic", NoSuchElementException.class, () -> outputTopic.readRecord());
+        final TestOutputTopic<Long, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
+        assertThrows("Uninitialized topic", NoSuchElementException.class, outputTopic::readRecord);
     }
 
     @Test
     public void testEmptyTopic() {
-        final TestInputTopic<String, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC, stringSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<String, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, stringSerde.deserializer(), stringSerde.deserializer());
+        final TestInputTopic<String, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC, stringSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<String, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, stringSerde.deserializer(), stringSerde.deserializer());
         //Feed word "Hello" to inputTopic and no kafka key, timestamp is irrelevant in this case
         inputTopic.pipeInput("Hello");
         assertThat(outputTopic.readValue(), equalTo("Hello"));
         //No more output in topic
-        assertThrows("Empty topic", NoSuchElementException.class, () -> outputTopic.readRecord());
+        assertThrows("Empty topic", NoSuchElementException.class, outputTopic::readRecord);
     }
 
     @Test
     public void testNonExistingInputTopic() {
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic("no-exist", longSerde.serializer(), stringSerde.serializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic("no-exist", longSerde.serializer(), stringSerde.serializer());
         assertThrows("Unknown topic", IllegalArgumentException.class, () -> inputTopic.pipeInput(1L, "Hello"));
     }
 
     @Test(expected = NullPointerException.class)
     public void shouldNotAllowToCreateTopicWithNullTopicName() {
-        final TestInputTopic<String, String> inputTopic = testDriver.createInputTopic(null, stringSerde.serializer(), stringSerde.serializer());
+        testDriver.createInputTopic(null, stringSerde.serializer(), stringSerde.serializer());
     }
 
     @Test(expected = NullPointerException.class)
     public void shouldNotAllowToCreateWithNullDriver() {
-        final TestInputTopic<String, String> inputTopic = new TestInputTopic<>(null, INPUT_TOPIC, stringSerde.serializer(), stringSerde.serializer(), Instant.now(), Duration.ZERO);
+        new TestInputTopic<>(null, INPUT_TOPIC, stringSerde.serializer(), stringSerde.serializer(), Instant.now(), Duration.ZERO);
     }
 
 
     @Test(expected = StreamsException.class)
     public void testWrongSerde() {
-        final TestInputTopic<String, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC_MAP, stringSerde.serializer(), stringSerde.serializer());
+        final TestInputTopic<String, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC_MAP, stringSerde.serializer(), stringSerde.serializer());
         inputTopic.pipeInput("1L", "Hello");
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void testDuration() {
-        final TestInputTopic<String, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC_MAP, stringSerde.serializer(), stringSerde.serializer(), testBaseTime, Duration.ofDays(-1));
+        testDriver.createInputTopic(INPUT_TOPIC_MAP, stringSerde.serializer(), stringSerde.serializer(), testBaseTime, Duration.ofDays(-1));
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void testNegativeAdvance() {
-        final TestInputTopic<String, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC_MAP, stringSerde.serializer(), stringSerde.serializer());
+        final TestInputTopic<String, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC_MAP, stringSerde.serializer(), stringSerde.serializer());
         inputTopic.advanceTime(Duration.ofDays(-1));
     }
 
     @Test
     public void testInputToString() {
-        final TestInputTopic<String, String> inputTopic = testDriver.createInputTopic("topicName", stringSerde.serializer(), stringSerde.serializer());
+        final TestInputTopic<String, String> inputTopic =
+            testDriver.createInputTopic("topicName", stringSerde.serializer(), stringSerde.serializer());
         assertThat(inputTopic.toString(), allOf(
                 containsString("TestInputTopic"),
                 containsString("topic='topicName'"),
@@ -371,25 +406,28 @@ public class TestTopicsTest {
 
     @Test(expected = NullPointerException.class)
     public void shouldNotAllowToCreateOutputTopicWithNullTopicName() {
-        final TestOutputTopic<String, String> outputTopic = testDriver.createOutputTopic(null, stringSerde.deserializer(), stringSerde.deserializer());
+        testDriver.createOutputTopic(null, stringSerde.deserializer(), stringSerde.deserializer());
     }
 
     @Test(expected = NullPointerException.class)
     public void shouldNotAllowToCreateOutputWithNullDriver() {
-        final TestOutputTopic<String, String> outputTopic = new TestOutputTopic<>(null, OUTPUT_TOPIC, stringSerde.deserializer(), stringSerde.deserializer());
+        new TestOutputTopic<>(null, OUTPUT_TOPIC, stringSerde.deserializer(), stringSerde.deserializer());
     }
 
     @Test(expected = SerializationException.class)
     public void testOutputWrongSerde() {
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<Long, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, longSerde.deserializer(), stringSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<Long, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, longSerde.deserializer(), stringSerde.deserializer());
         inputTopic.pipeInput(1L, "Hello");
         assertThat(outputTopic.readKeyValue(), equalTo(new KeyValue<>(1L, "Hello")));
     }
 
     @Test
     public void testOutputToString() {
-        final TestOutputTopic<String, String> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC, stringSerde.deserializer(), stringSerde.deserializer());
+        final TestOutputTopic<String, String> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC, stringSerde.deserializer(), stringSerde.deserializer());
         assertThat(outputTopic.toString(), allOf(
                 containsString("TestOutputTopic"),
                 containsString("topic='output1'"),
@@ -399,8 +437,10 @@ public class TestTopicsTest {
 
     @Test
     public void testRecordsToList() {
-        final TestInputTopic<Long, String> inputTopic = testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
-        final TestOutputTopic<String, Long> outputTopic = testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
+        final TestInputTopic<Long, String> inputTopic =
+            testDriver.createInputTopic(INPUT_TOPIC_MAP, longSerde.serializer(), stringSerde.serializer());
+        final TestOutputTopic<String, Long> outputTopic =
+            testDriver.createOutputTopic(OUTPUT_TOPIC_MAP, stringSerde.deserializer(), longSerde.deserializer());
         final List<String> inputList = Arrays.asList("This", "is", "an", "example");
         final List<KeyValue<Long, String>> input = new LinkedList<>();
         final List<TestRecord<String, Long>> expected = new LinkedList<>();
diff --git a/streams/test-utils/src/test/java/org/apache/kafka/streams/TopologyTestDriverTest.java b/streams/test-utils/src/test/java/org/apache/kafka/streams/TopologyTestDriverTest.java
index 7e95392..d7ac6b4 100644
--- a/streams/test-utils/src/test/java/org/apache/kafka/streams/TopologyTestDriverTest.java
+++ b/streams/test-utils/src/test/java/org/apache/kafka/streams/TopologyTestDriverTest.java
@@ -99,15 +99,17 @@ public class TopologyTestDriverTest {
     private final byte[] key2 = new byte[0];
     private final byte[] value2 = new byte[0];
     private final long timestamp2 = 43L;
-    private final TestRecord<byte[], byte[]> testRecord2 = new TestRecord<>(key2, value2, null, timestamp2);
 
     //Factory and records for testing already deprecated methods
     @SuppressWarnings("deprecation")
-    private final org.apache.kafka.streams.test.ConsumerRecordFactory<byte[], byte[]> consumerRecordFactory = new org.apache.kafka.streams.test.ConsumerRecordFactory<>(
+    private final org.apache.kafka.streams.test.ConsumerRecordFactory<byte[], byte[]> consumerRecordFactory =
+        new org.apache.kafka.streams.test.ConsumerRecordFactory<>(
             new ByteArraySerializer(),
             new ByteArraySerializer());
-    private final ConsumerRecord<byte[], byte[]> consumerRecord1 = consumerRecordFactory.create(SOURCE_TOPIC_1, key1, value1, headers, timestamp1);
-    private final ConsumerRecord<byte[], byte[]> consumerRecord2 = consumerRecordFactory.create(SOURCE_TOPIC_2, key2, value2, timestamp2);
+    private final ConsumerRecord<byte[], byte[]> consumerRecord1 =
+        consumerRecordFactory.create(SOURCE_TOPIC_1, key1, value1, headers, timestamp1);
+    private final ConsumerRecord<byte[], byte[]> consumerRecord2 =
+        consumerRecordFactory.create(SOURCE_TOPIC_2, key2, value2, timestamp2);
 
     private TopologyTestDriver testDriver;
     private final Properties config = mkProperties(mkMap(
@@ -220,7 +222,7 @@ public class TopologyTestDriverTest {
         }
     }
 
-    private final class MockPunctuator implements Punctuator {
+    private final static class MockPunctuator implements Punctuator {
         private final List<Long> punctuatedAt = new LinkedList<>();
 
         @Override
@@ -229,7 +231,7 @@ public class TopologyTestDriverTest {
         }
     }
 
-    private final class MockProcessor implements Processor {
+    private final static class MockProcessor implements Processor {
         private final Collection<Punctuation> punctuations;
         private ProcessorContext context;
 
@@ -365,7 +367,12 @@ public class TopologyTestDriverTest {
 
         for (final String sourceTopicName : sourceTopicNames) {
             topology.addGlobalStore(
-                Stores.<Bytes, byte[]>keyValueStoreBuilder(Stores.inMemoryKeyValueStore(sourceTopicName + "-globalStore"), null, null).withLoggingDisabled(),
+                Stores.<Bytes, byte[]>keyValueStoreBuilder(
+                    Stores.inMemoryKeyValueStore(
+                        sourceTopicName + "-globalStore"),
+                    null,
+                    null)
+                    .withLoggingDisabled(),
                 sourceTopicName,
                 null,
                 null,
@@ -396,28 +403,37 @@ public class TopologyTestDriverTest {
 
     @Test
     public void shouldThrowForUnknownTopic() {
-        final String unknownTopic = "unknownTopic";
-        final byte[] nullValue = null;
-
         testDriver = new TopologyTestDriver(new Topology(), config);
-        assertThrows(IllegalArgumentException.class, () -> {
-            testDriver.pipeRecord(unknownTopic, new TestRecord<byte[], byte[]>(nullValue), new ByteArraySerializer(), new ByteArraySerializer(), Instant.now());
-        });
+        assertThrows(
+            IllegalArgumentException.class,
+            () -> testDriver.pipeRecord(
+                "unknownTopic",
+                new TestRecord<>((byte[]) null),
+                new ByteArraySerializer(),
+                new ByteArraySerializer(),
+                Instant.now())
+        );
     }
 
     @Test
     public void shouldThrowForMissingTime() {
         testDriver = new TopologyTestDriver(new Topology(), config);
-        assertThrows(IllegalStateException.class, () -> {
-            testDriver.pipeRecord(SINK_TOPIC_1, new TestRecord<String, String>("value"), new StringSerializer(), new StringSerializer(), null);
-        });
+        assertThrows(
+            IllegalStateException.class,
+            () -> testDriver.pipeRecord(
+                SINK_TOPIC_1,
+                new TestRecord<>("value"),
+                new StringSerializer(),
+                new StringSerializer(),
+                null));
     }
 
     @Deprecated
     @Test
     public void shouldThrowForUnknownTopicDeprecated() {
         final String unknownTopic = "unknownTopic";
-        final org.apache.kafka.streams.test.ConsumerRecordFactory<byte[], byte[]> consumerRecordFactory = new org.apache.kafka.streams.test.ConsumerRecordFactory<>(
+        final org.apache.kafka.streams.test.ConsumerRecordFactory<byte[], byte[]> consumerRecordFactory =
+            new org.apache.kafka.streams.test.ConsumerRecordFactory<>(
                 "unknownTopic",
                 new ByteArraySerializer(),
                 new ByteArraySerializer());
@@ -522,14 +538,16 @@ public class TopologyTestDriverTest {
 
         testDriver = new TopologyTestDriver(topology, config);
 
-        final org.apache.kafka.streams.test.ConsumerRecordFactory<Long, String> source1Factory = new org.apache.kafka.streams.test.ConsumerRecordFactory<>(
-            SOURCE_TOPIC_1,
-            Serdes.Long().serializer(),
-            Serdes.String().serializer());
-        final org.apache.kafka.streams.test.ConsumerRecordFactory<Integer, Double> source2Factory = new org.apache.kafka.streams.test.ConsumerRecordFactory<>(
-            SOURCE_TOPIC_2,
-            Serdes.Integer().serializer(),
-            Serdes.Double().serializer());
+        final org.apache.kafka.streams.test.ConsumerRecordFactory<Long, String> source1Factory =
+            new org.apache.kafka.streams.test.ConsumerRecordFactory<>(
+                SOURCE_TOPIC_1,
+                Serdes.Long().serializer(),
+                Serdes.String().serializer());
+        final org.apache.kafka.streams.test.ConsumerRecordFactory<Integer, Double> source2Factory =
+            new org.apache.kafka.streams.test.ConsumerRecordFactory<>(
+                SOURCE_TOPIC_2,
+                Serdes.Integer().serializer(),
+                Serdes.Double().serializer());
 
         final Long source1Key = 42L;
         final String source1Value = "anyString";
@@ -540,12 +558,14 @@ public class TopologyTestDriverTest {
         final ConsumerRecord<byte[], byte[]> consumerRecord2 = source2Factory.create(source2Key, source2Value);
 
         testDriver.pipeInput(consumerRecord1);
-        final ProducerRecord<Long, String> record1 = testDriver.readOutput(SINK_TOPIC_1, Serdes.Long().deserializer(), Serdes.String().deserializer());
+        final ProducerRecord<Long, String> record1 =
+            testDriver.readOutput(SINK_TOPIC_1, Serdes.Long().deserializer(), Serdes.String().deserializer());
         assertThat(record1.key(), equalTo(source1Key));
         assertThat(record1.value(), equalTo(source1Value));
 
         testDriver.pipeInput(consumerRecord2);
-        final ProducerRecord<Integer, Double> record2 = testDriver.readOutput(SINK_TOPIC_1, Serdes.Integer().deserializer(), Serdes.Double().deserializer());
+        final ProducerRecord<Integer, Double> record2 =
+            testDriver.readOutput(SINK_TOPIC_1, Serdes.Integer().deserializer(), Serdes.Double().deserializer());
         assertThat(record2.key(), equalTo(source2Key));
         assertThat(record2.value(), equalTo(source2Value));
     }
@@ -724,42 +744,42 @@ public class TopologyTestDriverTest {
         final List<Long> expectedPunctuations = new LinkedList<>();
 
         expectedPunctuations.add(42L);
-        pipeRecord(SOURCE_TOPIC_1, new TestRecord<byte[], byte[]>(key1, value1, null, 42L));
+        pipeRecord(SOURCE_TOPIC_1, new TestRecord<>(key1, value1, null, 42L));
         assertThat(mockPunctuator.punctuatedAt, equalTo(expectedPunctuations));
 
-        pipeRecord(SOURCE_TOPIC_1, new TestRecord<byte[], byte[]>(key1, value1, null, 42L));
+        pipeRecord(SOURCE_TOPIC_1, new TestRecord<>(key1, value1, null, 42L));
         assertThat(mockPunctuator.punctuatedAt, equalTo(expectedPunctuations));
 
         expectedPunctuations.add(51L);
-        pipeRecord(SOURCE_TOPIC_1, new TestRecord<byte[], byte[]>(key1, value1, null, 51L));
+        pipeRecord(SOURCE_TOPIC_1, new TestRecord<>(key1, value1, null, 51L));
         assertThat(mockPunctuator.punctuatedAt, equalTo(expectedPunctuations));
 
-        pipeRecord(SOURCE_TOPIC_1, new TestRecord<byte[], byte[]>(key1, value1, null, 52L));
+        pipeRecord(SOURCE_TOPIC_1, new TestRecord<>(key1, value1, null, 52L));
         assertThat(mockPunctuator.punctuatedAt, equalTo(expectedPunctuations));
 
         expectedPunctuations.add(61L);
-        pipeRecord(SOURCE_TOPIC_1, new TestRecord<byte[], byte[]>(key1, value1, null, 61L));
+        pipeRecord(SOURCE_TOPIC_1, new TestRecord<>(key1, value1, null, 61L));
         assertThat(mockPunctuator.punctuatedAt, equalTo(expectedPunctuations));
 
-        pipeRecord(SOURCE_TOPIC_1, new TestRecord<byte[], byte[]>(key1, value1, null, 65L));
+        pipeRecord(SOURCE_TOPIC_1, new TestRecord<>(key1, value1, null, 65L));
         assertThat(mockPunctuator.punctuatedAt, equalTo(expectedPunctuations));
 
         expectedPunctuations.add(71L);
-        pipeRecord(SOURCE_TOPIC_1, new TestRecord<byte[], byte[]>(key1, value1, null, 71L));
+        pipeRecord(SOURCE_TOPIC_1, new TestRecord<>(key1, value1, null, 71L));
         assertThat(mockPunctuator.punctuatedAt, equalTo(expectedPunctuations));
 
-        pipeRecord(SOURCE_TOPIC_1, new TestRecord<byte[], byte[]>(key1, value1, null, 72L));
+        pipeRecord(SOURCE_TOPIC_1, new TestRecord<>(key1, value1, null, 72L));
         assertThat(mockPunctuator.punctuatedAt, equalTo(expectedPunctuations));
 
         expectedPunctuations.add(95L);
-        pipeRecord(SOURCE_TOPIC_1, new TestRecord<byte[], byte[]>(key1, value1, null, 95L));
+        pipeRecord(SOURCE_TOPIC_1, new TestRecord<>(key1, value1, null, 95L));
         assertThat(mockPunctuator.punctuatedAt, equalTo(expectedPunctuations));
 
         expectedPunctuations.add(101L);
-        pipeRecord(SOURCE_TOPIC_1, new TestRecord<byte[], byte[]>(key1, value1, null, 101L));
+        pipeRecord(SOURCE_TOPIC_1, new TestRecord<>(key1, value1, null, 101L));
         assertThat(mockPunctuator.punctuatedAt, equalTo(expectedPunctuations));
 
-        pipeRecord(SOURCE_TOPIC_1, new TestRecord<byte[], byte[]>(key1, value1, null, 102L));
+        pipeRecord(SOURCE_TOPIC_1, new TestRecord<>(key1, value1, null, 102L));
         assertThat(mockPunctuator.punctuatedAt, equalTo(expectedPunctuations));
     }
 
@@ -1186,7 +1206,7 @@ public class TopologyTestDriverTest {
     }
 
     private void pipeInput(final String topic, final String key, final Long value, final Long time) {
-        testDriver.pipeRecord(topic, new TestRecord<String, Long>(key, value, null, time),
+        testDriver.pipeRecord(topic, new TestRecord<>(key, value, null, time),
                 new StringSerializer(), new LongSerializer(), null);
     }
     
@@ -1253,14 +1273,14 @@ public class TopologyTestDriverTest {
         assertTrue(testDriver.isEmpty("result-topic"));
     }
 
-    private class CustomMaxAggregatorSupplier implements ProcessorSupplier<String, Long> {
+    private static class CustomMaxAggregatorSupplier implements ProcessorSupplier<String, Long> {
         @Override
         public Processor<String, Long> get() {
             return new CustomMaxAggregator();
         }
     }
 
-    private class CustomMaxAggregator implements Processor<String, Long> {
+    private static class CustomMaxAggregator implements Processor<String, Long> {
         ProcessorContext context;
         private KeyValueStore<String, Long> store;
 
@@ -1341,7 +1361,9 @@ public class TopologyTestDriverTest {
             },
             "sourceProcessor"
         );
-        topology.addStateStore(Stores.keyValueStoreBuilder(Stores.persistentKeyValueStore("storeProcessorStore"), Serdes.String(), Serdes.Long()), "storeProcessor");
+        topology.addStateStore(Stores.keyValueStoreBuilder(
+            Stores.persistentKeyValueStore("storeProcessorStore"), Serdes.String(), Serdes.Long()),
+            "storeProcessor");
 
         final Properties config = new Properties();
         config.put(StreamsConfig.APPLICATION_ID_CONFIG, "test-TopologyTestDriver-cleanup");
@@ -1352,7 +1374,7 @@ public class TopologyTestDriverTest {
 
         try (final TopologyTestDriver testDriver = new TopologyTestDriver(topology, config)) {
             assertNull(testDriver.getKeyValueStore("storeProcessorStore").get("a"));
-            testDriver.pipeRecord("input-topic", new TestRecord<String, Long>("a", 1L),
+            testDriver.pipeRecord("input-topic", new TestRecord<>("a", 1L),
                     new StringSerializer(), new LongSerializer(), Instant.now());
             Assert.assertEquals(1L, testDriver.getKeyValueStore("storeProcessorStore").get("a"));
         }
@@ -1377,7 +1399,12 @@ public class TopologyTestDriverTest {
             final KeyValueStore<String, String> globalStore = testDriver.getKeyValueStore("globalStore");
             Assert.assertNotNull(globalStore);
             Assert.assertNotNull(testDriver.getAllStateStores().get("globalStore"));
-            testDriver.pipeRecord("topic", new TestRecord<String, String>("k1", "value1"), new StringSerializer(), new StringSerializer(), Instant.now());
+            testDriver.pipeRecord(
+                "topic",
+                new TestRecord<>("k1", "value1"),
+                new StringSerializer(),
+                new StringSerializer(),
+                Instant.now());
             // we expect to have both in the global store, the one from pipeInput and the one from the producer
             Assert.assertEquals("value1", globalStore.get("k1"));
         }
@@ -1406,7 +1433,7 @@ public class TopologyTestDriverTest {
         final  Pattern pattern2Source2 = Pattern.compile("source-topic-[A-Z]");
         final  String consumerTopic2 = "source-topic-Z";
 
-        final TestRecord<byte[], byte[]> consumerRecord2 = new TestRecord<byte[], byte[]>(key2, value2, null, timestamp2);
+        final TestRecord<byte[], byte[]> consumerRecord2 = new TestRecord<>(key2, value2, null, timestamp2);
 
         testDriver = new TopologyTestDriver(setupMultipleSourcesPatternTopology(pattern2Source1, pattern2Source2), config);
 
diff --git a/streams/test-utils/src/test/java/org/apache/kafka/streams/test/TestRecordTest.java b/streams/test-utils/src/test/java/org/apache/kafka/streams/test/TestRecordTest.java
index 9977fc5..5739693 100644
--- a/streams/test-utils/src/test/java/org/apache/kafka/streams/test/TestRecordTest.java
+++ b/streams/test-utils/src/test/java/org/apache/kafka/streams/test/TestRecordTest.java
@@ -32,7 +32,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.allOf;
 import static org.hamcrest.Matchers.hasProperty;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 
 public class TestRecordTest {
@@ -102,16 +101,16 @@ public class TestRecordTest {
                     new RecordHeader("bar", (byte[]) null),
                 });
         final TestRecord<String, Integer> headerMismatch = new TestRecord<>(key, value, headers2, recordTime);
-        assertFalse(testRecord.equals(headerMismatch));
+        assertNotEquals(testRecord, headerMismatch);
 
         final TestRecord<String, Integer> keyMisMatch = new TestRecord<>("test-mismatch", value, headers, recordTime);
-        assertFalse(testRecord.equals(keyMisMatch));
+        assertNotEquals(testRecord, keyMisMatch);
 
         final TestRecord<String, Integer> valueMisMatch = new TestRecord<>(key, 2, headers, recordTime);
-        assertFalse(testRecord.equals(valueMisMatch));
+        assertNotEquals(testRecord, valueMisMatch);
 
         final TestRecord<String, Integer> timeMisMatch = new TestRecord<>(key, value, headers, recordTime.plusMillis(1));
-        assertFalse(testRecord.equals(timeMisMatch));
+        assertNotEquals(testRecord, timeMisMatch);
 
         final TestRecord<String, Integer> nullFieldsRecord = new TestRecord<>(null, null, null, (Instant) null);
         assertEquals(nullFieldsRecord, nullFieldsRecord);
@@ -121,21 +120,21 @@ public class TestRecordTest {
     @Test
     public void testPartialConstructorEquals() {
         final TestRecord<String, Integer> record1 = new TestRecord<>(value);
-        assertThat(record1, equalTo(new TestRecord<String, Integer>(null, value, null, (Instant) null)));
+        assertThat(record1, equalTo(new TestRecord<>(null, value, null, (Instant) null)));
 
         final TestRecord<String, Integer> record2 = new TestRecord<>(key, value);
-        assertThat(record2, equalTo(new TestRecord<String, Integer>(key, value, null, (Instant) null)));
+        assertThat(record2, equalTo(new TestRecord<>(key, value, null, (Instant) null)));
 
         final TestRecord<String, Integer> record3 = new TestRecord<>(key, value, headers);
-        assertThat(record3, equalTo(new TestRecord<String, Integer>(key, value, headers, (Long) null)));
+        assertThat(record3, equalTo(new TestRecord<>(key, value, headers, (Long) null)));
 
         final TestRecord<String, Integer> record4 = new TestRecord<>(key, value, recordTime);
-        assertThat(record4, equalTo(new TestRecord<String, Integer>(key, value, null, recordMs)));
+        assertThat(record4, equalTo(new TestRecord<>(key, value, null, recordMs)));
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void testInvalidRecords() {
-        new TestRecord<String, Integer>(key, value, headers,  -1L);
+        new TestRecord<>(key, value, headers,  -1L);
     }
 
     @Test
@@ -150,7 +149,8 @@ public class TestRecordTest {
     @Test
     public void testConsumerRecord() {
         final String topicName = "topic";
-        final ConsumerRecord<String, Integer> consumerRecord = new ConsumerRecord<>(topicName, 1, 0, recordMs, TimestampType.CREATE_TIME, 0L, 0, 0, key, value, headers);
+        final ConsumerRecord<String, Integer> consumerRecord =
+            new ConsumerRecord<>(topicName, 1, 0, recordMs, TimestampType.CREATE_TIME, 0L, 0, 0, key, value, headers);
         final TestRecord<String, Integer> testRecord = new TestRecord<>(consumerRecord);
         final TestRecord<String, Integer> expectedRecord = new TestRecord<>(key, value, headers, recordTime);
         assertEquals(expectedRecord, testRecord);
@@ -159,7 +159,8 @@ public class TestRecordTest {
     @Test
     public void testProducerRecord() {
         final String topicName = "topic";
-        final ProducerRecord<String, Integer> producerRecord = new ProducerRecord<>(topicName, 1, recordMs, key, value, headers);
+        final ProducerRecord<String, Integer> producerRecord =
+            new ProducerRecord<>(topicName, 1, recordMs, key, value, headers);
         final TestRecord<String, Integer> testRecord = new TestRecord<>(producerRecord);
         final TestRecord<String, Integer> expectedRecord = new TestRecord<>(key, value, headers, recordTime);
         assertEquals(expectedRecord, testRecord);


[kafka] 01/02: KAFKA-8122: Fix Kafka Streams EOS integration test (#7470)

Posted by mj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mjsax pushed a commit to branch 2.4
in repository https://gitbox.apache.org/repos/asf/kafka.git

commit 641dfa47f3fc82917b23a676141eff2b87cc63c8
Author: Matthias J. Sax <ma...@confluent.io>
AuthorDate: Fri Oct 11 23:59:01 2019 -0700

    KAFKA-8122: Fix Kafka Streams EOS integration test (#7470)
    
    Reviewers: Guozhang Wang <gu...@confluent.io>, Chris Pettitt <cp...@confluent.io>, Bill Bejeck <bi...@confluent.io>
---
 .../integration/AbstractJoinIntegrationTest.java   | 44 ++++++++++------------
 .../streams/integration/EosIntegrationTest.java    | 28 +++++++-------
 .../org/apache/kafka/test/StreamsTestUtils.java    | 23 +++++++++++
 3 files changed, 57 insertions(+), 38 deletions(-)

diff --git a/streams/src/test/java/org/apache/kafka/streams/integration/AbstractJoinIntegrationTest.java b/streams/src/test/java/org/apache/kafka/streams/integration/AbstractJoinIntegrationTest.java
index daea1d7..6660a20 100644
--- a/streams/src/test/java/org/apache/kafka/streams/integration/AbstractJoinIntegrationTest.java
+++ b/streams/src/test/java/org/apache/kafka/streams/integration/AbstractJoinIntegrationTest.java
@@ -58,6 +58,7 @@ import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import static org.apache.kafka.test.StreamsTestUtils.startKafkaStreamsAndWaitForRunningState;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.core.Is.is;
 
@@ -102,21 +103,21 @@ public abstract class AbstractJoinIntegrationTest {
     AtomicBoolean finalResultReached = new AtomicBoolean(false);
 
     private final List<Input<String>> input = Arrays.asList(
-            new Input<>(INPUT_TOPIC_LEFT, null),
-            new Input<>(INPUT_TOPIC_RIGHT, null),
-            new Input<>(INPUT_TOPIC_LEFT, "A"),
-            new Input<>(INPUT_TOPIC_RIGHT, "a"),
-            new Input<>(INPUT_TOPIC_LEFT, "B"),
-            new Input<>(INPUT_TOPIC_RIGHT, "b"),
-            new Input<>(INPUT_TOPIC_LEFT, null),
-            new Input<>(INPUT_TOPIC_RIGHT, null),
-            new Input<>(INPUT_TOPIC_LEFT, "C"),
-            new Input<>(INPUT_TOPIC_RIGHT, "c"),
-            new Input<>(INPUT_TOPIC_RIGHT, null),
-            new Input<>(INPUT_TOPIC_LEFT, null),
-            new Input<>(INPUT_TOPIC_RIGHT, null),
-            new Input<>(INPUT_TOPIC_RIGHT, "d"),
-            new Input<>(INPUT_TOPIC_LEFT, "D")
+        new Input<>(INPUT_TOPIC_LEFT, null),
+        new Input<>(INPUT_TOPIC_RIGHT, null),
+        new Input<>(INPUT_TOPIC_LEFT, "A"),
+        new Input<>(INPUT_TOPIC_RIGHT, "a"),
+        new Input<>(INPUT_TOPIC_LEFT, "B"),
+        new Input<>(INPUT_TOPIC_RIGHT, "b"),
+        new Input<>(INPUT_TOPIC_LEFT, null),
+        new Input<>(INPUT_TOPIC_RIGHT, null),
+        new Input<>(INPUT_TOPIC_LEFT, "C"),
+        new Input<>(INPUT_TOPIC_RIGHT, "c"),
+        new Input<>(INPUT_TOPIC_RIGHT, null),
+        new Input<>(INPUT_TOPIC_LEFT, null),
+        new Input<>(INPUT_TOPIC_RIGHT, null),
+        new Input<>(INPUT_TOPIC_RIGHT, "d"),
+        new Input<>(INPUT_TOPIC_LEFT, "D")
     );
 
     final ValueJoiner<String, String, String> valueJoiner = (value1, value2) -> value1 + "-" + value2;
@@ -198,7 +199,7 @@ public abstract class AbstractJoinIntegrationTest {
         KeyValueTimestamp<Long, String> expectedFinalResult = null;
 
         try {
-            streams.start();
+            startKafkaStreamsAndWaitForRunningState(streams);
 
             final long firstTimestamp = System.currentTimeMillis();
             long ts = firstTimestamp;
@@ -231,19 +232,12 @@ public abstract class AbstractJoinIntegrationTest {
     /*
      * Runs the actual test. Checks the final result only after expected number of records have been consumed.
      */
-    void runTest(final KeyValueTimestamp<Long, String> expectedFinalResult) throws Exception {
-        runTest(expectedFinalResult, null);
-    }
-
-    /*
-     * Runs the actual test. Checks the final result only after expected number of records have been consumed.
-     */
     void runTest(final KeyValueTimestamp<Long, String> expectedFinalResult, final String storeName) throws Exception {
         IntegrationTestUtils.purgeLocalStreamsState(STREAMS_CONFIG);
         streams = new KafkaStreams(builder.build(), STREAMS_CONFIG);
 
         try {
-            streams.start();
+            startKafkaStreamsAndWaitForRunningState(streams);
 
             final long firstTimestamp = System.currentTimeMillis();
             long ts = firstTimestamp;
@@ -288,7 +282,7 @@ public abstract class AbstractJoinIntegrationTest {
         }
     }
 
-    private final class Input<V> {
+    private static final class Input<V> {
         String topic;
         KeyValue<Long, V> record;
 
diff --git a/streams/src/test/java/org/apache/kafka/streams/integration/EosIntegrationTest.java b/streams/src/test/java/org/apache/kafka/streams/integration/EosIntegrationTest.java
index 7523a62..15d6789 100644
--- a/streams/src/test/java/org/apache/kafka/streams/integration/EosIntegrationTest.java
+++ b/streams/src/test/java/org/apache/kafka/streams/integration/EosIntegrationTest.java
@@ -60,6 +60,8 @@ import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import static org.apache.kafka.test.StreamsTestUtils.startKafkaStreamsAndWaitForRunningState;
+import static org.apache.kafka.test.TestUtils.waitForCondition;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertNotNull;
@@ -170,7 +172,7 @@ public class EosIntegrationTest {
                 properties);
 
             try (final KafkaStreams streams = new KafkaStreams(builder.build(), config)) {
-                streams.start();
+                startKafkaStreamsAndWaitForRunningState(streams, MAX_WAIT_TIME_MS);
 
                 final List<KeyValue<Long, Long>> inputData = prepareData(i * 100, i * 100 + 10L, 0L, 1L);
 
@@ -253,7 +255,7 @@ public class EosIntegrationTest {
             properties);
 
         try (final KafkaStreams streams = new KafkaStreams(builder.build(), config)) {
-            streams.start();
+            startKafkaStreamsAndWaitForRunningState(streams, MAX_WAIT_TIME_MS);
 
             final List<KeyValue<Long, Long>> firstBurstOfData = prepareData(0L, 5L, 0L);
             final List<KeyValue<Long, Long>> secondBurstOfData = prepareData(5L, 8L, 0L);
@@ -319,7 +321,7 @@ public class EosIntegrationTest {
         // after fail over, we should read 40 committed records (even if 50 record got written)
 
         try (final KafkaStreams streams = getKafkaStreams(false, "appDir", 2)) {
-            streams.start();
+            startKafkaStreamsAndWaitForRunningState(streams, MAX_WAIT_TIME_MS);
 
             final List<KeyValue<Long, Long>> committedDataBeforeFailure = prepareData(0L, 10L, 0L, 1L);
             final List<KeyValue<Long, Long>> uncommittedDataBeforeFailure = prepareData(10L, 15L, 0L, 1L);
@@ -332,7 +334,7 @@ public class EosIntegrationTest {
 
             writeInputData(committedDataBeforeFailure);
 
-            TestUtils.waitForCondition(
+            waitForCondition(
                 () -> commitRequested.get() == 2, MAX_WAIT_TIME_MS,
                 "StreamsTasks did not request commit.");
 
@@ -347,7 +349,7 @@ public class EosIntegrationTest {
             errorInjected.set(true);
             writeInputData(dataAfterFailure);
 
-            TestUtils.waitForCondition(
+            waitForCondition(
                 () -> uncaughtException != null, MAX_WAIT_TIME_MS,
                 "Should receive uncaught exception from one StreamThread.");
 
@@ -387,7 +389,7 @@ public class EosIntegrationTest {
         // per key (even if some records got processed twice)
 
         try (final KafkaStreams streams = getKafkaStreams(true, "appDir", 2)) {
-            streams.start();
+            startKafkaStreamsAndWaitForRunningState(streams, MAX_WAIT_TIME_MS);
 
             final List<KeyValue<Long, Long>> committedDataBeforeFailure = prepareData(0L, 10L, 0L, 1L);
             final List<KeyValue<Long, Long>> uncommittedDataBeforeFailure = prepareData(10L, 15L, 0L, 1L, 2L, 3L);
@@ -400,7 +402,7 @@ public class EosIntegrationTest {
 
             writeInputData(committedDataBeforeFailure);
 
-            TestUtils.waitForCondition(
+            waitForCondition(
                 () -> commitRequested.get() == 2, MAX_WAIT_TIME_MS,
                 "SteamsTasks did not request commit.");
 
@@ -417,7 +419,7 @@ public class EosIntegrationTest {
             errorInjected.set(true);
             writeInputData(dataAfterFailure);
 
-            TestUtils.waitForCondition(
+            waitForCondition(
                 () -> uncaughtException != null, MAX_WAIT_TIME_MS,
                 "Should receive uncaught exception from one StreamThread.");
 
@@ -462,8 +464,8 @@ public class EosIntegrationTest {
             final KafkaStreams streams1 = getKafkaStreams(false, "appDir1", 1);
             final KafkaStreams streams2 = getKafkaStreams(false, "appDir2", 1)
         ) {
-            streams1.start();
-            streams2.start();
+            startKafkaStreamsAndWaitForRunningState(streams1, MAX_WAIT_TIME_MS);
+            startKafkaStreamsAndWaitForRunningState(streams2, MAX_WAIT_TIME_MS);
 
             final List<KeyValue<Long, Long>> committedDataBeforeGC = prepareData(0L, 10L, 0L, 1L);
             final List<KeyValue<Long, Long>> uncommittedDataBeforeGC = prepareData(10L, 15L, 0L, 1L);
@@ -478,7 +480,7 @@ public class EosIntegrationTest {
 
             writeInputData(committedDataBeforeGC);
 
-            TestUtils.waitForCondition(
+            waitForCondition(
                 () -> commitRequested.get() == 2, MAX_WAIT_TIME_MS,
                 "SteamsTasks did not request commit.");
 
@@ -493,7 +495,7 @@ public class EosIntegrationTest {
             gcInjected.set(true);
             writeInputData(dataToTriggerFirstRebalance);
 
-            TestUtils.waitForCondition(
+            waitForCondition(
                 () -> streams1.allMetadata().size() == 1
                     && streams2.allMetadata().size() == 1
                     && (streams1.allMetadata().iterator().next().topicPartitions().size() == 2
@@ -511,7 +513,7 @@ public class EosIntegrationTest {
             checkResultPerKey(committedRecordsAfterRebalance, expectedCommittedRecordsAfterRebalance);
 
             doGC = false;
-            TestUtils.waitForCondition(
+            waitForCondition(
                 () -> streams1.allMetadata().size() == 1
                     && streams2.allMetadata().size() == 1
                     && streams1.allMetadata().iterator().next().topicPartitions().size() == 1
diff --git a/streams/src/test/java/org/apache/kafka/test/StreamsTestUtils.java b/streams/src/test/java/org/apache/kafka/test/StreamsTestUtils.java
index 87a693d..f25326e 100644
--- a/streams/src/test/java/org/apache/kafka/test/StreamsTestUtils.java
+++ b/streams/src/test/java/org/apache/kafka/test/StreamsTestUtils.java
@@ -21,6 +21,7 @@ import org.apache.kafka.common.MetricName;
 import org.apache.kafka.common.serialization.Serde;
 import org.apache.kafka.common.serialization.Serdes;
 import org.apache.kafka.common.utils.Bytes;
+import org.apache.kafka.streams.KafkaStreams;
 import org.apache.kafka.streams.KeyValue;
 import org.apache.kafka.streams.StreamsConfig;
 import org.apache.kafka.streams.kstream.Windowed;
@@ -31,8 +32,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import static org.apache.kafka.common.metrics.Sensor.RecordingLevel.DEBUG;
+import static org.apache.kafka.test.TestUtils.DEFAULT_MAX_WAIT_MS;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.MatcherAssert.assertThat;
 
@@ -79,6 +83,25 @@ public final class StreamsTestUtils {
         return getStreamsConfig(UUID.randomUUID().toString());
     }
 
+    public static void startKafkaStreamsAndWaitForRunningState(final KafkaStreams kafkaStreams) throws InterruptedException {
+        startKafkaStreamsAndWaitForRunningState(kafkaStreams, DEFAULT_MAX_WAIT_MS);
+    }
+
+    public static void startKafkaStreamsAndWaitForRunningState(final KafkaStreams kafkaStreams,
+                                                               final long timeoutMs) throws InterruptedException {
+        final CountDownLatch countDownLatch = new CountDownLatch(1);
+        kafkaStreams.setStateListener((newState, oldState) -> {
+            if (newState == KafkaStreams.State.RUNNING) {
+                countDownLatch.countDown();
+            }
+        });
+
+        kafkaStreams.start();
+        assertThat(
+            "KafkaStreams did not transit to RUNNING state within " + timeoutMs + " milli seconds.",
+            countDownLatch.await(timeoutMs, TimeUnit.MILLISECONDS), equalTo(true));
+    }
+
     public static <K, V> List<KeyValue<K, V>> toList(final Iterator<KeyValue<K, V>> iterator) {
         final List<KeyValue<K, V>> results = new ArrayList<>();