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


##########
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 {
+        awaitUnfrozen();
+
+        super.write(ses, data, timeout);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeReceipt(TcpDiscoveryIoSession ses, int res, 
long timeout) throws IOException,
+        IgniteCheckedException {
+        awaitUnfrozen();
+
+        super.writeReceipt(ses, res, timeout);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected <T extends Message> T readMessage(
+            TcpDiscoveryIoSession ses,
+            long timeout) throws IOException,
+        IgniteCheckedException {

Review Comment:
   ```suggestion
           TcpDiscoveryIoSession ses,
           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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to