use of org.apache.nifi.processors.standard.util.FlowFileAttributesSerializer in project nifi by apache.
the class TestWaitNotifyProtocol method testNiFiVersionUpgrade.
/**
* Test migration across NiFi version upgrade.
* Old version of Wait/Notify processors use FlowFileAttributesSerializer for cache entries.
* New version uses StringSerializer. WaitNotifyProtocol should be able to migrate old cache entries.
*/
@Test
public void testNiFiVersionUpgrade() throws Exception {
doAnswer(successfulReplace).when(cache).replace(any(), any(), any());
// Simulate old cache entry.
final FlowFileAttributesSerializer attributesSerializer = new FlowFileAttributesSerializer();
final Map<String, String> cachedAttributes = new HashMap<>();
cachedAttributes.put("key1", "value1");
cachedAttributes.put("key2", "value2");
cachedAttributes.put("key3", "value3");
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
attributesSerializer.serialize(cachedAttributes, bos);
final String signalId = "old-entry";
cacheEntries.put(signalId, new AtomicCacheEntry<>(signalId, new String(bos.toByteArray(), StandardCharsets.UTF_8), 0L));
final WaitNotifyProtocol protocol = new WaitNotifyProtocol(cache);
final Signal signal = protocol.getSignal(signalId);
assertEquals(1, signal.getCount(DEFAULT_COUNT_NAME));
assertEquals("value1", signal.getAttributes().get("key1"));
assertEquals("value2", signal.getAttributes().get("key2"));
assertEquals("value3", signal.getAttributes().get("key3"));
cacheEntries.put(signalId, new AtomicCacheEntry<>(signalId, "UNSUPPORTED_FORMAT", 0L));
try {
protocol.getSignal(signalId);
fail("Should fail since cached value was not in expected format.");
} catch (DeserializationException e) {
}
}
Aggregations