Search in sources :

Example 1 with StateProvider

use of org.apache.nifi.components.state.StateProvider in project nifi by apache.

the class AbstractTestStateProvider method testReplaceWithNonExistingValue.

@Test
public void testReplaceWithNonExistingValue() throws Exception {
    final StateProvider provider = getProvider();
    StateMap stateMap = provider.getState(componentId);
    assertNotNull(stateMap);
    final Map<String, String> newValue = new HashMap<>();
    newValue.put("value", "value");
    final boolean replaced = provider.replace(stateMap, newValue, componentId);
    assertFalse(replaced);
}
Also used : StateProvider(org.apache.nifi.components.state.StateProvider) HashMap(java.util.HashMap) StateMap(org.apache.nifi.components.state.StateMap) Test(org.junit.Test)

Example 2 with StateProvider

use of org.apache.nifi.components.state.StateProvider in project nifi by apache.

the class AbstractTestStateProvider method testClear.

@Test
public void testClear() throws IOException {
    final StateProvider provider = getProvider();
    StateMap stateMap = provider.getState(componentId);
    assertNotNull(stateMap);
    assertEquals(-1L, stateMap.getVersion());
    assertTrue(stateMap.toMap().isEmpty());
    provider.setState(Collections.singletonMap("testClear", "value"), componentId);
    stateMap = provider.getState(componentId);
    assertNotNull(stateMap);
    assertEquals(0, stateMap.getVersion());
    assertEquals("value", stateMap.get("testClear"));
    provider.clear(componentId);
    stateMap = provider.getState(componentId);
    assertNotNull(stateMap);
    assertEquals(1L, stateMap.getVersion());
    assertTrue(stateMap.toMap().isEmpty());
}
Also used : StateProvider(org.apache.nifi.components.state.StateProvider) StateMap(org.apache.nifi.components.state.StateMap) Test(org.junit.Test)

Example 3 with StateProvider

use of org.apache.nifi.components.state.StateProvider in project nifi by apache.

the class AbstractTestStateProvider method testReplaceWithWrongVersion.

@Test
public void testReplaceWithWrongVersion() throws IOException {
    final String key = "testReplaceWithWrongVersion";
    final StateProvider provider = getProvider();
    provider.setState(Collections.singletonMap(key, "value1"), componentId);
    StateMap stateMap = provider.getState(componentId);
    assertNotNull(stateMap);
    assertEquals("value1", stateMap.get(key));
    assertEquals(0, stateMap.getVersion());
    provider.setState(Collections.singletonMap(key, "intermediate value"), componentId);
    assertFalse(provider.replace(stateMap, Collections.singletonMap(key, "value2"), componentId));
    stateMap = provider.getState(componentId);
    assertEquals(key, stateMap.toMap().keySet().iterator().next());
    assertEquals(1, stateMap.toMap().size());
    assertEquals("intermediate value", stateMap.get(key));
    assertEquals(1, stateMap.getVersion());
}
Also used : StateProvider(org.apache.nifi.components.state.StateProvider) StateMap(org.apache.nifi.components.state.StateMap) Test(org.junit.Test)

Example 4 with StateProvider

use of org.apache.nifi.components.state.StateProvider in project nifi by apache.

the class AbstractTestStateProvider method testReplaceWithNonExistingValueAndVersionGreaterThanNegativeOne.

@Test
public void testReplaceWithNonExistingValueAndVersionGreaterThanNegativeOne() throws Exception {
    final StateProvider provider = getProvider();
    final StateMap stateMap = new StateMap() {

        @Override
        public long getVersion() {
            return 4;
        }

        @Override
        public String get(String key) {
            return null;
        }

        @Override
        public Map<String, String> toMap() {
            return Collections.emptyMap();
        }
    };
    final Map<String, String> newValue = new HashMap<>();
    newValue.put("value", "value");
    final boolean replaced = provider.replace(stateMap, newValue, componentId);
    assertFalse(replaced);
}
Also used : StateProvider(org.apache.nifi.components.state.StateProvider) HashMap(java.util.HashMap) StateMap(org.apache.nifi.components.state.StateMap) Test(org.junit.Test)

Example 5 with StateProvider

use of org.apache.nifi.components.state.StateProvider in project nifi by apache.

the class AbstractTestStateProvider method testOnComponentRemoved.

@Test
public void testOnComponentRemoved() throws IOException, InterruptedException {
    final StateProvider provider = getProvider();
    final Map<String, String> newValue = new HashMap<>();
    newValue.put("value", "value");
    provider.setState(newValue, componentId);
    final StateMap stateMap = provider.getState(componentId);
    assertEquals(0L, stateMap.getVersion());
    provider.onComponentRemoved(componentId);
    // wait for the background process to complete
    Thread.sleep(1000L);
    final StateMap stateMapAfterRemoval = provider.getState(componentId);
    // version should be -1 because the state has been removed entirely.
    assertEquals(-1L, stateMapAfterRemoval.getVersion());
}
Also used : StateProvider(org.apache.nifi.components.state.StateProvider) HashMap(java.util.HashMap) StateMap(org.apache.nifi.components.state.StateMap) Test(org.junit.Test)

Aggregations

StateProvider (org.apache.nifi.components.state.StateProvider)16 StateMap (org.apache.nifi.components.state.StateMap)15 Test (org.junit.Test)14 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)4 IOException (java.io.IOException)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 SSLContext (javax.net.ssl.SSLContext)1 StandardPropertyValue (org.apache.nifi.attribute.expression.language.StandardPropertyValue)1 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)1 PropertyValue (org.apache.nifi.components.PropertyValue)1 ValidationContext (org.apache.nifi.components.ValidationContext)1 ValidationResult (org.apache.nifi.components.ValidationResult)1 StateProviderInitializationContext (org.apache.nifi.components.state.StateProviderInitializationContext)1 ConfigParseException (org.apache.nifi.controller.state.ConfigParseException)1 StandardStateProviderInitializationContext (org.apache.nifi.controller.state.StandardStateProviderInitializationContext)1 StateManagerConfiguration (org.apache.nifi.controller.state.config.StateManagerConfiguration)1 StateProviderConfiguration (org.apache.nifi.controller.state.config.StateProviderConfiguration)1