AMashenkov commented on code in PR #4430:
URL: https://github.com/apache/ignite-3/pull/4430#discussion_r1778810911


##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItKeyValueViewSimpleSchemaApiTest.java:
##########
@@ -0,0 +1,783 @@
+/*
+ * 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.table;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.lang.IgniteStringFormatter;
+import org.apache.ignite.internal.schema.Column;
+import org.apache.ignite.internal.schema.SchemaTestUtils;
+import org.apache.ignite.internal.testframework.IgniteTestUtils;
+import org.apache.ignite.internal.type.NativeType;
+import org.apache.ignite.internal.type.NativeTypeSpec;
+import org.apache.ignite.internal.type.NativeTypes;
+import org.apache.ignite.lang.MarshallerException;
+import org.apache.ignite.lang.UnexpectedNullValueException;
+import org.apache.ignite.table.KeyValueView;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Named;
+import org.junit.jupiter.api.function.Executable;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Unified KeyValueView API test with simple value type.
+ */
+public class ItKeyValueViewSimpleSchemaApiTest extends 
ItKeyValueViewApiBaseTest {
+    private static final String TABLE_NAME_SIMPLE_TYPE = "test_simple";
+
+    private static final String TABLE_NAME_NON_NULLABLE_VALUE = 
"test_non_nullable_value";
+
+    @BeforeAll
+    public void createTable() {
+        createTable(TABLE_NAME_SIMPLE_TYPE, List.of(new Column("VAL", 
NativeTypes.INT64, true)));
+        createTable(TABLE_NAME_NON_NULLABLE_VALUE, List.of(new Column("VAL", 
NativeTypes.INT64, false)));
+
+        for (NativeType type : SchemaTestUtils.ALL_TYPES) {
+            String tableName = "T_" + type.spec().name();
+
+            createTable(tableName, false,
+                    List.of(new Column("id", NativeTypes.INT64, false)),
+                    List.of(new Column("VAL", type, true)));
+        }
+
+        // Validate all types are tested.
+        Set<NativeTypeSpec> nativeTypes = EnumSet.allOf(NativeTypeSpec.class);
+
+        assertEquals(nativeTypes,
+                
SchemaTestUtils.ALL_TYPES.stream().map(NativeType::spec).collect(Collectors.toSet()));
+    }
+
+    @ParameterizedTest
+    @MethodSource("testCases")
+    public void put(TestCase<Long, Long> testCase) {
+        KeyValueView<Long, Long> tbl = testCase.view();
+
+        assertNull(tbl.get(null, 1L));
+
+        // Put KV pair.
+        tbl.put(null, 1L, 11L);
+
+        assertEquals(11L, tbl.get(null, 1L));
+        assertEquals(11L, tbl.get(null, 1L));
+
+        // Update KV pair.
+        tbl.put(null, 1L, 22L);
+
+        assertEquals(22L, tbl.get(null, 1L));
+        assertEquals(22L, tbl.get(null, 1L));
+
+        // Put `null` value.
+        tbl.put(null, 1L, null);
+        assertTrue(tbl.contains(null, 1L));
+
+        testCase.checkNullValueError(() -> tbl.get(null, 1L), "getNullable");
+        assertNull(tbl.getNullable(null, 1L).get());
+
+        // Put KV pair.
+        tbl.put(null, 1L, 33L);
+        assertEquals(33L, tbl.get(null, 1L));
+    }
+
+    @ParameterizedTest
+    @MethodSource("testCases")
+    public void putIfAbsent(TestCase<Long, Long> testCase) {
+        KeyValueView<Long, Long> tbl = testCase.view();
+
+        assertNull(tbl.get(null, 1L));
+
+        // Insert new KV pair.
+        assertTrue(tbl.putIfAbsent(null, 1L, 11L));
+        assertEquals(11L, tbl.get(null, 1L));
+
+        // Update KV pair.
+        assertFalse(tbl.putIfAbsent(null, 1L, 22L));
+        assertEquals(11L, tbl.get(null, 1L));
+
+        // Put null value
+        assertFalse(tbl.putIfAbsent(null, 1L, null));
+        assertEquals(11L, tbl.get(null, 1L));
+
+        assertTrue(tbl.putIfAbsent(null, 2L, null));
+        assertTrue(tbl.contains(null, 2L));
+        assertNull(tbl.getNullable(null, 2L).get());
+    }
+
+    @ParameterizedTest
+    @MethodSource("testCases")
+    public void getNullable(TestCase<Long, Long> testCase) {
+        KeyValueView<Long, Long> tbl = testCase.view();
+
+        assertNull(tbl.getNullable(null, 1L));
+
+        // Put KV pair.
+        tbl.put(null, 1L, 11L);
+
+        assertEquals(11L, tbl.getNullable(null, 1L).get());
+
+        tbl.put(null, 1L, null);
+
+        testCase.checkNullValueError(() -> tbl.get(null, 1L), "getNullable");
+        assertNull(tbl.getNullable(null, 1L).get());
+
+        // Remove KV pair.
+        tbl.remove(null, 1L);
+
+        assertNull(tbl.get(null, 1L));
+        assertNull(tbl.getNullable(null, 1L));
+
+        // Put KV pair.
+        tbl.put(null, 1L, 22L);
+        assertEquals(22L, tbl.get(null, 1L));
+        assertEquals(22L, tbl.getNullable(null, 1L).get());
+    }
+
+    @ParameterizedTest
+    @MethodSource("testCases")
+    public void getOrDefault(TestCase<Long, Long> testCase) {
+        KeyValueView<Long, Long> tbl = testCase.view();
+
+        assertEquals(Long.MAX_VALUE, tbl.getOrDefault(null, 1L, 
Long.MAX_VALUE));
+        assertNull(tbl.getOrDefault(null, 1L, null));
+
+        // Put KV pair.
+        tbl.put(null, 1L, 11L);
+
+        assertEquals(11L, tbl.getOrDefault(null, 1L, Long.MAX_VALUE));
+        assertEquals(11L, tbl.getOrDefault(null, 1L, null));
+
+        tbl.put(null, 1L, null);
+
+        testCase.checkNullValueError(() -> tbl.get(null, 1L), "getNullable");
+        assertNull(tbl.getOrDefault(null, 1L, null));
+
+        // TODO https://issues.apache.org/jira/browse/IGNITE-21793 
getOrDefault should return default value for null
+        if (!testCase.thin) {
+            assertEquals(Long.MAX_VALUE, tbl.getOrDefault(null, 1L, 
Long.MAX_VALUE));
+        }
+
+        // Remove KV pair.
+        tbl.remove(null, 1L);
+
+        assertNull(tbl.get(null, 1L));
+        assertNull(tbl.getOrDefault(null, 1L, null));
+        assertEquals(Long.MAX_VALUE, tbl.getOrDefault(null, 1L, 
Long.MAX_VALUE));
+
+        // Put KV pair.
+        tbl.put(null, 1L, 22L);
+        assertEquals(22L, tbl.get(null, 1L));
+        assertEquals(22L, tbl.getOrDefault(null, 1L, null));
+        assertEquals(22L, tbl.getOrDefault(null, 1L, Long.MAX_VALUE));
+    }
+
+    @ParameterizedTest
+    @MethodSource("testCases")
+    public void getAndPut(TestCase<Long, Long> testCase) {
+        KeyValueView<Long, Long> tbl = testCase.view();
+
+        // Insert new tuple.
+        assertNull(tbl.getAndPut(null, 1L, 11L));
+
+        assertEquals(11L, tbl.get(null, 1L));
+
+        assertEquals(11L, tbl.getAndPut(null, 1L, 22L));
+        assertEquals(22L, tbl.get(null, 1L));
+
+        tbl.put(null, 1L, null);
+        assertTrue(tbl.contains(null, 1L));
+        assertNull(tbl.getNullable(null, 1L).get());
+
+        testCase.checkNullValueError(() -> tbl.getAndPut(null, 1L, 33L), 
"getNullableAndPut");
+        assertEquals(33L, tbl.getNullable(null, 1L).get()); // Previous 
operation applied.
+
+        // Check null value
+        assertNotNull(tbl.getAndPut(null, 1L, null));
+    }
+
+    @ParameterizedTest
+    @MethodSource("testCases")
+    public void getNullableAndPut(TestCase<Long, Long> testCase) {
+        KeyValueView<Long, Long> tbl = testCase.view();
+
+        // getNullableAndPut
+        assertNull(tbl.getAndPut(null, 1L, 11L));

Review Comment:
   What does the comment mean?
   



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to