rpuch commented on code in PR #2566:
URL: https://github.com/apache/ignite-3/pull/2566#discussion_r1322934137


##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/schemasync/ItSchemaSyncSingleNodeTest.java:
##########
@@ -0,0 +1,207 @@
+/*
+ * 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.schemasync;
+
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.apache.ignite.internal.Cluster;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.tx.InternalTransaction;
+import org.apache.ignite.internal.tx.TxState;
+import org.apache.ignite.lang.ErrorGroups.Transactions;
+import org.apache.ignite.lang.IgniteException;
+import org.apache.ignite.table.Table;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.apache.ignite.tx.TransactionException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+/**
+ * Tests about basic Schema Synchronization properties that can be tested 
using just one Ignite node.
+ */
+class ItSchemaSyncSingleNodeTest extends ClusterPerTestIntegrationTest {
+    private static final int UNKNOWN_RECORD_ID = 999;
+
+    private static final int NODES_TO_START = 1;
+
+    private static final String TABLE_NAME = "test";
+    private static final String UNRELATED_TABLE_NAME = "unrelated_table";
+
+    private IgniteImpl node;
+
+    @Override
+    protected int initialNodes() {
+        return NODES_TO_START;
+    }
+
+    @BeforeEach
+    void assignNode() {
+        node = cluster.node(0);
+    }
+
+    /**
+     * Makes sure that the following sequence results in an operation failure 
and transaction rollback.
+     *
+     * <ol>
+     *     <li>A table is created</li>
+     *     <li>A transaction is started</li>
+     *     <li>The table is enlisted in the transaction</li>
+     *     <li>The table is ALTERed</li>
+     *     <li>An attempt to read or write to the table in the transaction is 
made</li>
+     * </ol>
+     */
+    @ParameterizedTest
+    @EnumSource(Operation.class)
+    void 
readWriteOperationInTxAfterAlteringSchemaOnTargetTableIsRejected(Operation 
operation) {
+        cluster.doInSession(0, session -> {
+            executeUpdate("create table " + TABLE_NAME + " (id int primary 
key, val varchar)", session);
+        });
+
+        Table table = node.tables().table(TABLE_NAME);
+
+        InternalTransaction tx = (InternalTransaction) 
node.transactions().begin();
+
+        enlistTableInTransaction(table, tx);
+
+        cluster.doInSession(0, session -> {
+            executeUpdate("alter table " + TABLE_NAME + " add column added 
int", session);
+        });
+
+        IgniteException ex;
+
+        if (operation.sql()) {
+            ex = assertThrows(IgniteException.class, () -> 
operation.execute(table, tx, cluster));
+            assertThat(
+                    ex.getMessage(),
+                    containsString("Table schema was updated since the 
transaction was started [table=1, startSchema=1, operationSchema=2")
+            );
+        } else {
+            ex = assertThrows(TransactionException.class, () -> 
operation.execute(table, tx, cluster));
+            assertThat(
+                    ex.getMessage(),
+                    is("Table schema was updated since the transaction was 
started [table=1, startSchema=1, operationSchema=2")
+            );
+        }
+
+        assertThat(ex.code(), is(Transactions.TX_INCOMPATIBLE_SCHEMA_ERR));
+
+        // TODO: IGNITE-20342 - Assert for SQL too.
+        if (!operation.sql()) {
+            assertThat(tx.state(), is(TxState.ABORTED));
+        }
+    }
+
+    private void enlistTableInTransaction(Table table, Transaction tx) {
+        executeReadOn(table, tx, cluster);
+    }
+
+    private static void executeReadOn(Table table, Transaction tx, Cluster 
cluster) {

Review Comment:
   I'm trying to underline that we are executing a read; how the read is 
executed (session, SELECT, etc) is irrelevant, hence the method



-- 
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]

Reply via email to