ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/3] incubator-ignite git commit: # ignite-437: assertRsEquals() was done more simpler
Date Thu, 19 Mar 2015 16:29:39 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-437-sqltests cdf934ba7 -> 6e25dec3b


# ignite-437: assertRsEquals() was done more simpler


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/cabe9474
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/cabe9474
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/cabe9474

Branch: refs/heads/ignite-437-sqltests
Commit: cabe947410acf00e15758d9aec55b76f5dc75dac
Parents: cdf934b
Author: Artem Shutak <ashutak@gridgain.com>
Authored: Thu Mar 19 17:31:30 2015 +0300
Committer: Artem Shutak <ashutak@gridgain.com>
Committed: Thu Mar 19 17:31:30 2015 +0300

----------------------------------------------------------------------
 .../query/h2/sql/IgniteVsH2QueryTest.java       | 130 ++++++++++---------
 1 file changed, 66 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/cabe9474/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/IgniteVsH2QueryTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/IgniteVsH2QueryTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/IgniteVsH2QueryTest.java
index 27f5d24..6f27088 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/IgniteVsH2QueryTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/sql/IgniteVsH2QueryTest.java
@@ -43,10 +43,7 @@ import static org.apache.ignite.cache.CacheDistributionMode.*;
 public class IgniteVsH2QueryTest extends GridCommonAbstractTest {
     /** */
     private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /** */
-    private static Ignite ignite;
-
+    
     /** Partitioned cache. */
     private static IgniteCache pCache;
 
@@ -114,7 +111,7 @@ public class IgniteVsH2QueryTest extends GridCommonAbstractTest {
     @Override protected void beforeTestsStarted() throws Exception {
         super.beforeTestsStarted();
 
-        ignite = startGrids(4);
+        Ignite ignite = startGrids(4);
 
         pCache = ignite.jcache("partitioned");
         
@@ -249,25 +246,25 @@ public class IgniteVsH2QueryTest extends GridCommonAbstractTest {
         Statement st = conn.createStatement();
         
         st.execute("create table if not exists ORGANIZATION" +
-            "  (id number unique," +
+            "  (id int unique," +
             "  name varchar(255))");
         
         st.execute("create table if not exists PERSON" +
-            "  (id number unique, " +
+            "  (id int unique, " +
             "  firstName varchar(255), " +
             "  lastName varchar(255)," +
-            "  orgId number not null," +
-            "  salary decimal )");
+            "  orgId int not null," +
+            "  salary double )");
 
         st.execute("create table if not exists PRODUCT" +
-            "  (id number unique, " +
+            "  (id int unique, " +
             "  name varchar(255), " +
-            "  price number)");
+            "  price int)");
 
         st.execute("create table if not exists PURCHASE" +
-            "  (id number unique, " +
-            "  personId varchar(255), " +
-            "  productId number)");
+            "  (id int unique, " +
+            "  personId int, " +
+            "  productId int)");
 
         conn.commit();
     }
@@ -304,72 +301,69 @@ public class IgniteVsH2QueryTest extends GridCommonAbstractTest {
     private void test0(IgniteCache cache, String sql, Object[] args, Order order) throws
SQLException {
         log.info("Sql=" + sql + ", args=" + Arrays.toString(args));
 
-        ResultSet h2Rs = null;
-        PreparedStatement st = null;
+        List<List<?>> h2Res = executeH2Query(sql, args);
 
-        try {
-            st = conn.prepareStatement(sql);
+        List<List<?>> cacheRes = cache.queryFields(new SqlFieldsQuery(sql).setArgs(args)).getAll();
 
+        assertRsEquals(h2Res, cacheRes, order);
+    }
+    
+    private List<List<?>> executeH2Query(String sql, Object[] args) throws SQLException
{
+        List<List<?>> res = new ArrayList<>();
+        ResultSet rs = null;
+
+        try(PreparedStatement st = conn.prepareStatement(sql)) {
             for (int idx = 0; idx < args.length; idx++) {
                 Object arg = args[idx];
 
                 fillArgByType(st, idx + 1, arg);
             }
 
-            h2Rs = st.executeQuery();
+            rs = st.executeQuery();
 
-            List<List<?>> cacheRes = cache.queryFields(new SqlFieldsQuery(sql).setArgs(args)).getAll();
+            int colCnt = rs.getMetaData().getColumnCount();
 
-            assertRsEquals(h2Rs, cacheRes, order);
+            while (rs.next()) {
+                List<Object> row = new ArrayList<>(colCnt);
+                
+                for (int i = 1; i <= colCnt; i++)
+                    row.add(rs.getObject(i));
+                
+                res.add(row);
+            }
         }
         finally {
-            U.closeQuiet(st);
-            U.closeQuiet(h2Rs);
+            U.closeQuiet(rs);
         }
-    }
-
-    private void assertRsEquals(ResultSet rs, List<List<?>> actualRs, Order order)
throws SQLException {
-        if (!rs.next()) {
-            assertTrue("Actual result set have to be empty.", actualRs.isEmpty());
-
-            return;
-        }
-
-        assertTrue("Actual result set cannot be empty.", !actualRs.isEmpty());
-
-        assertEquals("Column count have to be equal.", rs.getMetaData().getColumnCount(),
actualRs.get(0).size());
-
-        int rsRowsCnt = 0;
-
-        do {
-            if (order == Order.ORDERED) {
-                assertTrue("Current rows counter have to be less than size of actual rs.",
rsRowsCnt < actualRs.size());
 
-                List<?> row = actualRs.get(rsRowsCnt);
-
-                boolean rowsAreEqual = rowEqualsCurrentRsRow(rs, row);
+        return res;
+    }
 
-                assertTrue("Rows " + currentRsRow2String(rs) + " and " + row + " have to
be equal.",
-                    rowsAreEqual);
-            }
-            else {
-                boolean currRowIsFound = false;
+    private void assertRsEquals(List<List<?>> rs1, List<List<?>>
rs2, Order order) {
+        assertEquals("Rows count has to be equal.", rs1.size(), rs2.size());
+        
+        switch (order){
+            case ORDERED:
+                for (int rowNum = 0; rowNum < rs1.size(); rowNum++) {
+                    List<?> row1 = rs1.get(rowNum);
+                    List<?> row2 = rs2.get(rowNum);
 
-                for (List<?> row : actualRs) {
-                    if (rowEqualsCurrentRsRow(rs, row)) {
-                        currRowIsFound = true;
+                    assertEquals("Columns count have to be equal.", row1.size(), row2.size());
 
-                        break;
-                    }
+                    for (int colNum = 0; colNum < row1.size(); colNum++)
+                        assertEquals("Row=" + rowNum + ", column=" + colNum, row1.get(colNum),
row2.get(colNum));
                 }
 
-                assertTrue("A row " + currentRsRow2String(rs) + " not found at " + actualRs
+ '.', currRowIsFound);
-            }
-
-            rsRowsCnt++;
-        } while (rs.next());
-
-        assertEquals("Count of results.", rsRowsCnt, actualRs.size());
+                break;
+            case RANDOM:
+                for (List<?> row1 : rs1)
+                    assertTrue("Actual result set has to contain row.\n" + "Result set="
+ rs2 + "\n" + "Row=" + row1, 
+                        rs2.contains(row1));
+                
+                break;
+            default: 
+                throw new IllegalStateException();
+        }
     }
 
     private static String currentRsRow2String(ResultSet rs) throws SQLException {
@@ -520,8 +514,10 @@ public class IgniteVsH2QueryTest extends GridCommonAbstractTest {
      */
     public void testOrdered() throws Exception {
         test0Ordered("select firstName, lastName" +
-            "  from Person" +
-            "  order by lastName, firstName");
+            "  from Person" 
+//                +
+//            "  order by lastName, firstName"
+        );
     }
 
     /**
@@ -544,6 +540,13 @@ public class IgniteVsH2QueryTest extends GridCommonAbstractTest {
     /**
      * @throws Exception If failed.
      */
+    public void testSimpleReplicatedSelect() throws Exception {
+        test0(rCache, "select id, name from \"replicated\".Product");
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testCrossCache() throws Exception {
         //TODO Investigate (should be 20 results instead of 8)
         test0("select firstName, lastName" +
@@ -738,7 +741,6 @@ public class IgniteVsH2QueryTest extends GridCommonAbstractTest {
             return key;
         }
 
-
         /** {@inheritDoc} */
         @Override public String toString() {
             return "Purchase [id=" + id + ", productId=" + productId + ", personId=" + personId
+ ']';


Mime
View raw message