Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ private Map<String, Long> combineCounters(final Map<String, Long> first, final M

final Map<String, Long> combined = new HashMap<>();
combined.putAll(first);
combined.putAll(second);
second.forEach((key, value) -> combined.merge(key, value, Long::sum));
return combined;
}

Expand Down Expand Up @@ -3391,12 +3391,16 @@ private void checkpoint(final StandardProcessSession session, final List<Provena
if (this.countersOnCommit.isEmpty()) {
this.countersOnCommit.putAll(session.countersOnCommit);
} else {
session.countersOnCommit.forEach((key, value) -> this.countersOnCommit.merge(key, value, (v1, v2) -> v1 + v2));
session.countersOnCommit.forEach((key, value) -> this.countersOnCommit.merge(key, value, Long::sum));
}
}

if (session.immediateCounters != null) {
this.immediateCounters.putAll(session.immediateCounters);
if (this.immediateCounters.isEmpty()) {
this.immediateCounters.putAll(session.immediateCounters);
} else {
session.immediateCounters.forEach((key, value) -> this.immediateCounters.merge(key, value, Long::sum));
}
}

this.deleteOnCommit.putAll(session.deleteOnCommit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,37 @@ public void testCheckpointMergesCounters() {
assertEquals(2, bCounters);
}

@Test
public void testCombineCounters() {
final Relationship relationship = new Relationship.Builder().name("A").build();

FlowFile flowFile = session.create();
session.transfer(flowFile, relationship);
session.adjustCounter("a", 1, false);
session.adjustCounter("b", 3, false);
session.adjustCounter("a", 3, true);
session.adjustCounter("b", 5, true);
session.checkpoint();

flowFile = session.create();
session.transfer(flowFile, relationship);
session.adjustCounter("a", 1, true);
session.adjustCounter("b", 2, true);
session.commit();

context.getFlowFileEventRepository().reportTransferEvents(10L).getReportEntries().forEach((k, v) -> {
v.getCounters().forEach((key, value) -> {
if (key.equals("a")) {
assertEquals(5L, (long) value);
}

if (key.equals("b")) {
assertEquals(10L, (long) value);
}
});
});
}

@Test
public void testReadCountCorrectWhenSkippingWithReadCallback() throws IOException {
final byte[] content = "This and that and the other.".getBytes(StandardCharsets.UTF_8);
Expand Down