vldpyatkov commented on code in PR #13366: URL: https://github.com/apache/ignite/pull/13366#discussion_r3756843010
########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SelectForUpdateIntegrationTest.java: ########## @@ -0,0 +1,682 @@ +/* + * 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.calcite.integration; + +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.Ignite; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.configuration.TransactionConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.TestRecordingCommunicationSpi; +import org.apache.ignite.internal.processors.query.IgniteSQLException; +import org.apache.ignite.internal.processors.query.QueryEngine; +import org.apache.ignite.internal.processors.query.calcite.QueryChecker; +import org.apache.ignite.internal.processors.query.calcite.message.QueryBatchMessage; +import org.apache.ignite.internal.processors.query.calcite.util.Commons; +import org.apache.ignite.internal.processors.query.calcite.util.IgniteResource; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.transactions.Transaction; +import org.junit.Test; + +import static org.apache.ignite.internal.processors.query.calcite.integration.AbstractBasicIntegrationTransactionalTest.SqlTransactionMode.ALL; +import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; +import static org.apache.ignite.transactions.TransactionState.ACTIVE; + +/** + * Integration tests for {@code SELECT ... FOR UPDATE} syntax. + */ +public class SelectForUpdateIntegrationTest extends AbstractBasicIntegrationTest { + /** */ + private static IgniteEx ignite0; + + /** */ + private static IgniteEx ignite1; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setTransactionConfiguration(new TransactionConfiguration() + .setTxAwareQueriesEnabled(true)) + .setCommunicationSpi(new TestRecordingCommunicationSpi()); + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + ignite0 = grid(0); + ignite1 = grid(1); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + ignite0 = null; + ignite1 = null; + + super.afterTestsStopped(); + } + + /** {@inheritDoc} */ + @Override protected QueryChecker assertQuery(Ignite ignite, String qry) { + Transaction tx = ignite.transactions().tx(); + QueryChecker checker; + + if (tx == null) + checker = super.assertQuery(ignite, qry); + else { + checker = new QueryChecker(qry, tx, ALL) { + @Override public void check() { + tx.suspend(); + + try { + super.check(); + } + finally { + tx.resume(); + } + } + + @Override protected QueryEngine getEngine() { + return Commons.lookupComponent(((IgniteEx)ignite).context(), QueryEngine.class); + } + }; + } + + return checker; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + sql("CREATE TABLE Person (id INT PRIMARY KEY, name VARCHAR, age INT, deptId INT, managerId INT) " + + "WITH atomicity=TRANSACTIONAL"); + sql("INSERT INTO Person (id, name, age) VALUES " + + "(1, 'Alice', 20), (2, 'Bob', 21), (3, 'Ann', 22), (4, 'Bill', 23)" + + ", (5, 'Alex', 24), (6, 'Ben', 25), (7, 'Cathy', 26), (8, 'Carl', 27), (9, 'Diana', 28)" + + ", (10, 'David', 29), (11, 'Eva', 30), (12, 'Evan', 31), (13, 'Fiona', 32), (14, 'Frank', 33)" + + ", (15, 'Grace', 34), (16, 'George', 35), (17, 'Hannah', 36), (18, 'Harry', 37), (19, 'Ivy', 38)" + + ", (20, 'Ian', 39), (21, 'Jack', 40), (22, 'Jill', 41), (23, 'Karen', 42), (24, 'Kyle', 43)" + + ", (25, 'Laura', 44), (26, 'Leo', 45), (27, 'Mia', 46), (28, 'Mike', 47), (29, 'Nina', 48)" + + ", (30, 'Nick', 49)"); + sql("UPDATE Person SET deptId = 1, managerId = 2 WHERE id = 1"); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + sql("DROP TABLE IF EXISTS Dept"); + sql("DROP TABLE IF EXISTS Person"); + + super.afterTest(); + } + + /** SELECT FOR UPDATE without OF locks rows of every table participating in a JOIN. */ + @Test + public void testSelectForUpdateJoinLocksAllTables() throws Exception { + createDeptTable(); + + CountDownLatch locked = new CountDownLatch(1); + CountDownLatch release = new CountDownLatch(1); + + IgniteInternalFuture<?> lockFut = GridTestUtils.runAsync(() -> { + try (Transaction tx = ignite0.transactions().txStart(PESSIMISTIC, READ_COMMITTED)) { + assertQuery(ignite0, + "SELECT p.id FROM Person p JOIN Dept d ON p.deptId = d.id WHERE p.id = 1 FOR UPDATE") Review Comment: https://issues.apache.org/jira/browse/IGNITE-28974 Ticket created. -- 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]
