sashapolo commented on a change in pull request #739:
URL: https://github.com/apache/ignite-3/pull/739#discussion_r840320473



##########
File path: 
modules/storage-api/src/test/java/org/apache/ignite/internal/storage/AbstractSortedIndexMvStorageTest.java
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.storage;
+
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.BACKWARDS;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.FORWARD;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.GREATER_OR_EQUAL;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.LESS_OR_EQUAL;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.ignite.configuration.schemas.table.ColumnChange;
+import org.apache.ignite.configuration.schemas.table.SortedIndexChange;
+import 
org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema;
+import org.apache.ignite.configuration.schemas.table.TableConfiguration;
+import org.apache.ignite.configuration.schemas.table.TableView;
+import 
org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import 
org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.schema.marshaller.MarshallerException;
+import org.apache.ignite.internal.schema.row.Row;
+import org.apache.ignite.internal.storage.index.IndexRowPrefix;
+import org.apache.ignite.internal.storage.index.SortedIndexMvStorage;
+import 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.IndexRowEx;
+import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.internal.util.Cursor;
+import org.apache.ignite.lang.IgniteException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Base test for MV index storages.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public abstract class AbstractSortedIndexMvStorageTest extends 
BaseMvStoragesTest {
+    protected static final String INDEX1 = "asc_asc";
+    protected static final String INDEX2 = "asc_desc";
+
+    protected TableConfiguration tableCfg;
+
+    @BeforeEach
+    void setUp(@InjectConfiguration(polymorphicExtensions = 
SortedIndexConfigurationSchema.class) TableConfiguration tableCfg) {
+        tableCfg.change(tableChange -> tableChange
+                .changePartitions(1)
+                .changePrimaryKey(pk -> pk.changeColumns("intKey", "strKey"))
+                .changeColumns(columns -> columns
+                        .create("intKey", column("intKey", "INT32"))
+                        .create("strKey", column("strKey", "STRING"))
+                        .create("intVal", column("intVal", "INT32"))
+                        .create("strVal", column("strVal", "STRING"))
+                )
+                .changeIndices(indexes -> indexes
+                        .create(INDEX1, idx -> 
idx.convert(SortedIndexChange.class).changeColumns(idxColumns -> idxColumns
+                                .create("strVal", c -> 
c.changeName("strVal").changeAsc(true))
+                                .create("intVal", c -> 
c.changeName("intVal").changeAsc(true))
+                        ))
+                        .create(INDEX2, idx -> 
idx.convert(SortedIndexChange.class).changeColumns(idxColumns -> idxColumns
+                                .create("strVal", c -> 
c.changeName("strVal").changeAsc(true))
+                                .create("intVal", c -> 
c.changeName("intVal").changeAsc(false))
+                        ))
+                )
+        ).join();
+
+        this.tableCfg = tableCfg;
+    }
+
+    private static Consumer<ColumnChange> column(String name, String typeName) 
{
+        return c -> c.changeName(name).changeNullable(false).changeType(type 
-> type.changeType(typeName));
+    }
+
+    /**
+     * Creates a storage instance for testing.
+     */
+    protected abstract MvPartitionStorage partitionStorage();
+
+    /**
+     * Creates a storage instanc efor testing.
+     */
+    protected abstract SortedIndexMvStorage createIndexStorage(String name, 
TableView tableCfg);
+
+    @Test
+    public void testEmpty() throws Exception {
+        SortedIndexMvStorage index1 = createIndexStorage(INDEX1, 
tableCfg.value());
+        SortedIndexMvStorage index2 = createIndexStorage(INDEX2, 
tableCfg.value());
+
+        assertEquals(List.of(), convert(index1.scan(null, null, (byte) 0, 
null, null)));
+        assertEquals(List.of(), convert(index2.scan(null, null, (byte) 0, 
null, null)));
+    }
+
+    @Test
+    public void testBounds() throws Exception {
+        SortedIndexMvStorage index1 = createIndexStorage(INDEX1, 
tableCfg.value());
+        SortedIndexMvStorage index2 = createIndexStorage(INDEX2, 
tableCfg.value());
+
+        TestValue val9010 = new TestValue(90, "10");
+        TestValue val8010 = new TestValue(80, "10");
+        TestValue val9020 = new TestValue(90, "20");
+        TestValue val8020 = new TestValue(80, "20");
+
+        insert(new TestKey(1, "1"), val9010, null);
+        insert(new TestKey(2, "2"), val8010, null);
+        insert(new TestKey(3, "3"), val9020, null);
+        insert(new TestKey(4, "4"), val8020, null);
+
+        // Test without bounds.
+        assertEquals(List.of(val8010, val9010, val8020, val9020), 
convert(index1.scan(
+                null, null, FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val9020, val8020, val9010, val8010), 
convert(index1.scan(
+                null, null, BACKWARDS, null, null
+        )));
+
+        assertEquals(List.of(val9010, val8010, val9020, val8020), 
convert(index2.scan(
+                null, null, FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val8020, val9020, val8010, val9010), 
convert(index2.scan(
+                null, null, BACKWARDS, null, null
+        )));
+
+        // Lower bound exclusive.
+        assertEquals(List.of(val8020, val9020), convert(index1.scan(
+                prefix("10"), null, FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val9020, val8020), convert(index1.scan(
+                prefix("10"), null, BACKWARDS, null, null
+        )));
+
+        assertEquals(List.of(val9020, val8020), convert(index2.scan(
+                prefix("10"), null, FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val8020, val9020), convert(index2.scan(
+                prefix("10"), null, BACKWARDS, null, null
+        )));
+
+        // Lower bound inclusive.
+        assertEquals(List.of(val8010, val9010, val8020, val9020), 
convert(index1.scan(
+                prefix("10"), null, GREATER_OR_EQUAL | FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val9020, val8020, val9010, val8010), 
convert(index1.scan(
+                prefix("10"), null, GREATER_OR_EQUAL | BACKWARDS, null, null
+        )));
+
+        assertEquals(List.of(val9010, val8010, val9020, val8020), 
convert(index2.scan(
+                prefix("10"), null, GREATER_OR_EQUAL | FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val8020, val9020, val8010, val9010), 
convert(index2.scan(
+                prefix("10"), null, GREATER_OR_EQUAL | BACKWARDS, null, null
+        )));
+
+        // Upper bound exclusive.
+        assertEquals(List.of(val8010, val9010), convert(index1.scan(
+                null, prefix("20"), FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val9010, val8010), convert(index1.scan(
+                null, prefix("20"), BACKWARDS, null, null
+        )));
+
+        assertEquals(List.of(val9010, val8010), convert(index2.scan(
+                null, prefix("20"), FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val8010, val9010), convert(index2.scan(
+                null, prefix("20"), BACKWARDS, null, null
+        )));
+
+        // Lower bound inclusive.

Review comment:
       Don't you test upper inclusive bound here?

##########
File path: 
modules/storage-api/src/test/java/org/apache/ignite/internal/storage/AbstractSortedIndexMvStorageTest.java
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.storage;
+
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.BACKWARDS;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.FORWARD;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.GREATER_OR_EQUAL;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.LESS_OR_EQUAL;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.ignite.configuration.schemas.table.ColumnChange;
+import org.apache.ignite.configuration.schemas.table.SortedIndexChange;
+import 
org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema;
+import org.apache.ignite.configuration.schemas.table.TableConfiguration;
+import org.apache.ignite.configuration.schemas.table.TableView;
+import 
org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import 
org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.schema.marshaller.MarshallerException;
+import org.apache.ignite.internal.schema.row.Row;
+import org.apache.ignite.internal.storage.index.IndexRowPrefix;
+import org.apache.ignite.internal.storage.index.SortedIndexMvStorage;
+import 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.IndexRowEx;
+import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.internal.util.Cursor;
+import org.apache.ignite.lang.IgniteException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Base test for MV index storages.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public abstract class AbstractSortedIndexMvStorageTest extends 
BaseMvStoragesTest {
+    protected static final String INDEX1 = "asc_asc";
+    protected static final String INDEX2 = "asc_desc";
+
+    protected TableConfiguration tableCfg;
+
+    @BeforeEach
+    void setUp(@InjectConfiguration(polymorphicExtensions = 
SortedIndexConfigurationSchema.class) TableConfiguration tableCfg) {
+        tableCfg.change(tableChange -> tableChange
+                .changePartitions(1)
+                .changePrimaryKey(pk -> pk.changeColumns("intKey", "strKey"))
+                .changeColumns(columns -> columns
+                        .create("intKey", column("intKey", "INT32"))
+                        .create("strKey", column("strKey", "STRING"))
+                        .create("intVal", column("intVal", "INT32"))
+                        .create("strVal", column("strVal", "STRING"))
+                )
+                .changeIndices(indexes -> indexes
+                        .create(INDEX1, idx -> 
idx.convert(SortedIndexChange.class).changeColumns(idxColumns -> idxColumns
+                                .create("strVal", c -> 
c.changeName("strVal").changeAsc(true))
+                                .create("intVal", c -> 
c.changeName("intVal").changeAsc(true))
+                        ))
+                        .create(INDEX2, idx -> 
idx.convert(SortedIndexChange.class).changeColumns(idxColumns -> idxColumns
+                                .create("strVal", c -> 
c.changeName("strVal").changeAsc(true))
+                                .create("intVal", c -> 
c.changeName("intVal").changeAsc(false))
+                        ))
+                )
+        ).join();
+
+        this.tableCfg = tableCfg;
+    }
+
+    private static Consumer<ColumnChange> column(String name, String typeName) 
{
+        return c -> c.changeName(name).changeNullable(false).changeType(type 
-> type.changeType(typeName));
+    }
+
+    /**
+     * Creates a storage instance for testing.
+     */
+    protected abstract MvPartitionStorage partitionStorage();
+
+    /**
+     * Creates a storage instanc efor testing.
+     */
+    protected abstract SortedIndexMvStorage createIndexStorage(String name, 
TableView tableCfg);
+
+    @Test
+    public void testEmpty() throws Exception {
+        SortedIndexMvStorage index1 = createIndexStorage(INDEX1, 
tableCfg.value());
+        SortedIndexMvStorage index2 = createIndexStorage(INDEX2, 
tableCfg.value());
+
+        assertEquals(List.of(), convert(index1.scan(null, null, (byte) 0, 
null, null)));
+        assertEquals(List.of(), convert(index2.scan(null, null, (byte) 0, 
null, null)));
+    }
+
+    @Test
+    public void testBounds() throws Exception {
+        SortedIndexMvStorage index1 = createIndexStorage(INDEX1, 
tableCfg.value());
+        SortedIndexMvStorage index2 = createIndexStorage(INDEX2, 
tableCfg.value());
+
+        TestValue val9010 = new TestValue(90, "10");
+        TestValue val8010 = new TestValue(80, "10");
+        TestValue val9020 = new TestValue(90, "20");
+        TestValue val8020 = new TestValue(80, "20");
+
+        insert(new TestKey(1, "1"), val9010, null);
+        insert(new TestKey(2, "2"), val8010, null);
+        insert(new TestKey(3, "3"), val9020, null);
+        insert(new TestKey(4, "4"), val8020, null);
+
+        // Test without bounds.
+        assertEquals(List.of(val8010, val9010, val8020, val9020), 
convert(index1.scan(
+                null, null, FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val9020, val8020, val9010, val8010), 
convert(index1.scan(
+                null, null, BACKWARDS, null, null
+        )));
+
+        assertEquals(List.of(val9010, val8010, val9020, val8020), 
convert(index2.scan(
+                null, null, FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val8020, val9020, val8010, val9010), 
convert(index2.scan(
+                null, null, BACKWARDS, null, null
+        )));
+
+        // Lower bound exclusive.
+        assertEquals(List.of(val8020, val9020), convert(index1.scan(
+                prefix("10"), null, FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val9020, val8020), convert(index1.scan(
+                prefix("10"), null, BACKWARDS, null, null
+        )));
+
+        assertEquals(List.of(val9020, val8020), convert(index2.scan(
+                prefix("10"), null, FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val8020, val9020), convert(index2.scan(
+                prefix("10"), null, BACKWARDS, null, null
+        )));
+
+        // Lower bound inclusive.
+        assertEquals(List.of(val8010, val9010, val8020, val9020), 
convert(index1.scan(
+                prefix("10"), null, GREATER_OR_EQUAL | FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val9020, val8020, val9010, val8010), 
convert(index1.scan(
+                prefix("10"), null, GREATER_OR_EQUAL | BACKWARDS, null, null
+        )));
+
+        assertEquals(List.of(val9010, val8010, val9020, val8020), 
convert(index2.scan(
+                prefix("10"), null, GREATER_OR_EQUAL | FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val8020, val9020, val8010, val9010), 
convert(index2.scan(
+                prefix("10"), null, GREATER_OR_EQUAL | BACKWARDS, null, null
+        )));
+
+        // Upper bound exclusive.
+        assertEquals(List.of(val8010, val9010), convert(index1.scan(
+                null, prefix("20"), FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val9010, val8010), convert(index1.scan(
+                null, prefix("20"), BACKWARDS, null, null
+        )));
+
+        assertEquals(List.of(val9010, val8010), convert(index2.scan(
+                null, prefix("20"), FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val8010, val9010), convert(index2.scan(
+                null, prefix("20"), BACKWARDS, null, null
+        )));
+
+        // Lower bound inclusive.
+        assertEquals(List.of(val8010, val9010, val8020, val9020), 
convert(index1.scan(
+                null, prefix("20"), LESS_OR_EQUAL | FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val9020, val8020, val9010, val8010), 
convert(index1.scan(
+                null, prefix("20"), LESS_OR_EQUAL | BACKWARDS, null, null
+        )));
+
+        assertEquals(List.of(val9010, val8010, val9020, val8020), 
convert(index2.scan(
+                null, prefix("20"), LESS_OR_EQUAL | FORWARD, null, null
+        )));
+
+        assertEquals(List.of(val8020, val9020, val8010, val9010), 
convert(index2.scan(
+                null, prefix("20"), LESS_OR_EQUAL | BACKWARDS, null, null
+        )));
+    }
+
+    protected void insert(TestKey key, TestValue value, Timestamp ts) {
+        MvPartitionStorage pk = partitionStorage();
+
+        BinaryRow binaryRow = binaryRow(key, value);
+
+        pk.addWrite(binaryRow, UUID.randomUUID());
+
+        pk.commitWrite(binaryRow, ts == null ? Timestamp.nextVersion() : ts);
+    }
+
+    protected IndexRowPrefix prefix(String val) {
+        return () -> new Object[]{val};
+    }
+
+    protected List<TestValue> convert(Cursor<IndexRowEx> cursor) throws 
Exception {
+        try (cursor) {
+            return StreamSupport.stream(cursor.spliterator(), false)

Review comment:
       I suggest adding a `default Stream stream()` method to the `Cursor` 
interface. I've already done this in my other PR, and it proved to be useful

##########
File path: 
modules/storage-api/src/test/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageTest.java
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.storage;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.internal.util.Cursor;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Base test for MV partition storages.
+ */
+public abstract class AbstractMvPartitionStorageTest extends 
BaseMvStoragesTest {
+    /**
+     * Creates a storage instance for testing.
+     */
+    protected abstract MvPartitionStorage partitionStorage();
+
+    /**
+     * Tests that reads and scan from empty storage return empty results.
+     */
+    @Test
+    public void testEmpty() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        BinaryRow binaryKey = binaryKey(new TestKey(10, "foo"));
+
+        // Read.
+        assertNull(pk.read(binaryKey, null));
+        assertNull(pk.read(binaryKey, Timestamp.nextVersion()));
+
+        // Scan.
+        assertEquals(List.of(), convert(pk.scan(row -> true, null)));
+        assertEquals(List.of(), convert(pk.scan(row -> true, 
Timestamp.nextVersion())));
+    }
+
+    /**
+     * Tests basic invariants of {@link MvPartitionStorage#addWrite(BinaryRow, 
UUID)}.
+     */
+    @Test
+    public void testAddWrite() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        TestKey key = new TestKey(10, "foo");
+        TestValue value = new TestValue(20, "bar");
+
+        BinaryRow binaryRow = binaryRow(key, value);
+
+        pk.addWrite(binaryRow, UUID.randomUUID());
+
+        // Attempt to write from another transaction.
+        assertThrows(TxIdMismatchException.class, () -> pk.addWrite(binaryRow, 
UUID.randomUUID()));
+
+        // Read without timestamp returns uncommited row.
+        assertEquals(value, value(pk.read(binaryKey(key), null)));
+
+        // Read with timestamp returns null.
+        assertNull(pk.read(binaryKey(key), Timestamp.nextVersion()));

Review comment:
       addWrite also influences the index, that is not tested

##########
File path: 
modules/storage-api/src/test/java/org/apache/ignite/internal/storage/AbstractSortedIndexMvStorageTest.java
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.storage;
+
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.BACKWARDS;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.FORWARD;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.GREATER_OR_EQUAL;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.LESS_OR_EQUAL;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.ignite.configuration.schemas.table.ColumnChange;
+import org.apache.ignite.configuration.schemas.table.SortedIndexChange;
+import 
org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema;
+import org.apache.ignite.configuration.schemas.table.TableConfiguration;
+import org.apache.ignite.configuration.schemas.table.TableView;
+import 
org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import 
org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.schema.marshaller.MarshallerException;
+import org.apache.ignite.internal.schema.row.Row;
+import org.apache.ignite.internal.storage.index.IndexRowPrefix;
+import org.apache.ignite.internal.storage.index.SortedIndexMvStorage;
+import 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.IndexRowEx;
+import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.internal.util.Cursor;
+import org.apache.ignite.lang.IgniteException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Base test for MV index storages.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public abstract class AbstractSortedIndexMvStorageTest extends 
BaseMvStoragesTest {
+    protected static final String INDEX1 = "asc_asc";
+    protected static final String INDEX2 = "asc_desc";
+
+    protected TableConfiguration tableCfg;
+
+    @BeforeEach
+    void setUp(@InjectConfiguration(polymorphicExtensions = 
SortedIndexConfigurationSchema.class) TableConfiguration tableCfg) {
+        tableCfg.change(tableChange -> tableChange
+                .changePartitions(1)
+                .changePrimaryKey(pk -> pk.changeColumns("intKey", "strKey"))
+                .changeColumns(columns -> columns
+                        .create("intKey", column("intKey", "INT32"))
+                        .create("strKey", column("strKey", "STRING"))
+                        .create("intVal", column("intVal", "INT32"))
+                        .create("strVal", column("strVal", "STRING"))
+                )
+                .changeIndices(indexes -> indexes
+                        .create(INDEX1, idx -> 
idx.convert(SortedIndexChange.class).changeColumns(idxColumns -> idxColumns
+                                .create("strVal", c -> 
c.changeName("strVal").changeAsc(true))
+                                .create("intVal", c -> 
c.changeName("intVal").changeAsc(true))
+                        ))
+                        .create(INDEX2, idx -> 
idx.convert(SortedIndexChange.class).changeColumns(idxColumns -> idxColumns
+                                .create("strVal", c -> 
c.changeName("strVal").changeAsc(true))
+                                .create("intVal", c -> 
c.changeName("intVal").changeAsc(false))
+                        ))
+                )
+        ).join();
+
+        this.tableCfg = tableCfg;
+    }
+
+    private static Consumer<ColumnChange> column(String name, String typeName) 
{
+        return c -> c.changeName(name).changeNullable(false).changeType(type 
-> type.changeType(typeName));
+    }
+
+    /**
+     * Creates a storage instance for testing.
+     */
+    protected abstract MvPartitionStorage partitionStorage();
+
+    /**
+     * Creates a storage instanc efor testing.
+     */
+    protected abstract SortedIndexMvStorage createIndexStorage(String name, 
TableView tableCfg);
+
+    @Test
+    public void testEmpty() throws Exception {
+        SortedIndexMvStorage index1 = createIndexStorage(INDEX1, 
tableCfg.value());
+        SortedIndexMvStorage index2 = createIndexStorage(INDEX2, 
tableCfg.value());

Review comment:
       why do you need to indices here?

##########
File path: 
modules/storage-api/src/test/java/org/apache/ignite/internal/storage/AbstractSortedIndexMvStorageTest.java
##########
@@ -0,0 +1,238 @@
+/*
+ * 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.storage;
+
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.BACKWARDS;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.FORWARD;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.GREATER_OR_EQUAL;
+import static 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.LESS_OR_EQUAL;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.ignite.configuration.schemas.table.ColumnChange;
+import org.apache.ignite.configuration.schemas.table.SortedIndexChange;
+import 
org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema;
+import org.apache.ignite.configuration.schemas.table.TableConfiguration;
+import org.apache.ignite.configuration.schemas.table.TableView;
+import 
org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import 
org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.schema.marshaller.MarshallerException;
+import org.apache.ignite.internal.schema.row.Row;
+import org.apache.ignite.internal.storage.index.IndexRowPrefix;
+import org.apache.ignite.internal.storage.index.SortedIndexMvStorage;
+import 
org.apache.ignite.internal.storage.index.SortedIndexMvStorage.IndexRowEx;
+import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.internal.util.Cursor;
+import org.apache.ignite.lang.IgniteException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Base test for MV index storages.
+ */
+@ExtendWith(ConfigurationExtension.class)
+public abstract class AbstractSortedIndexMvStorageTest extends 
BaseMvStoragesTest {
+    protected static final String INDEX1 = "asc_asc";
+    protected static final String INDEX2 = "asc_desc";
+
+    protected TableConfiguration tableCfg;
+
+    @BeforeEach
+    void setUp(@InjectConfiguration(polymorphicExtensions = 
SortedIndexConfigurationSchema.class) TableConfiguration tableCfg) {
+        tableCfg.change(tableChange -> tableChange
+                .changePartitions(1)
+                .changePrimaryKey(pk -> pk.changeColumns("intKey", "strKey"))
+                .changeColumns(columns -> columns
+                        .create("intKey", column("intKey", "INT32"))
+                        .create("strKey", column("strKey", "STRING"))
+                        .create("intVal", column("intVal", "INT32"))
+                        .create("strVal", column("strVal", "STRING"))
+                )
+                .changeIndices(indexes -> indexes
+                        .create(INDEX1, idx -> 
idx.convert(SortedIndexChange.class).changeColumns(idxColumns -> idxColumns
+                                .create("strVal", c -> 
c.changeName("strVal").changeAsc(true))
+                                .create("intVal", c -> 
c.changeName("intVal").changeAsc(true))
+                        ))
+                        .create(INDEX2, idx -> 
idx.convert(SortedIndexChange.class).changeColumns(idxColumns -> idxColumns
+                                .create("strVal", c -> 
c.changeName("strVal").changeAsc(true))
+                                .create("intVal", c -> 
c.changeName("intVal").changeAsc(false))
+                        ))
+                )
+        ).join();
+
+        this.tableCfg = tableCfg;
+    }
+
+    private static Consumer<ColumnChange> column(String name, String typeName) 
{
+        return c -> c.changeName(name).changeNullable(false).changeType(type 
-> type.changeType(typeName));
+    }
+
+    /**
+     * Creates a storage instance for testing.
+     */
+    protected abstract MvPartitionStorage partitionStorage();
+
+    /**
+     * Creates a storage instanc efor testing.
+     */
+    protected abstract SortedIndexMvStorage createIndexStorage(String name, 
TableView tableCfg);
+
+    @Test
+    public void testEmpty() throws Exception {
+        SortedIndexMvStorage index1 = createIndexStorage(INDEX1, 
tableCfg.value());
+        SortedIndexMvStorage index2 = createIndexStorage(INDEX2, 
tableCfg.value());
+
+        assertEquals(List.of(), convert(index1.scan(null, null, (byte) 0, 
null, null)));
+        assertEquals(List.of(), convert(index2.scan(null, null, (byte) 0, 
null, null)));
+    }
+
+    @Test
+    public void testBounds() throws Exception {

Review comment:
       There are no tests  for the following scenarios:
   1. Non null timestamp 
   2. Non null partition filter
   3. Test that index scan returns correct values as described in the design 
document's example

##########
File path: 
modules/storage-api/src/test/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageTest.java
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.storage;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.internal.util.Cursor;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Base test for MV partition storages.
+ */
+public abstract class AbstractMvPartitionStorageTest extends 
BaseMvStoragesTest {
+    /**
+     * Creates a storage instance for testing.
+     */
+    protected abstract MvPartitionStorage partitionStorage();
+
+    /**
+     * Tests that reads and scan from empty storage return empty results.
+     */
+    @Test
+    public void testEmpty() throws Exception {

Review comment:
       I would suggest to split this test into two

##########
File path: 
modules/storage-api/src/test/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageTest.java
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.storage;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.internal.util.Cursor;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Base test for MV partition storages.
+ */
+public abstract class AbstractMvPartitionStorageTest extends 
BaseMvStoragesTest {
+    /**
+     * Creates a storage instance for testing.
+     */
+    protected abstract MvPartitionStorage partitionStorage();
+
+    /**
+     * Tests that reads and scan from empty storage return empty results.
+     */
+    @Test
+    public void testEmpty() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        BinaryRow binaryKey = binaryKey(new TestKey(10, "foo"));
+
+        // Read.
+        assertNull(pk.read(binaryKey, null));
+        assertNull(pk.read(binaryKey, Timestamp.nextVersion()));
+
+        // Scan.
+        assertEquals(List.of(), convert(pk.scan(row -> true, null)));
+        assertEquals(List.of(), convert(pk.scan(row -> true, 
Timestamp.nextVersion())));
+    }
+
+    /**
+     * Tests basic invariants of {@link MvPartitionStorage#addWrite(BinaryRow, 
UUID)}.
+     */
+    @Test
+    public void testAddWrite() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        TestKey key = new TestKey(10, "foo");
+        TestValue value = new TestValue(20, "bar");
+
+        BinaryRow binaryRow = binaryRow(key, value);
+
+        pk.addWrite(binaryRow, UUID.randomUUID());
+
+        // Attempt to write from another transaction.
+        assertThrows(TxIdMismatchException.class, () -> pk.addWrite(binaryRow, 
UUID.randomUUID()));
+
+        // Read without timestamp returns uncommited row.
+        assertEquals(value, value(pk.read(binaryKey(key), null)));
+
+        // Read with timestamp returns null.
+        assertNull(pk.read(binaryKey(key), Timestamp.nextVersion()));
+    }
+
+    /**
+     * Tests basic invariants of {@link 
MvPartitionStorage#abortWrite(BinaryRow)}.
+     */
+    @Test
+    public void testAbortWrite() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        TestKey key = new TestKey(10, "foo");
+        TestValue value = new TestValue(20, "bar");
+
+        pk.addWrite(binaryRow(key, value), UUID.randomUUID());
+
+        pk.abortWrite(binaryKey(key));
+
+        // Aborted row can't be read.
+        assertNull(pk.read(binaryKey(key), null));
+    }
+
+    /**
+     * Tests basic invariants of {@link 
MvPartitionStorage#commitWrite(BinaryRow, Timestamp)}.
+     */
+    @Test
+    public void testCommitWrite() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        TestKey key = new TestKey(10, "foo");
+        TestValue value = new TestValue(20, "bar");
+
+        BinaryRow binaryRow = binaryRow(key, value);
+
+        pk.addWrite(binaryRow, UUID.randomUUID());
+
+        Timestamp tsBefore = Timestamp.nextVersion();
+
+        Timestamp tsExact = Timestamp.nextVersion();
+        pk.commitWrite(binaryRow, tsExact);
+
+        Timestamp tsAfter = Timestamp.nextVersion();
+
+        // Row is invisible at the time before writing.
+        assertNull(pk.read(binaryRow, tsBefore));
+
+        // Row is valid at the time during and after writing.
+        assertEquals(value, value(pk.read(binaryRow, null)));
+        assertEquals(value, value(pk.read(binaryRow, tsExact)));
+        assertEquals(value, value(pk.read(binaryRow, tsAfter)));
+
+        TestValue newValue = new TestValue(30, "duh");
+
+        pk.addWrite(binaryRow(key, newValue), UUID.randomUUID());
+
+        // Same checks, but now there are two different versions.
+        assertNull(pk.read(binaryRow, tsBefore));
+
+        assertEquals(newValue, value(pk.read(binaryRow, null)));
+
+        assertEquals(value, value(pk.read(binaryRow, tsExact)));
+        assertEquals(value, value(pk.read(binaryRow, tsAfter)));
+        assertEquals(value, value(pk.read(binaryRow, 
Timestamp.nextVersion())));
+
+        pk.commitWrite(binaryKey(key), Timestamp.nextVersion());
+
+        assertEquals(newValue, value(pk.read(binaryRow, null)));
+        assertEquals(newValue, value(pk.read(binaryRow, 
Timestamp.nextVersion())));
+    }
+
+    /**
+     * Tests basic invariants of {@link MvPartitionStorage#scan(Predicate, 
Timestamp)}.
+     */
+    @Test
+    public void testScan() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        TestKey key1 = new TestKey(1, "1");
+        TestValue value1 = new TestValue(10, "xxx");
+
+        TestKey key2 = new TestKey(2, "2");
+        TestValue value2 = new TestValue(20, "yyy");
+
+        pk.addWrite(binaryRow(key1, value1), UUID.randomUUID());
+        pk.addWrite(binaryRow(key2, value2), UUID.randomUUID());
+
+        // Scan with and without filters.
+        assertEquals(List.of(value1, value2), convert(pk.scan(row -> true, 
null)));
+        assertEquals(List.of(value1), convert(pk.scan(row -> key(row).intKey 
== 1, null)));
+        assertEquals(List.of(value2), convert(pk.scan(row -> key(row).intKey 
== 2, null)));
+
+        Timestamp ts1 = Timestamp.nextVersion();
+
+        Timestamp ts2 = Timestamp.nextVersion();
+        pk.commitWrite(binaryKey(key1), ts2);
+
+        Timestamp ts3 = Timestamp.nextVersion();
+
+        Timestamp ts4 = Timestamp.nextVersion();
+        pk.commitWrite(binaryKey(key2), ts4);
+
+        Timestamp ts5 = Timestamp.nextVersion();
+
+        // Full scan with various timestamp values.
+        assertEquals(List.of(), convert(pk.scan(row -> true, ts1)));
+
+        assertEquals(List.of(value1), convert(pk.scan(row -> true, ts2)));
+        assertEquals(List.of(value1), convert(pk.scan(row -> true, ts3)));
+
+        assertEquals(List.of(value1, value2), convert(pk.scan(row -> true, 
ts4)));
+        assertEquals(List.of(value1, value2), convert(pk.scan(row -> true, 
ts5)));
+    }
+
+    private List<TestValue> convert(Cursor<BinaryRow> cursor) throws Exception 
{
+        try (cursor) {
+            List<TestValue> list = StreamSupport.stream(cursor.spliterator(), 
false)

Review comment:
       can be written shorter, for example:
   ```
   return StreamSupport.stream(cursor.spliterator(), false)
           .map(this::value)
           .sorted(Comparator.nullsFirst(Comparator.naturalOrder()))
           .collect(Collectors.toList());
   ```        

##########
File path: 
modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/RocksDbTableStorage.java
##########
@@ -138,6 +139,7 @@ public void start() throws StorageException {
         DBOptions dbOptions = new DBOptions()
                 .setCreateIfMissing(true)
                 .setCreateMissingColumnFamilies(true)
+                .setWalRecoveryMode(WALRecoveryMode.SkipAnyCorruptedRecords)

Review comment:
       Why is this needed?

##########
File path: 
modules/storage-api/src/test/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageTest.java
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.storage;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.internal.util.Cursor;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Base test for MV partition storages.
+ */
+public abstract class AbstractMvPartitionStorageTest extends 
BaseMvStoragesTest {
+    /**
+     * Creates a storage instance for testing.
+     */
+    protected abstract MvPartitionStorage partitionStorage();
+
+    /**
+     * Tests that reads and scan from empty storage return empty results.
+     */
+    @Test
+    public void testEmpty() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        BinaryRow binaryKey = binaryKey(new TestKey(10, "foo"));
+
+        // Read.
+        assertNull(pk.read(binaryKey, null));
+        assertNull(pk.read(binaryKey, Timestamp.nextVersion()));
+
+        // Scan.
+        assertEquals(List.of(), convert(pk.scan(row -> true, null)));
+        assertEquals(List.of(), convert(pk.scan(row -> true, 
Timestamp.nextVersion())));
+    }
+
+    /**
+     * Tests basic invariants of {@link MvPartitionStorage#addWrite(BinaryRow, 
UUID)}.
+     */
+    @Test
+    public void testAddWrite() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        TestKey key = new TestKey(10, "foo");
+        TestValue value = new TestValue(20, "bar");
+
+        BinaryRow binaryRow = binaryRow(key, value);
+
+        pk.addWrite(binaryRow, UUID.randomUUID());
+
+        // Attempt to write from another transaction.
+        assertThrows(TxIdMismatchException.class, () -> pk.addWrite(binaryRow, 
UUID.randomUUID()));
+
+        // Read without timestamp returns uncommited row.
+        assertEquals(value, value(pk.read(binaryKey(key), null)));
+
+        // Read with timestamp returns null.
+        assertNull(pk.read(binaryKey(key), Timestamp.nextVersion()));
+    }
+
+    /**
+     * Tests basic invariants of {@link 
MvPartitionStorage#abortWrite(BinaryRow)}.
+     */
+    @Test
+    public void testAbortWrite() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        TestKey key = new TestKey(10, "foo");
+        TestValue value = new TestValue(20, "bar");
+
+        pk.addWrite(binaryRow(key, value), UUID.randomUUID());
+
+        pk.abortWrite(binaryKey(key));
+
+        // Aborted row can't be read.
+        assertNull(pk.read(binaryKey(key), null));
+    }
+
+    /**
+     * Tests basic invariants of {@link 
MvPartitionStorage#commitWrite(BinaryRow, Timestamp)}.
+     */
+    @Test
+    public void testCommitWrite() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        TestKey key = new TestKey(10, "foo");
+        TestValue value = new TestValue(20, "bar");
+
+        BinaryRow binaryRow = binaryRow(key, value);
+
+        pk.addWrite(binaryRow, UUID.randomUUID());
+
+        Timestamp tsBefore = Timestamp.nextVersion();
+
+        Timestamp tsExact = Timestamp.nextVersion();
+        pk.commitWrite(binaryRow, tsExact);
+
+        Timestamp tsAfter = Timestamp.nextVersion();
+
+        // Row is invisible at the time before writing.
+        assertNull(pk.read(binaryRow, tsBefore));
+
+        // Row is valid at the time during and after writing.
+        assertEquals(value, value(pk.read(binaryRow, null)));
+        assertEquals(value, value(pk.read(binaryRow, tsExact)));
+        assertEquals(value, value(pk.read(binaryRow, tsAfter)));
+
+        TestValue newValue = new TestValue(30, "duh");
+
+        pk.addWrite(binaryRow(key, newValue), UUID.randomUUID());
+
+        // Same checks, but now there are two different versions.
+        assertNull(pk.read(binaryRow, tsBefore));
+
+        assertEquals(newValue, value(pk.read(binaryRow, null)));
+
+        assertEquals(value, value(pk.read(binaryRow, tsExact)));
+        assertEquals(value, value(pk.read(binaryRow, tsAfter)));
+        assertEquals(value, value(pk.read(binaryRow, 
Timestamp.nextVersion())));
+
+        pk.commitWrite(binaryKey(key), Timestamp.nextVersion());
+
+        assertEquals(newValue, value(pk.read(binaryRow, null)));

Review comment:
       should we also check that previous value can still be extracted after a 
commit?

##########
File path: 
modules/storage-api/src/test/java/org/apache/ignite/internal/storage/AbstractMvPartitionStorageTest.java
##########
@@ -0,0 +1,206 @@
+/*
+ * 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.storage;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+import org.apache.ignite.internal.schema.BinaryRow;
+import org.apache.ignite.internal.tx.Timestamp;
+import org.apache.ignite.internal.util.Cursor;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Base test for MV partition storages.
+ */
+public abstract class AbstractMvPartitionStorageTest extends 
BaseMvStoragesTest {
+    /**
+     * Creates a storage instance for testing.
+     */
+    protected abstract MvPartitionStorage partitionStorage();
+
+    /**
+     * Tests that reads and scan from empty storage return empty results.
+     */
+    @Test
+    public void testEmpty() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        BinaryRow binaryKey = binaryKey(new TestKey(10, "foo"));
+
+        // Read.
+        assertNull(pk.read(binaryKey, null));
+        assertNull(pk.read(binaryKey, Timestamp.nextVersion()));
+
+        // Scan.
+        assertEquals(List.of(), convert(pk.scan(row -> true, null)));
+        assertEquals(List.of(), convert(pk.scan(row -> true, 
Timestamp.nextVersion())));
+    }
+
+    /**
+     * Tests basic invariants of {@link MvPartitionStorage#addWrite(BinaryRow, 
UUID)}.
+     */
+    @Test
+    public void testAddWrite() throws Exception {
+        MvPartitionStorage pk = partitionStorage();
+
+        TestKey key = new TestKey(10, "foo");
+        TestValue value = new TestValue(20, "bar");
+
+        BinaryRow binaryRow = binaryRow(key, value);
+
+        pk.addWrite(binaryRow, UUID.randomUUID());
+
+        // Attempt to write from another transaction.
+        assertThrows(TxIdMismatchException.class, () -> pk.addWrite(binaryRow, 
UUID.randomUUID()));
+
+        // Read without timestamp returns uncommited row.
+        assertEquals(value, value(pk.read(binaryKey(key), null)));
+
+        // Read with timestamp returns null.
+        assertNull(pk.read(binaryKey(key), Timestamp.nextVersion()));
+    }
+
+    /**
+     * Tests basic invariants of {@link 
MvPartitionStorage#abortWrite(BinaryRow)}.
+     */
+    @Test
+    public void testAbortWrite() throws Exception {

Review comment:
       `abortWrite` also influences the state of the indexes, that's not tested 
anywhere




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