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 classDeprecated.static classDeprecated.MockProcessorContext.CapturedPunctuatorholds 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 aMockProcessorContextwith a specified taskId and null stateDir. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.appConfigsWithPrefix(String prefix) Deprecated.Deprecated.voidcommit()Deprecated.booleanDeprecated.WhetherProcessorContext.commit()has been called in this context.longDeprecated.longDeprecated.<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.Headersheaders()Deprecated.Returns the headers of the current input record; could benullif it is not available.org.apache.kafka.common.serialization.Serde<?> keySerde()Deprecated.org.apache.kafka.streams.StreamsMetricsmetrics()Deprecated.longoffset()Deprecated.intDeprecated.org.apache.kafka.streams.processor.internals.RecordCollectorDeprecated.voidregister(org.apache.kafka.streams.processor.StateStore store, org.apache.kafka.streams.processor.StateRestoreCallback stateRestoreCallbackIsIgnoredInMock) Deprecated.voidDeprecated.Reset the commit capture tofalse(whether or not it was previouslytrue).voidDeprecated.Clear the captured forwarded data.org.apache.kafka.streams.processor.Cancellableschedule(Duration interval, org.apache.kafka.streams.processor.PunctuationType type, org.apache.kafka.streams.processor.Punctuator callback) Deprecated.Deprecated.Get the punctuators scheduled so far.voidsetCurrentStreamTimeMs(long currentStreamTimeMs) Deprecated.voidsetCurrentSystemTimeMs(long currentSystemTimeMs) Deprecated.voidsetHeaders(org.apache.kafka.common.header.Headers headers) Deprecated.The context exposes this metadata for use in the processor.voidsetOffset(long offset) Deprecated.The context exposes this metadata for use in the processor.voidsetPartition(int partition) Deprecated.The context exposes this metadata for use in the processor.voidsetRecordMetadata(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.voidsetRecordTimestamp(long recordTimestamp) Deprecated.The context exposes this metadata for use in the processor.voidDeprecated.The context exposes this metadata for use in the processor.stateDir()Deprecated.org.apache.kafka.streams.processor.TaskIdtaskId()Deprecated.longDeprecated.topic()Deprecated.org.apache.kafka.common.serialization.Serde<?> Deprecated.
-
Constructor Details
-
MockProcessorContext
public MockProcessorContext()Deprecated.Create aMockProcessorContextwith dummyconfigandtaskIdandnullstateDir. 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 aMockProcessorContextwith dummytaskIdandnullstateDir. 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 aMockProcessorContextwith a specified taskId and null stateDir.- Parameters:
config- aPropertiesobject, 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:
applicationIdin interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
taskId
public org.apache.kafka.streams.processor.TaskId taskId()Deprecated.- Specified by:
taskIdin interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
appConfigs
Deprecated.- Specified by:
appConfigsin interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
appConfigsWithPrefix
Deprecated.- Specified by:
appConfigsWithPrefixin interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
currentSystemTimeMs
public long currentSystemTimeMs()Deprecated.- Specified by:
currentSystemTimeMsin interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
currentStreamTimeMs
public long currentStreamTimeMs()Deprecated.- Specified by:
currentStreamTimeMsin interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
keySerde
public org.apache.kafka.common.serialization.Serde<?> keySerde()Deprecated.- Specified by:
keySerdein interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
valueSerde
public org.apache.kafka.common.serialization.Serde<?> valueSerde()Deprecated.- Specified by:
valueSerdein interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
stateDir
Deprecated.- Specified by:
stateDirin interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
metrics
public org.apache.kafka.streams.StreamsMetrics metrics()Deprecated.- Specified by:
metricsin 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:
topicin interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
partition
public int partition()Deprecated.- Specified by:
partitionin interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
offset
public long offset()Deprecated.- Specified by:
offsetin 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 benullif it is not available.Note, that headers should never be
nullin the actual Kafka Streams runtime, even if they could be empty. However, this mock does not guarantee non-nullheaders. Thus, you either need to add anullcheck to your production code to use this mock for testing, or you always need to set headers manually viasetHeaders(Headers)to avoid aNullPointerExceptionfrom yourValueTransformerimplementation.- Specified by:
headersin interfaceorg.apache.kafka.streams.processor.ProcessorContext- Returns:
- the headers
-
timestamp
public long timestamp()Deprecated.- Specified by:
timestampin 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:
registerin interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
getStateStore
Deprecated.- Specified by:
getStateStorein 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:
schedulein 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:
forwardin 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:
forwardin 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:
commitin interfaceorg.apache.kafka.streams.processor.ProcessorContext
-
committed
public boolean committed()Deprecated.WhetherProcessorContext.commit()has been called in this context.- Returns:
trueiffProcessorContext.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:
recordCollectorin interfaceorg.apache.kafka.streams.processor.internals.RecordCollector.Supplier
-
MockProcessorContextinstead.