You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "wernerdv (via GitHub)" <gi...@apache.org> on 2026/10/01 08:38:29 UTC

Re: [PR] IGNITE-29072 Fix tests using Thread.suspend() for JDK 21 [ignite]

wernerdv commented on code in PR #13619:
URL: https://github.com/apache/ignite/pull/13619#discussion_r4153430577


##########
modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TestTcpDiscoverySpi.java:
##########
@@ -53,9 +56,98 @@ public class TestTcpDiscoverySpi extends TcpDiscoverySpi implements IgniteDiscov
     /** */
     private IgniteDiscoverySpiInternalListener internalLsnr;
 
+    /** Latch released on {@link #unfreeze()}, {@code null} if the discovery I/O is not frozen. */
+    private volatile CountDownLatch freezeLatch;
+
+    /**
+     * Freezes the discovery I/O of this node: every socket read and write blocks until {@link #unfreeze()} is called.
+     * The node keeps accepting TCP connections. Emulates a node whose threads hang, e.g. at a long GC pause.
+     */
+    public synchronized void freeze() {
+        if (freezeLatch == null)
+            freezeLatch = new CountDownLatch(1);
+    }
+
+    /** Releases the discovery I/O frozen by {@link #freeze()}. */
+    public synchronized void unfreeze() {
+        if (freezeLatch != null) {
+            freezeLatch.countDown();
+
+            freezeLatch = null;
+        }
+    }
+
+    /**
+     * Blocks while the discovery I/O is frozen.
+     *
+     * @throws InterruptedIOException If interrupted.
+     */
+    private void awaitUnfrozen() throws InterruptedIOException {
+        CountDownLatch latch = freezeLatch;
+
+        if (latch == null)
+            return;
+
+        try {
+            latch.await();
+        }
+        catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+
+            throw new InterruptedIOException("Interrupted while discovery I/O is frozen.");
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void write(TcpDiscoveryIoSession ses, byte[] data, long timeout) throws IOException,
+        IgniteCheckedException {

Review Comment:
   ```suggestion
       @Override protected void write(TcpDiscoveryIoSession ses, byte[] data, long timeout) throws IOException, IgniteCheckedException {
   ```



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org