Search in sources :

Example 11 with StateProvider

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

the class StandardStateManagerProvider method create.

public static StateManagerProvider create(final NiFiProperties properties, final VariableRegistry variableRegistry) throws ConfigParseException, IOException {
    final StateProvider localProvider = createLocalStateProvider(properties, variableRegistry);
    final StateProvider clusterProvider;
    if (properties.isNode()) {
        clusterProvider = createClusteredStateProvider(properties, variableRegistry);
    } else {
        clusterProvider = null;
    }
    return new StandardStateManagerProvider(localProvider, clusterProvider);
}
Also used : StateProvider(org.apache.nifi.components.state.StateProvider)

Example 12 with StateProvider

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

the class ITRedisStateProvider 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) LinkedHashMap(java.util.LinkedHashMap) StateMap(org.apache.nifi.components.state.StateMap) Test(org.junit.Test)

Example 13 with StateProvider

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

the class ITRedisStateProvider method testToMap.

@Test
public void testToMap() throws IOException {
    final String key = "testKeySet";
    final StateProvider provider = getProvider();
    Map<String, String> map = provider.getState(componentId).toMap();
    assertNotNull(map);
    assertTrue(map.isEmpty());
    provider.setState(Collections.singletonMap(key, "value"), componentId);
    map = provider.getState(componentId).toMap();
    assertNotNull(map);
    assertEquals(1, map.size());
    assertEquals("value", map.get(key));
    provider.setState(Collections.<String, String>emptyMap(), componentId);
    final StateMap stateMap = provider.getState(componentId);
    map = stateMap.toMap();
    assertNotNull(map);
    assertTrue(map.isEmpty());
    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 14 with StateProvider

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

the class ITRedisStateProvider 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 15 with StateProvider

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

the class ITRedisStateProvider method testReplaceSuccessful.

@Test
public void testReplaceSuccessful() throws IOException {
    final String key = "testReplaceSuccessful";
    final StateProvider provider = getProvider();
    StateMap map = provider.getState(componentId);
    assertNotNull(map);
    assertEquals(-1, map.getVersion());
    assertNotNull(map.toMap());
    assertTrue(map.toMap().isEmpty());
    provider.setState(Collections.singletonMap(key, "value1"), componentId);
    map = provider.getState(componentId);
    assertNotNull(map);
    assertEquals(0, map.getVersion());
    assertEquals("value1", map.get(key));
    assertEquals("value1", map.toMap().get(key));
    final Map<String, String> newMap = new HashMap<>(map.toMap());
    newMap.put(key, "value2");
    assertTrue(provider.replace(map, newMap, componentId));
    map = provider.getState(componentId);
    assertEquals("value2", map.get(key));
    assertEquals(1L, map.getVersion());
}
Also used : StateProvider(org.apache.nifi.components.state.StateProvider) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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