Search in sources :

Example 6 with TestObjectWithAllTypes

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

the class RecordViewOperationsTest method upsert.

@Test
public void upsert() {
    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.
    tbl.upsert(null, obj);
    assertEquals(obj, tbl.get(null, key));
    // Upsert row.
    tbl.upsert(null, obj2);
    assertEquals(obj2, tbl.get(null, key));
    // Remove row.
    tbl.delete(null, key);
    assertNull(tbl.get(null, key));
    // Insert new row.
    tbl.upsert(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 7 with TestObjectWithAllTypes

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

the class RecordViewOperationsTest method randomObject.

@NotNull
private TestObjectWithAllTypes randomObject(Random rnd, TestObjectWithAllTypes key) {
    TestObjectWithAllTypes obj = TestObjectWithAllTypes.randomObject(rnd);
    obj.setPrimitiveLongCol(key.getPrimitiveLongCol());
    return obj;
}
Also used : TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with TestObjectWithAllTypes

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

the class RecordViewOperationsTest method insert.

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

Example 9 with TestObjectWithAllTypes

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

the class RecordViewOperationsTest method replace.

@Test
public void replace() {
    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();
    // Ignore replace operation for non-existed row.
    assertFalse(tbl.replace(null, obj));
    assertNull(tbl.get(null, key));
    // Insert new row.
    tbl.upsert(null, obj);
    // Replace existed row.
    assertTrue(tbl.replace(null, obj2));
    assertEquals(obj2, tbl.get(null, key));
    // Replace existed row.
    assertTrue(tbl.replace(null, obj3));
    assertEquals(obj3, tbl.get(null, key));
    // Remove existed row.
    assertTrue(tbl.delete(null, key));
    assertNull(tbl.get(null, key));
    tbl.upsert(null, obj);
    assertEquals(obj, tbl.get(null, key));
}
Also used : TestObjectWithAllTypes(org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes) Test(org.junit.jupiter.api.Test)

Example 10 with TestObjectWithAllTypes

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

the class RecordViewOperationsTest method getAll.

@Test
public void getAll() {
    final TestObjectWithAllTypes key1 = key(rnd);
    final TestObjectWithAllTypes key2 = key(rnd);
    final TestObjectWithAllTypes key3 = key(rnd);
    final TestObjectWithAllTypes val1 = randomObject(rnd, key1);
    final TestObjectWithAllTypes val3 = randomObject(rnd, key3);
    RecordView<TestObjectWithAllTypes> tbl = recordView();
    tbl.upsertAll(null, List.of(val1, val3));
    Collection<TestObjectWithAllTypes> res = tbl.getAll(null, List.of(key1, key2, key3));
    assertEquals(2, res.size());
    assertTrue(res.contains(val1));
    assertTrue(res.contains(val3));
}
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