public class MockProcessSession extends Object implements ProcessSession
Modifier and Type | Field and Description |
---|---|
private Set<Long> |
beingProcessed |
private boolean |
committed |
private Map<String,Long> |
counterMap |
private Map<Long,MockFlowFile> |
currentVersions |
private boolean |
enforceStreamsClosed |
private static AtomicLong |
enqueuedIndex |
private Map<FlowFile,InputStream> |
openInputStreams |
private Map<FlowFile,OutputStream> |
openOutputStreams |
private Map<Long,MockFlowFile> |
originalVersions |
private List<MockFlowFile> |
penalized |
private Processor |
processor |
private MockFlowFileQueue |
processorQueue |
private MockProvenanceReporter |
provenanceReporter |
private Map<FlowFile,Integer> |
readRecursionSet |
private Set<Long> |
removedFlowFiles |
private boolean |
rolledback |
private SharedSessionState |
sharedState |
private StateManager |
stateManager |
private Map<Relationship,List<MockFlowFile>> |
transferMap |
private Set<FlowFile> |
writeRecursionSet |
Constructor and Description |
---|
MockProcessSession(SharedSessionState sharedState,
Processor processor) |
MockProcessSession(SharedSessionState sharedState,
Processor processor,
boolean enforceStreamsClosed,
StateManager stateManager) |
MockProcessSession(SharedSessionState sharedState,
Processor processor,
StateManager stateManager) |
Modifier and Type | Method and Description |
---|---|
void |
adjustCounter(String name,
long delta,
boolean immediate) |
FlowFile |
append(FlowFile flowFile,
OutputStreamCallback callback) |
void |
assertAllFlowFiles(FlowFileValidator validator)
Asserts that all FlowFiles that were transferred are compliant with the
given validator.
|
void |
assertAllFlowFiles(Relationship relationship,
FlowFileValidator validator)
Asserts that all FlowFiles that were transferred in the given relationship
are compliant with the given validator.
|
void |
assertAllFlowFilesTransferred(Relationship relationship)
Asserts that all FlowFiles that were transferred were transferred to the
given relationship
|
void |
assertAllFlowFilesTransferred(Relationship relationship,
int count)
Asserts that all FlowFiles that were transferred were transferred to the
given relationship and that the number of FlowFiles transferred is equal
to
count |
void |
assertAllFlowFilesTransferred(String relationship)
Asserts that all FlowFiles that were transferred were transferred to the
given relationship
|
void |
assertAllFlowFilesTransferred(String relationship,
int count)
Asserts that all FlowFiles that were transferred were transferred to the
given relationship and that the number of FlowFiles transferred is equal
to
count |
void |
assertCommitted()
Assert that
commit() has been called |
void |
assertNotCommitted()
Assert that
commit() has not been called |
void |
assertNotRolledBack()
Assert that
rollback() has not been called |
void |
assertQueueEmpty()
Assert that there are no FlowFiles left on the input queue.
|
void |
assertQueueNotEmpty()
Assert that at least one FlowFile is on the input queue
|
void |
assertRolledBack()
Assert that
rollback() has been called |
void |
assertTransferCount(Relationship relationship,
int count)
Assert that the number of FlowFiles transferred to the given relationship
is equal to the given count
|
void |
assertTransferCount(String relationship,
int count)
Assert that the number of FlowFiles transferred to the given relationship
is equal to the given count
|
void |
clearCommitted()
Clear the 'committed' flag so that we can test that the next iteration of
Processor.onTrigger(org.apache.nifi.processor.ProcessContext, org.apache.nifi.processor.ProcessSessionFactory) commits or rolls back the
session |
void |
clearRollback()
Clear the 'rolledBack' flag so that we can test that the next iteration
of
Processor.onTrigger(org.apache.nifi.processor.ProcessContext, org.apache.nifi.processor.ProcessSessionFactory) commits or rolls back the
session |
void |
clearState(Scope scope) |
void |
clearTransferState()
Removes all state information about FlowFiles that have been transferred
|
MockFlowFile |
clone(FlowFile flowFile) |
MockFlowFile |
clone(FlowFile flowFile,
long offset,
long size) |
private void |
closeStreams(Map<FlowFile,? extends Closeable> streamMap,
boolean enforceClosed) |
void |
commit() |
MockFlowFile |
create() |
MockFlowFile |
create(Collection<FlowFile> flowFiles) |
MockFlowFile |
create(FlowFile flowFile) |
MockFlowFile |
createFlowFile(byte[] data) |
MockFlowFile |
createFlowFile(byte[] data,
Map<String,String> attrs) |
MockFlowFile |
createFlowFile(File file) |
private void |
decrementReadCount(FlowFile flowFile) |
void |
exportTo(FlowFile flowFile,
OutputStream out) |
void |
exportTo(FlowFile flowFile,
Path path,
boolean append) |
MockFlowFile |
get() |
List<FlowFile> |
get(FlowFileFilter filter) |
List<FlowFile> |
get(int maxResults) |
byte[] |
getContentAsByteArray(MockFlowFile flowFile) |
List<MockFlowFile> |
getFlowFilesForRelationship(Relationship relationship) |
List<MockFlowFile> |
getFlowFilesForRelationship(String relationship) |
List<MockFlowFile> |
getPenalizedFlowFiles() |
ProvenanceReporter |
getProvenanceReporter() |
QueueSize |
getQueueSize() |
int |
getRemovedCount() |
StateMap |
getState(Scope scope) |
MockFlowFile |
importFrom(InputStream in,
FlowFile flowFile) |
MockFlowFile |
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.
|
private static Map<String,String> |
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.
|
MockFlowFile |
merge(Collection<FlowFile> sources,
FlowFile destination) |
MockFlowFile |
merge(Collection<FlowFile> sources,
FlowFile destination,
byte[] header,
byte[] footer,
byte[] demarcator) |
private void |
migrate(MockProcessSession newOwner,
Collection<MockFlowFile> flowFiles) |
void |
migrate(ProcessSession newOwner,
Collection<FlowFile> flowFiles) |
MockFlowFile |
penalize(FlowFile flowFile) |
MockFlowFile |
putAllAttributes(FlowFile flowFile,
Map<String,String> attrs) |
MockFlowFile |
putAttribute(FlowFile flowFile,
String attrName,
String attrValue) |
InputStream |
read(FlowFile flowFile) |
void |
read(FlowFile flowFile,
boolean allowSessionStreamManagement,
InputStreamCallback callback) |
void |
read(FlowFile flowFile,
InputStreamCallback callback) |
private byte[] |
readFully(InputStream in) |
void |
remove(Collection<FlowFile> flowFiles) |
void |
remove(FlowFile flowFile) |
MockFlowFile |
removeAllAttributes(FlowFile flowFile,
Pattern keyPattern) |
MockFlowFile |
removeAllAttributes(FlowFile flowFile,
Set<String> attrNames) |
MockFlowFile |
removeAttribute(FlowFile flowFile,
String attrName) |
boolean |
replaceState(StateMap oldValue,
Map<String,String> newValue,
Scope scope) |
void |
rollback() |
void |
rollback(boolean penalize) |
void |
setState(Map<String,String> state,
Scope scope) |
void |
transfer(Collection<FlowFile> flowFiles) |
void |
transfer(Collection<FlowFile> flowFiles,
Relationship relationship) |
void |
transfer(FlowFile flowFile) |
void |
transfer(FlowFile flowFile,
Relationship relationship) |
MockFlowFile |
unpenalize(FlowFile flowFile) |
private void |
updateLastQueuedDate(MockFlowFile mockFlowFile) |
private List<FlowFile> |
validateState(Collection<FlowFile> flowFiles) |
private MockFlowFile |
validateState(FlowFile flowFile) |
OutputStream |
write(FlowFile flowFile) |
MockFlowFile |
write(FlowFile flowFile,
OutputStreamCallback callback) |
MockFlowFile |
write(FlowFile flowFile,
StreamCallback callback) |
private final Map<Relationship,List<MockFlowFile>> transferMap
private final MockFlowFileQueue processorQueue
private final List<MockFlowFile> penalized
private final Processor processor
private final Map<Long,MockFlowFile> currentVersions
private final Map<Long,MockFlowFile> originalVersions
private final SharedSessionState sharedState
private final MockProvenanceReporter provenanceReporter
private final boolean enforceStreamsClosed
private final Map<FlowFile,InputStream> openInputStreams
private final Map<FlowFile,OutputStream> openOutputStreams
private final StateManager stateManager
private boolean committed
private boolean rolledback
private static final AtomicLong enqueuedIndex
public MockProcessSession(SharedSessionState sharedState, Processor processor)
public MockProcessSession(SharedSessionState sharedState, Processor processor, StateManager stateManager)
public MockProcessSession(SharedSessionState sharedState, Processor processor, boolean enforceStreamsClosed, StateManager stateManager)
public void adjustCounter(String name, long delta, boolean immediate)
adjustCounter
in interface ProcessSession
public void migrate(ProcessSession newOwner, Collection<FlowFile> flowFiles)
migrate
in interface ProcessSession
private void migrate(MockProcessSession newOwner, Collection<MockFlowFile> flowFiles)
public MockFlowFile clone(FlowFile flowFile)
clone
in interface ProcessSession
public MockFlowFile clone(FlowFile flowFile, long offset, long size)
clone
in interface ProcessSession
private void closeStreams(Map<FlowFile,? extends Closeable> streamMap, boolean enforceClosed)
public void commit()
commit
in interface ProcessSession
public void clearCommitted()
Processor.onTrigger(org.apache.nifi.processor.ProcessContext, org.apache.nifi.processor.ProcessSessionFactory)
commits or rolls back the
sessionpublic void clearRollback()
Processor.onTrigger(org.apache.nifi.processor.ProcessContext, org.apache.nifi.processor.ProcessSessionFactory)
commits or rolls back the
sessionpublic MockFlowFile create()
create
in interface ProcessSession
public MockFlowFile create(FlowFile flowFile)
create
in interface ProcessSession
public MockFlowFile create(Collection<FlowFile> flowFiles)
create
in interface ProcessSession
public void exportTo(FlowFile flowFile, OutputStream out)
exportTo
in interface ProcessSession
public void exportTo(FlowFile flowFile, Path path, boolean append)
exportTo
in interface ProcessSession
public MockFlowFile get()
get
in interface ProcessSession
public List<FlowFile> get(int maxResults)
get
in interface ProcessSession
public List<FlowFile> get(FlowFileFilter filter)
get
in interface ProcessSession
public QueueSize getQueueSize()
getQueueSize
in interface ProcessSession
public MockFlowFile importFrom(InputStream in, FlowFile flowFile)
importFrom
in interface ProcessSession
public MockFlowFile importFrom(Path path, boolean keepSourceFile, FlowFile flowFile)
importFrom
in interface ProcessSession
public MockFlowFile merge(Collection<FlowFile> sources, FlowFile destination)
merge
in interface ProcessSession
public MockFlowFile putAllAttributes(FlowFile flowFile, Map<String,String> attrs)
putAllAttributes
in interface ProcessSession
public MockFlowFile putAttribute(FlowFile flowFile, String attrName, String attrValue)
putAttribute
in interface ProcessSession
public void read(FlowFile flowFile, InputStreamCallback callback)
read
in interface ProcessSession
public void read(FlowFile flowFile, boolean allowSessionStreamManagement, InputStreamCallback callback)
read
in interface ProcessSession
private void incrementReadCount(FlowFile flowFile)
private void decrementReadCount(FlowFile flowFile)
public InputStream read(FlowFile flowFile)
read
in interface ProcessSession
public void remove(FlowFile flowFile)
remove
in interface ProcessSession
public void remove(Collection<FlowFile> flowFiles)
remove
in interface ProcessSession
public MockFlowFile removeAllAttributes(FlowFile flowFile, Set<String> attrNames)
removeAllAttributes
in interface ProcessSession
public MockFlowFile removeAllAttributes(FlowFile flowFile, Pattern keyPattern)
removeAllAttributes
in interface ProcessSession
public MockFlowFile removeAttribute(FlowFile flowFile, String attrName)
removeAttribute
in interface ProcessSession
public void rollback()
rollback
in interface ProcessSession
public void rollback(boolean penalize)
rollback
in interface ProcessSession
public void transfer(FlowFile flowFile)
transfer
in interface ProcessSession
private void updateLastQueuedDate(MockFlowFile mockFlowFile)
public void transfer(Collection<FlowFile> flowFiles)
transfer
in interface ProcessSession
public void transfer(FlowFile flowFile, Relationship relationship)
transfer
in interface ProcessSession
public void transfer(Collection<FlowFile> flowFiles, Relationship relationship)
transfer
in interface ProcessSession
public MockFlowFile write(FlowFile flowFile, OutputStreamCallback callback)
write
in interface ProcessSession
public OutputStream write(FlowFile flowFile)
write
in interface ProcessSession
public FlowFile append(FlowFile flowFile, OutputStreamCallback callback)
append
in interface ProcessSession
public MockFlowFile write(FlowFile flowFile, StreamCallback callback)
write
in interface ProcessSession
private byte[] readFully(InputStream in) throws IOException
IOException
public List<MockFlowFile> getFlowFilesForRelationship(Relationship relationship)
public List<MockFlowFile> getPenalizedFlowFiles()
public List<MockFlowFile> getFlowFilesForRelationship(String relationship)
relationship
- to get flowfiles forpublic MockFlowFile createFlowFile(File file) throws IOException
IOException
public MockFlowFile createFlowFile(byte[] data)
public MockFlowFile createFlowFile(byte[] data, Map<String,String> attrs)
public MockFlowFile merge(Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator)
merge
in interface ProcessSession
private List<FlowFile> validateState(Collection<FlowFile> flowFiles)
private MockFlowFile validateState(FlowFile flowFile)
private FlowFile inheritAttributes(FlowFile source, FlowFile destination)
source
- the FlowFile from which to copy attributesdestination
- the FlowFile to which to copy attributesprivate FlowFile inheritAttributes(Collection<FlowFile> sources, FlowFile destination)
sources
- to inherit common attributes fromprivate static Map<String,String> intersectAttributes(Collection<FlowFile> flowFileList)
flowFileList
- a list of flow filespublic void assertCommitted()
commit()
has been calledpublic void assertNotCommitted()
commit()
has not been calledpublic void assertRolledBack()
rollback()
has been calledpublic void assertNotRolledBack()
rollback()
has not been calledpublic void assertTransferCount(Relationship relationship, int count)
relationship
- to validate transfer count ofcount
- items transfer to given relationshippublic void assertTransferCount(String relationship, int count)
relationship
- to validate transfer count ofcount
- items transfer to given relationshippublic void assertQueueEmpty()
public void assertQueueNotEmpty()
public void assertAllFlowFilesTransferred(String relationship)
relationship
- to check for transferred flow filespublic void assertAllFlowFilesTransferred(Relationship relationship)
relationship
- to validatepublic void assertAllFlowFiles(FlowFileValidator validator)
validator
- validator to usepublic void assertAllFlowFiles(Relationship relationship, FlowFileValidator validator)
validator
- validator to usepublic void clearTransferState()
public void assertAllFlowFilesTransferred(Relationship relationship, int count)
count
relationship
- to validatecount
- number of items sent to that relationship (expected)public void assertAllFlowFilesTransferred(String relationship, int count)
count
relationship
- to validatecount
- number of items sent to that relationship (expected)public int getRemovedCount()
public ProvenanceReporter getProvenanceReporter()
getProvenanceReporter
in interface ProcessSession
public void setState(Map<String,String> state, Scope scope) throws IOException
setState
in interface ProcessSession
IOException
public StateMap getState(Scope scope) throws IOException
getState
in interface ProcessSession
IOException
public boolean replaceState(StateMap oldValue, Map<String,String> newValue, Scope scope) throws IOException
replaceState
in interface ProcessSession
IOException
public void clearState(Scope scope) throws IOException
clearState
in interface ProcessSession
IOException
public MockFlowFile penalize(FlowFile flowFile)
penalize
in interface ProcessSession
public MockFlowFile unpenalize(FlowFile flowFile)
public byte[] getContentAsByteArray(MockFlowFile flowFile)
boolean isFlowFileKnown(FlowFile flowFile)
flowFile
- the FlowFile to checktrue
if the FlowFile is known in this session,
false
otherwise.Copyright © 2021 Apache NiFi Project. All rights reserved.