You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "arnabnandy7 (via GitHub)" <gi...@apache.org> on 2026/08/29 16:19:03 UTC
[PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
arnabnandy7 opened a new pull request, #23307:
URL: https://github.com/apache/kafka/pull/23307
## Description
Remove Hamcrest usage from `ApiUtilsTest` and `ClientMetricsTest` as part of KAFKA-20953.
The assertions now use their JUnit 5 equivalents:
- `assertThrows` and `assertTrue` for exception and message validation.
- `assertEquals` for sensor comparison.
This is a test-only migration and does not change production behavior.
## Testing
```bash
./gradlew :streams:test \
--tests org.apache.kafka.streams.internals.ApiUtilsTest \
--tests org.apache.kafka.streams.internals.metrics.ClientMetricsTest
```
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #23307:
URL: https://github.com/apache/kafka/pull/23307
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
Posted by "arnabnandy7 (via GitHub)" <gi...@apache.org>.
arnabnandy7 commented on PR #23307:
URL: https://github.com/apache/kafka/pull/23307#issuecomment-5491233653
> Hi @arnabnandy7, I was the original assignee on this ticket and I'm already working on it. As a general rule, please check with the current assignee before reassigning any ticket that already has one.
Sure, will keep in mind.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #23307:
URL: https://github.com/apache/kafka/pull/23307#discussion_r3906902399
##########
streams/src/test/java/org/apache/kafka/streams/internals/ApiUtilsTest.java:
##########
@@ -39,49 +38,45 @@ public class ApiUtilsTest {
public void shouldThrowNullPointerExceptionForNullDuration() {
final String nullDurationPrefix = prepareMillisCheckFailMsgPrefix(null, "nullDuration");
- try {
- validateMillisecondDuration(null, nullDurationPrefix);
- fail("Expected exception when null passed to duration.");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(nullDurationPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondDuration(null, nullDurationPrefix)
+ );
+ assertTrue(e.getMessage().contains(nullDurationPrefix));
}
@Test
public void shouldThrowArithmeticExceptionForMaxDuration() {
final Duration maxDurationInDays = Duration.ofDays(MAX_ACCEPTABLE_DAYS_FOR_DURATION);
final String maxDurationPrefix = prepareMillisCheckFailMsgPrefix(maxDurationInDays, "maxDuration");
- try {
- validateMillisecondDuration(maxDurationInDays, maxDurationPrefix);
- fail("Expected exception when maximum days passed for duration, because of long overflow");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(maxDurationPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondDuration(maxDurationInDays, maxDurationPrefix)
+ );
+ assertTrue(e.getMessage().contains(maxDurationPrefix));
}
@Test
public void shouldThrowNullPointerExceptionForNullInstant() {
final String nullInstantPrefix = prepareMillisCheckFailMsgPrefix(null, "nullInstant");
- try {
- validateMillisecondInstant(null, nullInstantPrefix);
- fail("Expected exception when null value passed for instant.");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(nullInstantPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
Review Comment:
ditto
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
Posted by "arnabnandy7 (via GitHub)" <gi...@apache.org>.
arnabnandy7 commented on code in PR #23307:
URL: https://github.com/apache/kafka/pull/23307#discussion_r3921996955
##########
streams/src/test/java/org/apache/kafka/streams/internals/ApiUtilsTest.java:
##########
@@ -36,52 +35,48 @@ public class ApiUtilsTest {
private static final long MAX_ACCEPTABLE_DAYS_FOR_DURATION_TO_MILLIS = 106751991167L;
@Test
- public void shouldThrowNullPointerExceptionForNullDuration() {
+ public void shouldThrowIllegalArgumentExceptionForNullDuration() {
final String nullDurationPrefix = prepareMillisCheckFailMsgPrefix(null, "nullDuration");
- try {
- validateMillisecondDuration(null, nullDurationPrefix);
- fail("Expected exception when null passed to duration.");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(nullDurationPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondDuration(null, nullDurationPrefix)
+ );
+ assertTrue(e.getMessage().contains(nullDurationPrefix));
}
@Test
public void shouldThrowArithmeticExceptionForMaxDuration() {
final Duration maxDurationInDays = Duration.ofDays(MAX_ACCEPTABLE_DAYS_FOR_DURATION);
final String maxDurationPrefix = prepareMillisCheckFailMsgPrefix(maxDurationInDays, "maxDuration");
- try {
- validateMillisecondDuration(maxDurationInDays, maxDurationPrefix);
- fail("Expected exception when maximum days passed for duration, because of long overflow");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(maxDurationPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondDuration(maxDurationInDays, maxDurationPrefix)
+ );
+ assertTrue(e.getMessage().contains(maxDurationPrefix));
}
@Test
- public void shouldThrowNullPointerExceptionForNullInstant() {
+ public void shouldThrowIllegalArgumentExceptionForNullInstant() {
final String nullInstantPrefix = prepareMillisCheckFailMsgPrefix(null, "nullInstant");
- try {
- validateMillisecondInstant(null, nullInstantPrefix);
- fail("Expected exception when null value passed for instant.");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(nullInstantPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondInstant(null, nullInstantPrefix)
+ );
+ assertTrue(e.getMessage().contains(nullInstantPrefix));
}
@Test
public void shouldThrowArithmeticExceptionForMaxInstant() {
Review Comment:
done @chia7712
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #23307:
URL: https://github.com/apache/kafka/pull/23307#discussion_r3919031835
##########
streams/src/test/java/org/apache/kafka/streams/internals/ApiUtilsTest.java:
##########
@@ -36,52 +35,48 @@ public class ApiUtilsTest {
private static final long MAX_ACCEPTABLE_DAYS_FOR_DURATION_TO_MILLIS = 106751991167L;
@Test
- public void shouldThrowNullPointerExceptionForNullDuration() {
+ public void shouldThrowIllegalArgumentExceptionForNullDuration() {
final String nullDurationPrefix = prepareMillisCheckFailMsgPrefix(null, "nullDuration");
- try {
- validateMillisecondDuration(null, nullDurationPrefix);
- fail("Expected exception when null passed to duration.");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(nullDurationPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondDuration(null, nullDurationPrefix)
+ );
+ assertTrue(e.getMessage().contains(nullDurationPrefix));
}
@Test
public void shouldThrowArithmeticExceptionForMaxDuration() {
final Duration maxDurationInDays = Duration.ofDays(MAX_ACCEPTABLE_DAYS_FOR_DURATION);
final String maxDurationPrefix = prepareMillisCheckFailMsgPrefix(maxDurationInDays, "maxDuration");
- try {
- validateMillisecondDuration(maxDurationInDays, maxDurationPrefix);
- fail("Expected exception when maximum days passed for duration, because of long overflow");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(maxDurationPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondDuration(maxDurationInDays, maxDurationPrefix)
+ );
+ assertTrue(e.getMessage().contains(maxDurationPrefix));
}
@Test
- public void shouldThrowNullPointerExceptionForNullInstant() {
+ public void shouldThrowIllegalArgumentExceptionForNullInstant() {
final String nullInstantPrefix = prepareMillisCheckFailMsgPrefix(null, "nullInstant");
- try {
- validateMillisecondInstant(null, nullInstantPrefix);
- fail("Expected exception when null value passed for instant.");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(nullInstantPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondInstant(null, nullInstantPrefix)
+ );
+ assertTrue(e.getMessage().contains(nullInstantPrefix));
}
@Test
public void shouldThrowArithmeticExceptionForMaxInstant() {
Review Comment:
ditto
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #23307:
URL: https://github.com/apache/kafka/pull/23307#discussion_r3944162441
##########
streams/src/test/java/org/apache/kafka/streams/internals/ApiUtilsTest.java:
##########
@@ -36,52 +35,48 @@ public class ApiUtilsTest {
private static final long MAX_ACCEPTABLE_DAYS_FOR_DURATION_TO_MILLIS = 106751991167L;
@Test
- public void shouldThrowNullPointerExceptionForNullDuration() {
+ public void shouldThrowIllegalArgumentExceptionForNullDuration() {
final String nullDurationPrefix = prepareMillisCheckFailMsgPrefix(null, "nullDuration");
- try {
- validateMillisecondDuration(null, nullDurationPrefix);
- fail("Expected exception when null passed to duration.");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(nullDurationPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondDuration(null, nullDurationPrefix)
+ );
+ assertTrue(e.getMessage().contains(nullDurationPrefix));
}
@Test
- public void shouldThrowArithmeticExceptionForMaxDuration() {
+ public void shouldThrowIllegalArgumentExceptionForMaxDuration() {
final Duration maxDurationInDays = Duration.ofDays(MAX_ACCEPTABLE_DAYS_FOR_DURATION);
final String maxDurationPrefix = prepareMillisCheckFailMsgPrefix(maxDurationInDays, "maxDuration");
- try {
- validateMillisecondDuration(maxDurationInDays, maxDurationPrefix);
- fail("Expected exception when maximum days passed for duration, because of long overflow");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(maxDurationPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondDuration(maxDurationInDays, maxDurationPrefix)
+ );
+ assertTrue(e.getMessage().contains(maxDurationPrefix));
}
@Test
- public void shouldThrowNullPointerExceptionForNullInstant() {
+ public void shouldThrowIllegalArgumentExceptionForNullInstant() {
final String nullInstantPrefix = prepareMillisCheckFailMsgPrefix(null, "nullInstant");
- try {
- validateMillisecondInstant(null, nullInstantPrefix);
- fail("Expected exception when null value passed for instant.");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(nullInstantPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondInstant(null, nullInstantPrefix)
+ );
+ assertTrue(e.getMessage().contains(nullInstantPrefix));
}
@Test
- public void shouldThrowArithmeticExceptionForMaxInstant() {
+ public void shouldThrowIllegalArgumentExceptionForMaxInstant() {
final String maxInstantPrefix = prepareMillisCheckFailMsgPrefix(Instant.MAX, "maxInstant");
- try {
- validateMillisecondInstant(Instant.MAX, maxInstantPrefix);
- fail("Expected exception when maximum value passed for instant, because of long overflow.");
Review Comment:
maybe we can keep this error message?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
Posted by "mingyen066 (via GitHub)" <gi...@apache.org>.
mingyen066 commented on PR #23307:
URL: https://github.com/apache/kafka/pull/23307#issuecomment-5491174602
Hi @arnabnandy7, I was the original assignee on this ticket and I'm already working on it. As a general rule, please check with the current assignee before reassigning any ticket that already has one.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
Posted by "mingyen066 (via GitHub)" <gi...@apache.org>.
mingyen066 commented on PR #23307:
URL: https://github.com/apache/kafka/pull/23307#issuecomment-5491230356
Since you've already started, feel free to keep this one — I'll review your PR.
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
Posted by "arnabnandy7 (via GitHub)" <gi...@apache.org>.
arnabnandy7 commented on PR #23307:
URL: https://github.com/apache/kafka/pull/23307#issuecomment-5499217713
@chia7712 both renamed with appropriate one's
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #23307:
URL: https://github.com/apache/kafka/pull/23307#discussion_r3906901153
##########
streams/src/test/java/org/apache/kafka/streams/internals/ApiUtilsTest.java:
##########
@@ -39,49 +38,45 @@ public class ApiUtilsTest {
public void shouldThrowNullPointerExceptionForNullDuration() {
final String nullDurationPrefix = prepareMillisCheckFailMsgPrefix(null, "nullDuration");
- try {
- validateMillisecondDuration(null, nullDurationPrefix);
- fail("Expected exception when null passed to duration.");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(nullDurationPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
Review Comment:
It seems the test name is not aligned with this exception. Could you fix that in this PR as well?
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] KAFKA-20953: Remove Hamcrest from Streams internals tests [kafka]
Posted by "arnabnandy7 (via GitHub)" <gi...@apache.org>.
arnabnandy7 commented on code in PR #23307:
URL: https://github.com/apache/kafka/pull/23307#discussion_r3944397589
##########
streams/src/test/java/org/apache/kafka/streams/internals/ApiUtilsTest.java:
##########
@@ -36,52 +35,48 @@ public class ApiUtilsTest {
private static final long MAX_ACCEPTABLE_DAYS_FOR_DURATION_TO_MILLIS = 106751991167L;
@Test
- public void shouldThrowNullPointerExceptionForNullDuration() {
+ public void shouldThrowIllegalArgumentExceptionForNullDuration() {
final String nullDurationPrefix = prepareMillisCheckFailMsgPrefix(null, "nullDuration");
- try {
- validateMillisecondDuration(null, nullDurationPrefix);
- fail("Expected exception when null passed to duration.");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(nullDurationPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondDuration(null, nullDurationPrefix)
+ );
+ assertTrue(e.getMessage().contains(nullDurationPrefix));
}
@Test
- public void shouldThrowArithmeticExceptionForMaxDuration() {
+ public void shouldThrowIllegalArgumentExceptionForMaxDuration() {
final Duration maxDurationInDays = Duration.ofDays(MAX_ACCEPTABLE_DAYS_FOR_DURATION);
final String maxDurationPrefix = prepareMillisCheckFailMsgPrefix(maxDurationInDays, "maxDuration");
- try {
- validateMillisecondDuration(maxDurationInDays, maxDurationPrefix);
- fail("Expected exception when maximum days passed for duration, because of long overflow");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(maxDurationPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondDuration(maxDurationInDays, maxDurationPrefix)
+ );
+ assertTrue(e.getMessage().contains(maxDurationPrefix));
}
@Test
- public void shouldThrowNullPointerExceptionForNullInstant() {
+ public void shouldThrowIllegalArgumentExceptionForNullInstant() {
final String nullInstantPrefix = prepareMillisCheckFailMsgPrefix(null, "nullInstant");
- try {
- validateMillisecondInstant(null, nullInstantPrefix);
- fail("Expected exception when null value passed for instant.");
- } catch (final IllegalArgumentException e) {
- assertThat(e.getMessage(), containsString(nullInstantPrefix));
- }
+ final IllegalArgumentException e = assertThrows(
+ IllegalArgumentException.class,
+ () -> validateMillisecondInstant(null, nullInstantPrefix)
+ );
+ assertTrue(e.getMessage().contains(nullInstantPrefix));
}
@Test
- public void shouldThrowArithmeticExceptionForMaxInstant() {
+ public void shouldThrowIllegalArgumentExceptionForMaxInstant() {
final String maxInstantPrefix = prepareMillisCheckFailMsgPrefix(Instant.MAX, "maxInstant");
- try {
- validateMillisecondInstant(Instant.MAX, maxInstantPrefix);
- fail("Expected exception when maximum value passed for instant, because of long overflow.");
Review Comment:
@chia7712 done
--
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: jira-unsubscribe@kafka.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org