|
19 | 19 | package org.apache.flink.runtime.util; |
20 | 20 |
|
21 | 21 | import org.apache.flink.core.testutils.CommonTestUtils; |
| 22 | +import org.apache.flink.runtime.io.network.netty.exception.RemoteTransportException; |
22 | 23 | import org.apache.flink.testutils.ClassLoaderUtils; |
23 | 24 | import org.apache.flink.util.ExceptionUtils; |
24 | 25 | import org.apache.flink.util.InstantiationUtil; |
25 | 26 | import org.apache.flink.util.SerializedThrowable; |
26 | 27 |
|
27 | 28 | import org.junit.jupiter.api.Test; |
28 | 29 |
|
| 30 | +import java.io.IOException; |
| 31 | +import java.net.InetSocketAddress; |
| 32 | +import java.net.SocketAddress; |
| 33 | +import java.util.ArrayList; |
| 34 | +import java.util.List; |
| 35 | +import java.util.concurrent.CountDownLatch; |
| 36 | + |
29 | 37 | import static org.assertj.core.api.Assertions.assertThat; |
30 | 38 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
31 | 39 | import static org.assertj.core.api.Assertions.fail; |
@@ -179,4 +187,60 @@ void testCopySuppressed() { |
179 | 187 | .isInstanceOf(SerializedThrowable.class) |
180 | 188 | .hasMessage("java.lang.Exception: suppressed"); |
181 | 189 | } |
| 190 | + |
| 191 | + @Test |
| 192 | + void testCyclicSuppressedThrowableSerialized() { |
| 193 | + SerializedThrowable serializedThrowable = new SerializedThrowable(mockThrowable()); |
| 194 | + assertThat(serializedThrowable).isNotNull(); |
| 195 | + } |
| 196 | + |
| 197 | + @Test |
| 198 | + void testCyclicSuppressedThrowableConcurrentSerialized() throws InterruptedException { |
| 199 | + Throwable throwable = mockThrowable(); |
| 200 | + CountDownLatch countDownLatch = new CountDownLatch(2); |
| 201 | + List<Thread> list = new ArrayList<>(); |
| 202 | + for (int i = 0; i < 2; i++) { |
| 203 | + String threadName = "t" + i; |
| 204 | + Thread t = createThread(countDownLatch, throwable, threadName); |
| 205 | + t.start(); |
| 206 | + countDownLatch.countDown(); |
| 207 | + list.add(t); |
| 208 | + } |
| 209 | + for (Thread thread : list) { |
| 210 | + thread.join(); |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + private static Thread createThread( |
| 215 | + CountDownLatch countDownLatch, Throwable throwable, String threadName) { |
| 216 | + Thread t = |
| 217 | + new Thread( |
| 218 | + () -> { |
| 219 | + try { |
| 220 | + countDownLatch.await(); |
| 221 | + SerializedThrowable serializedThrowable = |
| 222 | + new SerializedThrowable(throwable); |
| 223 | + assertThat(serializedThrowable).isNotNull(); |
| 224 | + } catch (Exception e) { |
| 225 | + throw new RuntimeException(e); |
| 226 | + } |
| 227 | + }); |
| 228 | + t.setName(threadName); |
| 229 | + return t; |
| 230 | + } |
| 231 | + |
| 232 | + private static Throwable mockThrowable() { |
| 233 | + SocketAddress remoteAddr = new InetSocketAddress(80); |
| 234 | + RemoteTransportException remoteTransportException = |
| 235 | + new RemoteTransportException( |
| 236 | + "Connection unexpectedly closed by remote task manager '" |
| 237 | + + remoteAddr |
| 238 | + + "'. " |
| 239 | + + "This might indicate that the remote task manager was lost.", |
| 240 | + remoteAddr, |
| 241 | + new IOException("connection reset by peer.")); |
| 242 | + RuntimeException runtimeException = new RuntimeException(remoteTransportException); |
| 243 | + remoteTransportException.addSuppressed(runtimeException); |
| 244 | + return remoteTransportException; |
| 245 | + } |
182 | 246 | } |
0 commit comments