lowka commented on code in PR #3335:
URL: https://github.com/apache/ignite-3/pull/3335#discussion_r1519538481


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/TransactionEnlistTest.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * 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.exec;
+
+import static 
org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_PARTITION_COUNT;
+import static 
org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.sql.engine.AsyncSqlCursor;
+import org.apache.ignite.internal.sql.engine.AsyncSqlCursorImpl;
+import org.apache.ignite.internal.sql.engine.InternalSqlRow;
+import org.apache.ignite.internal.sql.engine.QueryProcessor;
+import org.apache.ignite.internal.sql.engine.SqlQueryType;
+import org.apache.ignite.internal.sql.engine.framework.DataProvider;
+import org.apache.ignite.internal.sql.engine.framework.NoOpTransaction;
+import org.apache.ignite.internal.sql.engine.framework.TestBuilders;
+import org.apache.ignite.internal.sql.engine.framework.TestCluster;
+import org.apache.ignite.internal.sql.engine.framework.TestNode;
+import org.apache.ignite.internal.sql.engine.prepare.QueryMetadata;
+import org.apache.ignite.internal.sql.engine.prepare.QueryPlan;
+import org.apache.ignite.internal.sql.engine.property.SqlProperties;
+import org.apache.ignite.internal.sql.engine.tx.QueryTransactionWrapperImpl;
+import org.apache.ignite.internal.sql.engine.util.InjectQueryCheckerFactory;
+import org.apache.ignite.internal.sql.engine.util.QueryChecker;
+import org.apache.ignite.internal.sql.engine.util.QueryCheckerExtension;
+import org.apache.ignite.internal.sql.engine.util.QueryCheckerFactory;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.tx.InternalTransaction;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.apache.ignite.internal.util.AsyncCursor;
+import org.apache.ignite.tx.IgniteTransactions;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mockito;
+
+/** Transactions enlist count test. */
+@ExtendWith(QueryCheckerExtension.class)
+public class TransactionEnlistTest extends BaseIgniteAbstractTest {
+    private static final String NODE_NAME1 = "N1";
+
+    @InjectQueryCheckerFactory
+    private static QueryCheckerFactory queryCheckerFactory;
+
+
+    private static final List<String> nodes = IntStream.range(2, 
DEFAULT_PARTITION_COUNT + 1)
+            .mapToObj(n -> "N" + n).collect(Collectors.toList());
+    private static final List<String> allNodes = IntStream.range(1, 
DEFAULT_PARTITION_COUNT + 1)
+            .mapToObj(n -> "N" + n).collect(Collectors.toList());
+
+    private static final TestCluster CLUSTER = TestBuilders.cluster()
+            .nodes(NODE_NAME1, nodes.toArray(String[]::new))
+            .addTable()
+            .name("T1")
+            .addKeyColumn("ID", NativeTypes.INT32)
+            .addColumn("VAL", NativeTypes.INT32)
+            .end()
+            .dataProviders(allNodes, "T1", 
TestBuilders.tableScan(DataProvider.fromCollection(List.of())))
+            .build();
+
+    @BeforeAll
+     static void startCluster() {
+        CLUSTER.start();
+    }
+
+    @AfterAll
+    static void stopCluster() throws Exception {
+        CLUSTER.stop();
+    }
+
+    /**
+     * Check that tx enlist is called only for exact partitions.
+     */
+    @Test
+    void testEnlistCall() {
+        NoOpTransaction tx = NoOpTransaction.readWrite("t1");
+
+        NoOpTransaction spiedTx = Mockito.spy(tx);
+
+        try {
+            assertQuery("INSERT INTO t1 VALUES(1, 2), (2, 3)", spiedTx)
+                    .check();
+        } catch (Exception ex) {
+            // No op.

Review Comment:
   I think its better to update `TestBuilders::TestExecutableTableRegistry` to 
return a mock of `UpdatableTable` for  instead of relying on the fact that an 
unidentifiable error is going to occur in this test.
   
   > UpdatableTable updatableTable = mock(UpdatableTable.class);
   > when(updatableTable.descriptor()).thenReturn(tableDescriptor());
      when(updatableTable.insertAll(any(), any(), 
any())).thenReturn(nullCompletedFuture());
      when(updatableTable.upsertAll(any(), any(), 
any())).thenReturn(nullCompletedFuture());
     when(updatableTable.deleteAll(any(), any(), 
any())).thenReturn(nullCompletedFuture());
               
   >
   > public Supplier<PartitionCalculator> partitionCalculator() {
         return table.partitionCalculator();
   }            



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