-
Notifications
You must be signed in to change notification settings - Fork 14.3k
KAFKA-19139 Plugin#wrapInstance should use LinkedHashMap instead of Map #19519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
e2deea8
00ebd57
ab76c55
ff068ac
8cf30e5
2b7380f
5b28fcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ | |
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
|
@@ -36,11 +35,15 @@ | |
|
||
public class PluginMetricsImplTest { | ||
|
||
private final Map<String, String> extraTags = Collections.singletonMap("my-tag", "my-value"); | ||
private static final LinkedHashMap<String, String> EXTRA_TAGS = new LinkedHashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we eliminate the static keyword? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is not what I wanted—using |
||
private Map<String, String> tags; | ||
private Metrics metrics; | ||
private int initialMetrics; | ||
|
||
static { | ||
EXTRA_TAGS.put("my-tag", "my-value"); | ||
} | ||
|
||
@BeforeEach | ||
void setup() { | ||
metrics = new Metrics(); | ||
|
@@ -53,26 +56,28 @@ void setup() { | |
@Test | ||
void testMetricName() { | ||
PluginMetricsImpl pmi = new PluginMetricsImpl(metrics, tags); | ||
MetricName metricName = pmi.metricName("name", "description", extraTags); | ||
MetricName metricName = pmi.metricName("name", "description", EXTRA_TAGS); | ||
assertEquals("name", metricName.name()); | ||
assertEquals("plugins", metricName.group()); | ||
assertEquals("description", metricName.description()); | ||
Map<String, String> expectedTags = new LinkedHashMap<>(tags); | ||
expectedTags.putAll(extraTags); | ||
expectedTags.putAll(EXTRA_TAGS); | ||
assertEquals(expectedTags, metricName.tags()); | ||
} | ||
|
||
@Test | ||
void testDuplicateTagName() { | ||
PluginMetricsImpl pmi = new PluginMetricsImpl(metrics, tags); | ||
LinkedHashMap<String, String> tags = new LinkedHashMap<>(); | ||
tags.put("k1", "value"); | ||
assertThrows(IllegalArgumentException.class, | ||
() -> pmi.metricName("name", "description", Collections.singletonMap("k1", "value"))); | ||
() -> pmi.metricName("name", "description", tags)); | ||
} | ||
|
||
@Test | ||
void testAddRemoveMetrics() { | ||
PluginMetricsImpl pmi = new PluginMetricsImpl(metrics, tags); | ||
MetricName metricName = pmi.metricName("name", "description", extraTags); | ||
MetricName metricName = pmi.metricName("name", "description", EXTRA_TAGS); | ||
pmi.addMetric(metricName, (Measurable) (config, now) -> 0.0); | ||
assertEquals(initialMetrics + 1, metrics.metrics().size()); | ||
|
||
|
@@ -88,7 +93,7 @@ void testAddRemoveMetrics() { | |
void testAddRemoveSensor() { | ||
PluginMetricsImpl pmi = new PluginMetricsImpl(metrics, tags); | ||
String sensorName = "my-sensor"; | ||
MetricName metricName = pmi.metricName("name", "description", extraTags); | ||
MetricName metricName = pmi.metricName("name", "description", EXTRA_TAGS); | ||
Sensor sensor = pmi.addSensor(sensorName); | ||
assertEquals(initialMetrics, metrics.metrics().size()); | ||
sensor.add(metricName, new Rate()); | ||
|
@@ -107,10 +112,10 @@ void testAddRemoveSensor() { | |
void testClose() throws IOException { | ||
PluginMetricsImpl pmi = new PluginMetricsImpl(metrics, tags); | ||
String sensorName = "my-sensor"; | ||
MetricName metricName1 = pmi.metricName("name1", "description", extraTags); | ||
MetricName metricName1 = pmi.metricName("name1", "description", EXTRA_TAGS); | ||
Sensor sensor = pmi.addSensor(sensorName); | ||
sensor.add(metricName1, new Rate()); | ||
MetricName metricName2 = pmi.metricName("name2", "description", extraTags); | ||
MetricName metricName2 = pmi.metricName("name2", "description", EXTRA_TAGS); | ||
pmi.addMetric(metricName2, (Measurable) (config, now) -> 1.0); | ||
|
||
assertEquals(initialMetrics + 2, metrics.metrics().size()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,10 +64,13 @@ public class ConnectMetricsTest { | |
WorkerConfig.KEY_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter", | ||
WorkerConfig.VALUE_CONVERTER_CLASS_CONFIG, "org.apache.kafka.connect.json.JsonConverter"); | ||
private static final ConnectorTaskId CONNECTOR_TASK_ID = new ConnectorTaskId("connector", 0); | ||
private static final Map<String, String> TAGS = Map.of("t1", "v1"); | ||
|
||
private static final LinkedHashMap<String, String> TAGS = new LinkedHashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
private ConnectMetrics metrics; | ||
|
||
|
||
static { | ||
TAGS.put("t1", "v1"); | ||
} | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
metrics = new ConnectMetrics("worker1", new WorkerConfig(WorkerConfig.baseConfigDef(), DEFAULT_WORKER_CONFIG), new MockTime(), "cluster-1"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static final LinkedHashMap<String, String> TAGS = new LinkedHashMap<>(Map.of("t1", "v1"));