From 224e2343c12ad80417eb1094a67b63f3ec56c2a7 Mon Sep 17 00:00:00 2001 From: apopov Date: Thu, 2 Nov 2017 10:22:28 +0300 Subject: [PATCH 1/3] fixed tests broken by IGNITE-6690 and IGNITE-5860 incompatibility --- .../spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java index 768f5f7f3d281..dc2e6bb2c5998 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java @@ -148,6 +148,7 @@ public void testNoHandshakeResponse() throws Exception { public void testDisconnectOnRequest() throws Exception { startTcpThread(new DisconnectOnRequestWorker()); + Thread.sleep(1000); simpleTest(); } @@ -322,7 +323,7 @@ class TcpDiscoverySpiWithOrderedIps extends TcpDiscoverySpi { Collections.sort(res, new Comparator() { @Override public int compare(InetSocketAddress o1, InetSocketAddress o2) { - return o1.toString().compareTo(o2.toString()); + return o2.toString().compareTo(o1.toString()); } }); From 126a25ef8f3125415c743acaea0b5e47fe1f047b Mon Sep 17 00:00:00 2001 From: apopov Date: Thu, 2 Nov 2017 11:22:03 +0300 Subject: [PATCH 2/3] fixed tests broken by IGNITE-6690 and IGNITE-5860 incompatibility --- .../tcp/TcpDiscoveryWithWrongServerTest.java | 53 +++++++++++-------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java index dc2e6bb2c5998..86ab564919927 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java @@ -29,6 +29,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.ignite.Ignite; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.spi.IgniteSpiException; @@ -40,14 +41,17 @@ * Client-based discovery SPI test with non-Ignite servers. */ public class TcpDiscoveryWithWrongServerTest extends GridCommonAbstractTest { - /** Non-Ignite Server port. */ + /** Non-Ignite Server port #1. */ private final static int SERVER_PORT = 47500; - /** Non-Ignite Server socket. */ - private ServerSocket srvSock; + /** Non-Ignite Server port #2. */ + private final static int LAST_SERVER_PORT = SERVER_PORT + 5; + + /** Non-Ignite Server sockets. */ + private List srvSocks = new ArrayList<>(); /** Count of accepted connections to non-Ignite Server. */ - private int connCnt; + private AtomicInteger connCnt = new AtomicInteger(0); /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { @@ -56,7 +60,7 @@ public class TcpDiscoveryWithWrongServerTest extends GridCommonAbstractTest { TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(); ipFinder.setAddresses(Collections.singleton("127.0.0.1:" + Integer.toString(SERVER_PORT) + ".." + - Integer.toString(SERVER_PORT + 2))); + Integer.toString(LAST_SERVER_PORT))); cfg.setDiscoverySpi(new TcpDiscoverySpiWithOrderedIps().setIpFinder(ipFinder)); @@ -68,7 +72,7 @@ public class TcpDiscoveryWithWrongServerTest extends GridCommonAbstractTest { /** {@inheritDoc} */ @Override protected void afterTest() throws Exception { - stopTcpThread(); + stopTcpThreads(); stopAllGrids(); @@ -79,23 +83,25 @@ public class TcpDiscoveryWithWrongServerTest extends GridCommonAbstractTest { * Starts tcp test thread * @param workerFactory one of WorkerFactory */ - private void startTcpThread(final WorkerFactory workerFactory) { - connCnt = 0; - + private void startTcpThread(final WorkerFactory workerFactory, final int port) { + final ServerSocket srvSock; try { - srvSock = new ServerSocket(SERVER_PORT, 10, InetAddress.getByName("127.0.0.1")); + srvSock = new ServerSocket(port, 10, InetAddress.getByName("127.0.0.1")); } catch (Exception e) { fail("Unexpected TcpServer exception " + e.getMessage()); + return; } + srvSocks.add(srvSock); + new GridTestThread(new Runnable() { @Override public void run() { try { while(!Thread.currentThread().isInterrupted()) { Socket clientSock = srvSock.accept(); - connCnt++; + connCnt.getAndIncrement(); // Create a new thread for socket connection. new GridTestThread(workerFactory.newWorker(clientSock)).start(); @@ -103,7 +109,7 @@ private void startTcpThread(final WorkerFactory workerFactory) { } catch (Exception e) { if (!srvSock.isClosed()) - e.printStackTrace(); + log.error("Unexpected error", e); } } }).start(); @@ -113,9 +119,10 @@ private void startTcpThread(final WorkerFactory workerFactory) { * Stops tcp test thread * @throws IOException IOException */ - private void stopTcpThread() throws IOException { - if (srvSock != null && !srvSock.isClosed()) - srvSock.close(); + private void stopTcpThreads() throws IOException { + for (ServerSocket srvSock: srvSocks) + if (!srvSock.isClosed()) + srvSock.close(); } /** @@ -124,7 +131,8 @@ private void stopTcpThread() throws IOException { * @throws Exception in case of error. */ public void testWrongHandshakeResponse() throws Exception { - startTcpThread(new SomeResponseWorker()); + startTcpThread(new SomeResponseWorker(), SERVER_PORT); + startTcpThread(new SomeResponseWorker(), LAST_SERVER_PORT); simpleTest(); } @@ -135,7 +143,8 @@ public void testWrongHandshakeResponse() throws Exception { * @throws Exception in case of error. */ public void testNoHandshakeResponse() throws Exception { - startTcpThread(new NoResponseWorker()); + startTcpThread(new NoResponseWorker(), SERVER_PORT); + startTcpThread(new NoResponseWorker(), LAST_SERVER_PORT); simpleTest(); } @@ -146,7 +155,8 @@ public void testNoHandshakeResponse() throws Exception { * @throws Exception in case of error. */ public void testDisconnectOnRequest() throws Exception { - startTcpThread(new DisconnectOnRequestWorker()); + startTcpThread(new DisconnectOnRequestWorker(), SERVER_PORT); + startTcpThread(new DisconnectOnRequestWorker(), LAST_SERVER_PORT); Thread.sleep(1000); simpleTest(); @@ -158,7 +168,8 @@ public void testDisconnectOnRequest() throws Exception { * @throws Exception in case of error. */ public void testEarlyDisconnect() throws Exception { - startTcpThread(new EarlyDisconnectWorker()); + startTcpThread(new EarlyDisconnectWorker(), SERVER_PORT); + startTcpThread(new EarlyDisconnectWorker(), LAST_SERVER_PORT); simpleTest(); } @@ -177,7 +188,7 @@ private void simpleTest() { assertEquals(2, srv.cluster().nodes().size()); assertEquals(2, client.cluster().nodes().size()); - assertTrue(connCnt >= 2); + assertTrue(connCnt.get() >= 2); srv.getOrCreateCache(DEFAULT_CACHE_NAME).put(1, 1); @@ -323,7 +334,7 @@ class TcpDiscoverySpiWithOrderedIps extends TcpDiscoverySpi { Collections.sort(res, new Comparator() { @Override public int compare(InetSocketAddress o1, InetSocketAddress o2) { - return o2.toString().compareTo(o1.toString()); + return o1.toString().compareTo(o2.toString()); } }); From ae93790872b8d9bf7b19da59a28b63fb2fca8dad Mon Sep 17 00:00:00 2001 From: apopov Date: Thu, 2 Nov 2017 11:24:54 +0300 Subject: [PATCH 3/3] fixed tests broken by IGNITE-6690 and IGNITE-5860 incompatibility --- .../spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java index 86ab564919927..a13017d13c599 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryWithWrongServerTest.java @@ -158,7 +158,6 @@ public void testDisconnectOnRequest() throws Exception { startTcpThread(new DisconnectOnRequestWorker(), SERVER_PORT); startTcpThread(new DisconnectOnRequestWorker(), LAST_SERVER_PORT); - Thread.sleep(1000); simpleTest(); }