Package org.apache.nifi.util
Class MockProcessSession
java.lang.Object
org.apache.nifi.util.MockProcessSession
- All Implemented Interfaces:
org.apache.nifi.processor.ProcessSession
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanprivate final booleanprivate booleanprivate final Map<Long, MockFlowFile> private final booleanprivate static final AtomicLongprivate final booleanprivate final Map<org.apache.nifi.flowfile.FlowFile, InputStream> private final Map<org.apache.nifi.flowfile.FlowFile, OutputStream> private final Map<Long, MockFlowFile> private final List<MockFlowFile> private final org.apache.nifi.processor.Processorprivate final MockFlowFileQueueprivate final MockProvenanceReporterprivate booleanprivate final SharedSessionStateprivate final org.apache.nifi.components.state.StateManagerprivate final Map<org.apache.nifi.processor.Relationship, List<MockFlowFile>> private final Set<org.apache.nifi.flowfile.FlowFile> -
Constructor Summary
ConstructorsModifierConstructorDescriptionMockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor) MockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor, boolean enforceStreamsClosed, org.apache.nifi.components.state.StateManager stateManager) MockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor, boolean enforceStreamsClosed, org.apache.nifi.components.state.StateManager stateManager, boolean allowSynchronousCommits) MockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor, boolean enforceStreamsClosed, org.apache.nifi.components.state.StateManager stateManager, boolean allowSynchronousCommits, boolean allowRecursiveReads) privateMockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor, boolean enforceStreamsClosed, org.apache.nifi.components.state.StateManager stateManager, boolean allowSynchronousCommits, boolean allowRecursiveReads, boolean failCommit) MockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor, org.apache.nifi.components.state.StateManager stateManager) -
Method Summary
Modifier and TypeMethodDescriptionvoidadjustCounter(String name, long delta, boolean immediate) org.apache.nifi.flowfile.FlowFileappend(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.io.OutputStreamCallback callback) 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.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 tocountvoidAssert that the session has been committedvoidAssert that the session has not been committedvoidAssert thatrollback()has not been calledvoidAssert that there are no FlowFiles left on the input queue.voidAssert that at least one FlowFile is on the input queuevoidAssert thatrollback()has been calledvoidassertTransferCount(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 countstatic MockProcessSession.Builderbuilder(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor) voidClear the 'committed' flag so that we can test that the next iteration ofProcessor.onTrigger(org.apache.nifi.processor.ProcessContext, org.apache.nifi.processor.ProcessSessionFactory)commits or rolls back the sessionvoidClear the 'rolledBack' flag so that we can test that the next iteration ofProcessor.onTrigger(org.apache.nifi.processor.ProcessContext, org.apache.nifi.processor.ProcessSessionFactory)commits or rolls back the sessionvoidclearState(org.apache.nifi.components.state.Scope scope) voidRemoves all state information about FlowFiles that have been transferredclone(org.apache.nifi.flowfile.FlowFile flowFile) clone(org.apache.nifi.flowfile.FlowFile flowFile, long offset, long size) private voidcloseStreams(Map<org.apache.nifi.flowfile.FlowFile, ? extends Closeable> streamMap, boolean enforceClosed) voidcommit()voidvoidcommitAsync(Runnable onSuccess, Consumer<Throwable> onFailure) private voidcreate()create(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles) create(org.apache.nifi.flowfile.FlowFile flowFile) createFlowFile(byte[] data) createFlowFile(byte[] data, Map<String, String> attrs) createFlowFile(File file) private voiddecrementReadCount(org.apache.nifi.flowfile.FlowFile flowFile) voidexportTo(org.apache.nifi.flowfile.FlowFile flowFile, OutputStream out) voidget()List<org.apache.nifi.flowfile.FlowFile> get(int maxResults) List<org.apache.nifi.flowfile.FlowFile> get(org.apache.nifi.processor.FlowFileFilter filter) byte[]getContentAsByteArray(MockFlowFile flowFile) getFlowFilesForRelationship(String relationship) getFlowFilesForRelationship(org.apache.nifi.processor.Relationship relationship) org.apache.nifi.provenance.ProvenanceReporterorg.apache.nifi.controller.queue.QueueSizeintorg.apache.nifi.components.state.StateMapgetState(org.apache.nifi.components.state.Scope scope) importFrom(InputStream in, org.apache.nifi.flowfile.FlowFile flowFile) importFrom(Path path, boolean keepSourceFile, org.apache.nifi.flowfile.FlowFile flowFile) private voidincrementReadCount(org.apache.nifi.flowfile.FlowFile flowFile) private org.apache.nifi.flowfile.FlowFileinheritAttributes(Collection<org.apache.nifi.flowfile.FlowFile> sources, org.apache.nifi.flowfile.FlowFile destination) Inherits the attributes from the given source flow files into the destination flow file.private org.apache.nifi.flowfile.FlowFileinheritAttributes(org.apache.nifi.flowfile.FlowFile source, org.apache.nifi.flowfile.FlowFile destination) Inherits the attributes from the given source flow file into another flow file.intersectAttributes(Collection<org.apache.nifi.flowfile.FlowFile> flowFileList) Returns the attributes that are common to every flow file given.(package private) booleanisFlowFileKnown(org.apache.nifi.flowfile.FlowFile flowFile) Checks if a FlowFile is known in this session.merge(Collection<org.apache.nifi.flowfile.FlowFile> sources, org.apache.nifi.flowfile.FlowFile destination) merge(Collection<org.apache.nifi.flowfile.FlowFile> sources, org.apache.nifi.flowfile.FlowFile destination, byte[] header, byte[] footer, byte[] demarcator) voidmigrate(org.apache.nifi.processor.ProcessSession newOwner) voidmigrate(org.apache.nifi.processor.ProcessSession newOwner, Collection<org.apache.nifi.flowfile.FlowFile> flowFiles) private voidmigrate(MockProcessSession newOwner, Collection<MockFlowFile> flowFiles) penalize(org.apache.nifi.flowfile.FlowFile flowFile) putAllAttributes(org.apache.nifi.flowfile.FlowFile flowFile, Map<String, String> attrs) putAttribute(org.apache.nifi.flowfile.FlowFile flowFile, String attrName, String attrValue) read(org.apache.nifi.flowfile.FlowFile flowFile) voidread(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.io.InputStreamCallback callback) private byte[]readFully(InputStream in) voidremove(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles) voidremove(org.apache.nifi.flowfile.FlowFile flowFile) removeAllAttributes(org.apache.nifi.flowfile.FlowFile flowFile, Pattern keyPattern) removeAllAttributes(org.apache.nifi.flowfile.FlowFile flowFile, Set<String> attrNames) removeAttribute(org.apache.nifi.flowfile.FlowFile flowFile, String attrName) booleanreplaceState(org.apache.nifi.components.state.StateMap oldValue, Map<String, String> newValue, org.apache.nifi.components.state.Scope scope) voidrollback()voidrollback(boolean penalize) voidvoidtransfer(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles) voidtransfer(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles, org.apache.nifi.processor.Relationship relationship) voidtransfer(org.apache.nifi.flowfile.FlowFile flowFile) voidtransfer(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.Relationship relationship) unpenalize(org.apache.nifi.flowfile.FlowFile flowFile) private voidupdateLastQueuedDate(MockFlowFile mockFlowFile) private voidupdateStateWithNewFlowFile(MockFlowFile newFlowFile) private List<org.apache.nifi.flowfile.FlowFile> validateState(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles) private MockFlowFilevalidateState(org.apache.nifi.flowfile.FlowFile flowFile) write(org.apache.nifi.flowfile.FlowFile flowFile) write(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.io.OutputStreamCallback callback) write(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.io.StreamCallback callback) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.nifi.processor.ProcessSession
commitAsync
-
Field Details
-
transferMap
-
processorQueue
-
beingProcessed
-
created
-
penalized
-
processor
private final org.apache.nifi.processor.Processor processor -
currentVersions
-
originalVersions
-
counterMap
-
readRecursionSet
-
writeRecursionSet
-
provenanceReporter
-
enforceStreamsClosed
private final boolean enforceStreamsClosed -
openInputStreams
-
openOutputStreams
-
stateManager
private final org.apache.nifi.components.state.StateManager stateManager -
allowSynchronousCommits
private final boolean allowSynchronousCommits -
allowRecursiveReads
private final boolean allowRecursiveReads -
failCommit
private final boolean failCommit -
committed
private boolean committed -
rolledBack
private boolean rolledBack -
removedFlowFiles
-
enqueuedIndex
-
-
Constructor Details
-
Method Details
-
adjustCounter
- Specified by:
adjustCounterin interfaceorg.apache.nifi.processor.ProcessSession
-
migrate
public void migrate(org.apache.nifi.processor.ProcessSession newOwner) - Specified by:
migratein interfaceorg.apache.nifi.processor.ProcessSession
-
migrate
public void migrate(org.apache.nifi.processor.ProcessSession newOwner, Collection<org.apache.nifi.flowfile.FlowFile> flowFiles) - Specified by:
migratein interfaceorg.apache.nifi.processor.ProcessSession
-
migrate
-
clone
- Specified by:
clonein interfaceorg.apache.nifi.processor.ProcessSession
-
clone
- Specified by:
clonein interfaceorg.apache.nifi.processor.ProcessSession
-
closeStreams
-
commit
public void commit()- Specified by:
commitin interfaceorg.apache.nifi.processor.ProcessSession
-
commitInternal
private void commitInternal() -
commitAsync
public void commitAsync()- Specified by:
commitAsyncin interfaceorg.apache.nifi.processor.ProcessSession
-
commitAsync
- Specified by:
commitAsyncin interfaceorg.apache.nifi.processor.ProcessSession
-
clearCommitted
public void clearCommitted()Clear the 'committed' flag so that we can test that the next iteration ofProcessor.onTrigger(org.apache.nifi.processor.ProcessContext, org.apache.nifi.processor.ProcessSessionFactory)commits or rolls back the session -
clearRollback
public void clearRollback()Clear the 'rolledBack' flag so that we can test that the next iteration ofProcessor.onTrigger(org.apache.nifi.processor.ProcessContext, org.apache.nifi.processor.ProcessSessionFactory)commits or rolls back the session -
create
- Specified by:
createin interfaceorg.apache.nifi.processor.ProcessSession
-
create
- Specified by:
createin interfaceorg.apache.nifi.processor.ProcessSession
-
create
- Specified by:
createin interfaceorg.apache.nifi.processor.ProcessSession
-
exportTo
- Specified by:
exportToin interfaceorg.apache.nifi.processor.ProcessSession
-
exportTo
- Specified by:
exportToin interfaceorg.apache.nifi.processor.ProcessSession
-
get
- Specified by:
getin interfaceorg.apache.nifi.processor.ProcessSession
-
get
- Specified by:
getin interfaceorg.apache.nifi.processor.ProcessSession
-
get
- Specified by:
getin interfaceorg.apache.nifi.processor.ProcessSession
-
getQueueSize
public org.apache.nifi.controller.queue.QueueSize getQueueSize()- Specified by:
getQueueSizein interfaceorg.apache.nifi.processor.ProcessSession
-
importFrom
- Specified by:
importFromin interfaceorg.apache.nifi.processor.ProcessSession
-
importFrom
public MockFlowFile importFrom(Path path, boolean keepSourceFile, org.apache.nifi.flowfile.FlowFile flowFile) - Specified by:
importFromin interfaceorg.apache.nifi.processor.ProcessSession
-
merge
public MockFlowFile merge(Collection<org.apache.nifi.flowfile.FlowFile> sources, org.apache.nifi.flowfile.FlowFile destination) - Specified by:
mergein interfaceorg.apache.nifi.processor.ProcessSession
-
putAllAttributes
public MockFlowFile putAllAttributes(org.apache.nifi.flowfile.FlowFile flowFile, Map<String, String> attrs) - Specified by:
putAllAttributesin interfaceorg.apache.nifi.processor.ProcessSession
-
putAttribute
public MockFlowFile putAttribute(org.apache.nifi.flowfile.FlowFile flowFile, String attrName, String attrValue) - Specified by:
putAttributein interfaceorg.apache.nifi.processor.ProcessSession
-
read
public void read(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.io.InputStreamCallback callback) - Specified by:
readin interfaceorg.apache.nifi.processor.ProcessSession
-
incrementReadCount
private void incrementReadCount(org.apache.nifi.flowfile.FlowFile flowFile) -
decrementReadCount
private void decrementReadCount(org.apache.nifi.flowfile.FlowFile flowFile) -
read
- Specified by:
readin interfaceorg.apache.nifi.processor.ProcessSession
-
remove
public void remove(org.apache.nifi.flowfile.FlowFile flowFile) - Specified by:
removein interfaceorg.apache.nifi.processor.ProcessSession
-
remove
- Specified by:
removein interfaceorg.apache.nifi.processor.ProcessSession
-
removeAllAttributes
public MockFlowFile removeAllAttributes(org.apache.nifi.flowfile.FlowFile flowFile, Set<String> attrNames) - Specified by:
removeAllAttributesin interfaceorg.apache.nifi.processor.ProcessSession
-
removeAllAttributes
public MockFlowFile removeAllAttributes(org.apache.nifi.flowfile.FlowFile flowFile, Pattern keyPattern) - Specified by:
removeAllAttributesin interfaceorg.apache.nifi.processor.ProcessSession
-
removeAttribute
- Specified by:
removeAttributein interfaceorg.apache.nifi.processor.ProcessSession
-
rollback
public void rollback()- Specified by:
rollbackin interfaceorg.apache.nifi.processor.ProcessSession
-
rollback
public void rollback(boolean penalize) - Specified by:
rollbackin interfaceorg.apache.nifi.processor.ProcessSession
-
transfer
public void transfer(org.apache.nifi.flowfile.FlowFile flowFile) - Specified by:
transferin interfaceorg.apache.nifi.processor.ProcessSession
-
updateLastQueuedDate
-
updateStateWithNewFlowFile
-
transfer
- Specified by:
transferin interfaceorg.apache.nifi.processor.ProcessSession
-
transfer
public void transfer(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.Relationship relationship) - Specified by:
transferin interfaceorg.apache.nifi.processor.ProcessSession
-
transfer
public void transfer(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles, org.apache.nifi.processor.Relationship relationship) - Specified by:
transferin interfaceorg.apache.nifi.processor.ProcessSession
-
write
public MockFlowFile write(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.io.OutputStreamCallback callback) - Specified by:
writein interfaceorg.apache.nifi.processor.ProcessSession
-
write
- Specified by:
writein interfaceorg.apache.nifi.processor.ProcessSession
-
append
public org.apache.nifi.flowfile.FlowFile append(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.io.OutputStreamCallback callback) - Specified by:
appendin interfaceorg.apache.nifi.processor.ProcessSession
-
write
public MockFlowFile write(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.io.StreamCallback callback) - Specified by:
writein interfaceorg.apache.nifi.processor.ProcessSession
-
readFully
- Throws:
IOException
-
getFlowFilesForRelationship
public List<MockFlowFile> getFlowFilesForRelationship(org.apache.nifi.processor.Relationship relationship) -
getPenalizedFlowFiles
-
getFlowFilesForRelationship
- Parameters:
relationship- to get flowfiles for- Returns:
- a List of FlowFiles in the order in which they were transferred to the given relationship
-
createFlowFile
- Throws:
IOException
-
createFlowFile
-
createFlowFile
-
merge
public MockFlowFile merge(Collection<org.apache.nifi.flowfile.FlowFile> sources, org.apache.nifi.flowfile.FlowFile destination, byte[] header, byte[] footer, byte[] demarcator) - Specified by:
mergein interfaceorg.apache.nifi.processor.ProcessSession
-
validateState
private List<org.apache.nifi.flowfile.FlowFile> validateState(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles) -
validateState
-
inheritAttributes
private org.apache.nifi.flowfile.FlowFile inheritAttributes(org.apache.nifi.flowfile.FlowFile source, org.apache.nifi.flowfile.FlowFile destination) Inherits the attributes from the given source flow file into another flow file. The UUID of the source becomes the parent UUID of this flow file. If a parent uuid had previously been established it will be replaced by the uuid of the given source- Parameters:
source- the FlowFile from which to copy attributesdestination- the FlowFile to which to copy attributes
-
inheritAttributes
private org.apache.nifi.flowfile.FlowFile inheritAttributes(Collection<org.apache.nifi.flowfile.FlowFile> sources, org.apache.nifi.flowfile.FlowFile destination) Inherits the attributes from the given source flow files into the destination flow file. The UUIDs of the sources becomes the parent UUIDs of the destination flow file. Only attributes which is common to all source items is copied into this flow files attributes. Any previously established parent UUIDs will be replaced by the UUIDs of the sources. It will capture the uuid of a certain number of source objects and may not capture all of them. How many it will capture is unspecified.- Parameters:
sources- to inherit common attributes from
-
intersectAttributes
private static Map<String,String> intersectAttributes(Collection<org.apache.nifi.flowfile.FlowFile> flowFileList) Returns the attributes that are common to every flow file given. The key and value must match exactly.- Parameters:
flowFileList- a list of flow files- Returns:
- the common attributes
-
assertCommitted
public void assertCommitted()Assert that the session has been committed -
assertNotCommitted
public void assertNotCommitted()Assert that the session has not been committed -
assertRolledBack
public void assertRolledBack()Assert thatrollback()has been called -
assertNotRolledBack
public void assertNotRolledBack()Assert thatrollback()has not been called -
assertTransferCount
public 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 validate transfer count ofcount- items transfer to given relationship
-
assertTransferCount
Assert that the number of FlowFiles transferred to the given relationship is equal to the given count- Parameters:
relationship- to validate transfer count ofcount- items transfer to given relationship
-
assertQueueEmpty
public void assertQueueEmpty()Assert that there are no FlowFiles left on the input queue. -
assertQueueNotEmpty
public void assertQueueNotEmpty()Assert that at least one FlowFile is on the input queue -
assertAllFlowFilesTransferred
Asserts that all FlowFiles that were transferred were transferred to the given relationship- Parameters:
relationship- to check for transferred flow files
-
assertAllFlowFilesTransferred
public void assertAllFlowFilesTransferred(org.apache.nifi.processor.Relationship relationship) Asserts that all FlowFiles that were transferred were transferred to the given relationship- Parameters:
relationship- to validate
-
assertAllFlowFiles
Asserts that all FlowFiles that were transferred are compliant with the given validator.- Parameters:
validator- validator to use
-
assertAllFlowFiles
public 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
-
clearTransferState
public void clearTransferState()Removes all state information about FlowFiles that have been transferred -
assertAllFlowFilesTransferred
public 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 validatecount- number of items sent to that relationship (expected)
-
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 validatecount- number of items sent to that relationship (expected)
-
getRemovedCount
public int getRemovedCount()- Returns:
- the number of FlowFiles that were removed
-
getProvenanceReporter
public org.apache.nifi.provenance.ProvenanceReporter getProvenanceReporter()- Specified by:
getProvenanceReporterin interfaceorg.apache.nifi.processor.ProcessSession
-
setState
public void setState(Map<String, String> state, org.apache.nifi.components.state.Scope scope) throws IOException- Specified by:
setStatein interfaceorg.apache.nifi.processor.ProcessSession- Throws:
IOException
-
getState
public org.apache.nifi.components.state.StateMap getState(org.apache.nifi.components.state.Scope scope) throws IOException - Specified by:
getStatein interfaceorg.apache.nifi.processor.ProcessSession- Throws:
IOException
-
replaceState
public boolean replaceState(org.apache.nifi.components.state.StateMap oldValue, Map<String, String> newValue, org.apache.nifi.components.state.Scope scope) throws IOException- Specified by:
replaceStatein interfaceorg.apache.nifi.processor.ProcessSession- Throws:
IOException
-
clearState
- Specified by:
clearStatein interfaceorg.apache.nifi.processor.ProcessSession- Throws:
IOException
-
penalize
- Specified by:
penalizein interfaceorg.apache.nifi.processor.ProcessSession
-
unpenalize
-
getContentAsByteArray
-
isFlowFileKnown
boolean isFlowFileKnown(org.apache.nifi.flowfile.FlowFile flowFile) Checks if a FlowFile is known in this session.- Parameters:
flowFile- the FlowFile to check- Returns:
trueif the FlowFile is known in this session,falseotherwise.