|
1 | 1 | /* |
2 | | - * Copyright 2016-2023 the original author or authors. |
| 2 | + * Copyright 2016-2024 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
56 | 56 | * @author Lars Bilger |
57 | 57 | * @author Tomek Szmytka |
58 | 58 | * @author Nico Heller |
| 59 | + * @author Kurt Hong |
59 | 60 | */ |
60 | 61 | class KafkaBinderMetricsTest { |
61 | 62 |
|
@@ -91,7 +92,7 @@ public void setup() { |
91 | 92 | org.mockito.BDDMockito.given(kafkaBinderConfigurationProperties.getMetrics().getOffsetLagMetricsInterval()) |
92 | 93 | .willReturn(Duration.ofSeconds(60)); |
93 | 94 | metrics = new KafkaBinderMetrics(binder, kafkaBinderConfigurationProperties, |
94 | | - consumerFactory, null |
| 95 | + consumerFactory, meterRegistry |
95 | 96 | ); |
96 | 97 | org.mockito.BDDMockito |
97 | 98 | .given(consumer.endOffsets(ArgumentMatchers.anyCollection())) |
@@ -351,6 +352,19 @@ public void shouldShutdownSchedulerOnClose() throws Exception { |
351 | 352 | assertThat(metrics.scheduler.isShutdown()).isTrue(); |
352 | 353 | } |
353 | 354 |
|
| 355 | + @Test |
| 356 | + public void shouldUnregisterMetersOnClose() throws Exception { |
| 357 | + final List<PartitionInfo> partitions = partitions(new Node(0, null, 0)); |
| 358 | + topicsInUse.put( |
| 359 | + TEST_TOPIC, |
| 360 | + new TopicInformation("group4-metrics", partitions, false) |
| 361 | + ); |
| 362 | + metrics.bindTo(meterRegistry); |
| 363 | + assertThat(meterRegistry.find(KafkaBinderMetrics.OFFSET_LAG_METRIC_NAME).meters()).hasSize(1); |
| 364 | + metrics.close(); |
| 365 | + assertThat(meterRegistry.find(KafkaBinderMetrics.OFFSET_LAG_METRIC_NAME).meters()).isEmpty(); |
| 366 | + } |
| 367 | + |
354 | 368 | private List<PartitionInfo> partitions(Node... nodes) { |
355 | 369 | List<PartitionInfo> partitions = new ArrayList<>(); |
356 | 370 | for (int i = 0; i < nodes.length; i++) { |
|
0 commit comments