sunm2n commented on code in PR #24240:
URL: https://github.com/apache/kafka/pull/24240#discussion_r4607786538
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStreamThreadTest.java:
##########
@@ -325,6 +328,132 @@ public Set<TopicPartition> partitions() {
assertFalse(new File(baseDirectoryName + File.separator + "testAppId"
+ File.separator + "global").exists());
}
+ @Test
+ public void
shouldClearInterruptStatusBeforeInvokingUncaughtExceptionHandler() {
+ final AtomicBoolean interruptedInHandler = new AtomicBoolean(true);
+ initializeConsumer();
+ interruptOnNextPoll(mockConsumer);
+ globalStreamThread.setUncaughtExceptionHandler(
+ e ->
interruptedInHandler.set(Thread.currentThread().isInterrupted())
+ );
+
+ try {
+ globalStreamThread.run();
+ } finally {
+ // clear the interrupt status since this thread may be reused by
JUnit
+ Thread.interrupted();
Review Comment:
Yes, that is simpler. The clear is at the top of StateConsumer.close() now,
and the ones in the finally and in closeStateConsumer() are gone, so three
clears are left: the two before the handler and this one.
##########
streams/src/test/java/org/apache/kafka/streams/processor/internals/GlobalStreamThreadTest.java:
##########
@@ -325,6 +328,132 @@ public Set<TopicPartition> partitions() {
assertFalse(new File(baseDirectoryName + File.separator + "testAppId"
+ File.separator + "global").exists());
}
+ @Test
+ public void
shouldClearInterruptStatusBeforeInvokingUncaughtExceptionHandler() {
+ final AtomicBoolean interruptedInHandler = new AtomicBoolean(true);
+ initializeConsumer();
+ interruptOnNextPoll(mockConsumer);
+ globalStreamThread.setUncaughtExceptionHandler(
+ e ->
interruptedInHandler.set(Thread.currentThread().isInterrupted())
+ );
+
+ try {
+ globalStreamThread.run();
+ } finally {
+ // clear the interrupt status since this thread may be reused by
JUnit
+ Thread.interrupted();
+ }
+
+ assertFalse(interruptedInHandler.get());
+ }
+
+ @Test
+ public void
shouldClearInterruptStatusBeforeInvokingUncaughtExceptionHandlerOnInvalidOffsetException()
{
+ final AtomicBoolean interruptedInHandler = new AtomicBoolean(true);
+ initializeConsumer();
+ mockConsumer.schedulePollTask(() -> {
+ Thread.currentThread().interrupt();
+ throw new InvalidOffsetException("Try Again!") {
Review Comment:
Done, added invalidOffsetException() and used it in all three places.
--
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]