|
18 | 18 |
|
19 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; |
20 | 20 | import static org.junit.jupiter.api.Assertions.assertFalse; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
21 | 22 | import static org.junit.jupiter.api.Assertions.assertThrows; |
22 | 23 | import static org.junit.jupiter.api.Assertions.assertTrue; |
23 | 24 |
|
24 | 25 | import java.util.Properties; |
| 26 | +import org.apache.auron.flink.metric.FlinkMetricNode; |
25 | 27 | import org.apache.auron.flink.utils.SchemaConverters; |
| 28 | +import org.apache.auron.metric.MetricNode; |
26 | 29 | import org.apache.auron.protobuf.FFIReaderExecNode; |
27 | 30 | import org.apache.auron.protobuf.FilterExecNode; |
28 | 31 | import org.apache.auron.protobuf.KafkaScanExecNode; |
|
31 | 34 | import org.apache.auron.protobuf.PhysicalPlanNode; |
32 | 35 | import org.apache.auron.protobuf.ProjectionExecNode; |
33 | 36 | import org.apache.flink.api.common.eventtime.WatermarkStrategy; |
| 37 | +import org.apache.flink.metrics.groups.UnregisteredMetricsGroup; |
34 | 38 | import org.apache.flink.table.data.RowData; |
35 | 39 | import org.apache.flink.table.types.logical.IntType; |
36 | 40 | import org.apache.flink.table.types.logical.LogicalType; |
@@ -228,4 +232,54 @@ void testApplyMergedCalcPlanReturnsSourcePlanWhenNoPlanStaged() { |
228 | 232 | fn.setWatermarkStrategy(WatermarkStrategy.<RowData>forMonotonousTimestamps()); |
229 | 233 | assertEquals(source, fn.applyMergedCalcPlan(source)); |
230 | 234 | } |
| 235 | + |
| 236 | + @Test |
| 237 | + void testMetricTreeForKafkaScanLeafHasNoChildren() { |
| 238 | + FlinkMetricNode root = FlinkMetricNode.fromPlan(kafkaScan(), new UnregisteredMetricsGroup()); |
| 239 | + assertLeaf(root); |
| 240 | + } |
| 241 | + |
| 242 | + @Test |
| 243 | + void testMetricTreeForFusedProjectKafkaScan() { |
| 244 | + PhysicalPlanNode fused = |
| 245 | + AuronKafkaSourceFunction.buildMergedPlan(logicalProjection(ffiReaderPlaceholder()), kafkaScan()); |
| 246 | + |
| 247 | + FlinkMetricNode root = FlinkMetricNode.fromPlan(fused, new UnregisteredMetricsGroup()); |
| 248 | + MetricNode scan = root.getChild(0); |
| 249 | + assertLeaf(scan); |
| 250 | + assertThrows(IndexOutOfBoundsException.class, () -> root.getChild(1)); |
| 251 | + } |
| 252 | + |
| 253 | + @Test |
| 254 | + void testMetricTreeForFusedProjectFilterKafkaScan() { |
| 255 | + PhysicalPlanNode filter = PhysicalPlanNode.newBuilder() |
| 256 | + .setFilter(FilterExecNode.newBuilder() |
| 257 | + .setInput(ffiReaderPlaceholder()) |
| 258 | + .build()) |
| 259 | + .build(); |
| 260 | + PhysicalPlanNode fused = AuronKafkaSourceFunction.buildMergedPlan(logicalProjection(filter), kafkaScan()); |
| 261 | + |
| 262 | + FlinkMetricNode root = FlinkMetricNode.fromPlan(fused, new UnregisteredMetricsGroup()); |
| 263 | + MetricNode filterNode = root.getChild(0); |
| 264 | + MetricNode scan = filterNode.getChild(0); |
| 265 | + assertLeaf(scan); |
| 266 | + assertThrows(IndexOutOfBoundsException.class, () -> root.getChild(1)); |
| 267 | + assertThrows(IndexOutOfBoundsException.class, () -> filterNode.getChild(1)); |
| 268 | + } |
| 269 | + |
| 270 | + @Test |
| 271 | + void testMetricTreeForApplyMergedCalcPlanOutput() { |
| 272 | + AuronKafkaSourceFunction fn = newFunction(); |
| 273 | + RowType projected = RowType.of(new LogicalType[] {new IntType()}, new String[] {"int"}); |
| 274 | + fn.setMergedCalcPlan(logicalProjection(ffiReaderPlaceholder()), projected); |
| 275 | + |
| 276 | + PhysicalPlanNode fused = fn.applyMergedCalcPlan(kafkaScan()); |
| 277 | + FlinkMetricNode root = FlinkMetricNode.fromPlan(fused, new UnregisteredMetricsGroup()); |
| 278 | + assertLeaf(root.getChild(0)); |
| 279 | + } |
| 280 | + |
| 281 | + private static void assertLeaf(MetricNode node) { |
| 282 | + assertNotNull(node); |
| 283 | + assertThrows(IndexOutOfBoundsException.class, () -> node.getChild(0)); |
| 284 | + } |
231 | 285 | } |
0 commit comments