From 7be43e9f6d0e9dcf653519099596148910cbdb52 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 6 Jan 2020 15:37:02 +0100 Subject: [PATCH] Fix ingest stats test bug. (#50653) This test code fixes a serialization test bug: https://gradle-enterprise.elastic.co/s/7x2ct6yywkw3o Rarely stats for the same processor are generated and the production code then sums up these stats. However the test code wasn't summing up in that case, which caused inconsistencies between the actual and expected results. Closes #50507 --- .../cluster/stats/ClusterStatsNodesTests.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodesTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodesTests.java index 1f5ebb72bca..58756f016da 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodesTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodesTests.java @@ -71,9 +71,23 @@ public class ClusterStatsNodesTests extends ESTestCase { NodeStats nodeStats = randomValueOtherThanMany(n -> n.getIngestStats() == null, NodeStatsTests::createNodeStats); SortedMap processorStats = new TreeMap<>(); - nodeStats.getIngestStats().getProcessorStats().values().forEach(l -> l.forEach(s -> processorStats.put(s.getType(), - new long[] { s.getStats().getIngestCount(), s.getStats().getIngestFailedCount(), - s.getStats().getIngestCurrent(), s.getStats().getIngestTimeInMillis()}))); + nodeStats.getIngestStats().getProcessorStats().values().forEach(stats -> { + stats.forEach(stat -> { + processorStats.compute(stat.getType(), (key, value) -> { + if (value == null) { + return new long[] { stat.getStats().getIngestCount(), stat.getStats().getIngestFailedCount(), + stat.getStats().getIngestCurrent(), stat.getStats().getIngestTimeInMillis()}; + } else { + value[0] += stat.getStats().getIngestCount(); + value[1] += stat.getStats().getIngestFailedCount(); + value[2] += stat.getStats().getIngestCurrent(); + value[3] += stat.getStats().getIngestTimeInMillis(); + return value; + } + }); + }); + }); + ClusterStatsNodes.IngestStats stats = new ClusterStatsNodes.IngestStats(Collections.singletonList(nodeStats)); assertThat(stats.pipelineCount, equalTo(nodeStats.getIngestStats().getProcessorStats().size())); String processorStatsString = "{";