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));
}
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));
}
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;
}
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));
}
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));
}
Aggregations