This is an automated email from the ASF dual-hosted git repository.
the-thing pushed a commit to branch 2.2.X
in repository https://gitbox.apache.org/repos/asf/mina.git
The following commit(s) were added to refs/heads/2.2.X by this push:
new 138beab92 `NioDatagramAcceptorTest` - static `ExceptionMonitor`
filtering (#78)
138beab92 is described below
commit 138beab92219ac1b06ff566ea7e5f1a69f483de2
Author: Marcin L <[email protected]>
AuthorDate: Tue Oct 13 08:29:23 2026 +0200
`NioDatagramAcceptorTest` - static `ExceptionMonitor` filtering (#78)
* filtering exceptions from NioDatagramAcceptor
* Additional logging added
* Print test names for caught exceptions.
---
.../socket/nio/NioDatagramAcceptorTest.java | 37 +++++++++++++++++++---
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git
a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java
b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java
index cca9be7ca..07d40e482 100644
---
a/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java
+++
b/mina-core/src/test/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptorTest.java
@@ -23,7 +23,11 @@ import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.transport.socket.DatagramSessionConfig;
import org.apache.mina.util.AcceptorBindUtil;
import org.apache.mina.util.ExceptionMonitor;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -34,14 +38,24 @@ import static org.junit.Assert.assertTrue;
public class NioDatagramAcceptorTest {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(NioDatagramAcceptorTest.class);
+
+ @Rule
+ public TestName testName = new TestName();
+
@Test
public void shouldDisposeAcceptorSilentlyWhenExecutorIsShutdown() {
AtomicReference<Throwable> exception = new AtomicReference<>();
+ ExceptionMonitor previous = ExceptionMonitor.getInstance();
ExceptionMonitor.setInstance(new ExceptionMonitor() {
@Override
public void exceptionCaught(Throwable cause) {
- exception.set(cause);
+ LOGGER.error("Exception caught in test {}",
testName.getMethodName(), cause);
+
+ if (isFromNioDatagramAcceptor(cause)) {
+ exception.set(cause);
+ }
}
});
@@ -61,7 +75,7 @@ public class NioDatagramAcceptorTest {
assertNull("Exception must not be thrown when disposing
executor service", exception.get());
}
} finally {
- ExceptionMonitor.setInstance(null);
+ ExceptionMonitor.setInstance(previous);
}
}
@@ -69,10 +83,15 @@ public class NioDatagramAcceptorTest {
public void
shouldThrowExceptionWhenThreadIsInterruptedAndServiceIsNotDisposing() {
AtomicReference<Throwable> exception = new AtomicReference<>();
+ ExceptionMonitor previous = ExceptionMonitor.getInstance();
ExceptionMonitor.setInstance(new ExceptionMonitor() {
@Override
public void exceptionCaught(Throwable cause) {
- exception.set(cause);
+ LOGGER.error("Exception caught in test {}",
testName.getMethodName(), cause);
+
+ if (isFromNioDatagramAcceptor(cause)) {
+ exception.set(cause);
+ }
}
});
@@ -103,7 +122,17 @@ public class NioDatagramAcceptorTest {
}
}
} finally {
- ExceptionMonitor.setInstance(null);
+ ExceptionMonitor.setInstance(previous);
+ }
+ }
+
+ private static boolean isFromNioDatagramAcceptor(Throwable cause) {
+ for (StackTraceElement stackTraceElement : cause.getStackTrace()) {
+ String className = stackTraceElement.getClassName();
+ if (className.equals(NioDatagramAcceptor.class.getName())) {
+ return true;
+ }
}
+ return false;
}
}