public interface TestRunner
Modifier and Type | Method and Description |
---|---|
void |
addControllerService(String identifier,
ControllerService service)
Adds the given
ControllerService to this TestRunner so that the
configured Processor can access it using the given
identifier . |
void |
addControllerService(String identifier,
ControllerService service,
Map<String,String> properties)
Adds the given
ControllerService to this TestRunner so that the
configured Processor can access it using the given
identifier . |
void |
assertAllFlowFilesTransferred(Relationship relationship)
Asserts that all FlowFiles that were transferred were transferred to the
given relationship
|
void |
assertAllFlowFilesTransferred(Relationship relationship,
int count)
Asserts that all FlowFiles that were transferred were transferred to the
given relationship and that the number of FlowFiles transferred is equal
to
count |
void |
assertAllFlowFilesTransferred(String relationship)
Asserts that all FlowFiles that were transferred were transferred to the
given relationship
|
void |
assertAllFlowFilesTransferred(String relationship,
int count)
Asserts that all FlowFiles that were transferred were transferred to the
given relationship and that the number of FlowFiles transferred is equal
to
count |
void |
assertNotValid()
Assert that the currently configured set of properties/annotation data
are NOT valid
|
void |
assertNotValid(ControllerService service)
Assert that the currently configured set of properties/annotation data
are NOT valid for the given Controller Service.
|
void |
assertQueueEmpty()
Assert that there are no FlowFiles left on the input queue.
|
void |
assertQueueNotEmpty()
Assert that there is at least one FlowFile left on the input queue.
|
void |
assertTransferCount(Relationship relationship,
int count)
Assert that the number of FlowFiles transferred to the given relationship
is equal to the given count
|
void |
assertTransferCount(String relationship,
int count)
Assert that the number of FlowFiles transferred to the given relationship
is equal to the given count
|
void |
assertValid()
Assert that the currently configured set of properties/annotation data
are valid
|
void |
assertValid(ControllerService service)
Assert that the currently configured set of properties/annotation data
are valid for the given Controller Service.
|
void |
clearTransferState()
Resets the Transfer Counts that indicate how many FlowFiles have been
transferred to each Relationship and removes from memory any FlowFiles
that have been transferred to this Relationships.
|
void |
disableControllerService(ControllerService service)
Marks the Controller Service as disabled so that it cannot be used by other components.
|
void |
enableControllerService(ControllerService service)
Marks the Controller Service as enabled so that it can be used by other components.
|
void |
enqueue(byte[] data)
Copies the content from the given byte array into memory and creates a
FlowFile from this content with no attributes and adds this FlowFile to
the Processor's Input Queue
|
void |
enqueue(byte[] data,
Map<String,String> attributes)
Copies the content from the given byte array into memory and creates a
FlowFile from this content with the given attributes and adds this
FlowFile to the Processor's Input Queue
|
void |
enqueue(FlowFile... flowFiles)
Enqueues the given FlowFiles into the Processor's input queue
|
void |
enqueue(InputStream data)
Reads the content from the given
InputStream into memory and
creates a FlowFile from this content with no attributes and adds this
FlowFile to the Processor's Input Queue |
void |
enqueue(InputStream data,
Map<String,String> attributes)
Reads the content from the given
InputStream into memory and
creates a FlowFile from this content with the given attributes and adds
this FlowFile to the Processor's Input Queue |
void |
enqueue(Path path)
Reads the content from the given
Path into memory and creates a
FlowFile from this content with no attributes and adds this FlowFile to
the Processor's Input Queue |
void |
enqueue(Path path,
Map<String,String> attributes)
Reads the content from the given
Path into memory and creates a
FlowFile from this content with the given attributes and adds this
FlowFile to the Processor's Input Queue |
byte[] |
getContentAsByteArray(MockFlowFile flowFile)
Copies the contents of the given
MockFlowFile into a byte array
and returns that byte array. |
ControllerService |
getControllerService(String identifier)
Returns the
ControllerService that is registered with the given
identifier, or null if no Controller Service exists with the
given identifier |
<T extends ControllerService> |
getControllerService(String identifier,
Class<T> serviceType)
Returns the
ControllerService that is registered with the given
identifier, cast as the provided service type, or null if no
Controller Service exists with the given identifier |
Long |
getCounterValue(String name)
Returns the current value of the counter with the specified name, or null
if no counter exists with the specified name
|
List<MockFlowFile> |
getFlowFilesForRelationship(Relationship relationship)
Returns a List of FlowFiles in the order in which they were transferred
to the given relationship
|
List<MockFlowFile> |
getFlowFilesForRelationship(String relationship)
Returns a List of FlowFiles in the order in which they were transferred
to the given relationship
|
ProcessContext |
getProcessContext()
Returns the that this
TestRunner will
use to invoke the
onTrigger
method |
Processor |
getProcessor()
Returns the
Processor for which this TestRunner is
configured |
ProcessSessionFactory |
getProcessSessionFactory()
Returns the
ProcessSessionFactory that this
TestRunner will use to invoke the
Processor.onTrigger(ProcessContext, ProcessSessionFactory) method |
ProvenanceReporter |
getProvenanceReporter()
Returns the
ProvenanceReporter that will be used by the
configured Processor for reporting Provenance Events. |
QueueSize |
getQueueSize()
Returns the current size of the Processor's Input Queue
|
int |
getRemovedCount()
Returns the number of FlowFiles that have been removed from the system
|
int |
getThreadCount()
|
boolean |
isControllerServiceEnabled(ControllerService service)
Returns
true if the given Controller Service is enabled, false if it is disabled. |
boolean |
isQueueEmpty()
Returns
true if the Input Queue to the Processor is empty,
false otherwise |
void |
removeControllerService(ControllerService service)
Removes the Controller Service from the TestRunner.
|
boolean |
removeProperty(PropertyDescriptor descriptor)
Removes the
PropertyDescriptor from the ProcessContext ,
effectively setting its value to null. |
void |
run()
Performs exactly the same operation as calling
run(int) with a
value of 1. |
void |
run(int iterations)
Performs the same operation as calling
run(int, boolean) with a
value of true |
void |
run(int iterations,
boolean stopOnFinish)
performs the same operation as calling
#run(int, boolean, int) with a value
of iterations , stopOnFinish , true |
void |
run(int iterations,
boolean stopOnFinish,
boolean initialize)
This method runs the
Processor iterations times,
using the sequence of steps below:
If initialize is true, run all methods on the Processor that are annotated with the
@OnScheduled annotation. |
void |
setAnnotationData(ControllerService service,
String annotationData)
Sets the annontation data of the given service to the provided annotation data.
|
void |
setAnnotationData(String annotationData)
Sets the annontation data.
|
ValidationResult |
setProperty(ControllerService service,
PropertyDescriptor property,
AllowableValue value)
Sets the given property on the given ControllerService
|
ValidationResult |
setProperty(ControllerService service,
PropertyDescriptor property,
String value)
Sets the given property on the given ControllerService
|
ValidationResult |
setProperty(ControllerService service,
String propertyName,
String value)
Sets the property with the given name on the given ControllerService
|
ValidationResult |
setProperty(PropertyDescriptor descriptor,
AllowableValue value)
Updates the value of the property with the given PropertyDescriptor to
the specified value IF and ONLY IF the value is valid according to the
descriptor's validator.
|
ValidationResult |
setProperty(PropertyDescriptor descriptor,
String value)
Updates the value of the property with the given PropertyDescriptor to
the specified value IF and ONLY IF the value is valid according to the
descriptor's validator.
|
ValidationResult |
setProperty(String propertyName,
String propertyValue)
Updates the value of the property with the given PropertyDescriptor to
the specified value IF and ONLY IF the value is valid according to the
descriptor's validator.
|
void |
setRelationshipAvailable(Relationship relationship)
Indicates to the Framework that the given Relationship should be
considered "available", meaning that the queues of all Connections that
contain this Relationship are not full.
|
void |
setRelationshipAvailable(String relationshipName)
Indicates to the Framework that the given Relationship with the given
name should be considered "available", meaning that the queues of all
Connections that contain this Relationship are not full.
|
void |
setRelationshipUnavailable(Relationship relationship)
Indicates to the Framework that the given Relationship should NOT be
considered "available", meaning that the queue of at least one Connection
that contain this Relationship is full.
|
void |
setRelationshipUnavailable(String relationshipName)
Indicates to the Framework that the Relationship with the given name
should NOT be considered "available", meaning that the queue of at least
one Connection that contain this Relationship is full.
|
void |
setThreadCount(int threadCount)
|
void |
setValidateExpressionUsage(boolean validate)
Specifies whether or not the TestRunner will validate the use of
Expression Language.
|
void |
shutdown()
Invokes all methods on the Processor that are annotated with the
@OnShutdown annotation. |
Processor getProcessor()
Processor
for which this TestRunner
is
configuredProcessSessionFactory getProcessSessionFactory()
ProcessSessionFactory
that this
TestRunner
will use to invoke the
Processor.onTrigger(ProcessContext, ProcessSessionFactory)
methodProcessContext getProcessContext()
TestRunner
will
use to invoke the
onTrigger
methodvoid run()
run(int)
with a
value of 1.void run(int iterations)
run(int, boolean)
with a
value of true
iterations
- void run(int iterations, boolean stopOnFinish)
#run(int, boolean, int)
with a value
of iterations
, stopOnFinish
, true
iterations
- stopOnFinish
- void run(int iterations, boolean stopOnFinish, boolean initialize)
Processor
iterations
times,
using the sequence of steps below:
initialize
is true, run all methods on the Processor that are annotated with the
@OnScheduled
annotation. If
any of these methods throws an Exception, the Unit Test will fail.
onTrigger
method to be invoked iterations
times. The number of threads
used to run these iterations is determined by the ThreadCount of this
TestRunner
. By default, the value is set to 1, but it can be
modified by calling the setThreadCount(int)
method.
onTrigger
,
all methods on the Processor that are annotated with the
@OnUnscheduled
annotation
are invoked. If any of these methods throws an Exception, the Unit Test
will fail.
shutdown
is true: Call all
methods on the Processor that is annotated with the
@OnStopped
annotation.
iterations
- stopOnFinish
- whether or not to run the Processor methods that are
annotated with @OnStopped
void shutdown()
@OnShutdown
annotation. If
any of these methods throws an Exception, the Unit Test will failvoid setThreadCount(int threadCount)
run()
or run(int)
methods.threadCount
- int getThreadCount()
run()
or run(int)
methods.ValidationResult setProperty(String propertyName, String propertyValue)
propertyName
- propertyValue
- ValidationResult setProperty(PropertyDescriptor descriptor, String value)
descriptor
- value
- ValidationResult setProperty(PropertyDescriptor descriptor, AllowableValue value)
descriptor
- value
- void setAnnotationData(String annotationData)
annotationData
- void assertAllFlowFilesTransferred(String relationship)
relationship
- void assertAllFlowFilesTransferred(Relationship relationship)
relationship
- void assertAllFlowFilesTransferred(String relationship, int count)
count
relationship
- count
- void assertAllFlowFilesTransferred(Relationship relationship, int count)
count
relationship
- count
- void assertTransferCount(Relationship relationship, int count)
relationship
- count
- void assertTransferCount(String relationship, int count)
relationship
- count
- void assertQueueEmpty()
boolean isQueueEmpty()
true
if the Input Queue to the Processor is empty,
false
otherwisevoid assertQueueNotEmpty()
void assertValid()
void assertNotValid()
void clearTransferState()
run
if the output is
to be examined after each run.void enqueue(FlowFile... flowFiles)
flowFiles
- void enqueue(Path path) throws IOException
Path
into memory and creates a
FlowFile from this content with no attributes and adds this FlowFile to
the Processor's Input Queuepath
- IOException
void enqueue(Path path, Map<String,String> attributes) throws IOException
Path
into memory and creates a
FlowFile from this content with the given attributes and adds this
FlowFile to the Processor's Input Queuepath
- attributes
- IOException
void enqueue(byte[] data)
data
- void enqueue(byte[] data, Map<String,String> attributes)
data
- attributes
- void enqueue(InputStream data)
InputStream
into memory and
creates a FlowFile from this content with no attributes and adds this
FlowFile to the Processor's Input Queuedata
- void enqueue(InputStream data, Map<String,String> attributes)
InputStream
into memory and
creates a FlowFile from this content with the given attributes and adds
this FlowFile to the Processor's Input Queuedata
- attributes
- byte[] getContentAsByteArray(MockFlowFile flowFile)
MockFlowFile
into a byte array
and returns that byte array.flowFile
- List<MockFlowFile> getFlowFilesForRelationship(String relationship)
relationship
- List<MockFlowFile> getFlowFilesForRelationship(Relationship relationship)
relationship
- ProvenanceReporter getProvenanceReporter()
ProvenanceReporter
that will be used by the
configured Processor
for reporting Provenance Events.QueueSize getQueueSize()
Long getCounterValue(String name)
name
- int getRemovedCount()
void setRelationshipAvailable(Relationship relationship)
relationship
- void setRelationshipAvailable(String relationshipName)
relationshipName
- void setRelationshipUnavailable(Relationship relationship)
relationship
- void setRelationshipUnavailable(String relationshipName)
relationshipName
- void addControllerService(String identifier, ControllerService service) throws InitializationException
ControllerService
to this TestRunner so that the
configured Processor can access it using the given
identifier
. The ControllerService is not expected to be
initialized, as the framework will create the appropriate
ControllerServiceInitializationContext
and initialize the ControllerService with no specified properties.
This will call any method on the given Controller Service that is annotated with
the @OnAdded
annotation.identifier
- service
- InitializationException
void addControllerService(String identifier, ControllerService service, Map<String,String> properties) throws InitializationException
ControllerService
to this TestRunner so that the
configured Processor can access it using the given
identifier
. The ControllerService is not expected to be
initialized, as the framework will create the appropriate
ControllerServiceInitializationContext
and initialize the ControllerService with the given properties.
This will call any method on the given Controller Service that is annotated with
the @OnAdded
annotation.identifier
- service
- properties
- InitializationException
void enableControllerService(ControllerService service)
Marks the Controller Service as enabled so that it can be used by other components.
This method will result in calling any method in the Controller Service that is
annotated with the @OnEnabled
annotation.
service
- void disableControllerService(ControllerService service)
Marks the Controller Service as disabled so that it cannot be used by other components.
This method will result in calling any method in the Controller Service that is
annotated with the @OnDisabled
annotation.
service
- boolean isControllerServiceEnabled(ControllerService service)
Returns true
if the given Controller Service is enabled, false
if it is disabled.
service
- IllegalArgumentException
- if the given ControllerService is not known by this TestRunner
(i.e., it has not been added via the addControllerService(String, ControllerService)
or
addControllerService(String, ControllerService, Map)
method or if the Controller Service
has been removed via the removeControllerService(ControllerService)
method.void removeControllerService(ControllerService service)
Removes the Controller Service from the TestRunner. This will call any method on the ControllerService
that is annotated with the @OnRemoved
annotation.
service
- IllegalStateException
- if the ControllerService is not disabledIllegalArgumentException
- if the given ControllerService is not known by this TestRunner
(i.e., it has not been added via the addControllerService(String, ControllerService)
or
addControllerService(String, ControllerService, Map)
method or if the Controller Service
has been removed via the removeControllerService(ControllerService)
method.ValidationResult setProperty(ControllerService service, PropertyDescriptor property, String value)
service
- property
- value
- IllegalStateException
- if the ControllerService is not disabledIllegalArgumentException
- if the given ControllerService is not known by this TestRunner
(i.e., it has not been added via the addControllerService(String, ControllerService)
or
addControllerService(String, ControllerService, Map)
method or if the Controller Service
has been removed via the removeControllerService(ControllerService)
method.ValidationResult setProperty(ControllerService service, PropertyDescriptor property, AllowableValue value)
service
- property
- value
- IllegalStateException
- if the ControllerService is not disabledIllegalArgumentException
- if the given ControllerService is not known by this TestRunner
(i.e., it has not been added via the addControllerService(String, ControllerService)
or
addControllerService(String, ControllerService, Map)
method or if the Controller Service
has been removed via the removeControllerService(ControllerService)
method.ValidationResult setProperty(ControllerService service, String propertyName, String value)
service
- property
- value
- IllegalStateException
- if the ControllerService is not disabledIllegalArgumentException
- if the given ControllerService is not known by this TestRunner
(i.e., it has not been added via the addControllerService(String, ControllerService)
or
addControllerService(String, ControllerService, Map)
method or if the Controller Service
has been removed via the removeControllerService(ControllerService)
method.void setAnnotationData(ControllerService service, String annotationData)
service
- annotationData
- IllegalStateException
- if the Controller Service is not disabledIllegalArgumentException
- if the given ControllerService is not known by this TestRunner
(i.e., it has not been added via the addControllerService(String, ControllerService)
or
addControllerService(String, ControllerService, Map)
method or if the Controller Service
has been removed via the removeControllerService(ControllerService)
method.ControllerService getControllerService(String identifier)
ControllerService
that is registered with the given
identifier, or null
if no Controller Service exists with the
given identifieridentifier
- void assertValid(ControllerService service)
IllegalArgumentException
- if the given ControllerService is not known by this TestRunner
(i.e., it has not been added via the addControllerService(String, ControllerService)
or
addControllerService(String, ControllerService, Map)
method or if the Controller Service
has been removed via the removeControllerService(ControllerService)
method.void assertNotValid(ControllerService service)
IllegalArgumentException
- if the given ControllerService is not known by this TestRunner
(i.e., it has not been added via the addControllerService(String, ControllerService)
or
addControllerService(String, ControllerService, Map)
method or if the Controller Service
has been removed via the removeControllerService(ControllerService)
method.<T extends ControllerService> T getControllerService(String identifier, Class<T> serviceType)
ControllerService
that is registered with the given
identifier, cast as the provided service type, or null
if no
Controller Service exists with the given identifierT
- identifier
- serviceType
- ClassCastException
- if the identifier given is registered for a
Controller Service but that Controller Service is not of the type
specifiedvoid setValidateExpressionUsage(boolean validate)
true
, which
means that an Exception will be thrown if the Processor attempts to
obtain the configured value of a Property without calling
evaluateAttributeExpressions
on the Property Value or if
evaluateAttributeExpressions
is called but the PropertyDescriptor indicates that the Expression
Language is not supported.
See Also:
PropertyDescriptor.Builder#expressionLanguageSupported(boolean)
validate
- boolean removeProperty(PropertyDescriptor descriptor)
PropertyDescriptor
from the ProcessContext
,
effectively setting its value to null.descriptor
- Copyright © 2015 Apache NiFi(incubating) Project. All rights reserved.