liveBook · Manning

TestInputTopic

As explained in Kafka Streams in Action, Second Edition

TestInputTopic is a Kafka Streams test utility representing an input topic and providing methods for piping test records into a topology.

TestInputTopic represents an input topic inside a Kafka Streams topology test. Created through TopologyTestDriver, it serializes supplied keys and values into the byte arrays the application would receive from Kafka. Its topic name must match the source topic configured by the topology. section 14.1.3

Use the input topic according to the data and timing behavior under test:

  • Call pipeValueList for simple value-only input, such as records whose keys are absent or derived entirely from values. section 14.1.3
  • Call pipeInput(key, value) for keyed records, including inputs used by stateful operations. section 14.1.3
  • Call pipeInput with an Instant when record timestamps must advance stream time for punctuation, windows, or other time-driven behavior. section 14.1.4
  • Call advanceTime when subsequent records should inherit a later input-topic event time; timestamped pipeInput advances driver stream time but not the topic's current event time. section 14.1.4
  • Use TestRecord values when tests need timestamps and headers together, and use Instant plus Duration overloads for controlled timestamp progression. section 14.1.3

Pipe records through a topology

Create the topic with matching name and serializers, pipe several values, then read the resulting records from a TestOutputTopic for assertion: inputTopic.pipeValueList(inputValues); List<String> actualOutput = outputTopic.readValuesToList(); assertThat(actualOutput, equalTo(expectedOutput)); section 14.1.3

Listing 14.11 Building the TopologyTestDriver and input and output topics
try (TopologyTestDriver driver =
                 new TopologyTestDriver(yellingTopology)) {     #1

    TestInputTopic<String, String> inputTopic =      #2
            driver.createInputTopic("src-topic",
                                    stringSerializer,
                                    stringSerializer);

    TestOutputTopic<String, String> outputTopic =     #3
            driver.createOutputTopic("out-topic",
                                    stringDeserializer,
                                    stringDeserializer);

Shows the complete TestInputTopic construction beside TopologyTestDriver and the matching TestOutputTopic setup. section 14.1.3

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains construction, serialization, input overloads, timestamp advancement, and event-time distinctions.
Examples
Uses value lists, keyed records, reduce outputs, timestamped transactions, and suppressed windowed results.
What it assumes
Assumes familiarity with Kafka Streams topologies, serializers, deserializers, and JUnit-style assertions.
What you can do after
Apply it via TopologyTestDriver to inject records and validate topology output, state, ordering, punctuation, or window behavior.
How it connects
Connects TopologyTestDriver, TestOutputTopic, serializers, deserializers, stream time, punctuation, windows, and stateful operations.

Also explained in

Compare how 2 books explain TestInputTopic →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.