bratwurzt commented on a change in pull request #7704: URL: https://github.com/apache/ignite/pull/7704#discussion_r428534696
########## File path: modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/QueryCursorSpliteratorCallsTest.java ########## @@ -0,0 +1,117 @@ +/* + * 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 org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteException; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.query.ContinuousQuery; +import org.apache.ignite.cache.query.Query; +import org.apache.ignite.cache.query.QueryCursor; +import org.apache.ignite.cache.query.ScanQuery; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.SqlQuery; +import org.apache.ignite.cache.query.TextQuery; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +/** + * Query cursor spliterator called multiple times without triggering IgniteException("Iterator is already fetched or + * query was cancelled.") + */ +public class QueryCursorSpliteratorCallsTest extends GridCommonAbstractTest { + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setCacheConfiguration(new CacheConfiguration<>(DEFAULT_CACHE_NAME) + .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL) + .setIndexedTypes(Integer.class, String.class)); + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGrids(1); + } + + /** + * @throws IgniteException If failed. + */ + @Test + public void testScanQueryCursorSpliteratorCalls() throws IgniteException { + doQueryCursorSpliteratorCalls(new ScanQuery<>((key, val) -> key != null)); + } + + /** + * @throws IgniteException If failed. + */ + @Test + public void testContinuousQueryCursorSpliteratorCalls() throws IgniteException { + doQueryCursorSpliteratorCalls(new ContinuousQuery<>() + .setInitialQuery(new ScanQuery<>((key, val) -> key != null)) + .setAutoUnsubscribe(true) + .setLocalListener(iterable -> {})); + } + + /** + * @throws IgniteException If failed. + */ + @Test + public void testSqlQueryCursorSpliteratorCalls() throws IgniteException { + doQueryCursorSpliteratorCalls(new SqlQuery<>("String", "from String")); + } + + /** + * @throws IgniteException If failed. + */ + @Test + public void testSqlFieldQueryCursorSpliteratorCalls() throws IgniteException { + doQueryCursorSpliteratorCalls(new SqlFieldsQuery("select _key from String")); + } + + /** + * @throws IgniteException If failed. + */ + @Test + public void testTextQueryCursorSpliteratorCalls() throws IgniteException { + doQueryCursorSpliteratorCalls(new TextQuery<>("String", "1")); + } + + /** + * Executes query on cache then calls {@link QueryCursor#iterator()} and {@link QueryCursor#spliterator()} + * sequentially. + * + * @param qry Query. + */ + private void doQueryCursorSpliteratorCalls(Query<?> qry) { + Ignite client = grid(0); + + IgniteCache<Object, String> cache = client.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)); + + try (QueryCursor<?> cur = cache.query(qry)) { + cur.iterator(); Review comment: This will not work, since you can't reuse QueryCursorImpl's iterator/spliterator. I think that's why there's `new IgniteException("Iterator is already fetched or query was cancelled.")` on iter() call. ~~Will add AutoClosableCursorSpliterator~~ will find a fix ---------------------------------------------------------------- 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]
