Index: modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java (revision 982f91a695442a4f2a63f7dc96761f7cc87a25cf) +++ modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java (date 1512732505490) @@ -92,6 +92,7 @@ import org.eclipse.jetty.util.ConcurrentHashSet; import org.jetbrains.annotations.Nullable; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.SECONDS; import static org.apache.ignite.events.EventType.EVT_JOB_MAPPED; import static org.apache.ignite.events.EventType.EVT_NODE_FAILED; @@ -442,6 +443,41 @@ assert cnt.await(7, SECONDS); } + /** + * @throws Exception If any error occurs. + */ + public void testFailureDetectionOnReceiptError() throws Exception { + TestReceiptFailedDiscoverySpi spi = new TestReceiptFailedDiscoverySpi(); + + nodeSpi.set(spi); + + Ignite g0 = startGrid(0); + + final CountDownLatch cnt = new CountDownLatch(1); + + g0.events().localListen( + new IgnitePredicate() { + @Override public boolean apply(Event evt) { + cnt.countDown(); + + return true; + } + }, + EventType.EVT_NODE_FAILED + ); + + Ignite g1 = startGrid(1); + + assertEquals(g0.cluster().nodes().size(), 2); + + assertEquals(g1.cluster().nodes().size(), 2); + + spi.receiptFailed = true; + + assertTrue("Next node have to be failed within failureDetectionTimeout", + cnt.await(spi.failureDetectionTimeout() + 3000, MILLISECONDS)); + } + /** * @throws Exception If any error occurs. */ @@ -2638,6 +2674,22 @@ } } + /** + * + */ + private static class TestReceiptFailedDiscoverySpi extends TcpDiscoverySpi { + /** */ + public volatile boolean receiptFailed; + + /** {@inheritDoc} */ + @Override protected int readReceipt(Socket sock, long timeout) throws IOException { + if (receiptFailed) + throw new IOException("Simulate receipt failed"); + + return super.readReceipt(sock, timeout); + } + } + /** * Starts new grid with given index. Method optimize is not invoked. *