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


##########
modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/exec/rel/ScannableTableSelfTest.java:
##########
@@ -0,0 +1,952 @@
+/*
+ * 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.rel;
+
+import static 
org.apache.ignite.internal.sql.engine.exec.exp.ExpressionFactoryImpl.UNSPECIFIED_VALUE_PLACEHOLDER;
+import static org.apache.ignite.lang.IgniteStringFormatter.format;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.when;
+
+import java.util.AbstractMap.SimpleEntry;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Flow.Publisher;
+import java.util.concurrent.Flow.Subscriber;
+import java.util.concurrent.Flow.Subscription;
+import java.util.concurrent.SubmissionPublisher;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory.Builder;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.index.SortedIndex;
+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.sql.engine.exec.ArrayRowHandler;
+import org.apache.ignite.internal.sql.engine.exec.ExecutionContext;
+import org.apache.ignite.internal.sql.engine.exec.RowHandler;
+import org.apache.ignite.internal.sql.engine.exec.RowHandler.RowFactory;
+import org.apache.ignite.internal.sql.engine.exec.ScannableTable;
+import org.apache.ignite.internal.sql.engine.exec.ScannableTableImpl;
+import org.apache.ignite.internal.sql.engine.exec.TableRowConverter;
+import org.apache.ignite.internal.sql.engine.exec.TxAttributes;
+import org.apache.ignite.internal.sql.engine.exec.exp.RangeCondition;
+import org.apache.ignite.internal.sql.engine.framework.NoOpTransaction;
+import org.apache.ignite.internal.sql.engine.metadata.PartitionWithTerm;
+import 
org.apache.ignite.internal.sql.engine.planner.AbstractPlannerTest.TestTableDescriptor;
+import org.apache.ignite.internal.sql.engine.schema.TableDescriptor;
+import org.apache.ignite.internal.sql.engine.trait.IgniteDistributions;
+import org.apache.ignite.internal.sql.engine.type.IgniteTypeFactory;
+import org.apache.ignite.internal.sql.engine.util.Commons;
+import org.apache.ignite.internal.table.InternalTable;
+import org.apache.ignite.internal.utils.PrimaryReplica;
+import org.apache.ignite.network.ClusterNode;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.Named;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+/**
+ * Unit tests for {@link ScannableTableImpl}. We check that scan/lookup 
operations call appropriate methods
+ * of the underlying APIs with required arguments.
+ */
+@ExtendWith(MockitoExtension.class)
+public class ScannableTableSelfTest {
+
+    private static final NoOpTransaction RO_TX = 
NoOpTransaction.readOnly("RO");
+
+    private static final NoOpTransaction RW_TX = 
NoOpTransaction.readWrite("RW");
+
+    private static final IgniteTypeFactory TYPE_FACTORY = 
Commons.typeFactory();
+
+    @Mock(lenient = true)
+    private InternalTable internalTable;
+
+    @Mock(lenient = true)
+    private ExecutionContext<Object[]> ctx;
+
+    @Mock
+    private BinaryRow binaryRow;
+
+    /**
+     * Table scan.
+     */
+    @ParameterizedTest
+    @MethodSource("transactions")
+    public void testTableScan(NoOpTransaction tx) {
+        TestInput data = new TestInput();
+        data.addRow(binaryRow);
+
+        Tester tester = new Tester(data);
+
+        int partitionId = 1;
+        long term = 2;
+
+        ResultCollector collector = tester.tableScan(partitionId, term, tx);
+
+        if (tx.isReadOnly()) {
+            HybridTimestamp timestamp = tx.readTimestamp();
+            ClusterNode clusterNode = tx.clusterNode();
+
+            verify(internalTable).scan(partitionId, timestamp, clusterNode);
+        } else {
+            ClusterNode clusterNode = tx.clusterNode();
+
+            verify(internalTable).scan(partitionId, tx.id(), new 
PrimaryReplica(clusterNode, term), null, null, null, 0, null);
+        }
+
+        data.sendRows();
+        data.done();
+
+        collector.expectRow(binaryRow);
+        collector.expectCompleted();
+    }
+
+    /**
+     * Table scan error propagation.
+     */
+    @ParameterizedTest
+    @MethodSource("transactions")
+    public void testTableScanError(NoOpTransaction tx) {
+        TestInput input = new TestInput();
+        input.addRow(binaryRow);
+
+        Tester tester = new Tester(input);
+
+        int partitionId = 1;
+        long term = 2;
+
+        ResultCollector collector = tester.tableScan(partitionId, term, tx);
+
+        input.sendRows();
+
+        RuntimeException err = new RuntimeException("err");
+        input.sendError(err);
+
+        collector.expectRow(binaryRow);
+        collector.expectError(err);
+    }
+
+    /**
+     * Index scan with different bounds.
+     */
+    @ParameterizedTest
+    @CsvSource({
+            // RO
+            "true, INCLUSIVE, NONE",
+            "true, EXCLUSIVE, NONE",
+            "true, NONE, INCLUSIVE",
+            "true, NONE, EXCLUSIVE",
+            "true, INCLUSIVE, INCLUSIVE",
+            "true, INCLUSIVE, EXCLUSIVE",
+            "true, EXCLUSIVE, INCLUSIVE",
+            "true, EXCLUSIVE, EXCLUSIVE",
+            // RW
+            "false, INCLUSIVE, NONE",
+            "false, EXCLUSIVE, NONE",
+            "false, NONE, INCLUSIVE",
+            "false, NONE, EXCLUSIVE",
+            "false, INCLUSIVE, INCLUSIVE",
+            "false, INCLUSIVE, EXCLUSIVE",
+            "false, EXCLUSIVE, INCLUSIVE",
+            "false, EXCLUSIVE, EXCLUSIVE",
+    })

Review Comment:
   fixed



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