use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class StandardNiFiServiceFacade method getProcessorState.
@Override
public ComponentStateDTO getProcessorState(final String processorId) {
final StateMap clusterState = isClustered() ? processorDAO.getState(processorId, Scope.CLUSTER) : null;
final StateMap localState = processorDAO.getState(processorId, Scope.LOCAL);
// processor will be non null as it was already found when getting the state
final ProcessorNode processor = processorDAO.getProcessor(processorId);
return dtoFactory.createComponentStateDTO(processorId, processor.getProcessor().getClass(), localState, clusterState);
}
use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class TestStateMapSerDe method testCreateRoundTrip.
@Test
public void testCreateRoundTrip() throws IOException {
final String componentId = "1234";
final StateMapSerDe serde = new StateMapSerDe();
final Map<String, String> stateValues = new HashMap<>();
stateValues.put("abc", "xyz");
stateValues.put("cba", "zyx");
final StateMap stateMap = new StandardStateMap(stateValues, 3L);
final StateMapUpdate record = new StateMapUpdate(stateMap, componentId, UpdateType.CREATE);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (final DataOutputStream out = new DataOutputStream(baos)) {
serde.serializeRecord(record, out);
}
final StateMapUpdate update;
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
try (final DataInputStream in = new DataInputStream(bais)) {
update = serde.deserializeRecord(in, serde.getVersion());
}
assertNotNull(update);
assertEquals(componentId, update.getComponentId());
assertEquals(UpdateType.CREATE, update.getUpdateType());
final StateMap recoveredStateMap = update.getStateMap();
assertEquals(3L, recoveredStateMap.getVersion());
assertEquals(stateValues, recoveredStateMap.toMap());
}
use of org.apache.nifi.components.state.StateMap 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);
}
use of org.apache.nifi.components.state.StateMap 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());
}
use of org.apache.nifi.components.state.StateMap 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());
}
Aggregations