sanpwc commented on code in PR #7270: URL: https://github.com/apache/ignite-3/pull/7270#discussion_r2644019210
########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIndexNodeTest.java: ########## @@ -0,0 +1,318 @@ +/* + * 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.runner.app; + +import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; +import static org.apache.ignite.internal.TestWrappers.unwrapTableViewInternal; +import static org.apache.ignite.internal.network.configuration.NetworkConfigurationSchema.DEFAULT_PORT; +import static org.apache.ignite.internal.storage.index.SortedIndexStorage.GREATER_OR_EQUAL; +import static org.apache.ignite.internal.storage.index.SortedIndexStorage.LESS_OR_EQUAL; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName; +import static org.apache.ignite.internal.testframework.flow.TestFlowUtils.subscribeToList; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Flow.Publisher; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteServer; +import org.apache.ignite.InitParameters; +import org.apache.ignite.InitParametersBuilder; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder; +import org.apache.ignite.internal.binarytuple.BinaryTupleReader; +import org.apache.ignite.internal.catalog.Catalog; +import org.apache.ignite.internal.catalog.CatalogManager; +import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor; +import org.apache.ignite.internal.schema.BinaryRow; +import org.apache.ignite.internal.schema.BinaryTuple; +import org.apache.ignite.internal.schema.BinaryTuplePrefix; +import org.apache.ignite.internal.schema.Column; +import org.apache.ignite.internal.schema.SchemaDescriptor; +import org.apache.ignite.internal.sql.SqlCommon; +import org.apache.ignite.internal.table.IndexScanCriteria; +import org.apache.ignite.internal.table.InternalTable; +import org.apache.ignite.internal.table.OperationContext; +import org.apache.ignite.internal.table.TableViewInternal; +import org.apache.ignite.internal.table.TxContext; +import org.apache.ignite.internal.testframework.IgniteAbstractTest; +import org.apache.ignite.internal.testframework.TestIgnitionManager; +import org.apache.ignite.internal.tx.InternalTransaction; +import org.apache.ignite.table.Table; +import org.apache.ignite.tx.TransactionOptions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; + +/** + * Integration tests running against a single Ignite node validating index behavior. + */ +public class ItIndexNodeTest extends IgniteAbstractTest { Review Comment: There are `ClusterPerClassIntegrationTest` and `ClusterPerTestIntegrationTest` abstract tests that might be used in order to properly start/init and stop ignite nodes. PerClass one will instantiate cluster in @BeforeAll, PerTest in @BeforeEach - meaning that every test will startup it's own cluster, usually we don't need this. In order to specify cluster size (amount of nodes) you may override `initialNodes()` ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIndexNodeTest.java: ########## @@ -0,0 +1,318 @@ +/* + * 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.runner.app; + +import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; +import static org.apache.ignite.internal.TestWrappers.unwrapTableViewInternal; +import static org.apache.ignite.internal.network.configuration.NetworkConfigurationSchema.DEFAULT_PORT; +import static org.apache.ignite.internal.storage.index.SortedIndexStorage.GREATER_OR_EQUAL; +import static org.apache.ignite.internal.storage.index.SortedIndexStorage.LESS_OR_EQUAL; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName; +import static org.apache.ignite.internal.testframework.flow.TestFlowUtils.subscribeToList; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Flow.Publisher; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteServer; +import org.apache.ignite.InitParameters; +import org.apache.ignite.InitParametersBuilder; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder; +import org.apache.ignite.internal.binarytuple.BinaryTupleReader; +import org.apache.ignite.internal.catalog.Catalog; +import org.apache.ignite.internal.catalog.CatalogManager; +import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor; +import org.apache.ignite.internal.schema.BinaryRow; +import org.apache.ignite.internal.schema.BinaryTuple; +import org.apache.ignite.internal.schema.BinaryTuplePrefix; +import org.apache.ignite.internal.schema.Column; +import org.apache.ignite.internal.schema.SchemaDescriptor; +import org.apache.ignite.internal.sql.SqlCommon; +import org.apache.ignite.internal.table.IndexScanCriteria; +import org.apache.ignite.internal.table.InternalTable; +import org.apache.ignite.internal.table.OperationContext; +import org.apache.ignite.internal.table.TableViewInternal; +import org.apache.ignite.internal.table.TxContext; +import org.apache.ignite.internal.testframework.IgniteAbstractTest; +import org.apache.ignite.internal.testframework.TestIgnitionManager; +import org.apache.ignite.internal.tx.InternalTransaction; +import org.apache.ignite.table.Table; +import org.apache.ignite.tx.TransactionOptions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; + +/** + * Integration tests running against a single Ignite node validating index behavior. + */ +public class ItIndexNodeTest extends IgniteAbstractTest { + private static final String NODE_CONFIG = "ignite.network.nodeFinder.netClusterNodes: [ \"localhost:" + DEFAULT_PORT + "\"]"; + + private static final String TABLE_NAME = "TEST_TABLE"; + private static final String HASH_IDX = "TEST_HASH_IDX"; + private static final String SORT_IDX = "TEST_SORT_IDX"; + private static final int LOWER_BOUND = 10; + private static final int UPPER_BOUND = 20; + private static final int VALUE = 15; + private static final int PART_ID = 0; + + private String nodeName; + + private IgniteServer node; + + private Ignite ignite; + private InternalTable internalTable; + private int hashIdx; + private int sortIdx; + + TableViewInternal tableViewInternal; + + @BeforeEach + void setUp(TestInfo testInfo) { + nodeName = testNodeName(testInfo, 0); + + node = TestIgnitionManager.start(nodeName, NODE_CONFIG, workDir.resolve(nodeName)); + + InitParameters parameters = new InitParametersBuilder() + .clusterName("cluster") + .metaStorageNodes(node) + .build(); + + node.initCluster(parameters); + + assertThat(node.waitForInitAsync(), willCompleteSuccessfully()); + + ignite = node.api(); + + // Create zone with 1 partition. + String createZoneSql = "CREATE ZONE IF NOT EXISTS test_zone (PARTITIONS 1, REPLICAS 1) STORAGE PROFILES ['default']"; + + String createTableSql = "CREATE TABLE " + TABLE_NAME + "(\n" + + " key int PRIMARY KEY,\n" + + " field1 int,\n" + + " field2 int\n" + + ") ZONE test_zone"; + String createHashIndexSql = "CREATE INDEX IF NOT EXISTS " + HASH_IDX + " ON " + TABLE_NAME + " USING HASH (field1)"; + String createSortIndexSql = "CREATE INDEX IF NOT EXISTS " + SORT_IDX + " ON " + TABLE_NAME + " USING SORTED (field2)"; + String insertWithParams = "INSERT INTO " + TABLE_NAME + " (key, field1, field2) VALUES (?, ?, ?)"; + + ignite.sql().execute(null, createZoneSql); + ignite.sql().execute(null, createTableSql); + ignite.sql().execute(null, createHashIndexSql); + ignite.sql().execute(null, createSortIndexSql); + ignite.sql().execute(null, insertWithParams, 1, VALUE, VALUE); + + IgniteImpl igniteImpl = unwrapIgniteImpl(ignite); + + CatalogManager catalogManager = igniteImpl.catalogManager(); + + Catalog catalog = catalogManager.activeCatalog(igniteImpl.clock().nowLong()); + + hashIdx = getIndexIdBy(HASH_IDX, catalog); + sortIdx = getIndexIdBy(SORT_IDX, catalog); + + // Get the public Table API. + Table table = ignite.tables().table(TABLE_NAME); + + assertNotNull(table); + + // Unwrap to get TableViewInternal. + tableViewInternal = unwrapTableViewInternal(table); + + // Get the InternalTable. + internalTable = tableViewInternal.internalTable(); + + assertNotNull(internalTable); + } + + @AfterEach + void tearDown() { + node.shutdown(); + } + + @Test + void testHashIndexThrowsWithRangeScan() { + Publisher<BinaryRow> publisher = internalTable.scan(PART_ID, null, hashIdx, + createMatchingRange()); + CompletableFuture<List<BinaryRow>> resultFuture = subscribeToList(publisher); + assertThrows(ExecutionException.class, () -> { Review Comment: Here and below, we should not only check that an exception is thrown, but also verify that it's an exception of proper class with proper error message. You may find the `org.apache.ignite.internal.testframework.IgniteTestUtils#assertThrowsWithCause(org.apache.ignite.internal.lang.RunnableX, java.lang.Class<? extends java.lang.Throwable>, java.lang.String)` helpful. Please pay attention to the last String param, that is a prefix of an expected message. Here's an example ``` assertThrowsWithCause(() -> marshaller.marshal(tuple1), InvalidTypeException.class, "Value too long [column='BYTES', type=BYTE_ARRAY(5)]" ); ``` ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItIndexNodeTest.java: ########## @@ -0,0 +1,318 @@ +/* + * 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.runner.app; + +import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl; +import static org.apache.ignite.internal.TestWrappers.unwrapTableViewInternal; +import static org.apache.ignite.internal.network.configuration.NetworkConfigurationSchema.DEFAULT_PORT; +import static org.apache.ignite.internal.storage.index.SortedIndexStorage.GREATER_OR_EQUAL; +import static org.apache.ignite.internal.storage.index.SortedIndexStorage.LESS_OR_EQUAL; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName; +import static org.apache.ignite.internal.testframework.flow.TestFlowUtils.subscribeToList; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Flow.Publisher; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteServer; +import org.apache.ignite.InitParameters; +import org.apache.ignite.InitParametersBuilder; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder; +import org.apache.ignite.internal.binarytuple.BinaryTupleReader; +import org.apache.ignite.internal.catalog.Catalog; +import org.apache.ignite.internal.catalog.CatalogManager; +import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor; +import org.apache.ignite.internal.schema.BinaryRow; +import org.apache.ignite.internal.schema.BinaryTuple; +import org.apache.ignite.internal.schema.BinaryTuplePrefix; +import org.apache.ignite.internal.schema.Column; +import org.apache.ignite.internal.schema.SchemaDescriptor; +import org.apache.ignite.internal.sql.SqlCommon; +import org.apache.ignite.internal.table.IndexScanCriteria; +import org.apache.ignite.internal.table.InternalTable; +import org.apache.ignite.internal.table.OperationContext; +import org.apache.ignite.internal.table.TableViewInternal; +import org.apache.ignite.internal.table.TxContext; +import org.apache.ignite.internal.testframework.IgniteAbstractTest; +import org.apache.ignite.internal.testframework.TestIgnitionManager; +import org.apache.ignite.internal.tx.InternalTransaction; +import org.apache.ignite.table.Table; +import org.apache.ignite.tx.TransactionOptions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; + +/** + * Integration tests running against a single Ignite node validating index behavior. + */ +public class ItIndexNodeTest extends IgniteAbstractTest { + private static final String NODE_CONFIG = "ignite.network.nodeFinder.netClusterNodes: [ \"localhost:" + DEFAULT_PORT + "\"]"; + + private static final String TABLE_NAME = "TEST_TABLE"; + private static final String HASH_IDX = "TEST_HASH_IDX"; + private static final String SORT_IDX = "TEST_SORT_IDX"; + private static final int LOWER_BOUND = 10; + private static final int UPPER_BOUND = 20; + private static final int VALUE = 15; + private static final int PART_ID = 0; + + private String nodeName; + + private IgniteServer node; + + private Ignite ignite; + private InternalTable internalTable; + private int hashIdx; + private int sortIdx; + + TableViewInternal tableViewInternal; + + @BeforeEach + void setUp(TestInfo testInfo) { + nodeName = testNodeName(testInfo, 0); + + node = TestIgnitionManager.start(nodeName, NODE_CONFIG, workDir.resolve(nodeName)); + + InitParameters parameters = new InitParametersBuilder() + .clusterName("cluster") + .metaStorageNodes(node) + .build(); + + node.initCluster(parameters); + + assertThat(node.waitForInitAsync(), willCompleteSuccessfully()); + + ignite = node.api(); + + // Create zone with 1 partition. + String createZoneSql = "CREATE ZONE IF NOT EXISTS test_zone (PARTITIONS 1, REPLICAS 1) STORAGE PROFILES ['default']"; + + String createTableSql = "CREATE TABLE " + TABLE_NAME + "(\n" + + " key int PRIMARY KEY,\n" + + " field1 int,\n" + + " field2 int\n" + + ") ZONE test_zone"; + String createHashIndexSql = "CREATE INDEX IF NOT EXISTS " + HASH_IDX + " ON " + TABLE_NAME + " USING HASH (field1)"; + String createSortIndexSql = "CREATE INDEX IF NOT EXISTS " + SORT_IDX + " ON " + TABLE_NAME + " USING SORTED (field2)"; + String insertWithParams = "INSERT INTO " + TABLE_NAME + " (key, field1, field2) VALUES (?, ?, ?)"; + + ignite.sql().execute(null, createZoneSql); + ignite.sql().execute(null, createTableSql); + ignite.sql().execute(null, createHashIndexSql); + ignite.sql().execute(null, createSortIndexSql); + ignite.sql().execute(null, insertWithParams, 1, VALUE, VALUE); Review Comment: Only one record? In order to properly check scan it's better to have multiple I guess. I do understand that it's not required for testing some invariants it's just covers more possibilities which is better. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
