@@ -71,42 +71,86 @@ public void testPipelineStatsMerge() {
71
71
);
72
72
}
73
73
74
- public void testProcessorStatsMerge () {
74
+ public void testProcessorStatsMergeZeroCounts () {
75
75
{
76
- var first = Map .of ("pipeline-1" , randomPipelineProcessorStats ());
76
+ var expected = randomPipelineProcessorStats ();
77
+ var first = Map .of ("pipeline-1" , expected );
78
+
79
+ // merging with an empty map yields the non-empty map
77
80
assertEquals (IngestStats .merge (Map .of (), first ), first );
78
81
assertEquals (IngestStats .merge (first , Map .of ()), first );
82
+
83
+ // it's the same exact reference, in fact
84
+ assertSame (expected , IngestStats .merge (Map .of (), first ).get ("pipeline-1" ));
85
+ assertSame (expected , IngestStats .merge (first , Map .of ()).get ("pipeline-1" ));
79
86
}
80
87
{
81
- var first = Map . of (
82
- "pipeline-1" ,
83
- randomPipelineProcessorStats (),
84
- "pipeline-2" ,
85
- randomPipelineProcessorStats ( ),
86
- "pipeline-3" ,
87
- randomPipelineProcessorStats ( )
88
+ var expected = randomPipelineProcessorStats ();
89
+ var first = Map . of ( "pipeline-1" , expected );
90
+ var zero = List . of (
91
+ new IngestStats . ProcessorStat ( "proc-1" , "type-1" , zeroStats ()) ,
92
+ new IngestStats . ProcessorStat ( "proc-1" , "type-2" , zeroStats () ),
93
+ new IngestStats . ProcessorStat ( "proc-2" , "type-1" , zeroStats ()) ,
94
+ new IngestStats . ProcessorStat ( "proc-3" , "type-3" , zeroStats () )
88
95
);
89
- var second = Map .of (
96
+ var second = Map .of ("pipeline-1" , zero );
97
+
98
+ // merging with a zero map yields the non-zero map
99
+ assertEquals (IngestStats .merge (second , first ), first );
100
+ assertEquals (IngestStats .merge (first , second ), first );
101
+
102
+ // it's the same exact reference, in fact
103
+ assertSame (expected , IngestStats .merge (second , first ).get ("pipeline-1" ));
104
+ assertSame (expected , IngestStats .merge (first , second ).get ("pipeline-1" ));
105
+ }
106
+ }
107
+
108
+ public void testProcessorStatsMerge () {
109
+ var first = Map .of (
110
+ "pipeline-1" ,
111
+ randomPipelineProcessorStats (),
112
+ "pipeline-2" ,
113
+ randomPipelineProcessorStats (),
114
+ "pipeline-3" ,
115
+ randomPipelineProcessorStats ()
116
+ );
117
+ var second = Map .of (
118
+ "pipeline-2" ,
119
+ randomPipelineProcessorStats (),
120
+ "pipeline-3" ,
121
+ randomPipelineProcessorStats (),
122
+ "pipeline-1" ,
123
+ randomPipelineProcessorStats ()
124
+ );
125
+
126
+ assertEquals (
127
+ IngestStats .merge (first , second ),
128
+ Map .of (
129
+ "pipeline-1" ,
130
+ expectedPipelineProcessorStats (first .get ("pipeline-1" ), second .get ("pipeline-1" )),
90
131
"pipeline-2" ,
91
- randomPipelineProcessorStats ( ),
132
+ expectedPipelineProcessorStats ( first . get ( "pipeline-2" ), second . get ( "pipeline-2" ) ),
92
133
"pipeline-3" ,
93
- randomPipelineProcessorStats (),
94
- "pipeline-1" ,
95
- randomPipelineProcessorStats ()
96
- );
134
+ expectedPipelineProcessorStats ( first . get ( "pipeline-3" ), second . get ( "pipeline-3" ))
135
+ )
136
+ );
137
+ }
97
138
98
- assertEquals (
99
- IngestStats .merge (first , second ),
100
- Map .of (
101
- "pipeline-1" ,
102
- expectedPipelineProcessorStats (first .get ("pipeline-1" ), second .get ("pipeline-1" )),
103
- "pipeline-2" ,
104
- expectedPipelineProcessorStats (first .get ("pipeline-2" ), second .get ("pipeline-2" )),
105
- "pipeline-3" ,
106
- expectedPipelineProcessorStats (first .get ("pipeline-3" ), second .get ("pipeline-3" ))
107
- )
108
- );
109
- }
139
+ public void testProcessorStatsMergeHeterogeneous () {
140
+ // if a pipeline has heterogeneous *non-zero* stats, then we defer to the one with a smaller total ingest count
141
+
142
+ var first = Map .of (
143
+ "pipeline-1" ,
144
+ List .of (
145
+ new IngestStats .ProcessorStat ("name-1" , "type-1" , new IngestStats .Stats (randomLongBetween (1 , 100 ), 0 , 0 , 0 )),
146
+ new IngestStats .ProcessorStat ("name-2" , "type-2" , new IngestStats .Stats (randomLongBetween (1 , 100 ), 0 , 0 , 0 ))
147
+ )
148
+ );
149
+ var expected = List .of (new IngestStats .ProcessorStat ("name-1" , "type-1" , new IngestStats .Stats (1 , 0 , 0 , 0 )));
150
+ var second = Map .of ("pipeline-1" , expected );
151
+
152
+ assertEquals (second , IngestStats .merge (first , second ));
153
+ assertSame (expected , IngestStats .merge (second , first ).get ("pipeline-1" ));
110
154
}
111
155
112
156
private static List <IngestStats .ProcessorStat > expectedPipelineProcessorStats (
@@ -117,7 +161,7 @@ private static List<IngestStats.ProcessorStat> expectedPipelineProcessorStats(
117
161
new IngestStats .ProcessorStat ("proc-1" , "type-1" , merge (first .get (0 ).stats (), second .get (0 ).stats ())),
118
162
new IngestStats .ProcessorStat ("proc-1" , "type-2" , merge (first .get (1 ).stats (), second .get (1 ).stats ())),
119
163
new IngestStats .ProcessorStat ("proc-2" , "type-1" , merge (first .get (2 ).stats (), second .get (2 ).stats ())),
120
- new IngestStats .ProcessorStat ("proc-3" , "type-4 " , merge (first .get (3 ).stats (), second .get (3 ).stats ()))
164
+ new IngestStats .ProcessorStat ("proc-3" , "type-3 " , merge (first .get (3 ).stats (), second .get (3 ).stats ()))
121
165
);
122
166
}
123
167
@@ -126,7 +170,7 @@ private static List<IngestStats.ProcessorStat> randomPipelineProcessorStats() {
126
170
randomProcessorStat ("proc-1" , "type-1" ),
127
171
randomProcessorStat ("proc-1" , "type-2" ),
128
172
randomProcessorStat ("proc-2" , "type-1" ),
129
- randomProcessorStat ("proc-3" , "type-4 " )
173
+ randomProcessorStat ("proc-3" , "type-3 " )
130
174
);
131
175
}
132
176
@@ -216,4 +260,8 @@ private static IngestStats.PipelineStat randomPipelineStat(String id) {
216
260
private static IngestStats .Stats randomStats () {
217
261
return new IngestStats .Stats (randomLong (), randomLong (), randomLong (), randomLong ());
218
262
}
263
+
264
+ private static IngestStats .Stats zeroStats () {
265
+ return new IngestStats .Stats (0 , 0 , 0 , 0 );
266
+ }
219
267
}
0 commit comments