Class MockStateManager

java.lang.Object
org.apache.nifi.state.MockStateManager
All Implemented Interfaces:
org.apache.nifi.components.state.StateManager

public class MockStateManager extends Object implements org.apache.nifi.components.state.StateManager
  • Field Details

    • versionIndex

      private final AtomicInteger versionIndex
    • localStateMap

      private org.apache.nifi.components.state.StateMap localStateMap
    • clusterStateMap

      private org.apache.nifi.components.state.StateMap clusterStateMap
    • failToGetLocalState

      private volatile boolean failToGetLocalState
    • failToSetLocalState

      private volatile boolean failToSetLocalState
    • failToGetClusterState

      private volatile boolean failToGetClusterState
    • failToSetClusterState

      private volatile boolean failToSetClusterState
    • ignoreAnnotations

      private volatile boolean ignoreAnnotations
    • localRetrievedCount

      private final AtomicLong localRetrievedCount
    • clusterRetrievedCount

      private final AtomicLong clusterRetrievedCount
    • usesLocalState

      private final boolean usesLocalState
    • usesClusterState

      private final boolean usesClusterState
    • executionMode

      private MockStateManager.ExecutionMode executionMode
  • Constructor Details

    • MockStateManager

      public MockStateManager(Object component)
  • Method Details

    • reset

      public void reset()
    • setExecutionMode

      public void setExecutionMode(MockStateManager.ExecutionMode executionMode)
    • 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.components.state.StateManager
      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.components.state.StateManager
      Throws:
      IOException
    • retrieveState

      private org.apache.nifi.components.state.StateMap retrieveState(org.apache.nifi.components.state.Scope scope)
    • getRetrievalCount

      public long getRetrievalCount(org.apache.nifi.components.state.Scope scope)
    • replace

      public boolean replace(org.apache.nifi.components.state.StateMap oldValue, Map<String,String> newValue, org.apache.nifi.components.state.Scope scope) throws IOException
      Specified by:
      replace in interface org.apache.nifi.components.state.StateManager
      Throws:
      IOException
    • clear

      public void clear(org.apache.nifi.components.state.Scope scope) throws IOException
      Specified by:
      clear in interface org.apache.nifi.components.state.StateManager
      Throws:
      IOException
    • verifyCanSet

      private void verifyCanSet(org.apache.nifi.components.state.Scope scope) throws IOException
      Throws:
      IOException
    • verifyCanGet

      private void verifyCanGet(org.apache.nifi.components.state.Scope scope) throws IOException
      Throws:
      IOException
    • setIgnoreAnnotations

      public void setIgnoreAnnotations(boolean ignore)
    • verifyAnnotation

      private void verifyAnnotation(org.apache.nifi.components.state.Scope scope)
    • getValue

      private String getValue(String key, org.apache.nifi.components.state.Scope scope)
    • assertStateEquals

      public void assertStateEquals(String key, String value, org.apache.nifi.components.state.Scope scope)
      Ensures that the state with the given key and scope is set to the given value, or else the test will fail
      Parameters:
      key - the state key
      value - the expected value
      scope - the scope
    • assertStateEquals

      public void assertStateEquals(Map<String,String> stateValues, org.apache.nifi.components.state.Scope scope)
      Ensures that the state is equal to the given values
      Parameters:
      stateValues - the values expected
      scope - the scope to compare the stateValues against
    • assertStateNotEquals

      public void assertStateNotEquals(Map<String,String> stateValues, org.apache.nifi.components.state.Scope scope)
      Ensures that the state is not equal to the given values
      Parameters:
      stateValues - the unexpected values
      scope - the scope to compare the stateValues against
    • assertStateNotEquals

      public void assertStateNotEquals(String key, String value, org.apache.nifi.components.state.Scope scope)
      Ensures that the state with the given key and scope is not set to the given value, or else the test will fail
      Parameters:
      key - the state key
      value - the unexpected value
      scope - the scope
    • assertStateSet

      public void assertStateSet(String key, org.apache.nifi.components.state.Scope scope)
      Ensures that some value is set for the given key and scope, or else the test will fail
      Parameters:
      key - the state key
      scope - the scope
    • assertStateNotSet

      public void assertStateNotSet(String key, org.apache.nifi.components.state.Scope scope)
      Ensures that no value is set for the given key and scope, or else the test will fail
      Parameters:
      key - the state key
      scope - the scope
    • assertStateSet

      public void assertStateSet(org.apache.nifi.components.state.Scope scope)
      Ensures that the state was set for the given scope, regardless of what the value was.
      Parameters:
      scope - the scope
    • assertStateNotSet

      public void assertStateNotSet()
      Ensures that state was not set for any scope
    • assertStateNotSet

      public void assertStateNotSet(org.apache.nifi.components.state.Scope scope)
      Ensures that the state was not set for the given scope
      Parameters:
      scope - the scope
    • setFailOnStateSet

      public void setFailOnStateSet(org.apache.nifi.components.state.Scope scope, boolean fail)
      Specifies whether or not the State Manager should throw an IOException when state is set for the given scope. Note that calls to replace(StateMap, Map, Scope) will fail only if the state would be set (i.e., if we call replace and the StateMap does not match the old value, it will not fail). Also note that if setting state is set to fail, clearing will also fail, as clearing is thought of as setting the state to empty
      Parameters:
      scope - the scope that should (or should not) fail
      fail - whether or not setting state should fail
    • setFailOnStateGet

      public void setFailOnStateGet(org.apache.nifi.components.state.Scope scope, boolean fail)
      Specifies whether or not the State Manager should throw an IOException when state is retrieved for the given scope.
      Parameters:
      scope - the scope that should (or should not) fail
      fail - whether or not retrieving state should fail