AMashenkov commented on a change in pull request #7412: IGNITE-12067 User SQL query execution metrics URL: https://github.com/apache/ignite/pull/7412#discussion_r378123620
########## File path: modules/indexing/src/test/java/org/apache/ignite/internal/metric/SqlStatisticsAbstractTest.java ########## @@ -0,0 +1,200 @@ +/* + * 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.metric; + +import java.util.Collections; +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.query.annotations.QuerySqlFunction; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * Abstract test for sql metrics tests. + */ +public class SqlStatisticsAbstractTest extends GridCommonAbstractTest { + /** + * Timeout for each wait on sync operation in seconds. + */ + public static final long WAIT_OP_TIMEOUT_SEC = 15; + + /** + * Number of rows in the test table. + */ + public static final int TABLE_SIZE = 10_000; + + /** + * Start the cache with a test table and test data. + */ + protected IgniteCache createCacheFrom(Ignite node) { + CacheConfiguration<Integer, String> ccfg = new CacheConfiguration<Integer, String>(DEFAULT_CACHE_NAME) + .setSqlFunctionClasses(SuspendQuerySqlFunctions.class) + .setQueryEntities(Collections.singleton( + new QueryEntity(Integer.class.getName(), String.class.getName()) + .setTableName("TAB") + .addQueryField("id", Integer.class.getName(), null) + .addQueryField("name", String.class.getName(), null) + .setKeyFieldName("id") + .setValueFieldName("name") + )); + + IgniteCache<Integer, String> cache = node.createCache(ccfg); + + try (IgniteDataStreamer<Object, Object> ds = node.dataStreamer(DEFAULT_CACHE_NAME)) { + for (int i = 0; i < TABLE_SIZE; i++) + ds.addData(i, UUID.randomUUID().toString()); + } + + return cache; + } + + /** + * Run async action and log if exception occured. + * + * @param act action to perform on other thread. + * @return future object to "action complited" event. + */ + protected IgniteInternalFuture runAsyncX(Runnable act) { + return GridTestUtils.runAsync(() -> { + try { + act.run(); + } + catch (Throwable th) { + log.error("Failed to perform async action. Probably test is broken.", th); + } + }); + } + + /** + * This class exports function to the sql engine. Function implementation allows us to suspend query execution on test + * logic condition. + */ + public static class SuspendQuerySqlFunctions { + /** + * How many rows should be processed (by all nodes in total) + */ + private static final int DFLT_PROCESS_ROWS_TO_SUSPEND = TABLE_SIZE / 4; + + /** + * Latch to await till full scan query that uses this class function have done some job, so some memory is Review comment: Next statement makes no sense here "so some memory is reserved." ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services