mjsax commented on code in PR #20883:
URL: https://github.com/apache/kafka/pull/20883#discussion_r2529197970


##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/metrics/StreamsMetricsImplTest.java:
##########
@@ -681,33 +680,110 @@ public void shouldGetExistingClientLevelSensor() {
 
     @Test
     public void shouldAddClientLevelImmutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new 
MetricConfig().recordLevel(recordingLevel);
         final String value = "immutable-value";
-        final ImmutableMetricValue immutableValue = new 
ImmutableMetricValue<>(value);
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, 
DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), 
eqMetricConfig(metricConfig), eq(immutableValue));
-        final StreamsMetricsImpl streamsMetrics = new 
StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
 
-        streamsMetrics.addClientLevelImmutableMetric(METRIC_NAME1, 
DESCRIPTION1, recordingLevel, value);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
+    }
+
+    @Test
+    public void shouldAddClientLevelImmutableMetricWithAdditionalTags() {
+        final RecordingLevel recordingLevel = RecordingLevel.INFO;
+        final String value = "immutable-value";
+
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelImmutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            Collections.singletonMap("additional-tag", "additional-value"),
+            recordingLevel,
+            value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID),
+                mkEntry("additional-tag", "additional-value")
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());
+        assertThat(metrics.metric(name).metricValue(), equalTo(value));
     }
 
     @Test
     public void shouldAddClientLevelMutableMetric() {
-        final Metrics metrics = mock(Metrics.class);
         final RecordingLevel recordingLevel = RecordingLevel.INFO;
-        final MetricConfig metricConfig = new 
MetricConfig().recordLevel(recordingLevel);
-        final Gauge<String> valueProvider = (config, now) -> "mutable-value";
-        when(metrics.metricName(METRIC_NAME1, CLIENT_LEVEL_GROUP, 
DESCRIPTION1, clientLevelTags))
-            .thenReturn(metricName1);
-        doNothing().when(metrics).addMetric(eq(metricName1), 
eqMetricConfig(metricConfig), eq(valueProvider));
-        final StreamsMetricsImpl streamsMetrics = new 
StreamsMetricsImpl(metrics, CLIENT_ID, PROCESS_ID, APPLICATION_ID,
-            time);
+        final String value = "mutable-value";
 
-        streamsMetrics.addClientLevelMutableMetric(METRIC_NAME1, DESCRIPTION1, 
recordingLevel, valueProvider);
+        final StreamsMetricsImpl streamsMetrics
+            = new StreamsMetricsImpl(metrics, CLIENT_ID, time);
+
+        streamsMetrics.addClientLevelMutableMetric(
+            METRIC_NAME1,
+            DESCRIPTION1,
+            recordingLevel,
+            (c, t) -> value
+        );
+
+        final MetricName name = metrics.metricName(
+            METRIC_NAME1,
+            CLIENT_LEVEL_GROUP,
+            mkMap(
+                mkEntry("client-id", CLIENT_ID)
+            )
+        );
+        assertThat(metrics.metric(name), notNullValue());

Review Comment:
   Let's change the other code, too. It's a little weird to not check the name 
(or is there some non-deterministic naming, like a "thread name" which could 
mess with us?)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to