From 48ff6a6b53994556f9d5bde0025657e280fa3090 Mon Sep 17 00:00:00 2001 From: David Arthur Date: Wed, 13 Nov 2024 13:28:38 -0500 Subject: [PATCH] MINOR Fix a few test names (#17788) Remove or update custom display names to make sure we actually include the test method as the first part of the display name. Reviewers: Chia-Ping Tsai , Bill Bejeck --- .../clients/consumer/RangeAssignorTest.java | 2 +- .../common/metrics/stats/SampledStatTest.java | 10 +++------- .../network/SslVersionsTransportLayerTest.java | 2 +- .../record/LazyDownConversionRecordsTest.java | 2 +- .../storage/RemoteLogMetadataCacheTest.java | 2 +- .../KafkaStreamsTelemetryIntegrationTest.java | 9 ++++----- ...eamsClientMetricsDelegatingReporterTest.java | 13 ++++++------- ...eamsThreadMetricsDelegatingReporterTest.java | 17 ++++++++--------- .../internals/KStreamNewProcessorApiTest.java | 3 --- .../streams/query/StateQueryResultTest.java | 11 ++++------- .../MockProcessorContextStateStoreTest.java | 2 +- 11 files changed, 30 insertions(+), 43 deletions(-) diff --git a/clients/src/test/java/org/apache/kafka/clients/consumer/RangeAssignorTest.java b/clients/src/test/java/org/apache/kafka/clients/consumer/RangeAssignorTest.java index 5fb2c169610..eb45d027977 100644 --- a/clients/src/test/java/org/apache/kafka/clients/consumer/RangeAssignorTest.java +++ b/clients/src/test/java/org/apache/kafka/clients/consumer/RangeAssignorTest.java @@ -103,7 +103,7 @@ public class RangeAssignorTest { assertTrue(assignment.get(consumer1).isEmpty()); } - @ParameterizedTest(name = "rackConfig = {0}") + @ParameterizedTest(name = "{displayName}.rackConfig = {0}") @EnumSource(RackConfig.class) public void testOneConsumerOneTopic(RackConfig rackConfig) { initializeRacks(rackConfig); diff --git a/clients/src/test/java/org/apache/kafka/common/metrics/stats/SampledStatTest.java b/clients/src/test/java/org/apache/kafka/common/metrics/stats/SampledStatTest.java index 680d7651c08..180ed58b48c 100644 --- a/clients/src/test/java/org/apache/kafka/common/metrics/stats/SampledStatTest.java +++ b/clients/src/test/java/org/apache/kafka/common/metrics/stats/SampledStatTest.java @@ -21,7 +21,6 @@ import org.apache.kafka.common.utils.MockTime; import org.apache.kafka.common.utils.Time; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.util.List; @@ -41,7 +40,6 @@ class SampledStatTest { } @Test - @DisplayName("Sample should be purged if doesn't overlap the window") public void testSampleIsPurgedIfDoesntOverlap() { MetricConfig config = new MetricConfig().timeWindow(1, SECONDS).samples(2); @@ -50,11 +48,10 @@ class SampledStatTest { time.sleep(2500); double numSamples = stat.measure(config, time.milliseconds()); - assertEquals(0, numSamples); + assertEquals(0, numSamples, "Sample should be purged if doesn't overlap the window"); } @Test - @DisplayName("Sample should be kept if overlaps the window") public void testSampleIsKeptIfOverlaps() { MetricConfig config = new MetricConfig().timeWindow(1, SECONDS).samples(2); @@ -63,11 +60,10 @@ class SampledStatTest { time.sleep(1500); double numSamples = stat.measure(config, time.milliseconds()); - assertEquals(1, numSamples); + assertEquals(1, numSamples, "Sample should be kept if overlaps the window"); } @Test - @DisplayName("Sample should be kept if overlaps the window and is n+1") public void testSampleIsKeptIfOverlapsAndExtra() { MetricConfig config = new MetricConfig().timeWindow(1, SECONDS).samples(2); @@ -80,7 +76,7 @@ class SampledStatTest { stat.record(config, 1, time.milliseconds()); double numSamples = stat.measure(config, time.milliseconds()); - assertEquals(3, numSamples); + assertEquals(3, numSamples, "Sample should be kept if overlaps the window and is n+1"); } // Creates a sample with events at the start and at the end. Positions clock at the end. diff --git a/clients/src/test/java/org/apache/kafka/common/network/SslVersionsTransportLayerTest.java b/clients/src/test/java/org/apache/kafka/common/network/SslVersionsTransportLayerTest.java index a1b8213d129..b1a7aa5bc1f 100644 --- a/clients/src/test/java/org/apache/kafka/common/network/SslVersionsTransportLayerTest.java +++ b/clients/src/test/java/org/apache/kafka/common/network/SslVersionsTransportLayerTest.java @@ -76,7 +76,7 @@ public class SslVersionsTransportLayerTest { * Tests that connection success with the default TLS version. * Note that debug mode for javax.net.ssl can be enabled via {@code System.setProperty("javax.net.debug", "ssl:handshake");} */ - @ParameterizedTest(name = "tlsServerProtocol = {0}, tlsClientProtocol = {1}") + @ParameterizedTest(name = "testTlsDefaults(tlsServerProtocol = {0}, tlsClientProtocol = {1})") @MethodSource("parameters") public void testTlsDefaults(List serverProtocols, List clientProtocols) throws Exception { // Create certificates for use by client and server. Add server cert to client truststore and vice versa. diff --git a/clients/src/test/java/org/apache/kafka/common/record/LazyDownConversionRecordsTest.java b/clients/src/test/java/org/apache/kafka/common/record/LazyDownConversionRecordsTest.java index 59ac60e3a80..171ac4b7047 100644 --- a/clients/src/test/java/org/apache/kafka/common/record/LazyDownConversionRecordsTest.java +++ b/clients/src/test/java/org/apache/kafka/common/record/LazyDownConversionRecordsTest.java @@ -86,7 +86,7 @@ public class LazyDownConversionRecordsTest { * than the number of bytes we get after conversion. This causes overflow message batch(es) to be appended towards the * end of the converted output. */ - @ParameterizedTest(name = "compressionType={0}, toMagic={1}, overflow={2}") + @ParameterizedTest @MethodSource("parameters") public void testConversion(CompressionType compressionType, byte toMagic, boolean overflow) throws IOException { doTestConversion(compressionType, toMagic, overflow); diff --git a/storage/src/test/java/org/apache/kafka/server/log/remote/metadata/storage/RemoteLogMetadataCacheTest.java b/storage/src/test/java/org/apache/kafka/server/log/remote/metadata/storage/RemoteLogMetadataCacheTest.java index 6b93f61dc7c..6e619a1dbb6 100644 --- a/storage/src/test/java/org/apache/kafka/server/log/remote/metadata/storage/RemoteLogMetadataCacheTest.java +++ b/storage/src/test/java/org/apache/kafka/server/log/remote/metadata/storage/RemoteLogMetadataCacheTest.java @@ -69,7 +69,7 @@ public class RemoteLogMetadataCacheTest { } } - @ParameterizedTest(name = "isInitialized={0}") + @ParameterizedTest @ValueSource(booleans = {true, false}) public void testCacheUpdateMetadataOnInvalidArgs(boolean isInitialized) { if (isInitialized) { diff --git a/streams/integration-tests/src/test/java/org/apache/kafka/streams/integration/KafkaStreamsTelemetryIntegrationTest.java b/streams/integration-tests/src/test/java/org/apache/kafka/streams/integration/KafkaStreamsTelemetryIntegrationTest.java index 50b11cdc6b1..3cd3698ad68 100644 --- a/streams/integration-tests/src/test/java/org/apache/kafka/streams/integration/KafkaStreamsTelemetryIntegrationTest.java +++ b/streams/integration-tests/src/test/java/org/apache/kafka/streams/integration/KafkaStreamsTelemetryIntegrationTest.java @@ -55,7 +55,6 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; @@ -148,8 +147,8 @@ public class KafkaStreamsTelemetryIntegrationTest { @ParameterizedTest @ValueSource(strings = {"INFO", "DEBUG", "TRACE"}) - @DisplayName("End-to-end test validating metrics pushed to broker") public void shouldPushMetricsToBroker(final String recordingLevel) throws Exception { + // End-to-end test validating metrics pushed to broker streamsApplicationProperties = props(true); streamsApplicationProperties.put(StreamsConfig.METRICS_RECORDING_LEVEL_CONFIG, recordingLevel); final Topology topology = simpleTopology(); @@ -202,8 +201,8 @@ public class KafkaStreamsTelemetryIntegrationTest { @ParameterizedTest @MethodSource("singleAndMultiTaskParameters") - @DisplayName("Streams metrics should get passed to Admin and Consumer") public void shouldPassMetrics(final String topologyType, final boolean stateUpdaterEnabled) throws Exception { + // Streams metrics should get passed to Admin and Consumer streamsApplicationProperties = props(stateUpdaterEnabled); final Topology topology = topologyType.equals("simple") ? simpleTopology() : complexTopology(); @@ -232,8 +231,8 @@ public class KafkaStreamsTelemetryIntegrationTest { @ParameterizedTest @MethodSource("multiTaskParameters") - @DisplayName("Correct streams metrics should get passed with dynamic membership") public void shouldPassCorrectMetricsDynamicInstances(final boolean stateUpdaterEnabled) throws Exception { + // Correct streams metrics should get passed with dynamic membership streamsApplicationProperties = props(stateUpdaterEnabled); streamsApplicationProperties.put(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory(appId).getPath() + "-ks1"); streamsApplicationProperties.put(StreamsConfig.CLIENT_ID_CONFIG, appId + "-ks1"); @@ -324,8 +323,8 @@ public class KafkaStreamsTelemetryIntegrationTest { } @Test - @DisplayName("Streams metrics should not be visible in client metrics") public void passedMetricsShouldNotLeakIntoClientMetrics() throws Exception { + // Streams metrics should not be visible in client metrics streamsApplicationProperties = props(true); final Topology topology = complexTopology(); diff --git a/streams/src/test/java/org/apache/kafka/streams/internals/metrics/StreamsClientMetricsDelegatingReporterTest.java b/streams/src/test/java/org/apache/kafka/streams/internals/metrics/StreamsClientMetricsDelegatingReporterTest.java index 032911b4790..113e96cf0ae 100644 --- a/streams/src/test/java/org/apache/kafka/streams/internals/metrics/StreamsClientMetricsDelegatingReporterTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/internals/metrics/StreamsClientMetricsDelegatingReporterTest.java @@ -26,7 +26,6 @@ import org.apache.kafka.common.utils.Time; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -75,26 +74,25 @@ class StreamsClientMetricsDelegatingReporterTest { } @Test - @DisplayName("Should register metrics from init method") public void shouldInitMetrics() { final List metrics = Arrays.asList(streamClientMetricOne, streamClientMetricTwo, streamClientMetricThree, kafkaMetricWithThreadIdTag); streamsClientMetricsDelegatingReporter.init(metrics); final List expectedMetrics = Arrays.asList(streamClientMetricOne, streamClientMetricTwo, streamClientMetricThree); - assertEquals(expectedMetrics, mockAdminClient.addedMetrics()); + assertEquals(expectedMetrics, mockAdminClient.addedMetrics(), + "Should register metrics from init method"); } @Test - @DisplayName("Should register client instance metrics only") public void shouldRegisterCorrectMetrics() { streamsClientMetricsDelegatingReporter.metricChange(kafkaMetricWithThreadIdTag); assertEquals(0, mockAdminClient.addedMetrics().size()); streamsClientMetricsDelegatingReporter.metricChange(streamClientMetricOne); - assertEquals(1, mockAdminClient.addedMetrics().size()); + assertEquals(1, mockAdminClient.addedMetrics().size(), + "Should register client instance metrics only"); } @Test - @DisplayName("Should remove client instance metrics") public void metricRemoval() { streamsClientMetricsDelegatingReporter.metricChange(streamClientMetricOne); streamsClientMetricsDelegatingReporter.metricChange(streamClientMetricTwo); @@ -102,6 +100,7 @@ class StreamsClientMetricsDelegatingReporterTest { assertEquals(3, mockAdminClient.addedMetrics().size()); streamsClientMetricsDelegatingReporter.metricRemoval(streamClientMetricOne); - assertEquals(2, mockAdminClient.addedMetrics().size()); + assertEquals(2, mockAdminClient.addedMetrics().size(), + "Should remove client instance metrics"); } } \ No newline at end of file diff --git a/streams/src/test/java/org/apache/kafka/streams/internals/metrics/StreamsThreadMetricsDelegatingReporterTest.java b/streams/src/test/java/org/apache/kafka/streams/internals/metrics/StreamsThreadMetricsDelegatingReporterTest.java index 03dbacb82b7..5ca74585e25 100644 --- a/streams/src/test/java/org/apache/kafka/streams/internals/metrics/StreamsThreadMetricsDelegatingReporterTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/internals/metrics/StreamsThreadMetricsDelegatingReporterTest.java @@ -27,7 +27,6 @@ import org.apache.kafka.common.utils.Time; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.util.Arrays; @@ -84,23 +83,22 @@ class StreamsThreadMetricsDelegatingReporterTest { @Test - @DisplayName("Init method should register metrics it receives as parameters") public void shouldInitMetrics() { final List allMetrics = Arrays.asList(kafkaMetricOneHasThreadIdTag, kafkaMetricTwoHasThreadIdTag, kafkaMetricThreeHasThreadIdTag); final List expectedMetrics = Arrays.asList(kafkaMetricOneHasThreadIdTag, kafkaMetricTwoHasThreadIdTag, kafkaMetricThreeHasThreadIdTag); streamsThreadMetricsDelegatingReporter.init(allMetrics); - assertEquals(expectedMetrics, mockConsumer.addedMetrics()); + assertEquals(expectedMetrics, mockConsumer.addedMetrics(), + "Init method should register metrics it receives as parameters"); } @Test - @DisplayName("Should register metrics with thread-id in tag map") public void shouldRegisterMetrics() { streamsThreadMetricsDelegatingReporter.metricChange(kafkaMetricOneHasThreadIdTag); - assertEquals(kafkaMetricOneHasThreadIdTag, mockConsumer.addedMetrics().get(0)); + assertEquals(kafkaMetricOneHasThreadIdTag, mockConsumer.addedMetrics().get(0), + "Should register metrics with thread-id in tag map"); } @Test - @DisplayName("Should remove metrics") public void shouldRemoveMetrics() { streamsThreadMetricsDelegatingReporter.metricChange(kafkaMetricOneHasThreadIdTag); streamsThreadMetricsDelegatingReporter.metricChange(kafkaMetricTwoHasThreadIdTag); @@ -109,13 +107,14 @@ class StreamsThreadMetricsDelegatingReporterTest { assertEquals(expected, mockConsumer.addedMetrics()); streamsThreadMetricsDelegatingReporter.metricRemoval(kafkaMetricOneHasThreadIdTag); expected = Arrays.asList(kafkaMetricTwoHasThreadIdTag, kafkaMetricThreeHasThreadIdTag); - assertEquals(expected, mockConsumer.addedMetrics()); + assertEquals(expected, mockConsumer.addedMetrics(), + "Should remove metrics"); } @Test - @DisplayName("Should not register metrics without thread-id tag") public void shouldNotRegisterMetricsWithoutThreadIdTag() { streamsThreadMetricsDelegatingReporter.metricChange(kafkaMetricWithoutThreadIdTag); - assertEquals(0, mockConsumer.addedMetrics().size()); + assertEquals(0, mockConsumer.addedMetrics().size(), + "Should not register metrics without thread-id tag"); } } \ No newline at end of file diff --git a/streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamNewProcessorApiTest.java b/streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamNewProcessorApiTest.java index 99282e0c735..3d338f89939 100644 --- a/streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamNewProcessorApiTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/kstream/internals/KStreamNewProcessorApiTest.java @@ -34,7 +34,6 @@ import org.apache.kafka.streams.state.StoreBuilder; import org.apache.kafka.streams.state.Stores; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -50,13 +49,11 @@ import static java.util.Arrays.asList; public class KStreamNewProcessorApiTest { @Test - @DisplayName("Should attach the state store using ConnectedStoreProvider") void shouldGetStateStoreWithConnectedStoreProvider() { runTest(false); } @Test - @DisplayName("Should attach the state store StreamBuilder.addStateStore") void shouldGetStateStoreWithStreamBuilder() { runTest(true); } diff --git a/streams/src/test/java/org/apache/kafka/streams/query/StateQueryResultTest.java b/streams/src/test/java/org/apache/kafka/streams/query/StateQueryResultTest.java index 4aa4c1e1820..f263e43bfa3 100644 --- a/streams/src/test/java/org/apache/kafka/streams/query/StateQueryResultTest.java +++ b/streams/src/test/java/org/apache/kafka/streams/query/StateQueryResultTest.java @@ -19,7 +19,6 @@ package org.apache.kafka.streams.query; import org.apache.kafka.streams.query.internals.SucceededQueryResult; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -40,26 +39,24 @@ class StateQueryResultTest { } @Test - @DisplayName("Zero query results shouldn't error") void getOnlyPartitionResultNoResultsTest() { stringStateQueryResult.addResult(0, noResultsFound); final QueryResult result = stringStateQueryResult.getOnlyPartitionResult(); - assertThat(result, nullValue()); + assertThat("Zero query results shouldn't error", result, nullValue()); } @Test - @DisplayName("Valid query results still works") void getOnlyPartitionResultWithSingleResultTest() { stringStateQueryResult.addResult(0, validResult); final QueryResult result = stringStateQueryResult.getOnlyPartitionResult(); - assertThat(result.getResult(), is("Foo")); + assertThat("Valid query results still works", result.getResult(), is("Foo")); } @Test - @DisplayName("More than one query result throws IllegalArgumentException ") void getOnlyPartitionResultMultipleResults() { stringStateQueryResult.addResult(0, validResult); stringStateQueryResult.addResult(1, validResult); - assertThrows(IllegalArgumentException.class, () -> stringStateQueryResult.getOnlyPartitionResult()); + assertThrows(IllegalArgumentException.class, () -> stringStateQueryResult.getOnlyPartitionResult(), + "More than one query result throws IllegalArgumentException"); } } \ No newline at end of file diff --git a/streams/test-utils/src/test/java/org/apache/kafka/streams/test/MockProcessorContextStateStoreTest.java b/streams/test-utils/src/test/java/org/apache/kafka/streams/test/MockProcessorContextStateStoreTest.java index d06cd44b900..51836d8cc41 100644 --- a/streams/test-utils/src/test/java/org/apache/kafka/streams/test/MockProcessorContextStateStoreTest.java +++ b/streams/test-utils/src/test/java/org/apache/kafka/streams/test/MockProcessorContextStateStoreTest.java @@ -155,7 +155,7 @@ public class MockProcessorContextStateStoreTest { return values.stream(); } - @ParameterizedTest(name = "builder = {0}, timestamped = {1}, caching = {2}, logging = {3}") + @ParameterizedTest @MethodSource(value = "parameters") public void shouldEitherInitOrThrow(final StoreBuilder builder, final boolean timestamped,