Search in sources :

Example 21 with TestObjectWithAllTypes

use of org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes in project ignite-3 by apache.

the class KeyValueViewOperationsTest method getAll.

@Test
public void getAll() {
    KeyValueView<TestKeyObject, TestObjectWithAllTypes> kvView = kvView();
    final TestKeyObject key1 = TestKeyObject.randomObject(rnd);
    final TestKeyObject key2 = TestKeyObject.randomObject(rnd);
    final TestKeyObject key3 = TestKeyObject.randomObject(rnd);
    final TestObjectWithAllTypes val1 = TestObjectWithAllTypes.randomObject(rnd);
    final TestObjectWithAllTypes val3 = TestObjectWithAllTypes.randomObject(rnd);
    kvView.putAll(null, Map.of(key1, val1, key3, val3));
    Map<TestKeyObject, TestObjectWithAllTypes> res = kvView.getAll(null, List.of(key1, key2, key3));
    assertEquals(2, res.size());
    assertEquals(val1, res.get(key1));
    assertEquals(val3, res.get(key3));
    assertNull(res.get(key2));
}
Also used : TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) Test(org.junit.jupiter.api.Test)

Example 22 with TestObjectWithAllTypes

use of org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes in project ignite-3 by apache.

the class RecordViewOperationsTest method getAndUpsert.

@Test
public void getAndUpsert() {
    final TestObjectWithAllTypes key = key(rnd);
    final TestObjectWithAllTypes obj = randomObject(rnd, key);
    final TestObjectWithAllTypes obj2 = randomObject(rnd, key);
    final TestObjectWithAllTypes obj3 = randomObject(rnd, key);
    RecordView<TestObjectWithAllTypes> tbl = recordView();
    assertNull(tbl.get(null, key));
    // Insert new row.
    assertNull(tbl.getAndUpsert(null, obj));
    assertEquals(obj, tbl.get(null, key));
    // Update exited row.
    assertEquals(obj, tbl.getAndUpsert(null, obj2));
    assertEquals(obj2, tbl.getAndUpsert(null, obj3));
    assertEquals(obj3, tbl.get(null, key));
}
Also used : TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) Test(org.junit.jupiter.api.Test)

Example 23 with TestObjectWithAllTypes

use of org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes in project ignite-3 by apache.

the class RecordViewOperationsTest method key.

@NotNull
private static TestObjectWithAllTypes key(Random rnd) {
    TestObjectWithAllTypes key = new TestObjectWithAllTypes();
    key.setPrimitiveLongCol(rnd.nextLong());
    return key;
}
Also used : TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with TestObjectWithAllTypes

use of org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes in project ignite-3 by apache.

the class RecordViewOperationsTest method replaceExact.

@Test
public void replaceExact() {
    final TestObjectWithAllTypes key = key(rnd);
    final TestObjectWithAllTypes obj = randomObject(rnd, key);
    final TestObjectWithAllTypes obj2 = randomObject(rnd, key);
    final TestObjectWithAllTypes obj3 = randomObject(rnd, key);
    final TestObjectWithAllTypes obj4 = randomObject(rnd, key);
    RecordView<TestObjectWithAllTypes> tbl = recordView();
    // Ignore replace operation for non-existed row.
    assertFalse(tbl.replace(null, obj, obj2));
    assertNull(tbl.get(null, key));
    // Insert new row.
    tbl.upsert(null, obj);
    // Ignore un-exepected row replacement.
    assertFalse(tbl.replace(null, obj2, obj3));
    assertEquals(obj, tbl.get(null, key));
    // Replace existed row.
    assertTrue(tbl.replace(null, obj, obj2));
    assertEquals(obj2, tbl.get(null, key));
    // Replace existed KV pair.
    assertTrue(tbl.replace(null, obj2, obj3));
    assertEquals(obj3, tbl.get(null, key));
    // Remove existed row.
    assertTrue(tbl.delete(null, key));
    assertNull(tbl.get(null, key));
    assertFalse(tbl.replace(null, key, obj4));
    assertNull(tbl.get(null, key));
}
Also used : TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) Test(org.junit.jupiter.api.Test)

Example 25 with TestObjectWithAllTypes

use of org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes in project ignite-3 by apache.

the class RecordViewOperationsTest method remove.

@Test
public void remove() {
    final TestObjectWithAllTypes key = key(rnd);
    final TestObjectWithAllTypes obj = randomObject(rnd, key);
    final TestObjectWithAllTypes obj2 = randomObject(rnd, key);
    RecordView<TestObjectWithAllTypes> tbl = recordView();
    // Delete not existed key.
    assertNull(tbl.get(null, key));
    assertFalse(tbl.delete(null, key));
    // Insert a new row.
    tbl.upsert(null, obj);
    // Delete existed row.
    assertEquals(obj, tbl.get(null, key));
    assertTrue(tbl.delete(null, key));
    assertNull(tbl.get(null, key));
    // Delete already deleted row.
    assertFalse(tbl.delete(null, key));
    // Insert a new row.
    tbl.upsert(null, obj2);
    assertEquals(obj2, tbl.get(null, key));
}
Also used : TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) Test(org.junit.jupiter.api.Test)

Aggregations

TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)30 Test (org.junit.jupiter.api.Test)20 SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)10 Column (org.apache.ignite.internal.schema.Column)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 MethodSource (org.junit.jupiter.params.provider.MethodSource)8 Row (org.apache.ignite.internal.schema.row.Row)5 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)4 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Random (java.util.Random)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)2 NativeTypes (org.apache.ignite.internal.schema.NativeTypes)2 BYTES (org.apache.ignite.internal.schema.NativeTypes.BYTES)2 DATE (org.apache.ignite.internal.schema.NativeTypes.DATE)2 DOUBLE (org.apache.ignite.internal.schema.NativeTypes.DOUBLE)2 FLOAT (org.apache.ignite.internal.schema.NativeTypes.FLOAT)2