ibessonov commented on a change in pull request #739: URL: https://github.com/apache/ignite-3/pull/739#discussion_r840407098
########## 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: It should be tested in tests for indexes -- 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]
