public class MockProcessSession extends java.lang.Object implements ProcessSession
Constructor and Description |
---|
MockProcessSession(SharedSessionState sharedState,
Processor processor) |
MockProcessSession(SharedSessionState sharedState,
Processor processor,
boolean enforceStreamsClosed) |
Modifier and Type | Method and Description |
---|---|
void |
adjustCounter(java.lang.String name,
long delta,
boolean immediate)
Adjusts counter data for the given counter name and takes care of
registering the counter if not already present.
|
FlowFile |
append(FlowFile flowFile,
OutputStreamCallback callback)
Executes the given callback against the content corresponding to the
given FlowFile, such that any data written to the OutputStream of the
content will be appended to the end of FlowFile.
|
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(java.lang.String relationship)
Asserts that all FlowFiles that were transferred were transferred to the
given relationship
|
void |
assertAllFlowFilesTransferred(java.lang.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(java.lang.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 |
clearTransferState()
Removes all state information about FlowFiles that have been transferred
|
MockFlowFile |
clone(FlowFile flowFile)
Creates a new FlowFile that is a clone of the given FlowFile as of the
time this is called, both in content and attributes.
|
MockFlowFile |
clone(FlowFile flowFile,
long offset,
long size)
Creates a new FlowFile whose parent is the given FlowFile.
|
void |
commit()
Commits the current session ensuring all operations against FlowFiles
within this session are atomically persisted.
|
MockFlowFile |
create()
Creates a new FlowFile in the repository with no content and without any
linkage to a parent FlowFile.
|
MockFlowFile |
create(java.util.Collection<FlowFile> flowFiles)
Creates a new FlowFile in the repository with no content but with a
parent linkage to the FlowFiles specified by the parents Collection.
|
MockFlowFile |
create(FlowFile flowFile)
Creates a new FlowFile in the repository with no content but with a
parent linkage to
parent . |
MockFlowFile |
createFlowFile(byte[] data) |
MockFlowFile |
createFlowFile(byte[] data,
java.util.Map<java.lang.String,java.lang.String> attrs) |
MockFlowFile |
createFlowFile(java.io.File file) |
void |
exportTo(FlowFile flowFile,
java.io.OutputStream out)
Writes the content of the given FlowFile to the given destination stream
|
void |
exportTo(FlowFile flowFile,
java.nio.file.Path path,
boolean append)
Writes the content of the given FlowFile to the given destination path.
|
MockFlowFile |
get() |
java.util.List<FlowFile> |
get(FlowFileFilter filter)
Returns all FlowFiles from all of the incoming queues for which the given
FlowFileFilter indicates should be accepted. |
java.util.List<FlowFile> |
get(int maxResults)
Returns up to
maxResults FlowFiles from the work queue. |
byte[] |
getContentAsByteArray(MockFlowFile flowFile) |
java.util.List<MockFlowFile> |
getFlowFilesForRelationship(Relationship relationship) |
java.util.List<MockFlowFile> |
getFlowFilesForRelationship(java.lang.String relationship) |
java.util.List<MockFlowFile> |
getPenalizedFlowFiles() |
ProvenanceReporter |
getProvenanceReporter()
Returns a ProvenanceReporter that is tied to this ProcessSession.
|
QueueSize |
getQueueSize() |
int |
getRemovedCount() |
MockFlowFile |
importFrom(java.io.InputStream in,
FlowFile flowFile)
Writes to the given FlowFile all content from the given content path.
|
MockFlowFile |
importFrom(java.nio.file.Path path,
boolean keepSourceFile,
FlowFile flowFile)
Writes to the given FlowFile all content from the given content path.
|
MockFlowFile |
merge(java.util.Collection<FlowFile> sources,
FlowFile destination)
Combines the content of all given source FlowFiles into a single given
destination FlowFile.
|
MockFlowFile |
merge(java.util.Collection<FlowFile> sources,
FlowFile destination,
byte[] header,
byte[] footer,
byte[] demarcator)
Combines the content of all given source FlowFiles into a single given
destination FlowFile.
|
void |
migrate(ProcessSession newOwner,
java.util.Collection<FlowFile> flowFiles)
Migrates ownership of the given FlowFiles from
this to the given newOwner . |
MockFlowFile |
penalize(FlowFile flowFile)
Sets a penalty for the given FlowFile which will make it unavailable to
be operated on any further during the penalty period.
|
MockFlowFile |
putAllAttributes(FlowFile flowFile,
java.util.Map<java.lang.String,java.lang.String> attrs)
Updates the given FlowFiles attributes with the given key/value pairs.
|
MockFlowFile |
putAttribute(FlowFile flowFile,
java.lang.String attrName,
java.lang.String attrValue)
Updates the given FlowFiles attributes with the given key/value pair.
|
java.io.InputStream |
read(FlowFile flowFile)
Provides an InputStream that can be used to read the contents of the given FlowFile.
|
void |
read(FlowFile flowFile,
boolean allowSessionStreamManagement,
InputStreamCallback callback)
Executes the given callback against the contents corresponding to the
given FlowFile.
|
void |
read(FlowFile flowFile,
InputStreamCallback callback)
Executes the given callback against the contents corresponding to the
given FlowFile.
|
void |
remove(java.util.Collection<FlowFile> flowFiles)
Ends the managed persistence for the given FlowFiles.
|
void |
remove(FlowFile flowFile)
Ends the managed persistence for the given FlowFile.
|
MockFlowFile |
removeAllAttributes(FlowFile flowFile,
java.util.regex.Pattern keyPattern)
Remove all attributes from the given FlowFile that have keys which match
the given pattern.
|
MockFlowFile |
removeAllAttributes(FlowFile flowFile,
java.util.Set<java.lang.String> attrNames)
Removes the attributes with the given keys from the given FlowFile.
|
MockFlowFile |
removeAttribute(FlowFile flowFile,
java.lang.String attrName)
Removes the given FlowFile attribute with the given key.
|
void |
rollback()
Reverts any changes made during this session.
|
void |
rollback(boolean penalize)
Reverts any changes made during this session.
|
void |
transfer(java.util.Collection<FlowFile> flowFiles)
Transfers the given FlowFiles back to the work queues from which the
FlowFiles were pulled.
|
void |
transfer(java.util.Collection<FlowFile> flowFiles,
Relationship relationship)
Transfers the given FlowFile to the appropriate destination processor
work queue(s) based on the given relationship.
|
void |
transfer(FlowFile flowFile)
Transfers the given FlowFile back to the work queue from which it was
pulled.
|
void |
transfer(FlowFile flowFile,
Relationship relationship)
Transfers the given FlowFile to the appropriate destination processor
work queue(s) based on the given relationship.
|
java.io.OutputStream |
write(FlowFile flowFile)
Provides an OutputStream that can be used to write to the contents of the
given FlowFile.
|
MockFlowFile |
write(FlowFile flowFile,
OutputStreamCallback callback)
Executes the given callback against the content corresponding to the
given FlowFile.
|
MockFlowFile |
write(FlowFile flowFile,
StreamCallback callback)
Executes the given callback against the content corresponding to the
given flow file.
|
public MockProcessSession(SharedSessionState sharedState, Processor processor)
public MockProcessSession(SharedSessionState sharedState, Processor processor, boolean enforceStreamsClosed)
public void adjustCounter(java.lang.String name, long delta, boolean immediate)
ProcessSession
adjustCounter
in interface ProcessSession
name
- the name of the counterdelta
- the delta by which to modify the counter (+ or -)immediate
- if true, the counter will be updated immediately,
without regard to whether the ProcessSession is commit or rolled back;
otherwise, the counter will be incremented only if and when the
ProcessSession is committed.public void migrate(ProcessSession newOwner, java.util.Collection<FlowFile> flowFiles)
ProcessSession
Migrates ownership of the given FlowFiles from this
to the given newOwner
.
When calling this method, all of the following pre-conditions must be met:
ProcessSession.write(FlowFile, OutputStreamCallback)
, ProcessSession.write(FlowFile, StreamCallback)
,
ProcessSession.read(FlowFile, InputStreamCallback)
, ProcessSession.read(FlowFile, boolean, InputStreamCallback)
for any of
the given FlowFiles.ProcessSession.read(FlowFile)
).ProcessSession.write(FlowFile)
.ProcessSession.create(FlowFile)
and passing the FlowFile
as the argument), then all children that were created must also be in the Collection of provided FlowFiles.
Also note, that if any FlowFile given is not the most up-to-date version of that FlowFile, then the most up-to-date
version of the FlowFile will be migrated to the new owner. For example, if a call to ProcessSession.putAttribute(FlowFile, String, String)
is made,
passing flowFile1
as the FlowFile, and then flowFile1
is passed to this method, then the newest version (including the
newly added attribute) will be migrated, not the outdated version of the FlowFile that flowFile1
points to.
migrate
in interface ProcessSession
newOwner
- the ProcessSession that is to become the new owner of all FlowFiles
that currently belong to this
.flowFiles
- the FlowFiles to migratepublic MockFlowFile clone(FlowFile flowFile)
ProcessSession
clone
in interface ProcessSession
flowFile
- FlowFile to be the source of cloning - given FlowFile must
be a part of the given sessionpublic MockFlowFile clone(FlowFile flowFile, long offset, long size)
ProcessSession
clone
in interface ProcessSession
flowFile
- to base the new flowfile attributes onoffset
- of the parent flowfile to base the child flowfile content onsize
- of the new flowfile from the offsetpublic void commit()
ProcessSession
Commits the current session ensuring all operations against FlowFiles within this session are atomically persisted. All FlowFiles operated on within this session must be accounted for by transfer or removal or the commit will fail.
As soon as the commit completes the session is again ready to be used
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()
ProcessSession
ProcessSession.create(FlowFile)
or
ProcessSession.create(Collection)
.
When this method is used, a Provenance CREATE or RECEIVE Event should be
generated. See the ProcessSession.getProvenanceReporter()
method and
ProvenanceReporter
class for more informationcreate
in interface ProcessSession
public MockFlowFile create(FlowFile flowFile)
ProcessSession
parent
. The newly created FlowFile will
inherit all of the parent's attributes except for the UUID. This method
will automatically generate a Provenance FORK event or a Provenance JOIN
event, depending on whether or not other FlowFiles are generated from the
same parent before the ProcessSession is committed.create
in interface ProcessSession
flowFile
- to base the new flowfile onpublic MockFlowFile create(java.util.Collection<FlowFile> flowFiles)
ProcessSession
create
in interface ProcessSession
flowFiles
- which the new flowfile should inherit shared attributes frompublic void exportTo(FlowFile flowFile, java.io.OutputStream out)
ProcessSession
exportTo
in interface ProcessSession
flowFile
- to export the content ofout
- to export the content topublic void exportTo(FlowFile flowFile, java.nio.file.Path path, boolean append)
ProcessSession
exportTo
in interface ProcessSession
flowFile
- to export the content ofpath
- to export the content toappend
- if true will append to the current content at the given
path; if false will replace any current contentpublic MockFlowFile get()
get
in interface ProcessSession
public java.util.List<FlowFile> get(int maxResults)
ProcessSession
maxResults
FlowFiles from the work queue. If
no FlowFiles are available, returns an empty list. Will not return null.
If multiple incoming queues are present, the behavior is unspecified in
terms of whether all queues or only a single queue will be polled in a
single call.get
in interface ProcessSession
maxResults
- the maximum number of FlowFiles to returnmaxResults
FlowFiles from the work queue. If
no FlowFiles are available, returns an empty list. Will not return null.public java.util.List<FlowFile> get(FlowFileFilter filter)
ProcessSession
Returns all FlowFiles from all of the incoming queues for which the given
FlowFileFilter
indicates should be accepted. Calls to this method
provide exclusive access to the underlying queues. I.e., no other thread
will be permitted to pull FlowFiles from this Processor's queues or add
FlowFiles to this Processor's incoming queues until this method call has
returned.
get
in interface ProcessSession
filter
- to limit which flow files are returnedFlowFileFilter
indicates should be accepted.public QueueSize getQueueSize()
getQueueSize
in interface ProcessSession
public MockFlowFile importFrom(java.io.InputStream in, FlowFile flowFile)
ProcessSession
importFrom
in interface ProcessSession
in
- the file from which content will be obtainedflowFile
- the FlowFile whose content will be updatedpublic MockFlowFile importFrom(java.nio.file.Path path, boolean keepSourceFile, FlowFile flowFile)
ProcessSession
importFrom
in interface ProcessSession
path
- the file from which content will be obtainedkeepSourceFile
- if true the content is simply copied; if false the
original content might be used in a destructive way for efficiency such
that the repository will have the data but the original data will be
gone. If false the source object will be removed or gone once imported.
It will not be restored if the session is rolled back so this must be
used with caution. In some cases it can result in tremendous efficiency
gains but is also dangerous.flowFile
- the FlowFile whose content will be updatedpublic MockFlowFile merge(java.util.Collection<FlowFile> sources, FlowFile destination)
ProcessSession
merge
in interface ProcessSession
sources
- the flowfiles to mergedestination
- the flowfile to use as the merged resultpublic MockFlowFile putAllAttributes(FlowFile flowFile, java.util.Map<java.lang.String,java.lang.String> attrs)
ProcessSession
uuid
, this attribute will be
ignored.putAllAttributes
in interface ProcessSession
flowFile
- to updateattrs
- the attributes to add to the given FlowFilepublic MockFlowFile putAttribute(FlowFile flowFile, java.lang.String attrName, java.lang.String attrValue)
ProcessSession
uuid
, this attribute will be ignored.putAttribute
in interface ProcessSession
flowFile
- to updateattrName
- of attributeattrValue
- of attributepublic void read(FlowFile flowFile, InputStreamCallback callback)
ProcessSession
read
in interface ProcessSession
flowFile
- flowfile to retrieve content ofcallback
- that will be called to read the flowfile contentpublic void read(FlowFile flowFile, boolean allowSessionStreamManagement, InputStreamCallback callback)
ProcessSession
read
in interface ProcessSession
flowFile
- flowfile to retrieve content ofallowSessionStreamManagement
- allow session to hold the stream open for performance reasonscallback
- that will be called to read the flowfile contentpublic java.io.InputStream read(FlowFile flowFile)
ProcessSession
ProcessSession.commit()
or ProcessSession.rollback()
is called, but the responsibility of doing so belongs to the caller. The InputStream will throw
an IOException if an attempt is made to read from the stream after the session is committed or
rolled back.read
in interface ProcessSession
flowFile
- the FlowFile to readpublic void remove(FlowFile flowFile)
ProcessSession
remove
in interface ProcessSession
flowFile
- to removepublic void remove(java.util.Collection<FlowFile> flowFiles)
ProcessSession
remove
in interface ProcessSession
flowFiles
- to removepublic MockFlowFile removeAllAttributes(FlowFile flowFile, java.util.Set<java.lang.String> attrNames)
ProcessSession
uuid
, this key will be ignoredremoveAllAttributes
in interface ProcessSession
flowFile
- to updateattrNames
- of attributepublic MockFlowFile removeAllAttributes(FlowFile flowFile, java.util.regex.Pattern keyPattern)
ProcessSession
uuid
, this key
will not be removed.removeAllAttributes
in interface ProcessSession
flowFile
- to updatekeyPattern
- may be null; if supplied is matched against each of the
FlowFile attribute keyspublic MockFlowFile removeAttribute(FlowFile flowFile, java.lang.String attrName)
ProcessSession
uuid
, this method will return the same FlowFile without
removing any attribute.removeAttribute
in interface ProcessSession
flowFile
- to updateattrName
- of attributepublic void rollback()
ProcessSession
ProcessSession.rollback(boolean)
passing
false
as the parameter.rollback
in interface ProcessSession
public void rollback(boolean penalize)
ProcessSession
rollback
in interface ProcessSession
penalize
- whether or not the FlowFiles that are being restored back
to their queues should be penalizedpublic void transfer(FlowFile flowFile)
ProcessSession
transfer
in interface ProcessSession
flowFile
- to transferpublic void transfer(java.util.Collection<FlowFile> flowFiles)
ProcessSession
transfer
in interface ProcessSession
flowFiles
- to transferpublic void transfer(FlowFile flowFile, Relationship relationship)
ProcessSession
transfer
in interface ProcessSession
flowFile
- to transferrelationship
- to transfer topublic void transfer(java.util.Collection<FlowFile> flowFiles, Relationship relationship)
ProcessSession
transfer
in interface ProcessSession
flowFiles
- to transferrelationship
- to transfer topublic MockFlowFile write(FlowFile flowFile, OutputStreamCallback callback)
ProcessSession
write
in interface ProcessSession
flowFile
- to write tocallback
- used to write new contentpublic java.io.OutputStream write(FlowFile flowFile)
ProcessSession
write
in interface ProcessSession
flowFile
- to write topublic FlowFile append(FlowFile flowFile, OutputStreamCallback callback)
ProcessSession
append
in interface ProcessSession
flowFile
- the flowfile for which content should be appendedcallback
- used to write new bytes to the flowfile contentpublic MockFlowFile write(FlowFile flowFile, StreamCallback callback)
ProcessSession
write
in interface ProcessSession
flowFile
- to read from and write tocallback
- used to read the old content and write new contentpublic java.util.List<MockFlowFile> getFlowFilesForRelationship(Relationship relationship)
public java.util.List<MockFlowFile> getPenalizedFlowFiles()
public java.util.List<MockFlowFile> getFlowFilesForRelationship(java.lang.String relationship)
relationship
- to get flowfiles forpublic MockFlowFile createFlowFile(java.io.File file) throws java.io.IOException
java.io.IOException
public MockFlowFile createFlowFile(byte[] data)
public MockFlowFile createFlowFile(byte[] data, java.util.Map<java.lang.String,java.lang.String> attrs)
public MockFlowFile merge(java.util.Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator)
ProcessSession
merge
in interface ProcessSession
sources
- to merge togetherdestination
- to merge toheader
- bytes that will be added to the beginning of the merged
output. May be null or empty.footer
- bytes that will be added to the end of the merged output.
May be null or empty.demarcator
- bytes that will be placed in between each object merged
together. May be null or empty.public 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(java.lang.String relationship, int count)
relationship
- to validate transfer count ofcount
- items transfer to given relationshippublic void assertQueueEmpty()
public void assertQueueNotEmpty()
public void assertAllFlowFilesTransferred(java.lang.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(java.lang.String relationship, int count)
count
relationship
- to validatecount
- number of items sent to that relationship (expected)public int getRemovedCount()
public ProvenanceReporter getProvenanceReporter()
ProcessSession
getProvenanceReporter
in interface ProcessSession
public MockFlowFile penalize(FlowFile flowFile)
ProcessSession
penalize
in interface ProcessSession
flowFile
- to penalizepublic byte[] getContentAsByteArray(MockFlowFile flowFile)