vladErmakov07 commented on a change in pull request #9164: URL: https://github.com/apache/ignite/pull/9164#discussion_r649339698
########## File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/IgniteSqlSinglePartitionMultiParallelismTest.java ########## @@ -0,0 +1,153 @@ +/* + * 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; + +import java.util.Collections; +import java.util.List; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest; +import org.junit.Test; + +import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; +import static org.apache.ignite.cache.CacheMode.PARTITIONED; +import static org.apache.ignite.cache.PartitionLossPolicy.READ_WRITE_SAFE; + +/** + * IGNITE-14120 Test for correct results in case of query with single partition and cache with parallelism > 1. + */ +public class IgniteSqlSinglePartitionMultiParallelismTest extends AbstractIndexingCommonTest { + /** */ + private static final String CACHE_NAME = "SC_NULL_TEST"; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGrids(1); + ignite(0).createCache(cacheConfig()); + createTable(); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + grid(0).destroyCaches(Collections.singletonList(CACHE_NAME)); + } + + /** + * @return Cache configuration. + */ + protected CacheConfiguration<Integer, Integer> cacheConfig() { + return new CacheConfiguration<Integer, Integer>() + .setName(CACHE_NAME) + .setCacheMode(PARTITIONED) + .setReadFromBackup(false) + .setStatisticsEnabled(true) + .setQueryParallelism(100) + .setSqlIndexMaxInlineSize(64) + .setBackups(0) + .setPartitionLossPolicy(READ_WRITE_SAFE) + .setAtomicityMode(TRANSACTIONAL); + } + + /** + * Check common case without partitions. Should be single result. + */ + @Test + public void assertSimpleCountQuery() throws Exception { + run(() -> { + List<List<?>> results = runQuery("select count(*) from SC_NULL_TEST"); + + Long res = (Long) results.get(0).get(0); + + assertEquals(1, results.size()); + assertEquals(Long.valueOf(999), res); + }); + } + + /** + * Check case with 1 partition. Partition segment must be calculated correctly. + */ + @Test + public void assertWhereCountFirstPartitionQuery() throws Exception { + run(() -> { + List<List<?>> results = runQuery("select count(*) from SC_NULL_TEST where ID=1"); + + Long res = (Long) results.get(0).get(0); + + assertEquals(1, results.size()); + assertEquals(Long.valueOf(1), res); + }); + } + + /** + * Check case with 1 partition. Partition segment must be calculated correctly. + */ + @Test + public void assertWhereCountAnotherPartitionQuery() throws Exception { + run(() -> { + List<List<?>> results = runQuery("select count(*) from SC_NULL_TEST where ID=973"); + + Long res = (Long) results.get(0).get(0); + + assertEquals(1, results.size()); + assertEquals(Long.valueOf(1), res); + }); + } + + /** + * Check case with 2 partition. Multiple partitions should not be affected. + */ + @Test + public void assertWhereCountMultiPartitionsQuery() throws Exception { + run(() -> { + List<List<?>> results = runQuery("select count(*) from SC_NULL_TEST where ID=5 or ID=995"); + + Long res = (Long) results.get(0).get(0); + + assertEquals(1, results.size()); + assertEquals(Long.valueOf(2), res); + }); + } + + /** */ + private void run(Runnable test) throws Exception { Review comment: Forgot about it, removed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
