Package org.apache.nifi.util
Interface TestRunner
- All Known Implementing Classes:
StandardProcessorTestRunner
public interface TestRunner
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddConnection(String relationshipName) Indicates to the Framework that the configured processor has a connection for the Relationship with the given name.voidaddConnection(org.apache.nifi.processor.Relationship relationship) Indicates to the Framework that the configured processor has a connection for the given Relationship.voidaddControllerService(String identifier, org.apache.nifi.controller.ControllerService service) Adds the givenControllerServiceto this TestRunner so that the configured Processor can access it using the givenidentifier.voidaddControllerService(String identifier, org.apache.nifi.controller.ControllerService service, Map<String, String> properties) Adds the givenControllerServiceto this TestRunner so that the configured Processor can access it using the givenidentifier.voidassertAllConditionsMet(String relationshipName, Predicate<MockFlowFile> predicate) Asserts that all FlowFiles meet all conditions.voidassertAllConditionsMet(org.apache.nifi.processor.Relationship relationship, Predicate<MockFlowFile> predicate) Asserts that all FlowFiles meet all conditions.voidassertAllFlowFiles(org.apache.nifi.processor.Relationship relationship, FlowFileValidator validator) Asserts that all FlowFiles that were transferred in the given relationship are compliant with the given validator.voidassertAllFlowFiles(FlowFileValidator validator) Asserts that all FlowFiles that were transferred are compliant with the given validator.voidassertAllFlowFilesContainAttribute(String attributeName) Asserts that all FlowFiles that were transferred contain the given attribute.voidassertAllFlowFilesContainAttribute(org.apache.nifi.processor.Relationship relationship, String attributeName) Asserts that all FlowFiles that were transferred to the given relationship contain the given attribute.voidassertAllFlowFilesTransferred(String relationship) Asserts that all FlowFiles that were transferred were transferred to the given relationshipvoidassertAllFlowFilesTransferred(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 tocountvoidassertAllFlowFilesTransferred(org.apache.nifi.processor.Relationship relationship) Asserts that all FlowFiles that were transferred were transferred to the given relationshipvoidassertAllFlowFilesTransferred(org.apache.nifi.processor.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 tocountvoidassertAttributes(org.apache.nifi.processor.Relationship relationship, Set<String> checkedAttributeNames, Set<Map<String, String>> expectedAttributes) Asserts that flowfiles on a given relationship have a certain set of attributes.voidassertContents(org.apache.nifi.processor.Relationship relationship, List<String> expectedContent) Asserts that flowfiles on a given relationship have certain contents.voidAssert that the currently configured set of properties/annotation data are NOT validvoidassertNotValid(org.apache.nifi.controller.ControllerService service) Assert that the currently configured set of properties/annotation data are NOT valid for the given Controller Service.voidassertPenalizeCount(int count) Assert that the number of FlowFiles that were penalized is equal to the given countvoidassertProvenanceEvent(org.apache.nifi.provenance.ProvenanceEventType eventType) Assert that provenance event was created with the specified event type.voidAssert that there are no FlowFiles left on the input queue.voidAssert that there is at least one FlowFile left on the input queue.voidassertTransferCount(String relationship, int count) Assert that the number of FlowFiles transferred to the given relationship is equal to the given countvoidassertTransferCount(org.apache.nifi.processor.Relationship relationship, int count) Assert that the number of FlowFiles transferred to the given relationship is equal to the given countvoidAssert that the currently configured set of properties/annotation data are validvoidassertValid(org.apache.nifi.controller.ControllerService service) Assert that the currently configured set of properties/annotation data are valid for the given Controller Service.voidClears all set properties from theProcessContext.voidClears the Provenance Events that have been emitted by the ProcessorvoidAllow for clearing the queue from all remaining flow files.voidResets 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.voiddisableControllerService(org.apache.nifi.controller.ControllerService service) Marks the Controller Service as disabled so that it cannot be used by other components.voidenableControllerService(org.apache.nifi.controller.ControllerService service) Marks the Controller Service as enabled so that it can be used by other components.voidenforceReadStreamsClosed(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 givenInputStreaminto 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 givenInputStreaminto 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 givenPathinto 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 givenPathinto memory and creates a FlowFile from this content with the given attributes and adds this FlowFile to the Processor's Input Queuevoidenqueue(org.apache.nifi.flowfile.FlowFile... flowFiles) Enqueues the given FlowFiles into the Processor's input queuebyte[]getContentAsByteArray(MockFlowFile flowFile) Copies the contents of the givenMockFlowFileinto a byte array and returns that byte array.org.apache.nifi.controller.ControllerServicegetControllerService(String identifier) <T extends org.apache.nifi.controller.ControllerService>
TgetControllerService(String identifier, Class<T> serviceType) getControllerServiceLogger(String identifier) Returns theMockComponentLogthat 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(org.apache.nifi.processor.Relationship relationship) Returns a List of FlowFiles in the order in which they were transferred to the given relationshipReturns theMockComponentLogthat is used by the Processor under test.Returns the current value for the given parameter name from the simulated Parameter ContextReturns a List of FlowFiles in the order in which they were transferred that were penalizedorg.apache.nifi.processor.ProcessContextorg.apache.nifi.processor.Processororg.apache.nifi.processor.ProcessSessionFactoryList<org.apache.nifi.provenance.ProvenanceEventRecord> Returns aListof allProvenanceEventRecords that were emitted by the Processororg.apache.nifi.controller.queue.QueueSizeintgetStateManager(org.apache.nifi.controller.ControllerService service) intbooleanisControllerServiceEnabled(org.apache.nifi.controller.ControllerService service) booleanbooleanisValid()booleanCauses the TestRunner to call the Processor'sProcessor.migrateProperties(PropertyConfiguration)method.Causes the TestRunner to call the Processor'sProcessor.migrateRelationships(RelationshipConfiguration)method.voidremoveConnection(String relationshipName) Removes the connection for the relationship with the given name from the configured processor.voidremoveConnection(org.apache.nifi.processor.Relationship relationship) Removes the connection for the given Relationship from the configured processor.voidremoveControllerService(org.apache.nifi.controller.ControllerService service) Removes the Controller Service from the TestRunner.booleanremoveProperty(String property) Removes the property from theProcessContext, effectively setting its value to null, or the property's default value, if it has one.booleanremoveProperty(org.apache.nifi.components.PropertyDescriptor descriptor) Removes thePropertyDescriptorfrom theProcessContext, effectively setting its value to null, or the property's default value, if it has one.booleanremoveProperty(org.apache.nifi.controller.ControllerService controllerService, String property) Removes thePropertyDescriptorfrom the ControllerService, effectively setting its value to null, or the property's default value, if it has one.booleanremoveProperty(org.apache.nifi.controller.ControllerService controllerService, org.apache.nifi.components.PropertyDescriptor descriptor) Removes thePropertyDescriptorfrom the ControllerService, effectively setting its value to null, or the property's default value, if it has one.voidrun()Performs exactly the same operation as callingrun(int)with a value of 1.voidrun(int iterations) Performs the same operation as callingrun(int, boolean)with a value oftruevoidrun(int iterations, boolean stopOnFinish) performs the same operation as callingrun(int, boolean, boolean)with a value ofiterations,stopOnFinish,truevoidrun(int iterations, boolean stopOnFinish, boolean initialize) This method runs theProcessoriterationstimes, using the sequence of steps below: Ifinitializeis true, run all methods on the Processor that are annotated with the@OnScheduledannotation.voidrun(int iterations, boolean stopOnFinish, boolean initialize, long runWait) This method runs theProcessoriterationstimes, using the sequence of steps below: Ifinitializeis true, run all methods on the Processor that are annotated with the@OnScheduledannotation.voidsetAllowRecursiveReads(boolean allow) Specifies whether the TestRunner will allow ProcessSession.read() multiple times for the same FlowFile while an InputStream is already open.voidsetAllowSynchronousSessionCommits(boolean allow) Specifies whether the TestRunner will allow ProcessSession.commit() to be called.voidsetAnnotationData(String annotationData) Sets the annotation data.voidsetAnnotationData(org.apache.nifi.controller.ControllerService service, String annotationData) Sets the annotation data of the given service to the provided annotation data.voidsetClustered(boolean clustered) voidsetConnected(boolean isConnected) voidsetEnvironmentVariableValue(String name, String value) Sets the value of the variable with the given name to be the given value.voidsetIncomingConnection(boolean hasIncomingConnection) Indicates to the framework that the configured processor has one or more incoming connections.voidsetIsConfiguredForClustering(boolean isConfiguredForClustering) voidsetNonLoopConnection(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.voidsetParameterContextValue(String parameterName, String parameterValue) Sets a parameter with the given name and value into the simulated Parameter Context.voidsetPrimaryNode(boolean primaryNode) org.apache.nifi.components.ValidationResultsetProperty(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.org.apache.nifi.components.ValidationResultsetProperty(org.apache.nifi.components.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.org.apache.nifi.components.ValidationResultsetProperty(org.apache.nifi.components.PropertyDescriptor descriptor, org.apache.nifi.components.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.org.apache.nifi.components.ValidationResultsetProperty(org.apache.nifi.controller.ControllerService service, String propertyName, String value) Sets the property with the given name on the given ControllerServiceorg.apache.nifi.components.ValidationResultsetProperty(org.apache.nifi.controller.ControllerService service, org.apache.nifi.components.PropertyDescriptor property, String value) Sets the given property on the given ControllerServiceorg.apache.nifi.components.ValidationResultsetProperty(org.apache.nifi.controller.ControllerService service, org.apache.nifi.components.PropertyDescriptor property, org.apache.nifi.components.DescribedValue value) Sets the given property on the given ControllerServicevoidsetRelationshipAvailable(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.voidsetRelationshipAvailable(org.apache.nifi.processor.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.voidsetRelationshipUnavailable(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.voidsetRelationshipUnavailable(org.apache.nifi.processor.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.voidsetRunSchedule(long runSchedule) Set the Run Schedule parameter (in milliseconds).voidsetThreadCount(int threadCount) voidsetValidateExpressionUsage(boolean validate) Specifies whether or not the TestRunner will validate the use of Expression Language.voidshutdown()Invokes all methods on the Processor that are annotated with the@OnShutdownannotation.voidstop()Invokes all methods on the Processor that are annotated with the@OnStoppedannotation.voidInvokes all methods on the Processor that are annotated with the@OnUnscheduledannotation.Collection<org.apache.nifi.components.ValidationResult> validate()Validates the currently configured set of properties/annotation dataCollection<org.apache.nifi.components.ValidationResult> validate(org.apache.nifi.controller.ControllerService service) Validates the currently configured set of properties/annotation data for the given Controller Service.List<org.apache.nifi.components.ConfigVerificationResult> Verifies the currently configured set of properties/annotation dataList<org.apache.nifi.components.ConfigVerificationResult> Verifies the currently configured set of properties/annotation data for the given Controller Service.
-
Method Details
-
getProcessor
org.apache.nifi.processor.Processor getProcessor()- Returns:
- the
Processorfor which thisTestRunneris configured
-
getProcessSessionFactory
org.apache.nifi.processor.ProcessSessionFactory getProcessSessionFactory()- Returns:
- the
ProcessSessionFactorythat thisTestRunnerwill use to invoke theProcessor.onTrigger(ProcessContext, ProcessSessionFactory)method
-
getProcessContext
org.apache.nifi.processor.ProcessContext getProcessContext()- Returns:
- the
ProcessContextthat thisTestRunnerwill use to invoke theonTriggermethod
-
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 theProcessoriterationstimes, using the sequence of steps below:-
If
initializeis true, run all methods on the Processor that are annotated with the@OnScheduledannotation. If any of these methods throws an Exception, the Unit Test will fail. -
Schedule the
onTriggermethod to be invokediterationstimes. 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@OnUnscheduledannotation 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
shutdownis true: Call all methods on the Processor that is annotated with the@OnStoppedannotation.
- Parameters:
iterations- number of iterationsstopOnFinish- whether or not to run the Processor methods that are annotated with@OnStoppedinitialize- true if must initialize
-
If
-
run
void run(int iterations, boolean stopOnFinish, boolean initialize, long runWait) This method runs theProcessoriterationstimes, using the sequence of steps below:-
If
initializeis true, run all methods on the Processor that are annotated with the@OnScheduledannotation. If any of these methods throws an Exception, the Unit Test will fail. -
Schedule the
onTriggermethod to be invokediterationstimes. 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@OnUnscheduledannotation 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
shutdownis true: Call all methods on the Processor that is annotated with the@OnStoppedannotation.
- Parameters:
iterations- number of iterationsstopOnFinish- whether or not to run the Processor methods that are annotated with@OnStoppedinitialize- true if must initializerunWait- indicates the amount of time in milliseconds that the framework should wait for processors to stop running before calling the@OnUnscheduledannotation
-
If
-
unSchedule
void unSchedule()Invokes all methods on the Processor that are annotated with the@OnUnscheduledannotation. 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@OnStoppedannotation. 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@OnShutdownannotation. 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
org.apache.nifi.components.ValidationResult setProperty(org.apache.nifi.components.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. Otherwise, Assertions.fail() is called, causing the unit test to fail- Parameters:
descriptor- descriptorvalue- value- Returns:
- result
-
setProperty
org.apache.nifi.components.ValidationResult setProperty(org.apache.nifi.components.PropertyDescriptor descriptor, org.apache.nifi.components.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. 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
void assertAllFlowFilesTransferred(org.apache.nifi.processor.Relationship relationship) 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
void assertAllFlowFilesTransferred(org.apache.nifi.processor.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- 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
void assertAllFlowFilesContainAttribute(org.apache.nifi.processor.Relationship relationship, String attributeName) 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
void assertAllFlowFiles(org.apache.nifi.processor.Relationship relationship, FlowFileValidator validator) 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(org.apache.nifi.processor.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
void assertContents(org.apache.nifi.processor.Relationship relationship, List<String> expectedContent) 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
void assertTransferCount(org.apache.nifi.processor.Relationship relationship, int count) 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:
trueif the Input Queue to the Processor is empty,falseotherwise
-
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 -
validate
Collection<org.apache.nifi.components.ValidationResult> validate()Validates the currently configured set of properties/annotation data- Returns:
- a Collection of ValidationResult
-
verify
Verifies the currently configured set of properties/annotation data- Parameters:
variables- the variables to use for verification- Returns:
- a Collection of ConfigVerificationResult
-
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 torunif the output is to be examined after each run. -
enqueue
void enqueue(org.apache.nifi.flowfile.FlowFile... flowFiles) Enqueues the given FlowFiles into the Processor's input queue- Parameters:
flowFiles- to enqueue
-
enqueue
Reads the content from the givenPathinto 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 givenPathinto 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 givenInputStreaminto 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 givenInputStreaminto 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 givenMockFlowFileinto 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
org.apache.nifi.controller.queue.QueueSize getQueueSize()- Returns:
- the current size of the Processor's Input Queue
-
clearQueue
void clearQueue()Allow for clearing the queue from all remaining flow files. -
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
void setRelationshipAvailable(org.apache.nifi.processor.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. This is generally used only when dealing with Processors that use theTriggerWhenAnyDestinationAvailableannotation.- 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
void addConnection(org.apache.nifi.processor.Relationship relationship) 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
void removeConnection(org.apache.nifi.processor.Relationship relationship) 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, org.apache.nifi.controller.ControllerService service) throws org.apache.nifi.reporting.InitializationException Adds the givenControllerServiceto 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 appropriateControllerServiceInitializationContextand initialize the ControllerService with no specified properties. This will call any method on the given Controller Service that is annotated with the@OnAddedannotation.- Parameters:
identifier- of serviceservice- the service- Throws:
org.apache.nifi.reporting.InitializationException- ie
-
addControllerService
void addControllerService(String identifier, org.apache.nifi.controller.ControllerService service, Map<String, String> properties) throws org.apache.nifi.reporting.InitializationExceptionAdds the givenControllerServiceto 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 appropriateControllerServiceInitializationContextand initialize the ControllerService with the given properties. This will call any method on the given Controller Service that is annotated with the@OnAddedannotation.- Parameters:
identifier- of serviceservice- the serviceproperties- service properties- Throws:
org.apache.nifi.reporting.InitializationException- ie
-
enableControllerService
void enableControllerService(org.apache.nifi.controller.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
@OnEnabledannotation.- Parameters:
service- the service to enable
-
disableControllerService
void disableControllerService(org.apache.nifi.controller.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
@OnDisabledannotation.- Parameters:
service- the service to disable
-
isControllerServiceEnabled
boolean isControllerServiceEnabled(org.apache.nifi.controller.ControllerService service) - Parameters:
service- the service- Returns:
trueif the given Controller Service is enabled,falseif 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
void removeControllerService(org.apache.nifi.controller.ControllerService service) Removes the Controller Service from the TestRunner. This will call any method on the ControllerService that is annotated with the
@OnRemovedannotation.- 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
org.apache.nifi.components.ValidationResult setProperty(org.apache.nifi.controller.ControllerService service, org.apache.nifi.components.PropertyDescriptor property, String 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
org.apache.nifi.components.ValidationResult setProperty(org.apache.nifi.controller.ControllerService service, org.apache.nifi.components.PropertyDescriptor property, org.apache.nifi.components.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
org.apache.nifi.components.ValidationResult setProperty(org.apache.nifi.controller.ControllerService service, String propertyName, String value) 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
ControllerServicethat is registered with the given identifier, ornullif no Controller Service exists with the given identifier
-
assertValid
void assertValid(org.apache.nifi.controller.ControllerService service) 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.
-
validate
Collection<org.apache.nifi.components.ValidationResult> validate(org.apache.nifi.controller.ControllerService service) Validates the currently configured set of properties/annotation data for the given Controller Service.- Parameters:
service- the service to validate- Returns:
- a Collection of ValidationResult
-
verify
List<org.apache.nifi.components.ConfigVerificationResult> verify(org.apache.nifi.controller.ControllerService service, Map<String, String> variables) Verifies the currently configured set of properties/annotation data for the given Controller Service.- Parameters:
variables- the variables to use for verification- Returns:
- a Collection of ConfigVerificationResult
-
assertNotValid
void assertNotValid(org.apache.nifi.controller.ControllerService service) 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
<T extends org.apache.nifi.controller.ControllerService> T getControllerService(String identifier, Class<T> serviceType) - Type Parameters:
T- type of service- Parameters:
identifier- identifier of serviceserviceType- type of service- Returns:
- the
ControllerServicethat is registered with the given identifier, cast as the provided service type, ornullif 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 callingevaluateAttributeExpressionson the Property Value or ifevaluateAttributeExpressionsis 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 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- whether to allow asynchronous session commits (i.e., calls to ProcessSession.commit())
-
setAllowRecursiveReads
void setAllowRecursiveReads(boolean allow) Specifies whether the TestRunner will allow ProcessSession.read() multiple times for the same FlowFile while an InputStream is already open. By default, the value isfalse, meaning that any call to ProcessSession.read() for a FlowFile already being read will throw an Exception. See JavaDocs forProcessSession.read(FlowFile)for more information- Parameters:
allow- whether to allow recursive reads of a FlowFile (i.e., calls to ProcessSession.read())
-
removeProperty
boolean removeProperty(org.apache.nifi.components.PropertyDescriptor descriptor) Removes thePropertyDescriptorfrom theProcessContext, effectively setting its value to null, or the property's default value, if it has one.- Parameters:
descriptor- of property to remove- Returns:
trueif removed,falseif the property was not set
-
removeProperty
boolean removeProperty(org.apache.nifi.controller.ControllerService controllerService, org.apache.nifi.components.PropertyDescriptor descriptor) Removes thePropertyDescriptorfrom 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:
trueif removed,falseif 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:
trueif removed,falseif the property was not set
-
removeProperty
boolean removeProperty(org.apache.nifi.controller.ControllerService controllerService, String property) Removes thePropertyDescriptorfrom 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:
trueif removed,falseif the property was not set
-
clearProperties
void clearProperties()Clears all set properties from theProcessContext. -
getProvenanceEvents
List<org.apache.nifi.provenance.ProvenanceEventRecord> getProvenanceEvents()Returns aListof allProvenanceEventRecords 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 theMockComponentLogthat is used by the Processor under test.- Returns:
- the logger
-
getControllerServiceLogger
Returns theMockComponentLogthat 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
nullif 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
-
getParameterContextValue
Returns the current value for the given parameter name from the simulated Parameter Context- Parameters:
name- the name of the parameter from the Parameter Context whose value should be returned.- Returns:
- the current value for the given parameter name from the simulated Parameter Context or
nullif no value is currently set - Throws:
NullPointerException- if the name is null
-
setParameterContextValue
Sets a parameter with the given name and value into the simulated Parameter Context. This makes available the parameter to the properties of the component being tested through parameter referencing such as#{name}.- Parameters:
parameterName- the name of the parameter to setparameterValue- the value of the parameter to set- Throws:
NullPointerException- if the name is null
-
assertAllConditionsMet
Asserts that all FlowFiles meet all conditions.- Parameters:
relationshipName- relationship namepredicate- conditions
-
assertAllConditionsMet
void assertAllConditionsMet(org.apache.nifi.processor.Relationship relationship, Predicate<MockFlowFile> predicate) 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-trueif 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
void assertProvenanceEvent(org.apache.nifi.provenance.ProvenanceEventType eventType) 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
-