Package org.apache.nifi.util
Class MockProcessSession
java.lang.Object
org.apache.nifi.util.MockProcessSession
- All Implemented Interfaces:
ProcessSession
-
Field Summary
Modifier and TypeFieldDescriptionprivate final boolean
private boolean
private final Map
<Long, MockFlowFile> private final boolean
private static final AtomicLong
private final Map
<FlowFile, InputStream> private final Map
<FlowFile, OutputStream> private final Map
<Long, MockFlowFile> private final List
<MockFlowFile> private final Processor
private final MockFlowFileQueue
private final MockProvenanceReporter
private boolean
private final SharedSessionState
private final StateManager
private final Map
<Relationship, List<MockFlowFile>> -
Constructor Summary
ConstructorDescriptionMockProcessSession
(SharedSessionState sharedState, Processor processor) MockProcessSession
(SharedSessionState sharedState, Processor processor, boolean enforceStreamsClosed, StateManager stateManager) MockProcessSession
(SharedSessionState sharedState, Processor processor, boolean enforceStreamsClosed, StateManager stateManager, boolean allowSynchronousCommits) MockProcessSession
(SharedSessionState sharedState, Processor processor, StateManager stateManager) -
Method Summary
Modifier and TypeMethodDescriptionvoid
adjustCounter
(String name, long delta, boolean immediate) append
(FlowFile flowFile, OutputStreamCallback callback) 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
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
Assert that the session has been committedvoid
Assert that the session has not been committedvoid
Assert thatrollback()
has not been calledvoid
Assert that there are no FlowFiles left on the input queue.void
Assert that at least one FlowFile is on the input queuevoid
Assert thatrollback()
has been calledvoid
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
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 sessionvoid
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 sessionvoid
clearState
(Scope scope) void
Removes all state information about FlowFiles that have been transferredprivate void
closeStreams
(Map<FlowFile, ? extends Closeable> streamMap, boolean enforceClosed) void
commit()
void
void
commitAsync
(Runnable onSuccess, Consumer<Throwable> onFailure) private void
create()
create
(Collection<FlowFile> flowFiles) createFlowFile
(byte[] data) createFlowFile
(byte[] data, Map<String, String> attrs) createFlowFile
(File file) private void
decrementReadCount
(FlowFile flowFile) void
exportTo
(FlowFile flowFile, OutputStream out) void
get()
get
(int maxResults) get
(FlowFileFilter filter) byte[]
getContentAsByteArray
(MockFlowFile flowFile) getFlowFilesForRelationship
(String relationship) getFlowFilesForRelationship
(Relationship relationship) int
importFrom
(InputStream in, FlowFile flowFile) importFrom
(Path path, boolean keepSourceFile, FlowFile flowFile) private void
incrementReadCount
(FlowFile flowFile) private FlowFile
inheritAttributes
(Collection<FlowFile> sources, FlowFile destination) Inherits the attributes from the given source flow files into the destination flow file.private FlowFile
inheritAttributes
(FlowFile source, FlowFile destination) Inherits the attributes from the given source flow file into another flow file.intersectAttributes
(Collection<FlowFile> flowFileList) Returns the attributes that are common to every flow file given.(package private) boolean
isFlowFileKnown
(FlowFile flowFile) Checks if a FlowFile is known in this session.merge
(Collection<FlowFile> sources, FlowFile destination) merge
(Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator) void
migrate
(ProcessSession newOwner) void
migrate
(ProcessSession newOwner, Collection<FlowFile> flowFiles) private void
migrate
(MockProcessSession newOwner, Collection<MockFlowFile> flowFiles) putAllAttributes
(FlowFile flowFile, Map<String, String> attrs) putAttribute
(FlowFile flowFile, String attrName, String attrValue) void
read
(FlowFile flowFile, InputStreamCallback callback) private byte[]
readFully
(InputStream in) void
remove
(Collection<FlowFile> flowFiles) void
removeAllAttributes
(FlowFile flowFile, Pattern keyPattern) removeAllAttributes
(FlowFile flowFile, Set<String> attrNames) removeAttribute
(FlowFile flowFile, String attrName) boolean
void
rollback()
void
rollback
(boolean penalize) void
void
transfer
(Collection<FlowFile> flowFiles) void
transfer
(Collection<FlowFile> flowFiles, Relationship relationship) void
void
transfer
(FlowFile flowFile, Relationship relationship) unpenalize
(FlowFile flowFile) private void
updateLastQueuedDate
(MockFlowFile mockFlowFile) private void
updateStateWithNewFlowFile
(MockFlowFile newFlowFile) validateState
(Collection<FlowFile> flowFiles) private MockFlowFile
validateState
(FlowFile flowFile) write
(FlowFile flowFile, OutputStreamCallback callback) write
(FlowFile flowFile, StreamCallback callback) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.nifi.processor.ProcessSession
commitAsync
-
Field Details
-
transferMap
-
processorQueue
-
beingProcessed
-
created
-
penalized
-
processor
-
currentVersions
-
originalVersions
-
counterMap
-
readRecursionSet
-
writeRecursionSet
-
provenanceReporter
-
enforceStreamsClosed
private final boolean enforceStreamsClosed -
openInputStreams
-
openOutputStreams
-
stateManager
-
allowSynchronousCommits
private final boolean allowSynchronousCommits -
committed
private boolean committed -
rolledback
private boolean rolledback -
removedFlowFiles
-
enqueuedIndex
-
-
Constructor Details
-
Method Details
-
adjustCounter
- Specified by:
adjustCounter
in interfaceProcessSession
-
migrate
- Specified by:
migrate
in interfaceProcessSession
-
migrate
- Specified by:
migrate
in interfaceProcessSession
-
migrate
-
clone
- Specified by:
clone
in interfaceProcessSession
-
clone
- Specified by:
clone
in interfaceProcessSession
-
closeStreams
-
commit
public void commit()- Specified by:
commit
in interfaceProcessSession
-
commitInternal
private void commitInternal() -
commitAsync
public void commitAsync()- Specified by:
commitAsync
in interfaceProcessSession
-
commitAsync
- Specified by:
commitAsync
in interfaceProcessSession
-
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:
create
in interfaceProcessSession
-
create
- Specified by:
create
in interfaceProcessSession
-
create
- Specified by:
create
in interfaceProcessSession
-
exportTo
- Specified by:
exportTo
in interfaceProcessSession
-
exportTo
- Specified by:
exportTo
in interfaceProcessSession
-
get
- Specified by:
get
in interfaceProcessSession
-
get
- Specified by:
get
in interfaceProcessSession
-
get
- Specified by:
get
in interfaceProcessSession
-
getQueueSize
- Specified by:
getQueueSize
in interfaceProcessSession
-
importFrom
- Specified by:
importFrom
in interfaceProcessSession
-
importFrom
- Specified by:
importFrom
in interfaceProcessSession
-
merge
- Specified by:
merge
in interfaceProcessSession
-
putAllAttributes
- Specified by:
putAllAttributes
in interfaceProcessSession
-
putAttribute
- Specified by:
putAttribute
in interfaceProcessSession
-
read
- Specified by:
read
in interfaceProcessSession
-
incrementReadCount
-
decrementReadCount
-
read
- Specified by:
read
in interfaceProcessSession
-
remove
- Specified by:
remove
in interfaceProcessSession
-
remove
- Specified by:
remove
in interfaceProcessSession
-
removeAllAttributes
- Specified by:
removeAllAttributes
in interfaceProcessSession
-
removeAllAttributes
- Specified by:
removeAllAttributes
in interfaceProcessSession
-
removeAttribute
- Specified by:
removeAttribute
in interfaceProcessSession
-
rollback
public void rollback()- Specified by:
rollback
in interfaceProcessSession
-
rollback
public void rollback(boolean penalize) - Specified by:
rollback
in interfaceProcessSession
-
transfer
- Specified by:
transfer
in interfaceProcessSession
-
updateLastQueuedDate
-
updateStateWithNewFlowFile
-
transfer
- Specified by:
transfer
in interfaceProcessSession
-
transfer
- Specified by:
transfer
in interfaceProcessSession
-
transfer
- Specified by:
transfer
in interfaceProcessSession
-
write
- Specified by:
write
in interfaceProcessSession
-
write
- Specified by:
write
in interfaceProcessSession
-
append
- Specified by:
append
in interfaceProcessSession
-
write
- Specified by:
write
in interfaceProcessSession
-
readFully
- Throws:
IOException
-
getFlowFilesForRelationship
-
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<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator) - Specified by:
merge
in interfaceProcessSession
-
validateState
-
validateState
-
inheritAttributes
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
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
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
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
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
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
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
- Specified by:
getProvenanceReporter
in interfaceProcessSession
-
setState
- Specified by:
setState
in interfaceProcessSession
- Throws:
IOException
-
getState
- Specified by:
getState
in interfaceProcessSession
- Throws:
IOException
-
replaceState
public boolean replaceState(StateMap oldValue, Map<String, String> newValue, Scope scope) throws IOException- Specified by:
replaceState
in interfaceProcessSession
- Throws:
IOException
-
clearState
- Specified by:
clearState
in interfaceProcessSession
- Throws:
IOException
-
penalize
- Specified by:
penalize
in interfaceProcessSession
-
unpenalize
-
getContentAsByteArray
-
isFlowFileKnown
Checks if a FlowFile is known in this session.- Parameters:
flowFile
- the FlowFile to check- Returns:
true
if the FlowFile is known in this session,false
otherwise.
-