Class MockProcessSession

java.lang.Object
org.apache.nifi.util.MockProcessSession
All Implemented Interfaces:
org.apache.nifi.processor.ProcessSession

public class MockProcessSession extends Object implements org.apache.nifi.processor.ProcessSession
  • Field Details

    • transferMap

      private final Map<org.apache.nifi.processor.Relationship,List<MockFlowFile>> transferMap
    • processorQueue

      private final MockFlowFileQueue processorQueue
    • beingProcessed

      private final Set<Long> beingProcessed
    • created

      private final Set<Long> created
    • penalized

      private final List<MockFlowFile> penalized
    • processor

      private final org.apache.nifi.processor.Processor processor
    • currentVersions

      private final Map<Long,MockFlowFile> currentVersions
    • originalVersions

      private final Map<Long,MockFlowFile> originalVersions
    • sharedState

      private final SharedSessionState sharedState
    • counterMap

      private final Map<String,Long> counterMap
    • readRecursionSet

      private final Map<org.apache.nifi.flowfile.FlowFile,Integer> readRecursionSet
    • writeRecursionSet

      private final Set<org.apache.nifi.flowfile.FlowFile> writeRecursionSet
    • provenanceReporter

      private final MockProvenanceReporter provenanceReporter
    • enforceStreamsClosed

      private final boolean enforceStreamsClosed
    • openInputStreams

      private final Map<org.apache.nifi.flowfile.FlowFile,InputStream> openInputStreams
    • openOutputStreams

      private final Map<org.apache.nifi.flowfile.FlowFile,OutputStream> 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

      private final Set<Long> removedFlowFiles
    • enqueuedIndex

      private static final AtomicLong enqueuedIndex
  • Constructor Details

    • MockProcessSession

      public MockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor)
    • MockProcessSession

      public MockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor, org.apache.nifi.components.state.StateManager stateManager)
    • MockProcessSession

      public MockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor, boolean enforceStreamsClosed, org.apache.nifi.components.state.StateManager stateManager)
    • MockProcessSession

      public MockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor, boolean enforceStreamsClosed, org.apache.nifi.components.state.StateManager stateManager, boolean allowSynchronousCommits)
    • MockProcessSession

      public MockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor, boolean enforceStreamsClosed, org.apache.nifi.components.state.StateManager stateManager, boolean allowSynchronousCommits, boolean allowRecursiveReads)
    • MockProcessSession

      private MockProcessSession(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor, boolean enforceStreamsClosed, org.apache.nifi.components.state.StateManager stateManager, boolean allowSynchronousCommits, boolean allowRecursiveReads, boolean failCommit)
  • Method Details

    • builder

      public static MockProcessSession.Builder builder(SharedSessionState sharedState, org.apache.nifi.processor.Processor processor)
    • adjustCounter

      public void adjustCounter(String name, long delta, boolean immediate)
      Specified by:
      adjustCounter in interface org.apache.nifi.processor.ProcessSession
    • migrate

      public void migrate(org.apache.nifi.processor.ProcessSession newOwner)
      Specified by:
      migrate in interface org.apache.nifi.processor.ProcessSession
    • migrate

      public void migrate(org.apache.nifi.processor.ProcessSession newOwner, Collection<org.apache.nifi.flowfile.FlowFile> flowFiles)
      Specified by:
      migrate in interface org.apache.nifi.processor.ProcessSession
    • migrate

      private void migrate(MockProcessSession newOwner, Collection<MockFlowFile> flowFiles)
    • clone

      public MockFlowFile clone(org.apache.nifi.flowfile.FlowFile flowFile)
      Specified by:
      clone in interface org.apache.nifi.processor.ProcessSession
    • clone

      public MockFlowFile clone(org.apache.nifi.flowfile.FlowFile flowFile, long offset, long size)
      Specified by:
      clone in interface org.apache.nifi.processor.ProcessSession
    • closeStreams

      private void closeStreams(Map<org.apache.nifi.flowfile.FlowFile,? extends Closeable> streamMap, boolean enforceClosed)
    • commit

      public void commit()
      Specified by:
      commit in interface org.apache.nifi.processor.ProcessSession
    • commitInternal

      private void commitInternal()
    • commitAsync

      public void commitAsync()
      Specified by:
      commitAsync in interface org.apache.nifi.processor.ProcessSession
    • commitAsync

      public void commitAsync(Runnable onSuccess, Consumer<Throwable> onFailure)
      Specified by:
      commitAsync in interface org.apache.nifi.processor.ProcessSession
    • clearCommitted

      public 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
    • clearRollback

      public 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
    • create

      public MockFlowFile create()
      Specified by:
      create in interface org.apache.nifi.processor.ProcessSession
    • create

      public MockFlowFile create(org.apache.nifi.flowfile.FlowFile flowFile)
      Specified by:
      create in interface org.apache.nifi.processor.ProcessSession
    • create

      public MockFlowFile create(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles)
      Specified by:
      create in interface org.apache.nifi.processor.ProcessSession
    • exportTo

      public void exportTo(org.apache.nifi.flowfile.FlowFile flowFile, OutputStream out)
      Specified by:
      exportTo in interface org.apache.nifi.processor.ProcessSession
    • exportTo

      public void exportTo(org.apache.nifi.flowfile.FlowFile flowFile, Path path, boolean append)
      Specified by:
      exportTo in interface org.apache.nifi.processor.ProcessSession
    • get

      public MockFlowFile get()
      Specified by:
      get in interface org.apache.nifi.processor.ProcessSession
    • get

      public List<org.apache.nifi.flowfile.FlowFile> get(int maxResults)
      Specified by:
      get in interface org.apache.nifi.processor.ProcessSession
    • get

      public List<org.apache.nifi.flowfile.FlowFile> get(org.apache.nifi.processor.FlowFileFilter filter)
      Specified by:
      get in interface org.apache.nifi.processor.ProcessSession
    • getQueueSize

      public org.apache.nifi.controller.queue.QueueSize getQueueSize()
      Specified by:
      getQueueSize in interface org.apache.nifi.processor.ProcessSession
    • importFrom

      public MockFlowFile importFrom(InputStream in, org.apache.nifi.flowfile.FlowFile flowFile)
      Specified by:
      importFrom in interface org.apache.nifi.processor.ProcessSession
    • importFrom

      public MockFlowFile importFrom(Path path, boolean keepSourceFile, org.apache.nifi.flowfile.FlowFile flowFile)
      Specified by:
      importFrom in interface org.apache.nifi.processor.ProcessSession
    • merge

      public MockFlowFile merge(Collection<org.apache.nifi.flowfile.FlowFile> sources, org.apache.nifi.flowfile.FlowFile destination)
      Specified by:
      merge in interface org.apache.nifi.processor.ProcessSession
    • putAllAttributes

      public MockFlowFile putAllAttributes(org.apache.nifi.flowfile.FlowFile flowFile, Map<String,String> attrs)
      Specified by:
      putAllAttributes in interface org.apache.nifi.processor.ProcessSession
    • putAttribute

      public MockFlowFile putAttribute(org.apache.nifi.flowfile.FlowFile flowFile, String attrName, String attrValue)
      Specified by:
      putAttribute in interface org.apache.nifi.processor.ProcessSession
    • read

      public void read(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.io.InputStreamCallback callback)
      Specified by:
      read in interface org.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

      public InputStream read(org.apache.nifi.flowfile.FlowFile flowFile)
      Specified by:
      read in interface org.apache.nifi.processor.ProcessSession
    • remove

      public void remove(org.apache.nifi.flowfile.FlowFile flowFile)
      Specified by:
      remove in interface org.apache.nifi.processor.ProcessSession
    • remove

      public void remove(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles)
      Specified by:
      remove in interface org.apache.nifi.processor.ProcessSession
    • removeAllAttributes

      public MockFlowFile removeAllAttributes(org.apache.nifi.flowfile.FlowFile flowFile, Set<String> attrNames)
      Specified by:
      removeAllAttributes in interface org.apache.nifi.processor.ProcessSession
    • removeAllAttributes

      public MockFlowFile removeAllAttributes(org.apache.nifi.flowfile.FlowFile flowFile, Pattern keyPattern)
      Specified by:
      removeAllAttributes in interface org.apache.nifi.processor.ProcessSession
    • removeAttribute

      public MockFlowFile removeAttribute(org.apache.nifi.flowfile.FlowFile flowFile, String attrName)
      Specified by:
      removeAttribute in interface org.apache.nifi.processor.ProcessSession
    • rollback

      public void rollback()
      Specified by:
      rollback in interface org.apache.nifi.processor.ProcessSession
    • rollback

      public void rollback(boolean penalize)
      Specified by:
      rollback in interface org.apache.nifi.processor.ProcessSession
    • transfer

      public void transfer(org.apache.nifi.flowfile.FlowFile flowFile)
      Specified by:
      transfer in interface org.apache.nifi.processor.ProcessSession
    • updateLastQueuedDate

      private void updateLastQueuedDate(MockFlowFile mockFlowFile)
    • updateStateWithNewFlowFile

      private void updateStateWithNewFlowFile(MockFlowFile newFlowFile)
    • transfer

      public void transfer(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles)
      Specified by:
      transfer in interface org.apache.nifi.processor.ProcessSession
    • transfer

      public void transfer(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.Relationship relationship)
      Specified by:
      transfer in interface org.apache.nifi.processor.ProcessSession
    • transfer

      public void transfer(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles, org.apache.nifi.processor.Relationship relationship)
      Specified by:
      transfer in interface org.apache.nifi.processor.ProcessSession
    • write

      public MockFlowFile write(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.io.OutputStreamCallback callback)
      Specified by:
      write in interface org.apache.nifi.processor.ProcessSession
    • write

      public OutputStream write(org.apache.nifi.flowfile.FlowFile flowFile)
      Specified by:
      write in interface org.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:
      append in interface org.apache.nifi.processor.ProcessSession
    • write

      public MockFlowFile write(org.apache.nifi.flowfile.FlowFile flowFile, org.apache.nifi.processor.io.StreamCallback callback)
      Specified by:
      write in interface org.apache.nifi.processor.ProcessSession
    • readFully

      private byte[] readFully(InputStream in) throws IOException
      Throws:
      IOException
    • getFlowFilesForRelationship

      public List<MockFlowFile> getFlowFilesForRelationship(org.apache.nifi.processor.Relationship relationship)
    • getPenalizedFlowFiles

      public List<MockFlowFile> getPenalizedFlowFiles()
    • getFlowFilesForRelationship

      public List<MockFlowFile> getFlowFilesForRelationship(String relationship)
      Parameters:
      relationship - to get flowfiles for
      Returns:
      a List of FlowFiles in the order in which they were transferred to the given relationship
    • createFlowFile

      public MockFlowFile createFlowFile(File file) throws IOException
      Throws:
      IOException
    • createFlowFile

      public MockFlowFile createFlowFile(byte[] data)
    • createFlowFile

      public MockFlowFile createFlowFile(byte[] data, Map<String,String> attrs)
    • 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:
      merge in interface org.apache.nifi.processor.ProcessSession
    • validateState

      private List<org.apache.nifi.flowfile.FlowFile> validateState(Collection<org.apache.nifi.flowfile.FlowFile> flowFiles)
    • validateState

      private MockFlowFile validateState(org.apache.nifi.flowfile.FlowFile flowFile)
    • 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 attributes
      destination - 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 that rollback() has been called
    • assertNotRolledBack

      public void assertNotRolledBack()
      Assert that rollback() 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 of
      count - items transfer to given relationship
    • assertTransferCount

      public void assertTransferCount(String 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 of
      count - 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

      public void assertAllFlowFilesTransferred(String relationship)
      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

      public void assertAllFlowFiles(FlowFileValidator validator)
      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 to count
      Parameters:
      relationship - to validate
      count - number of items sent to that relationship (expected)
    • assertAllFlowFilesTransferred

      public 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
      Parameters:
      relationship - to validate
      count - 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:
      getProvenanceReporter in interface org.apache.nifi.processor.ProcessSession
    • setState

      public void setState(Map<String,String> state, org.apache.nifi.components.state.Scope scope) throws IOException
      Specified by:
      setState in interface org.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:
      getState in interface org.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:
      replaceState in interface org.apache.nifi.processor.ProcessSession
      Throws:
      IOException
    • clearState

      public void clearState(org.apache.nifi.components.state.Scope scope) throws IOException
      Specified by:
      clearState in interface org.apache.nifi.processor.ProcessSession
      Throws:
      IOException
    • penalize

      public MockFlowFile penalize(org.apache.nifi.flowfile.FlowFile flowFile)
      Specified by:
      penalize in interface org.apache.nifi.processor.ProcessSession
    • unpenalize

      public MockFlowFile unpenalize(org.apache.nifi.flowfile.FlowFile flowFile)
    • getContentAsByteArray

      public byte[] getContentAsByteArray(MockFlowFile flowFile)
    • 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:
      true if the FlowFile is known in this session, false otherwise.