From 416f427434f143f32c2e04943c8cd8c98a5bca1e Mon Sep 17 00:00:00 2001 From: Alexander Paschenko Date: Wed, 22 Feb 2017 13:10:53 +0300 Subject: [PATCH 1/3] IGNITE-4741 JDBC DML streaming test fix --- .../ignite/internal/jdbc2/JdbcStreamingSelfTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java index 5e206eef2248b..3ef065d383c85 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java @@ -145,8 +145,9 @@ public void testStreamedInsert() throws Exception { // Data is not there yet. assertNull(grid(0).cache(null).get(100000)); - // Let the stream flush. - U.sleep(1500); + // Closing connection makes it wait for streamer close + // and thus for data load completion as well + conn.close(); // Now let's check it's all there. assertEquals(1, grid(0).cache(null).get(1)); @@ -176,8 +177,9 @@ public void testStreamedInsertWithOverwritesAllowed() throws Exception { // Data is not there yet. assertNull(grid(0).cache(null).get(100000)); - // Let the stream flush. - U.sleep(1500); + // Closing connection makes it wait for streamer close + // and thus for data load completion as well + conn.close(); // Now let's check it's all there. assertEquals(1, grid(0).cache(null).get(1)); From 783c0c2dc8aadedb40866fda73376d521b2a33f1 Mon Sep 17 00:00:00 2001 From: devozerov Date: Wed, 22 Feb 2017 13:45:56 +0300 Subject: [PATCH 2/3] Speeding up tests. --- .../clients/src/test/config/jdbc-config.xml | 2 +- .../internal/jdbc2/JdbcStreamingSelfTest.java | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/clients/src/test/config/jdbc-config.xml b/modules/clients/src/test/config/jdbc-config.xml index 5e6e12ce69921..27d26171a781d 100644 --- a/modules/clients/src/test/config/jdbc-config.xml +++ b/modules/clients/src/test/config/jdbc-config.xml @@ -43,7 +43,7 @@ - 127.0.0.1:47500..47549 + 127.0.0.1:47500..47501 diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java index 3ef065d383c85..0073f9d5d65b8 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java @@ -20,6 +20,7 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; +import java.util.Collections; import java.util.Properties; import org.apache.ignite.IgniteJdbcDriver; import org.apache.ignite.IgniteLogger; @@ -41,7 +42,7 @@ */ public class JdbcStreamingSelfTest extends GridCommonAbstractTest { /** IP finder. */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); /** JDBC URL. */ private static final String BASE_URL = CFG_URL_PREFIX + "modules/clients/src/test/config/jdbc-config.xml"; @@ -52,6 +53,10 @@ public class JdbcStreamingSelfTest extends GridCommonAbstractTest { /** */ protected transient IgniteLogger log; + static { + IP_FINDER.setAddresses(Collections.singleton("127.0.0.1:47500..47501")); + } + /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { return getConfiguration0(gridName); @@ -75,6 +80,7 @@ private IgniteConfiguration getConfiguration0(String gridName) throws Exception ); cfg.setCacheConfiguration(cache); + cfg.setLocalHost("127.0.0.1"); TcpDiscoverySpi disco = new TcpDiscoverySpi(); @@ -89,7 +95,7 @@ private IgniteConfiguration getConfiguration0(String gridName) throws Exception /** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { - startGridsMultiThreaded(3); + startGrids(2); Class.forName("org.apache.ignite.IgniteJdbcDriver"); } @@ -135,7 +141,7 @@ public void testStreamedInsert() throws Exception { PreparedStatement stmt = conn.prepareStatement("insert into Integer(_key, _val) values (?, ?)"); - for (int i = 1; i <= 100000; i++) { + for (int i = 1; i <= 100; i++) { stmt.setInt(1, i); stmt.setInt(2, i); @@ -143,7 +149,7 @@ public void testStreamedInsert() throws Exception { } // Data is not there yet. - assertNull(grid(0).cache(null).get(100000)); + assertNull(grid(0).cache(null).get(100)); // Closing connection makes it wait for streamer close // and thus for data load completion as well @@ -151,7 +157,7 @@ public void testStreamedInsert() throws Exception { // Now let's check it's all there. assertEquals(1, grid(0).cache(null).get(1)); - assertEquals(100000, grid(0).cache(null).get(100000)); + assertEquals(100, grid(0).cache(null).get(100)); // 5 should still point to 500. assertEquals(500, grid(0).cache(null).get(5)); @@ -167,7 +173,7 @@ public void testStreamedInsertWithOverwritesAllowed() throws Exception { PreparedStatement stmt = conn.prepareStatement("insert into Integer(_key, _val) values (?, ?)"); - for (int i = 1; i <= 100000; i++) { + for (int i = 1; i <= 100; i++) { stmt.setInt(1, i); stmt.setInt(2, i); @@ -175,7 +181,7 @@ public void testStreamedInsertWithOverwritesAllowed() throws Exception { } // Data is not there yet. - assertNull(grid(0).cache(null).get(100000)); + assertNull(grid(0).cache(null).get(100)); // Closing connection makes it wait for streamer close // and thus for data load completion as well @@ -183,7 +189,7 @@ public void testStreamedInsertWithOverwritesAllowed() throws Exception { // Now let's check it's all there. assertEquals(1, grid(0).cache(null).get(1)); - assertEquals(100000, grid(0).cache(null).get(100000)); + assertEquals(100, grid(0).cache(null).get(100)); // 5 should now point to 5 as we've turned overwriting on. assertEquals(5, grid(0).cache(null).get(5)); From b9abd2f1fa53476f331205d74fabc9879afa3288 Mon Sep 17 00:00:00 2001 From: Alexander Paschenko Date: Wed, 22 Feb 2017 14:02:20 +0300 Subject: [PATCH 3/3] IGNITE-4741 JdbcStreamingSelfTest minors --- .../internal/jdbc2/JdbcStreamingSelfTest.java | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java index 0073f9d5d65b8..6837a41a5d6bc 100644 --- a/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java +++ b/modules/clients/src/test/java/org/apache/ignite/internal/jdbc2/JdbcStreamingSelfTest.java @@ -29,7 +29,6 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; -import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; @@ -41,9 +40,6 @@ * Data streaming test. */ public class JdbcStreamingSelfTest extends GridCommonAbstractTest { - /** IP finder. */ - private static final TcpDiscoveryVmIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - /** JDBC URL. */ private static final String BASE_URL = CFG_URL_PREFIX + "modules/clients/src/test/config/jdbc-config.xml"; @@ -53,10 +49,6 @@ public class JdbcStreamingSelfTest extends GridCommonAbstractTest { /** */ protected transient IgniteLogger log; - static { - IP_FINDER.setAddresses(Collections.singleton("127.0.0.1:47500..47501")); - } - /** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { return getConfiguration0(gridName); @@ -84,7 +76,10 @@ private IgniteConfiguration getConfiguration0(String gridName) throws Exception TcpDiscoverySpi disco = new TcpDiscoverySpi(); - disco.setIpFinder(IP_FINDER); + TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + ipFinder.setAddresses(Collections.singleton("127.0.0.1:47500..47501")); + + disco.setIpFinder(ipFinder); cfg.setDiscoverySpi(disco); @@ -137,7 +132,8 @@ private Connection createConnection(boolean allowOverwrite) throws Exception { public void testStreamedInsert() throws Exception { conn = createConnection(false); - ignite(0).cache(null).put(5, 500); + for (int i = 10; i <= 100; i += 10) + ignite(0).cache(null).put(i, i * 100); PreparedStatement stmt = conn.prepareStatement("insert into Integer(_key, _val) values (?, ?)"); @@ -148,19 +144,17 @@ public void testStreamedInsert() throws Exception { stmt.executeUpdate(); } - // Data is not there yet. - assertNull(grid(0).cache(null).get(100)); - // Closing connection makes it wait for streamer close // and thus for data load completion as well conn.close(); // Now let's check it's all there. - assertEquals(1, grid(0).cache(null).get(1)); - assertEquals(100, grid(0).cache(null).get(100)); - - // 5 should still point to 500. - assertEquals(500, grid(0).cache(null).get(5)); + for (int i = 1; i <= 100; i++) { + if (i % 10 != 0) + assertEquals(i, grid(0).cache(null).get(i)); + else // All that divides by 10 evenly should point to numbers 100 times greater - see above + assertEquals(i * 100, grid(0).cache(null).get(i)); + } } /** @@ -169,7 +163,8 @@ public void testStreamedInsert() throws Exception { public void testStreamedInsertWithOverwritesAllowed() throws Exception { conn = createConnection(true); - ignite(0).cache(null).put(5, 500); + for (int i = 10; i <= 100; i += 10) + ignite(0).cache(null).put(i, i * 100); PreparedStatement stmt = conn.prepareStatement("insert into Integer(_key, _val) values (?, ?)"); @@ -180,18 +175,13 @@ public void testStreamedInsertWithOverwritesAllowed() throws Exception { stmt.executeUpdate(); } - // Data is not there yet. - assertNull(grid(0).cache(null).get(100)); - // Closing connection makes it wait for streamer close // and thus for data load completion as well conn.close(); // Now let's check it's all there. - assertEquals(1, grid(0).cache(null).get(1)); - assertEquals(100, grid(0).cache(null).get(100)); - - // 5 should now point to 5 as we've turned overwriting on. - assertEquals(5, grid(0).cache(null).get(5)); + // i should point to i at all times as we've turned overwrites on above. + for (int i = 1; i <= 100; i++) + assertEquals(i, grid(0).cache(null).get(i)); } }