tkalkirill commented on code in PR #2254: URL: https://github.com/apache/ignite-3/pull/2254#discussion_r1280227560
########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItIndexDdlTest.java: ########## @@ -0,0 +1,100 @@ +/* + * 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.sql.engine; + +import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_SCHEMA_NAME; + +import org.apache.ignite.internal.testframework.IgniteTestUtils; +import org.apache.ignite.lang.IndexAlreadyExistsException; +import org.apache.ignite.lang.IndexNotFoundException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Integration tests for DDL statements that affect indexes. + */ +public class ItIndexDdlTest extends ClusterPerClassIntegrationTest { + private static final String TABLE_NAME = "TEST_TABLE"; + + private static final String INDEX_NAME = "TEST_INDEX"; + + @BeforeEach + void setUp() { + sql(String.format("CREATE TABLE IF NOT EXISTS %s (key BIGINT PRIMARY KEY, valInt INT, valStr VARCHAR)", TABLE_NAME)); + } + + @AfterEach + void tearDown() { + sql(String.format("DROP TABLE IF EXISTS %S", TABLE_NAME)); + } + + @Test + public void testAddIndex() { + tryToCreateIndex(TABLE_NAME, INDEX_NAME, true); + + IgniteTestUtils.assertThrows( + IndexAlreadyExistsException.class, + () -> tryToCreateIndex(TABLE_NAME, INDEX_NAME, true), + String.format("Index already exists [name=\"%s\".\"%s\"]", DEFAULT_SCHEMA_NAME, INDEX_NAME) + ); + + tryToCreateIndex(TABLE_NAME, INDEX_NAME, false); + } + + @Test + void testDropIndex() { + tryToCreateIndex(TABLE_NAME, INDEX_NAME, true); + + // Let's check the drop on an existing index. + tryToDropIndex(INDEX_NAME, true); + + // Let's check the drop on a non-existent index. + IgniteTestUtils.assertThrows( + IndexNotFoundException.class, + () -> tryToDropIndex(INDEX_NAME, true), + String.format("Index does not exist [name=\"%s\".\"%s\"]", DEFAULT_SCHEMA_NAME, INDEX_NAME) + ); + + tryToCreateIndex(TABLE_NAME, INDEX_NAME, false); + } + + /** + * Tries to create the index. + * + * @param tableName Table name. + * @param indexName Index name. + * @param failIfNotExist Throw an exception if the index does not exist. + */ + private static void tryToCreateIndex(String tableName, String indexName, boolean failIfNotExist) { Review Comment: fix it -- 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]
