IGNITE-14854 Fix tests IgniteCacheLocalQueryDefaultTimeoutSelfTest for lazy=true mode (#9161)

diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQueryDefaultTimeoutSelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQueryDefaultTimeoutSelfTest.java
index 62475a1..29a014e 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQueryDefaultTimeoutSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/local/IgniteCacheLocalQueryDefaultTimeoutSelfTest.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.cache.local;
 
 import java.util.Arrays;
+import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import org.apache.ignite.Ignite;
@@ -28,6 +29,7 @@
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.internal.processors.query.timeout.TimedQueryHelper;
 import org.apache.ignite.internal.util.typedef.X;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
 import org.junit.Test;
@@ -39,21 +41,22 @@
  */
 public class IgniteCacheLocalQueryDefaultTimeoutSelfTest extends GridCommonAbstractTest {
     /** Cache size. */
-    private static final int CACHE_SIZE = 10_000;
+    private static final int CACHE_SIZE = 1_000;
 
     /** Default query timeout */
     private static final long DEFAULT_QUERY_TIMEOUT = 1000;
 
     /** */
-    private static final String QUERY = "select a._val, b._val from String a, String b";
+    private static final String QUERY = "select a._val, b._val, longProcess(a._key, 5) from String a, String b";
 
     /** {@inheritDoc} */
     @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
 
-        CacheConfiguration<Integer, String> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
-        ccfg.setIndexedTypes(Integer.class, String.class);
-        ccfg.setCacheMode(LOCAL);
+        CacheConfiguration<Integer, String> ccfg = new CacheConfiguration<Integer, String>(DEFAULT_CACHE_NAME)
+            .setIndexedTypes(Integer.class, String.class)
+            .setCacheMode(LOCAL)
+            .setSqlFunctionClasses(TimedQueryHelper.class);
 
         cfg.setCacheConfiguration(ccfg);
         cfg.setSqlConfiguration(new SqlConfiguration().setDefaultQueryTimeout(DEFAULT_QUERY_TIMEOUT));
@@ -139,7 +142,12 @@
         }
 
         try (QueryCursor<List<?>> ignored = cursor) {
-            cursor.iterator();
+            Iterator<List<?>> it = cursor.iterator();
+
+            if (qry.isLazy()) {
+                while (it.hasNext())
+                    it.next();
+            }
 
             fail("Expecting timeout");
         }
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/AbstractDefaultQueryTimeoutTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/AbstractDefaultQueryTimeoutTest.java
index a64f53e..7ab8938 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/AbstractDefaultQueryTimeoutTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/AbstractDefaultQueryTimeoutTest.java
@@ -32,19 +32,6 @@
  *
  */
 public abstract class AbstractDefaultQueryTimeoutTest extends AbstractIndexingCommonTest {
-    /** Update query. */
-    private final boolean updateQuery;
-
-    /** */
-    protected AbstractDefaultQueryTimeoutTest() {
-        this(false);
-    }
-
-    /** */
-    protected AbstractDefaultQueryTimeoutTest(boolean updateQuery) {
-        this.updateQuery = updateQuery;
-    }
-
     /** {@inheritDoc} */
     @Override protected void afterTest() throws Exception {
         stopAllGrids();
@@ -52,6 +39,11 @@
         super.afterTest();
     }
 
+    /** */
+    protected boolean updateQuery() {
+        return false;
+    }
+
     /**
      * Check the default query timeout.
      * Steps:
@@ -216,7 +208,7 @@
 
         helper.createCache(ign);
 
-        String qryText = updateQuery ? helper.buildTimedUpdateQuery() : helper.buildTimedQuery();
+        String qryText = updateQuery() ? helper.buildTimedUpdateQuery() : helper.buildTimedQuery();
 
         IgniteInternalFuture<?> fut1 = GridTestUtils.runAsync(() -> {
             executeQuery(qryText, 500);
@@ -261,7 +253,7 @@
         helper.createCache(grid(0));
 
         Callable<Void> c = () -> {
-            String qryText = updateQuery ? helper.buildTimedUpdateQuery() : helper.buildTimedQuery();
+            String qryText = updateQuery() ? helper.buildTimedUpdateQuery() : helper.buildTimedQuery();
 
             if (explicitTimeout != null)
                 executeQuery(qryText, explicitTimeout);
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutTestSuite.java
index b116e94..5b6ef54 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutTestSuite.java
@@ -27,9 +27,6 @@
 @Suite.SuiteClasses({
     DefaultQueryTimeoutConfigurationTest.class,
     DefaultQueryTimeoutThickJavaTest.class,
-    DefaultQueryTimeoutThickJavaLazyTest.class,
-    DefaultQueryTimeoutThickJavaUpdateTest.class,
-    DefaultQueryTimeoutThickJavaUpdateLazyTest.class,
     DefaultQueryTimeoutThinJavaTest.class,
     DefaultQueryTimeoutThinJdbcTest.class
 })
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaLazyTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaLazyTest.java
deleted file mode 100644
index 2bd995c..0000000
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaLazyTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.query.timeout;
-
-/**
- *
- */
-public class DefaultQueryTimeoutThickJavaLazyTest extends DefaultQueryTimeoutThickJavaTest {
-    /** */
-    public DefaultQueryTimeoutThickJavaLazyTest() {
-        super(false, true);
-    }
-}
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaTest.java
index 448119d..ee6d6ff 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaTest.java
@@ -17,47 +17,70 @@
 
 package org.apache.ignite.internal.processors.query.timeout;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
+
 import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 /**
  *
  */
+@RunWith(Parameterized.class)
 public class DefaultQueryTimeoutThickJavaTest extends AbstractDefaultQueryTimeoutTest {
-    /** Lazy. */
-    private final boolean lazy;
+    /** Lazy mode. */
+    @Parameterized.Parameter(value = 0)
+    public boolean lazy;
+
+    /** Execute update queries. */
+    @Parameterized.Parameter(value = 1)
+    public boolean update;
+
+    /** Execute local queries. */
+    @Parameterized.Parameter(value = 2)
+    public boolean local;
 
     /** */
-    public DefaultQueryTimeoutThickJavaTest() {
-        this(false, false);
+    @Parameterized.Parameters(name = "lazy={0}, update={1}, local={2}")
+    public static List<Object[]> parameters() {
+        ArrayList<Object[]> params = new ArrayList<>();
+
+        boolean[] arrBool = new boolean[] {true, false};
+
+        for (boolean lazy0 : arrBool) {
+            for (boolean update0 : arrBool) {
+                for (boolean local0 : arrBool) {
+                    if (local0 && update0)
+                        continue;
+
+                    params.add(new Object[] {lazy0, update0, local0});
+                }
+            }
+        }
+
+        return params;
     }
 
-    /** */
-    protected DefaultQueryTimeoutThickJavaTest(boolean updateQuery, boolean lazy) {
-        super(updateQuery);
-
-        this.lazy = lazy;
-    }
-
-    /** {@inheritDoc} */
+        /** {@inheritDoc} */
     @Override protected void prepareQueryExecution() throws Exception {
         super.prepareQueryExecution();
 
-        startClientGrid(10);
+        startClientGrid("cli");
     }
 
     /** {@inheritDoc} */
     @Override protected void executeQuery(String sql) throws Exception {
-        executeQuery0(new SqlFieldsQuery(sql).setLazy(lazy));
+        executeQuery0(new SqlFieldsQuery(sql));
     }
 
     /** {@inheritDoc} */
     @Override protected void executeQuery(String sql, int timeout) throws Exception {
         executeQuery0(new SqlFieldsQuery(sql)
-            .setLazy(lazy)
             .setTimeout(timeout, TimeUnit.MILLISECONDS));
     }
 
@@ -68,11 +91,17 @@
     }
 
     /** */
+    @Override protected boolean updateQuery() {
+        return update;
+    }
+
+    /** */
     private void executeQuery0(SqlFieldsQuery qry) throws Exception {
-        IgniteEx cli = grid(10);
-
         qry.setLazy(lazy);
+        qry.setLocal(local);
 
-        cli.context().query().querySqlFields(qry, false).getAll();
+        IgniteEx ign = local ? grid(0) : grid("cli");
+
+        ign.context().query().querySqlFields(qry, false).getAll();
     }
 }
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaUpdateLazyTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaUpdateLazyTest.java
deleted file mode 100644
index a178589..0000000
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaUpdateLazyTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.query.timeout;
-
-/**
- *
- */
-public class DefaultQueryTimeoutThickJavaUpdateLazyTest extends DefaultQueryTimeoutThickJavaTest {
-    /** */
-    public DefaultQueryTimeoutThickJavaUpdateLazyTest() {
-        super(true, true);
-    }
-}
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaUpdateTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaUpdateTest.java
deleted file mode 100644
index 1b6b5bf..0000000
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/timeout/DefaultQueryTimeoutThickJavaUpdateTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.processors.query.timeout;
-
-/**
- *
- */
-public class DefaultQueryTimeoutThickJavaUpdateTest extends DefaultQueryTimeoutThickJavaTest {
-    /** */
-    public DefaultQueryTimeoutThickJavaUpdateTest() {
-        super(true, false);
-    }
-}