Package org.apache.nifi.util
Interface TestRunner
- All Known Implementing Classes:
StandardProcessorTestRunner
public interface TestRunner
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addConnection
(String relationshipName) Indicates to the Framework that the configured processor has a connection for the Relationship with the given name.void
addConnection
(Relationship relationship) Indicates to the Framework that the configured processor has a connection for the given Relationship.void
addControllerService
(String identifier, ControllerService service) Adds the givenControllerService
to this TestRunner so that the configured Processor can access it using the givenidentifier
.void
addControllerService
(String identifier, ControllerService service, Map<String, String> properties) Adds the givenControllerService
to this TestRunner so that the configured Processor can access it using the givenidentifier
.void
assertAllConditionsMet
(String relationshipName, Predicate<MockFlowFile> predicate) Asserts that all FlowFiles meet all conditions.void
assertAllConditionsMet
(Relationship relationship, Predicate<MockFlowFile> predicate) Asserts that all FlowFiles meet all conditions.void
assertAllFlowFiles
(Relationship relationship, FlowFileValidator validator) Asserts that all FlowFiles that were transferred in the given relationship are compliant with the given validator.void
assertAllFlowFiles
(FlowFileValidator validator) Asserts that all FlowFiles that were transferred are compliant with the given validator.void
assertAllFlowFilesContainAttribute
(String attributeName) Asserts that all FlowFiles that were transferred contain the given attribute.void
assertAllFlowFilesContainAttribute
(Relationship relationship, String attributeName) Asserts that all FlowFiles that were transferred to the given relationship contain the given attribute.void
assertAllFlowFilesTransferred
(String relationship) Asserts that all FlowFiles that were transferred were transferred to the given relationshipvoid
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 tocount
void
assertAllFlowFilesTransferred
(Relationship relationship) Asserts that all FlowFiles that were transferred were transferred to the given relationshipvoid
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 tocount
void
assertAttributes
(Relationship relationship, Set<String> checkedAttributeNames, Set<Map<String, String>> expectedAttributes) Asserts that flowfiles on a given relationship have a certain set of attributes.void
assertContents
(Relationship relationship, List<String> expectedContent) Asserts that flowfiles on a given relationship have certain contents.void
Assert that the currently configured set of properties/annotation data are NOT validvoid
assertNotValid
(ControllerService service) Assert that the currently configured set of properties/annotation data are NOT valid for the given Controller Service.void
assertPenalizeCount
(int count) Assert that the number of FlowFiles that were penalized is equal to the given countvoid
assertProvenanceEvent
(ProvenanceEventType eventType) Assert that provenance event was created with the specified event type.void
Assert that there are no FlowFiles left on the input queue.void
Assert that there is at least one FlowFile left on the input queue.void
assertTransferCount
(String relationship, int count) Assert that the number of FlowFiles transferred to the given relationship is equal to the given countvoid
assertTransferCount
(Relationship relationship, int count) Assert that the number of FlowFiles transferred to the given relationship is equal to the given countvoid
Assert that the currently configured set of properties/annotation data are validvoid
assertValid
(ControllerService service) Assert that the currently configured set of properties/annotation data are valid for the given Controller Service.void
Clears all set properties from theProcessContext
.void
Clears the Provenance Events that have been emitted by the Processorvoid
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
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
enforceReadStreamsClosed
(boolean enforce) By default, ifProcessSession.read(FlowFile)
is called, the InputStream that is returned MUST be closed by the processor under test or calls toProcessSession.commit()
will throw an Exception.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 QueueCopies 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 Queueenqueue
(InputStream data) Reads the content from the givenInputStream
into memory and creates a FlowFile from this content with no attributes and adds this FlowFile to the Processor's Input Queueenqueue
(InputStream data, Map<String, String> attributes) Reads the content from the givenInputStream
into memory and creates a FlowFile from this content with the given attributes and adds this FlowFile to the Processor's Input QueueCreates a FlowFile with the content set to the given string (in UTF-8 format), with no attributes, and adds this FlowFile to the Processor's Input QueueCreates a FlowFile with the content set to the given string (in UTF-8 format), with the given attributes, and adds this FlowFile to the Processor's Input QueueReads the content from the givenPath
into memory and creates a FlowFile from this content with no attributes and adds this FlowFile to the Processor's Input QueueReads the content from the givenPath
into memory and creates a FlowFile from this content with the given attributes and adds this FlowFile to the Processor's Input Queuevoid
Enqueues the given FlowFiles into the Processor's input queuebyte[]
getContentAsByteArray
(MockFlowFile flowFile) Copies the contents of the givenMockFlowFile
into a byte array and returns that byte array.getControllerService
(String identifier) <T extends ControllerService>
TgetControllerService
(String identifier, Class<T> serviceType) getControllerServiceLogger
(String identifier) Returns theMockComponentLog
that is used by the specified controller service.getCounterValue
(String name) Returns the current value of the variable with the given namegetFlowFilesForRelationship
(String relationship) Returns a List of FlowFiles in the order in which they were transferred to the given relationshipgetFlowFilesForRelationship
(Relationship relationship) Returns a List of FlowFiles in the order in which they were transferred to the given relationshipReturns theMockComponentLog
that is used by the Processor under test.Returns a List of FlowFiles in the order in which they were transferred that were penalizedReturns aList
of allProvenanceEventRecord
s that were emitted by the Processorint
getStateManager
(ControllerService service) int
boolean
boolean
boolean
isValid()
boolean
Causes the TestRunner to call the Processor'sProcessor.migrateProperties(PropertyConfiguration)
method.Causes the TestRunner to call the Processor'sProcessor.migrateRelationships(RelationshipConfiguration)
method.void
removeConnection
(String relationshipName) Removes the connection for the relationship with the given name from the configured processor.void
removeConnection
(Relationship relationship) Removes the connection for the given Relationship from the configured processor.void
removeControllerService
(ControllerService service) Removes the Controller Service from the TestRunner.boolean
removeProperty
(String property) Removes the property from theProcessContext
, effectively setting its value to null, or the property's default value, if it has one.boolean
removeProperty
(PropertyDescriptor descriptor) Removes thePropertyDescriptor
from theProcessContext
, effectively setting its value to null, or the property's default value, if it has one.boolean
removeProperty
(ControllerService controllerService, String property) Removes thePropertyDescriptor
from the ControllerService, effectively setting its value to null, or the property's default value, if it has one.boolean
removeProperty
(ControllerService controllerService, PropertyDescriptor descriptor) Removes thePropertyDescriptor
from the ControllerService, effectively setting its value to null, or the property's default value, if it has one.void
run()
Performs exactly the same operation as callingrun(int)
with a value of 1.void
run
(int iterations) Performs the same operation as callingrun(int, boolean)
with a value oftrue
void
run
(int iterations, boolean stopOnFinish) performs the same operation as callingrun(int, boolean, boolean)
with a value ofiterations
,stopOnFinish
,true
void
run
(int iterations, boolean stopOnFinish, boolean initialize) This method runs theProcessor
iterations
times, using the sequence of steps below: Ifinitialize
is true, run all methods on the Processor that are annotated with the@OnScheduled
annotation.void
run
(int iterations, boolean stopOnFinish, boolean initialize, long runWait) This method runs theProcessor
iterations
times, using the sequence of steps below: Ifinitialize
is true, run all methods on the Processor that are annotated with the@OnScheduled
annotation.void
setAllowSynchronousSessionCommits
(boolean allow) Specifies whether or not the TestRunner will allow ProcessSession.commit() to be called.void
setAnnotationData
(String annotationData) Sets the annotation data.void
setAnnotationData
(ControllerService service, String annotationData) Sets the annotation data of the given service to the provided annotation data.void
setClustered
(boolean clustered) void
setConnected
(boolean isConnected) void
setEnvironmentVariableValue
(String name, String value) Sets the value of the variable with the given name to be the given value.void
setIncomingConnection
(boolean hasIncomingConnection) Indicates to the framework that the configured processor has one or more incoming connections.void
setIsConfiguredForClustering
(boolean isConfiguredForClustering) void
setNonLoopConnection
(boolean hasNonLoopConnection) Indicates to the framework that the configured processor has one or more incoming connections for which the processor is not also the source.void
setPrimaryNode
(boolean primaryNode) 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.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.setProperty
(PropertyDescriptor descriptor, DescribedValue 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.setProperty
(ControllerService service, String propertyName, String value) Sets the property with the given name on the given ControllerServicesetProperty
(ControllerService service, PropertyDescriptor property, String value) Sets the given property on the given ControllerServicesetProperty
(ControllerService service, PropertyDescriptor property, DescribedValue value) Sets the given property on the given ControllerServicevoid
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
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
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
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
setRunSchedule
(long runSchedule) Set the Run Schedule parameter (in milliseconds).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.void
stop()
Invokes all methods on the Processor that are annotated with the@OnStopped
annotation.void
Invokes all methods on the Processor that are annotated with the@OnUnscheduled
annotation.
-
Method Details
-
getProcessor
Processor getProcessor()- Returns:
- the
Processor
for which thisTestRunner
is configured
-
getProcessSessionFactory
ProcessSessionFactory getProcessSessionFactory()- Returns:
- the
ProcessSessionFactory
that thisTestRunner
will use to invoke theProcessor.onTrigger(ProcessContext, ProcessSessionFactory)
method
-
getProcessContext
ProcessContext getProcessContext()- Returns:
- the
ProcessContext
that thisTestRunner
will use to invoke theonTrigger
method
-
isYieldCalled
boolean isYieldCalled() -
run
void run()Performs exactly the same operation as callingrun(int)
with a value of 1. -
run
void run(int iterations) Performs the same operation as callingrun(int, boolean)
with a value oftrue
- Parameters:
iterations
- number of iterations
-
run
void run(int iterations, boolean stopOnFinish) performs the same operation as callingrun(int, boolean, boolean)
with a value ofiterations
,stopOnFinish
,true
- Parameters:
iterations
- number of iterationsstopOnFinish
- flag to stop when finished
-
run
void run(int iterations, boolean stopOnFinish, boolean initialize) This method runs theProcessor
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. If any of these methods throws an Exception, the Unit Test will fail. -
Schedule the
onTrigger
method to be invokediterations
times. The number of threads used to run these iterations is determined by the ThreadCount of thisTestRunner
. By default, the value is set to 1, but it can be modified by calling thesetThreadCount(int)
method. -
As soon as the first thread finishes its execution of
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. - Waits for all threads to finish execution.
-
If and only if the value of
shutdown
is true: Call all methods on the Processor that is annotated with the@OnStopped
annotation.
- Parameters:
iterations
- number of iterationsstopOnFinish
- whether or not to run the Processor methods that are annotated with@OnStopped
initialize
- true if must initialize
-
If
-
run
void run(int iterations, boolean stopOnFinish, boolean initialize, long runWait) This method runs theProcessor
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. If any of these methods throws an Exception, the Unit Test will fail. -
Schedule the
onTrigger
method to be invokediterations
times. The number of threads used to run these iterations is determined by the ThreadCount of thisTestRunner
. By default, the value is set to 1, but it can be modified by calling thesetThreadCount(int)
method. -
As soon as the first thread finishes its execution of
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. - Waits for all threads to finish execution.
-
If and only if the value of
shutdown
is true: Call all methods on the Processor that is annotated with the@OnStopped
annotation.
- Parameters:
iterations
- number of iterationsstopOnFinish
- whether or not to run the Processor methods that are annotated with@OnStopped
initialize
- true if must initializerunWait
- indicates the amount of time in milliseconds that the framework should wait for processors to stop running before calling the@OnUnscheduled
annotation
-
If
-
unSchedule
void unSchedule()Invokes all methods on the Processor that are annotated with the@OnUnscheduled
annotation. If any of these methods throws an Exception, the Unit Test will fail -
stop
void stop()Invokes all methods on the Processor that are annotated with the@OnStopped
annotation. If any of these methods throws an Exception, the Unit Test will fail -
shutdown
void shutdown()Invokes all methods on the Processor that are annotated with the@OnShutdown
annotation. If any of these methods throws an Exception, the Unit Test will fail -
setThreadCount
void setThreadCount(int threadCount) Updates the number of threads that will be used to run the Processor when calling therun()
orrun(int)
methods.- Parameters:
threadCount
- num threads
-
getThreadCount
int getThreadCount() -
setProperty
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. Otherwise, Assertions.fail() is called, causing the unit test to fail- Parameters:
propertyName
- namepropertyValue
- value- Returns:
- result
-
setProperty
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. Otherwise, Assertions.fail() is called, causing the unit test to fail- Parameters:
descriptor
- descriptorvalue
- value- Returns:
- result
-
setProperty
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. Otherwise, Assertions.fail() is called, causing the unit test to fail- Parameters:
descriptor
- descriptorvalue
- allowable valu- Returns:
- result
-
setAnnotationData
Sets the annotation data.- Parameters:
annotationData
- data
-
assertAllFlowFilesTransferred
Asserts that all FlowFiles that were transferred were transferred to the given relationship- Parameters:
relationship
- to verify
-
assertAllFlowFilesTransferred
Asserts that all FlowFiles that were transferred were transferred to the given relationship- Parameters:
relationship
- to verify
-
assertAllFlowFilesTransferred
Asserts that all FlowFiles that were transferred were transferred to the given relationship and that the number of FlowFiles transferred is equal tocount
- Parameters:
relationship
- to verifycount
- number of expected transfers
-
assertAllFlowFilesTransferred
Asserts that all FlowFiles that were transferred were transferred to the given relationship and that the number of FlowFiles transferred is equal tocount
- Parameters:
relationship
- to verifycount
- number of expected transfers
-
assertAllFlowFilesContainAttribute
Asserts that all FlowFiles that were transferred contain the given attribute.- Parameters:
attributeName
- attribute to look for
-
assertAllFlowFilesContainAttribute
Asserts that all FlowFiles that were transferred to the given relationship contain the given attribute.- Parameters:
relationship
- relationship to checkattributeName
- attribute to look for
-
assertAllFlowFiles
Asserts that all FlowFiles that were transferred are compliant with the given validator.- Parameters:
validator
- validator to use
-
assertAllFlowFiles
Asserts that all FlowFiles that were transferred in the given relationship are compliant with the given validator.- Parameters:
validator
- validator to use
-
assertAttributes
void assertAttributes(Relationship relationship, Set<String> checkedAttributeNames, Set<Map<String, String>> expectedAttributes) Asserts that flowfiles on a given relationship have a certain set of attributes.- Parameters:
relationship
- The relationship on which to check the attributes of flowfilescheckedAttributeNames
- The names of attributes that should be checkedexpectedAttributes
- The expected attributes of all flowfiles
-
assertContents
Asserts that flowfiles on a given relationship have certain contents.- Parameters:
relationship
- The relationship on which to check the contents of flowfilesexpectedContent
- The expected contents of all flowfiles
-
assertTransferCount
Assert that the number of FlowFiles transferred to the given relationship is equal to the given count- Parameters:
relationship
- to verifycount
- number of expected transfers
-
assertTransferCount
Assert that the number of FlowFiles transferred to the given relationship is equal to the given count- Parameters:
relationship
- to verifycount
- number of expected transfers
-
assertPenalizeCount
void assertPenalizeCount(int count) Assert that the number of FlowFiles that were penalized is equal to the given count- Parameters:
count
- number of expected penalized
-
assertQueueEmpty
void assertQueueEmpty()Assert that there are no FlowFiles left on the input queue. -
isQueueEmpty
boolean isQueueEmpty()- Returns:
true
if the Input Queue to the Processor is empty,false
otherwise
-
assertQueueNotEmpty
void assertQueueNotEmpty()Assert that there is at least one FlowFile left on the input queue. -
assertValid
void assertValid()Assert that the currently configured set of properties/annotation data are valid -
isValid
boolean isValid() -
assertNotValid
void assertNotValid()Assert that the currently configured set of properties/annotation data are NOT valid -
clearTransferState
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. This method should be called between successive calls torun
if the output is to be examined after each run. -
enqueue
Enqueues the given FlowFiles into the Processor's input queue- Parameters:
flowFiles
- to enqueue
-
enqueue
Reads the content from the givenPath
into memory and creates a FlowFile from this content with no attributes and adds this FlowFile to the Processor's Input Queue- Parameters:
path
- to read content from- Throws:
IOException
- if unable to read content
-
enqueue
Reads the content from the givenPath
into memory and creates a FlowFile from this content with the given attributes and adds this FlowFile to the Processor's Input Queue- Parameters:
path
- to read content fromattributes
- attributes to use for new flow file- Throws:
IOException
- if unable to read content
-
enqueue
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- Parameters:
data
- to enqueue
-
enqueue
Creates a FlowFile with the content set to the given string (in UTF-8 format), with no attributes, and adds this FlowFile to the Processor's Input Queue- Parameters:
data
- to enqueue
-
enqueue
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- Parameters:
data
- to enqueueattributes
- to use for enqueued item
-
enqueue
Creates a FlowFile with the content set to the given string (in UTF-8 format), with the given attributes, and adds this FlowFile to the Processor's Input Queue- Parameters:
data
- to enqueueattributes
- to use for enqueued item
-
enqueue
Reads the content from the givenInputStream
into memory and creates a FlowFile from this content with no attributes and adds this FlowFile to the Processor's Input Queue- Parameters:
data
- to source data from
-
enqueue
Reads the content from the givenInputStream
into memory and creates a FlowFile from this content with the given attributes and adds this FlowFile to the Processor's Input Queue- Parameters:
data
- source of dataattributes
- to use for flow files
-
getContentAsByteArray
Copies the contents of the givenMockFlowFile
into a byte array and returns that byte array.- Parameters:
flowFile
- to get content for- Returns:
- byte array of flowfile content
-
getFlowFilesForRelationship
Returns a List of FlowFiles in the order in which they were transferred to the given relationship- Parameters:
relationship
- to get flowfiles for- Returns:
- flowfiles transferred to given relationship
-
getFlowFilesForRelationship
Returns a List of FlowFiles in the order in which they were transferred to the given relationship- Parameters:
relationship
- to get flowfiles for- Returns:
- flowfiles transferred to given relationship
-
getPenalizedFlowFiles
List<MockFlowFile> getPenalizedFlowFiles()Returns a List of FlowFiles in the order in which they were transferred that were penalized- Returns:
- flowfiles that were penalized
-
getQueueSize
QueueSize getQueueSize()- Returns:
- the current size of the Processor's Input Queue
-
getCounterValue
- Parameters:
name
- of counter- Returns:
- the current value of the counter with the specified name, or null if no counter exists with the specified name
-
getRemovedCount
int getRemovedCount()- Returns:
- the number of FlowFiles that have been removed from the system
-
setRelationshipAvailable
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. This is generally used only when dealing with Processors that use theTriggerWhenAnyDestinationAvailable
annotation.- Parameters:
relationship
- to mark as available
-
setRelationshipAvailable
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. This is generally used only when dealing with Processors that use theTriggerWhenAnyDestinationAvailable
- Parameters:
relationshipName
- relationship name
-
setIncomingConnection
void setIncomingConnection(boolean hasIncomingConnection) Indicates to the framework that the configured processor has one or more incoming connections.- Parameters:
hasIncomingConnection
- whether or not the configured processor should behave as though it has an incoming connection
-
setNonLoopConnection
void setNonLoopConnection(boolean hasNonLoopConnection) Indicates to the framework that the configured processor has one or more incoming connections for which the processor is not also the source.- Parameters:
hasNonLoopConnection
- whether or not the configured processor should behave as though it has a non-looping incoming connection
-
addConnection
Indicates to the Framework that the configured processor has a connection for the given Relationship.- Parameters:
relationship
- that has a connection
-
addConnection
Indicates to the Framework that the configured processor has a connection for the Relationship with the given name.- Parameters:
relationshipName
- name of relationship that has a connection
-
removeConnection
Removes the connection for the given Relationship from the configured processor.- Parameters:
relationship
- to remove
-
removeConnection
Removes the connection for the relationship with the given name from the configured processor.- Parameters:
relationshipName
- name of the relationship to remove
-
addControllerService
void addControllerService(String identifier, ControllerService service) throws InitializationException Adds the givenControllerService
to this TestRunner so that the configured Processor can access it using the givenidentifier
. The ControllerService is not expected to be initialized, as the framework will create the appropriateControllerServiceInitializationContext
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.- Parameters:
identifier
- of serviceservice
- the service- Throws:
InitializationException
- ie
-
addControllerService
void addControllerService(String identifier, ControllerService service, Map<String, String> properties) throws InitializationExceptionAdds the givenControllerService
to this TestRunner so that the configured Processor can access it using the givenidentifier
. The ControllerService is not expected to be initialized, as the framework will create the appropriateControllerServiceInitializationContext
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.- Parameters:
identifier
- of serviceservice
- the serviceproperties
- service properties- Throws:
InitializationException
- ie
-
enableControllerService
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.- Parameters:
service
- the service to enable
-
disableControllerService
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.- Parameters:
service
- the service to disable
-
isControllerServiceEnabled
- Parameters:
service
- the service- Returns:
true
if the given Controller Service is enabled,false
if it is disabled- Throws:
IllegalArgumentException
- if the given ControllerService is not known by this TestRunner (i.e., it has not been added via theaddControllerService(String, ControllerService)
oraddControllerService(String, ControllerService, Map)
method or if the Controller Service has been removed via theremoveControllerService(ControllerService)
method.
-
removeControllerService
Removes the Controller Service from the TestRunner. This will call any method on the ControllerService that is annotated with the
@OnRemoved
annotation.- Parameters:
service
- the service- Throws:
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 theaddControllerService(String, ControllerService)
oraddControllerService(String, ControllerService, Map)
method or if the Controller Service has been removed via theremoveControllerService(ControllerService)
method.
-
setProperty
Sets the given property on the given ControllerService- Parameters:
service
- to modifyproperty
- to modifyvalue
- value to use- Returns:
- result
- Throws:
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 theaddControllerService(String, ControllerService)
oraddControllerService(String, ControllerService, Map)
method or if the Controller Service has been removed via theremoveControllerService(ControllerService)
method.
-
setProperty
ValidationResult setProperty(ControllerService service, PropertyDescriptor property, DescribedValue value) Sets the given property on the given ControllerService- Parameters:
service
- to modifyproperty
- to modifyvalue
- value to use- Returns:
- result
- Throws:
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 theaddControllerService(String, ControllerService)
oraddControllerService(String, ControllerService, Map)
method or if the Controller Service has been removed via theremoveControllerService(ControllerService)
method.
-
setProperty
Sets the property with the given name on the given ControllerService- Parameters:
service
- to modifypropertyName
- to modifyvalue
- value to use- Returns:
- result
- Throws:
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 theaddControllerService(String, ControllerService)
oraddControllerService(String, ControllerService, Map)
method or if the Controller Service has been removed via theremoveControllerService(ControllerService)
method.
-
setAnnotationData
Sets the annotation data of the given service to the provided annotation data.- Parameters:
service
- to modifyannotationData
- the data- Throws:
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 theaddControllerService(String, ControllerService)
oraddControllerService(String, ControllerService, Map)
method or if the Controller Service has been removed via theremoveControllerService(ControllerService)
method.
-
getControllerService
- Parameters:
identifier
- of controller service- Returns:
- the
ControllerService
that is registered with the given identifier, ornull
if no Controller Service exists with the given identifier
-
assertValid
Assert that the currently configured set of properties/annotation data are valid for the given Controller Service.- Parameters:
service
- the service to validate- Throws:
IllegalArgumentException
- if the given ControllerService is not known by this TestRunner (i.e., it has not been added via theaddControllerService(String, ControllerService)
oraddControllerService(String, ControllerService, Map)
method or if the Controller Service has been removed via theremoveControllerService(ControllerService)
method.
-
assertNotValid
Assert that the currently configured set of properties/annotation data are NOT valid for the given Controller Service.- Parameters:
service
- the service to validate- Throws:
IllegalArgumentException
- if the given ControllerService is not known by this TestRunner (i.e., it has not been added via theaddControllerService(String, ControllerService)
oraddControllerService(String, ControllerService, Map)
method or if the Controller Service has been removed via theremoveControllerService(ControllerService)
method.
-
getControllerService
- Type Parameters:
T
- type of service- Parameters:
identifier
- identifier of serviceserviceType
- type of service- Returns:
- the
ControllerService
that is registered with the given identifier, cast as the provided service type, ornull
if no Controller Service exists with the given identifier - Throws:
ClassCastException
- if the identifier given is registered for a Controller Service but that Controller Service is not of the type specified
-
setValidateExpressionUsage
void setValidateExpressionUsage(boolean validate) Specifies whether or not the TestRunner will validate the use of Expression Language. By default, the value istrue
, which means that an Exception will be thrown if the Processor attempts to obtain the configured value of a Property without callingevaluateAttributeExpressions
on the Property Value or ifevaluateAttributeExpressions
is called but the PropertyDescriptor indicates that the Expression Language is not supported.See Also:
PropertyDescriptor.Builder.expressionLanguageSupported(ExpressionLanguageScope)
- Parameters:
validate
- whether there is any need to validate the EL was used
-
setAllowSynchronousSessionCommits
void setAllowSynchronousSessionCommits(boolean allow) Specifies whether or not the TestRunner will allow ProcessSession.commit() to be called. By default, the value isfalse
, meaning that any call to ProcessSession.commit() will throw an Exception. See JavaDocs forProcessSession.commit()
for more information- Parameters:
allow
- whethr or not to allow asynchronous session commits (i.e., calls to ProcessSession.commit())
-
removeProperty
Removes thePropertyDescriptor
from theProcessContext
, effectively setting its value to null, or the property's default value, if it has one.- Parameters:
descriptor
- of property to remove- Returns:
true
if removed,false
if the property was not set
-
removeProperty
Removes thePropertyDescriptor
from the ControllerService, effectively setting its value to null, or the property's default value, if it has one.- Parameters:
controllerService
- the controller service to remove the property fromdescriptor
- of property to remove- Returns:
true
if removed,false
if the property was not set
-
removeProperty
Removes the property from theProcessContext
, effectively setting its value to null, or the property's default value, if it has one.- Parameters:
property
- name of the property to remove- Returns:
true
if removed,false
if the property was not set
-
removeProperty
Removes thePropertyDescriptor
from the ControllerService, effectively setting its value to null, or the property's default value, if it has one.- Parameters:
controllerService
- the controller service to remove the property fromproperty
- name of the property to remove- Returns:
true
if removed,false
if the property was not set
-
clearProperties
void clearProperties()Clears all set properties from theProcessContext
. -
getProvenanceEvents
List<ProvenanceEventRecord> getProvenanceEvents()Returns aList
of allProvenanceEventRecord
s that were emitted by the Processor- Returns:
- a List of all Provenance Events that were emitted by the Processor
-
clearProvenanceEvents
void clearProvenanceEvents()Clears the Provenance Events that have been emitted by the Processor -
getLogger
MockComponentLog getLogger()Returns theMockComponentLog
that is used by the Processor under test.- Returns:
- the logger
-
getControllerServiceLogger
Returns theMockComponentLog
that is used by the specified controller service.- Parameters:
identifier
- a controller service identifier- Returns:
- the logger
-
getStateManager
MockStateManager getStateManager()- Returns:
- the State Manager that is used to stored and retrieve state
-
getStateManager
- Parameters:
service
- the controller service of interest- Returns:
- the State Manager that is used to store and retrieve state for the given controller service
-
setClustered
void setClustered(boolean clustered) - Parameters:
clustered
- Specify if this test emulates running in a clustered environment
-
setIsConfiguredForClustering
void setIsConfiguredForClustering(boolean isConfiguredForClustering) - Parameters:
isConfiguredForClustering
- Specify if this test emulates running in an environment where the expected cluster state equals with the argument.
-
setPrimaryNode
void setPrimaryNode(boolean primaryNode) - Parameters:
primaryNode
- Specify if this test emulates running as a primary node
-
setConnected
void setConnected(boolean isConnected) - Parameters:
isConnected
- Specify if this test emulates ongoing cluster connection
-
getEnvironmentVariableValue
Returns the current value of the variable with the given name- Parameters:
name
- the name of the variable whose value should be returned.- Returns:
- the current value of the variable with the given name or
null
if no value is currently set - Throws:
NullPointerException
- if the name is null
-
setEnvironmentVariableValue
Sets the value of the variable with the given name to be the given value. This exposes the variable for use by the Expression Language. NOTE - this method is only for testing purposes as we only support variables coming from environment and system variables. This usage is to avoid the need to set env/sys variables in the tests.- Parameters:
name
- the name of the variable to setvalue
- the value of the variable- Throws:
NullPointerException
- if either the name or the value is null
-
assertAllConditionsMet
Asserts that all FlowFiles meet all conditions.- Parameters:
relationshipName
- relationship namepredicate
- conditions
-
assertAllConditionsMet
Asserts that all FlowFiles meet all conditions.- Parameters:
relationship
- relationshippredicate
- conditions
-
enforceReadStreamsClosed
void enforceReadStreamsClosed(boolean enforce) By default, ifProcessSession.read(FlowFile)
is called, the InputStream that is returned MUST be closed by the processor under test or calls toProcessSession.commit()
will throw an Exception. This method allows the developer to indicate explicitly that they do or do not want this functionality. The ProcessSession that is used in the framework when running NiFi does not enforce this, as the framework itself tracks the InputStreams that it returns and ensures that they are properly closed on session commit or rollback. However, it is considered a best practice for Processors to close the streams themselves whenever they are no longer needed. There may be cases, however, where this is not feasible or easy and this method provides developers the ability to indicate that by disabling enforcement so that the framework will handle this.- Parameters:
enforce
-true
if calls to session.commit() should fail if the read streams are not properly closed.
-
setRunSchedule
void setRunSchedule(long runSchedule) Set the Run Schedule parameter (in milliseconds). If set, this will be the duration between two calls of the onTrigger method.- Parameters:
runSchedule
- Run schedule duration in milliseconds.
-
assertProvenanceEvent
Assert that provenance event was created with the specified event type.- Parameters:
eventType
- Provenance event type
-
migrateProperties
PropertyMigrationResult migrateProperties()Causes the TestRunner to call the Processor'sProcessor.migrateProperties(PropertyConfiguration)
method. The effects that are caused by calling the method are applied, as they would be in a running NiFi instance. Unlike in a running NiFi instance, though, the operations that were performed are captured so that they can be examined and assertions made about the migration that occurred.- Returns:
- the results of migrating properties
-
migrateRelationships
RelationshipMigrationResult migrateRelationships()Causes the TestRunner to call the Processor'sProcessor.migrateRelationships(RelationshipConfiguration)
method. The effects that are caused by calling the method are applied, as they would be in a running NiFi instance. Unlike in a running NiFi instance, though, the operations that were performed are captured so that they can be examined and assertions made about the migration that occurred.- Returns:
- the results of migrating relationships
-