### Question:
ListGCSBucket extends AbstractGCSProcessor { void persistState(final ProcessContext context) { Map<String, String> state = new HashMap<>(); state.put(CURRENT_TIMESTAMP, String.valueOf(currentTimestamp)); int i = 0; for (String key : currentKeys) { state.put(CURRENT_KEY_PREFIX+i, key); i++; } try { context.getStateManager().setState(state, Scope.CLUSTER); } catch (IOException ioe) { getLogger().error("Failed to save cluster-wide state. If NiFi is restarted, data duplication may occur", ioe); } }  @Override List<PropertyDescriptor> getSupportedPropertyDescriptors(); @Override Set<Relationship> getRelationships(); @Override void onTrigger(ProcessContext context, ProcessSession session); static final PropertyDescriptor BUCKET; static final PropertyDescriptor PREFIX; static final PropertyDescriptor USE_GENERATIONS; static final Set<Relationship> relationships; static final String CURRENT_TIMESTAMP; static final String CURRENT_KEY_PREFIX; }### Answer:
@Test public void testPersistState() throws Exception { reset(storage); final ListGCSBucket processor = getProcessor(); final TestRunner runner = buildNewRunner(processor); addRequiredPropertiesToRunner(runner); runner.assertValid(); assertEquals("Cluster StateMap should be fresh (version -1L)", -1L, runner.getProcessContext().getStateManager().getState(Scope.CLUSTER).getVersion() ); processor.currentKeys = ImmutableSet.of( "test-key-0", "test-key-1" ); processor.currentTimestamp = 4L; processor.persistState(runner.getProcessContext()); final StateMap stateMap = runner.getStateManager().getState(Scope.CLUSTER); assertEquals( "Cluster StateMap should have been written to", 1L, stateMap.getVersion() ); assertEquals( ImmutableMap.of( ListGCSBucket.CURRENT_TIMESTAMP, String.valueOf(4L), ListGCSBucket.CURRENT_KEY_PREFIX+"0", "test-key-0", ListGCSBucket.CURRENT_KEY_PREFIX+"1", "test-key-1" ), stateMap.toMap() ); }
@Test public void testFailedPersistState() throws Exception { reset(storage); final ListGCSBucket processor = getProcessor(); final TestRunner runner = buildNewRunner(processor); addRequiredPropertiesToRunner(runner); runner.assertValid(); runner.getStateManager().setFailOnStateSet(Scope.CLUSTER, true); processor.currentKeys = ImmutableSet.of( "test-key-0", "test-key-1" ); processor.currentTimestamp = 4L; assertTrue(runner.getLogger().getErrorMessages().isEmpty()); processor.persistState(runner.getProcessContext()); final List<LogMessage> logMessages = runner.getLogger().getErrorMessages(); assertFalse(logMessages.isEmpty()); assertEquals( 1, logMessages.size() ); }