Repository: ignite
Updated Branches:
  refs/heads/ignite-5937 b1e50296d -> a5a8fba32


ignite-5937


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

Branch: refs/heads/ignite-5937
Commit: a5a8fba32bfd5ead0478ce12b2cf39236e7e271a
Parents: b1e5029
Author: sboikov <[email protected]>
Authored: Mon Oct 23 14:27:40 2017 +0300
Committer: sboikov <[email protected]>
Committed: Mon Oct 23 15:35:42 2017 +0300

----------------------------------------------------------------------
 .../cache/mvcc/CacheMvccSqlQueriesTest.java     | 184 ++++++++++---------
 1 file changed, 101 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a5a8fba3/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlQueriesTest.java
----------------------------------------------------------------------
diff --git 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlQueriesTest.java
 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlQueriesTest.java
index 5115eb1..4ba0fcd 100644
--- 
a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlQueriesTest.java
+++ 
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/mvcc/CacheMvccSqlQueriesTest.java
@@ -429,14 +429,14 @@ public class CacheMvccSqlQueriesTest extends 
CacheMvccAbstractTest {
     /**
      * @throws Exception If failed.
      */
-    public void testMaxTransactional_SingleNode() throws Exception {
+    public void testMaxMinTransactional_SingleNode() throws Exception {
         maxMinTransactional(true);
     }
 
     /**
      * @throws Exception If failed.
      */
-    public void testMaxTransactional_ClientServer() throws Exception {
+    public void testMaxMinTransactional_ClientServer() throws Exception {
         maxMinTransactional(false);
     }
 
@@ -456,96 +456,109 @@ public class CacheMvccSqlQueriesTest extends 
CacheMvccAbstractTest {
         final int THREAD_KEY_RANGE = OP_RANGE * THREAD_OPS;
 
         GridInClosure3<Integer, List<TestCache>, AtomicBoolean> writer =
-                new GridInClosure3<Integer, List<TestCache>, AtomicBoolean>() {
-                    @Override public void apply(Integer idx, List<TestCache> 
caches, AtomicBoolean stop) {
-                        ThreadLocalRandom rnd = ThreadLocalRandom.current();
-
-                        int min = idx * THREAD_KEY_RANGE;
-
-                        info("Thread range [start=" + min + ']');
+            new GridInClosure3<Integer, List<TestCache>, AtomicBoolean>() {
+                @Override public void apply(Integer idx, List<TestCache> 
caches, AtomicBoolean stop) {
+                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
 
-                        int cnt = 0;
+                    int min = idx * THREAD_KEY_RANGE;
 
-                        boolean add = true;
+                    info("Thread range [start=" + min + ']');
 
-                        int op = 0;
+                    int cnt = 0;
 
-                        while (!stop.get()) {
-                            TestCache<Integer, MvccTestSqlIndexValue> cache = 
randomCache(caches, rnd);
+                    boolean add = true;
 
-                            try {
-                                int startKey = min + op * OP_RANGE;
+                    int op = 0;
 
-                                if (add) {
-                                    Map<Integer, MvccTestSqlIndexValue> vals = 
new HashMap<>();
+                    while (!stop.get()) {
+                        TestCache<Integer, MvccTestSqlIndexValue> cache = 
randomCache(caches, rnd);
 
-                                    for (int i = 0; i < 10; i++) {
-                                        Integer key = startKey + i + 1;
+                        try {
+                            int startKey = min + op * OP_RANGE;
 
-                                        vals.put(key, new 
MvccTestSqlIndexValue(key));
-                                    }
+                            if (add) {
+                                Map<Integer, MvccTestSqlIndexValue> vals = new 
HashMap<>();
 
-                                    cache.cache.putAll(vals);
+                                for (int i = 0; i < 10; i++) {
+                                    Integer key = startKey + i + 1;
 
-                                    info("put " + vals.keySet());
+                                    vals.put(key, new 
MvccTestSqlIndexValue(key));
                                 }
-                                else {
-                                    Set<Integer> rmvKeys = new HashSet<>();
 
-                                    for (int i = 0; i < 10; i++)
-                                        rmvKeys.add(startKey + i + 1);
+                                cache.cache.putAll(vals);
 
-                                    cache.cache.removeAll(rmvKeys);
+                                // info("put " + vals.keySet());
+                            }
+                            else {
+                                Set<Integer> rmvKeys = new HashSet<>();
 
-                                    info("remove " + rmvKeys);
-                                }
+                                for (int i = 0; i < 10; i++)
+                                    rmvKeys.add(startKey + i + 1);
 
-                                if (++op == THREAD_OPS) {
-                                    add = !add;
+                                cache.cache.removeAll(rmvKeys);
 
-                                    op = 0;
-                                }
+                                // info("remove " + rmvKeys);
                             }
-                            finally {
-                                cache.readUnlock();
+
+                            if (++op == THREAD_OPS) {
+                                add = !add;
+
+                                op = 0;
                             }
                         }
-
-                        info("Writer finished, updates: " + cnt);
+                        finally {
+                            cache.readUnlock();
+                        }
                     }
-                };
+
+                    info("Writer finished, updates: " + cnt);
+                }
+            };
 
         GridInClosure3<Integer, List<TestCache>, AtomicBoolean> reader =
-                new GridInClosure3<Integer, List<TestCache>, AtomicBoolean>() {
-                    @Override public void apply(Integer idx, List<TestCache> 
caches, AtomicBoolean stop) {
-                        ThreadLocalRandom rnd = ThreadLocalRandom.current();
+            new GridInClosure3<Integer, List<TestCache>, AtomicBoolean>() {
+                @Override public void apply(Integer idx, List<TestCache> 
caches, AtomicBoolean stop) {
+                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
 
-                        List<SqlFieldsQuery> qrys = new ArrayList<>();
+                    List<SqlFieldsQuery> maxQrys = new ArrayList<>();
+                    List<SqlFieldsQuery> minQrys = new ArrayList<>();
 
-                        qrys.add(new SqlFieldsQuery("select max(idxVal1) from 
MvccTestSqlIndexValue"));
+                    maxQrys.add(new SqlFieldsQuery("select max(idxVal1) from 
MvccTestSqlIndexValue"));
+                    maxQrys.add(new SqlFieldsQuery("select max(idxVal1) from 
MvccTestSqlIndexValue where idxVal1 >= 0"));
 
-                        qrys.add(new SqlFieldsQuery("select min(idxVal1) from 
MvccTestSqlIndexValue"));
+                    minQrys.add(new SqlFieldsQuery("select min(idxVal1) from 
MvccTestSqlIndexValue"));
+                    minQrys.add(new SqlFieldsQuery("select min(idxVal1) from 
MvccTestSqlIndexValue where idxVal1 >= 0"));
 
-                        while (!stop.get()) {
-                            TestCache<Integer, MvccTestSqlIndexValue> cache = 
randomCache(caches, rnd);
+                    while (!stop.get()) {
+                        TestCache<Integer, MvccTestSqlIndexValue> cache = 
randomCache(caches, rnd);
 
-                            try {
-                                for (SqlFieldsQuery qry : qrys) {
-                                    List<List<?>> res = 
cache.cache.query(qry).getAll();
+                        try {
+                            for (SqlFieldsQuery qry : maxQrys) {
+                                List<List<?>> res = 
cache.cache.query(qry).getAll();
 
-                                    assertEquals(1, res.size());
+                                assertEquals(1, res.size());
 
-                                    Integer m = (Integer)res.get(0).get(0);
+                                Integer m = (Integer)res.get(0).get(0);
 
-                                    assertTrue(m == null || m % 10 == 0);
-                                }
+                                assertTrue(m == null || m % 10 == 0);
                             }
-                            finally {
-                                cache.readUnlock();
+
+                            for (SqlFieldsQuery qry : minQrys) {
+                                List<List<?>> res = 
cache.cache.query(qry).getAll();
+
+                                assertEquals(1, res.size());
+
+                                Integer m = (Integer)res.get(0).get(0);
+
+                                assertTrue(m == null || m % 10 == 1);
                             }
                         }
+                        finally {
+                            cache.readUnlock();
+                        }
                     }
-                };
+                }
+            };
 
         int srvs;
         int clients;
@@ -580,52 +593,57 @@ public class CacheMvccSqlQueriesTest extends 
CacheMvccAbstractTest {
     public void testSqlQueriesWithMvcc() throws Exception {
         Ignite srv0 = startGrid(0);
 
-        IgniteCache<Integer, MvccTestSqlIndexValue> cache =  
(IgniteCache)srv0.createCache(
+        IgniteCache<Integer, MvccTestSqlIndexValue> cache = 
(IgniteCache)srv0.createCache(
             cacheConfiguration(PARTITIONED, FULL_SYNC, 0, 
DFLT_PARTITION_COUNT).
                 setIndexedTypes(Integer.class, MvccTestSqlIndexValue.class));
 
         for (int i = 0; i < 10; i++)
             cache.put(i, new MvccTestSqlIndexValue(i));
 
-        {
-            SqlFieldsQuery qry = new SqlFieldsQuery("select max(idxVal1) from 
MvccTestSqlIndexValue");
+        checkSingleResult(cache, new SqlFieldsQuery("select max(idxVal1) from 
MvccTestSqlIndexValue"), 9);
 
-            cache.query(qry).getAll();
-        }
+        checkSingleResult(cache, new SqlFieldsQuery("select max(idxVal1) from 
MvccTestSqlIndexValue where idxVal1 > 0"), 9);
 
-        {
-            SqlFieldsQuery qry = new SqlFieldsQuery("select min(idxVal1) from 
MvccTestSqlIndexValue");
+        checkSingleResult(cache, new SqlFieldsQuery("select max(idxVal1) from 
MvccTestSqlIndexValue where idxVal1 < 5"), 4);
 
-            cache.query(qry).getAll();
-        }
+        checkSingleResult(cache, new SqlFieldsQuery("select min(idxVal1) from 
MvccTestSqlIndexValue"), 0);
 
-        {
+        checkSingleResult(cache, new SqlFieldsQuery("select min(idxVal1) from 
MvccTestSqlIndexValue where idxVal1 < 100"), 0);
 
-            SqlFieldsQuery qry = new SqlFieldsQuery("select count(*) from 
MvccTestSqlIndexValue");
+        checkSingleResult(cache, new SqlFieldsQuery("select min(idxVal1) from 
MvccTestSqlIndexValue where idxVal1 < 5"), 0);
 
-            cache.query(qry).getAll();
-        }
+        checkSingleResult(cache, new SqlFieldsQuery("select min(idxVal1) from 
MvccTestSqlIndexValue where idxVal1 > 5"), 6);
 
-        {
+        checkSingleResult(cache, new SqlFieldsQuery("select count(*) from 
MvccTestSqlIndexValue"), 10L);
 
-            SqlFieldsQuery qry = new SqlFieldsQuery("select count(*) from 
MvccTestSqlIndexValue where idxVal1=5");
+        checkSingleResult(cache, new SqlFieldsQuery("select count(*) from 
MvccTestSqlIndexValue where idxVal1 >= 0"), 10L);
 
-            cache.query(qry).getAll();
-        }
+        checkSingleResult(cache, new SqlFieldsQuery("select count(*) from 
MvccTestSqlIndexValue where idxVal1 >= 0 and idxVal1 < 100"), 10L);
 
-        {
+        checkSingleResult(cache, new SqlFieldsQuery("select count(*) from 
MvccTestSqlIndexValue where idxVal1 >0 and idxVal1 < 5"), 4L);
 
-            SqlFieldsQuery qry = new SqlFieldsQuery("select count(*) from 
MvccTestSqlIndexValue where idxVal1 >= 0 and idxVal1 < 5");
+        checkSingleResult(cache, new SqlFieldsQuery("select count(*) from 
MvccTestSqlIndexValue where idxVal1 >= 1"), 9L);
 
-            cache.query(qry).getAll();
-        }
+        checkSingleResult(cache, new SqlFieldsQuery("select count(*) from 
MvccTestSqlIndexValue where idxVal1 > 100"), 0L);
 
-        {
+        checkSingleResult(cache, new SqlFieldsQuery("select count(*) from 
MvccTestSqlIndexValue where idxVal1 = 1"), 1L);
+    }
 
-            SqlFieldsQuery qry = new SqlFieldsQuery("select sum(idxVal1) from 
MvccTestSqlIndexValue");
+    /**
+     * @param cache Cache.
+     * @param qry Query.
+     * @param exp Expected value.
+     */
+    private void checkSingleResult(IgniteCache cache, SqlFieldsQuery qry, 
Object exp) {
+        List<List<?>> res = cache.query(qry).getAll();
 
-            cache.query(qry).getAll();
-        }
+        assertEquals(1, res.size());
+
+        List<?> row = res.get(0);
+
+        assertEquals(1, row.size());
+
+        assertEquals(exp, row.get(0));
     }
 
     /**

Reply via email to