Class MockProcessorContext
java.lang.Object
org.apache.kafka.streams.processor.MockProcessorContext
- All Implemented Interfaces:
org.apache.kafka.streams.processor.internals.RecordCollector.Supplier
,org.apache.kafka.streams.processor.ProcessorContext
@Deprecated
public class MockProcessorContext
extends Object
implements org.apache.kafka.streams.processor.ProcessorContext, org.apache.kafka.streams.processor.internals.RecordCollector.Supplier
Deprecated.
MockProcessorContext
is a mock of ProcessorContext
for users to test their
ValueTransformer
implementations.
The tests for this class (org.apache.kafka.streams.MockProcessorContextTest) include several behavioral tests that serve as example usage.
Note that this class does not take any automated actions (such as firing scheduled punctuators). It simply captures any data it witnesses.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Deprecated.static class
Deprecated.MockProcessorContext.CapturedPunctuator
holds captured punctuators, along with their scheduling information. -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.MockProcessorContext
(Properties config) Deprecated.MockProcessorContext
(Properties config, org.apache.kafka.streams.processor.TaskId taskId, File stateDir) Deprecated.Create aMockProcessorContext
with a specified taskId and null stateDir. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.appConfigsWithPrefix
(String prefix) Deprecated.Deprecated.void
commit()
Deprecated.boolean
Deprecated.WhetherProcessorContext.commit()
has been called in this context.long
Deprecated.long
Deprecated.<K,
V> void forward
(K key, V value) Deprecated.<K,
V> void forward
(K key, V value, org.apache.kafka.streams.processor.To to) Deprecated.Deprecated.Get all the forwarded data this context has observed.Deprecated.Get all the forwarded data this context has observed for a specific child by name.<S extends org.apache.kafka.streams.processor.StateStore>
SgetStateStore
(String name) Deprecated.org.apache.kafka.common.header.Headers
headers()
Deprecated.Returns the headers of the current input record; could benull
if it is not available.org.apache.kafka.common.serialization.Serde
<?> keySerde()
Deprecated.org.apache.kafka.streams.StreamsMetrics
metrics()
Deprecated.long
offset()
Deprecated.int
Deprecated.org.apache.kafka.streams.processor.internals.RecordCollector
Deprecated.void
register
(org.apache.kafka.streams.processor.StateStore store, org.apache.kafka.streams.processor.StateRestoreCallback stateRestoreCallbackIsIgnoredInMock) Deprecated.void
Deprecated.Reset the commit capture tofalse
(whether or not it was previouslytrue
).void
Deprecated.Clear the captured forwarded data.org.apache.kafka.streams.processor.Cancellable
schedule
(Duration interval, org.apache.kafka.streams.processor.PunctuationType type, org.apache.kafka.streams.processor.Punctuator callback) Deprecated.Deprecated.Get the punctuators scheduled so far.void
setCurrentStreamTimeMs
(long currentStreamTimeMs) Deprecated.void
setCurrentSystemTimeMs
(long currentSystemTimeMs) Deprecated.void
setHeaders
(org.apache.kafka.common.header.Headers headers) Deprecated.The context exposes this metadata for use in the processor.void
setOffset
(long offset) Deprecated.The context exposes this metadata for use in the processor.void
setPartition
(int partition) Deprecated.The context exposes this metadata for use in the processor.void
setRecordMetadata
(String topic, int partition, long offset, org.apache.kafka.common.header.Headers headers, long timestamp) Deprecated.The context exposes these metadata for use in the processor.void
setRecordTimestamp
(long recordTimestamp) Deprecated.The context exposes this metadata for use in the processor.void
Deprecated.The context exposes this metadata for use in the processor.stateDir()
Deprecated.org.apache.kafka.streams.processor.TaskId
taskId()
Deprecated.long
Deprecated.topic()
Deprecated.org.apache.kafka.common.serialization.Serde
<?> Deprecated.
-
Constructor Details
-
MockProcessorContext
public MockProcessorContext()Deprecated.Create aMockProcessorContext
with dummyconfig
andtaskId
andnull
stateDir
. Most unit tests using this mock won't need to know the taskId, and most unit tests should be able to get by with theInMemoryKeyValueStore
, so the stateDir won't matter. -
MockProcessorContext
Deprecated.Create aMockProcessorContext
with dummytaskId
andnull
stateDir
. Most unit tests using this mock won't need to know the taskId, and most unit tests should be able to get by with theInMemoryKeyValueStore
, so the stateDir won't matter.- Parameters:
config
- a Properties object, used to configure the context and the processor.
-
MockProcessorContext
public MockProcessorContext(Properties config, org.apache.kafka.streams.processor.TaskId taskId, File stateDir) Deprecated.Create aMockProcessorContext
with a specified taskId and null stateDir.- Parameters:
config
- aProperties
object, used to configure the context and the processor.taskId
- aTaskId
, which the context makes available viataskId()
.stateDir
- aFile
, which the context makes available viwstateDir()
.
-
-
Method Details
-
applicationId
Deprecated.- Specified by:
applicationId
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
taskId
public org.apache.kafka.streams.processor.TaskId taskId()Deprecated.- Specified by:
taskId
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
appConfigs
Deprecated.- Specified by:
appConfigs
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
appConfigsWithPrefix
Deprecated.- Specified by:
appConfigsWithPrefix
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
currentSystemTimeMs
public long currentSystemTimeMs()Deprecated.- Specified by:
currentSystemTimeMs
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
currentStreamTimeMs
public long currentStreamTimeMs()Deprecated.- Specified by:
currentStreamTimeMs
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
keySerde
public org.apache.kafka.common.serialization.Serde<?> keySerde()Deprecated.- Specified by:
keySerde
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
valueSerde
public org.apache.kafka.common.serialization.Serde<?> valueSerde()Deprecated.- Specified by:
valueSerde
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
stateDir
Deprecated.- Specified by:
stateDir
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
metrics
public org.apache.kafka.streams.StreamsMetrics metrics()Deprecated.- Specified by:
metrics
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
setRecordMetadata
public void setRecordMetadata(String topic, int partition, long offset, org.apache.kafka.common.header.Headers headers, long timestamp) Deprecated.The context exposes these metadata for use in the processor. Normally, they are set by the Kafka Streams framework, but for the purpose of driving unit tests, you can set them directly.- Parameters:
topic
- A topic namepartition
- A partition numberoffset
- A record offsettimestamp
- A record timestamp
-
setTopic
Deprecated.The context exposes this metadata for use in the processor. Normally, they are set by the Kafka Streams framework, but for the purpose of driving unit tests, you can set it directly. Setting this attribute doesn't affect the others.- Parameters:
topic
- A topic name
-
setPartition
public void setPartition(int partition) Deprecated.The context exposes this metadata for use in the processor. Normally, they are set by the Kafka Streams framework, but for the purpose of driving unit tests, you can set it directly. Setting this attribute doesn't affect the others.- Parameters:
partition
- A partition number
-
setOffset
public void setOffset(long offset) Deprecated.The context exposes this metadata for use in the processor. Normally, they are set by the Kafka Streams framework, but for the purpose of driving unit tests, you can set it directly. Setting this attribute doesn't affect the others.- Parameters:
offset
- A record offset
-
setHeaders
public void setHeaders(org.apache.kafka.common.header.Headers headers) Deprecated.The context exposes this metadata for use in the processor. Normally, they are set by the Kafka Streams framework, but for the purpose of driving unit tests, you can set it directly. Setting this attribute doesn't affect the others.- Parameters:
headers
- Record headers
-
setRecordTimestamp
public void setRecordTimestamp(long recordTimestamp) Deprecated.The context exposes this metadata for use in the processor. Normally, they are set by the Kafka Streams framework, but for the purpose of driving unit tests, you can set it directly. Setting this attribute doesn't affect the others.- Parameters:
recordTimestamp
- A record timestamp
-
setCurrentSystemTimeMs
public void setCurrentSystemTimeMs(long currentSystemTimeMs) Deprecated. -
setCurrentStreamTimeMs
public void setCurrentStreamTimeMs(long currentStreamTimeMs) Deprecated. -
topic
Deprecated.- Specified by:
topic
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
partition
public int partition()Deprecated.- Specified by:
partition
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
offset
public long offset()Deprecated.- Specified by:
offset
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
headers
public org.apache.kafka.common.header.Headers headers()Deprecated.Returns the headers of the current input record; could benull
if it is not available.Note, that headers should never be
null
in the actual Kafka Streams runtime, even if they could be empty. However, this mock does not guarantee non-null
headers. Thus, you either need to add anull
check to your production code to use this mock for testing, or you always need to set headers manually viasetHeaders(Headers)
to avoid aNullPointerException
from yourValueTransformer
implementation.- Specified by:
headers
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
- Returns:
- the headers
-
timestamp
public long timestamp()Deprecated.- Specified by:
timestamp
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
register
public void register(org.apache.kafka.streams.processor.StateStore store, org.apache.kafka.streams.processor.StateRestoreCallback stateRestoreCallbackIsIgnoredInMock) Deprecated.- Specified by:
register
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
getStateStore
Deprecated.- Specified by:
getStateStore
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
schedule
public org.apache.kafka.streams.processor.Cancellable schedule(Duration interval, org.apache.kafka.streams.processor.PunctuationType type, org.apache.kafka.streams.processor.Punctuator callback) throws IllegalArgumentException Deprecated.- Specified by:
schedule
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
- Throws:
IllegalArgumentException
-
scheduledPunctuators
Deprecated.Get the punctuators scheduled so far. The returned list is not affected by subsequent calls toschedule(...)
.- Returns:
- A list of captured punctuators.
-
forward
public <K,V> void forward(K key, V value) Deprecated.- Specified by:
forward
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
forward
public <K,V> void forward(K key, V value, org.apache.kafka.streams.processor.To to) Deprecated.- Specified by:
forward
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
forwarded
Deprecated.Get all the forwarded data this context has observed. The returned list will not be affected by subsequent interactions with the context. The data in the list is in the same order as the calls toforward(...)
.- Returns:
- A list of key/value pairs that were previously passed to the context.
-
forwarded
Deprecated.Get all the forwarded data this context has observed for a specific child by name. The returned list will not be affected by subsequent interactions with the context. The data in the list is in the same order as the calls toforward(...)
.- Parameters:
childName
- The child name to retrieve forwards for- Returns:
- A list of key/value pairs that were previously passed to the context.
-
resetForwards
public void resetForwards()Deprecated.Clear the captured forwarded data. -
commit
public void commit()Deprecated.- Specified by:
commit
in interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
committed
public boolean committed()Deprecated.WhetherProcessorContext.commit()
has been called in this context.- Returns:
true
iffProcessorContext.commit()
has been called in this context since construction or reset.
-
resetCommit
public void resetCommit()Deprecated.Reset the commit capture tofalse
(whether or not it was previouslytrue
). -
recordCollector
public org.apache.kafka.streams.processor.internals.RecordCollector recordCollector()Deprecated.- Specified by:
recordCollector
in interfaceorg.apache.kafka.streams.processor.internals.RecordCollector.Supplier
-
MockProcessorContext
instead.