use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method replaceExact.
@Test
public void replaceExact() {
SchemaDescriptor schema = schemaDescriptor();
KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
final Tuple key = Tuple.create().set("id", 1L);
final Tuple key2 = Tuple.create().set("id", 2L);
final Tuple val = Tuple.create().set("val", 11L);
final Tuple val2 = Tuple.create().set("val", 22L);
// Ignore replace operation for non-existed KV pair.
assertFalse(tbl.replace(null, key2, val, val2));
assertNull(tbl.get(null, key2));
tbl.put(null, key, val);
// Replace existed KV pair.
assertTrue(tbl.replace(null, key, val, val2));
assertEqualsValues(schema, val2, tbl.get(null, key));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method remove.
@Test
public void remove() {
SchemaDescriptor schema = schemaDescriptor();
KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
final Tuple key = Tuple.create().set("id", 1L);
final Tuple key2 = Tuple.create().set("id", 2L);
final Tuple val = Tuple.create().set("val", 11L);
final Tuple val2 = Tuple.create().set("val", 22L);
// Put KV pair.
tbl.put(null, key, val);
// Delete existed key.
assertEqualsValues(schema, val, tbl.get(null, key));
assertTrue(tbl.remove(null, key));
assertNull(tbl.get(null, key));
// Delete already deleted key.
assertFalse(tbl.remove(null, key));
// Put KV pair.
tbl.put(null, key, val2);
assertEqualsValues(schema, val2, tbl.get(null, key));
// Delete existed key.
assertTrue(tbl.remove(null, Tuple.create().set("id", 1L)));
assertNull(tbl.get(null, key));
// Delete not existed key.
assertNull(tbl.get(null, key2));
assertFalse(tbl.remove(null, key2));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method put.
@Test
public void put() {
SchemaDescriptor schema = schemaDescriptor();
KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
final Tuple key = Tuple.create().set("id", 1L);
final Tuple val = Tuple.create().set("val", 11L);
final Tuple val2 = Tuple.create().set("val", 22L);
final Tuple val3 = Tuple.create().set("val", 33L);
assertNull(tbl.get(null, key));
// Put KV pair.
tbl.put(null, key, val);
assertEqualsValues(schema, val, tbl.get(null, key));
assertEqualsValues(schema, val, tbl.get(null, Tuple.create().set("id", 1L)));
// Update KV pair.
tbl.put(null, key, val2);
assertEqualsValues(schema, val2, tbl.get(null, key));
assertEqualsValues(schema, val2, tbl.get(null, Tuple.create().set("id", 1L)));
// Remove KV pair.
tbl.put(null, key, null);
assertNull(tbl.get(null, key));
// Put KV pair.
tbl.put(null, key, val3);
assertEqualsValues(schema, val3, tbl.get(null, key));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class KeyValueBinaryViewOperationsTest method replace.
@Test
public void replace() {
SchemaDescriptor schema = schemaDescriptor();
KeyValueView<Tuple, Tuple> tbl = createTable(schema).keyValueView();
final Tuple key = Tuple.create().set("id", 1L);
final Tuple key2 = Tuple.create().set("id", 2L);
final Tuple val = Tuple.create().set("val", 11L);
final Tuple val2 = Tuple.create().set("val", 22L);
final Tuple val3 = Tuple.create().set("val", 33L);
// Ignore replace operation for non-existed KV pair.
assertFalse(tbl.replace(null, key, val));
assertNull(tbl.get(null, key));
tbl.put(null, key, val);
// Replace existed KV pair.
assertTrue(tbl.replace(null, key, val2));
assertEqualsValues(schema, val2, tbl.get(null, key));
// Ignore replace operation for non-existed KV pair.
assertFalse(tbl.replace(null, key2, val3));
assertNull(tbl.get(null, key2));
tbl.put(null, key, val3);
assertEqualsValues(schema, val3, tbl.get(null, key));
}
use of org.apache.ignite.internal.schema.SchemaDescriptor in project ignite-3 by apache.
the class RecordBinaryViewOperationsTest method insert.
// TODO: IGNITE-16468 Extend test coverage.
@Test
public void insert() {
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, new Column[] { new Column("val".toUpperCase(), NativeTypes.INT64, false) });
RecordView<Tuple> tbl = createTableImpl(schema).recordView();
final Tuple tuple = Tuple.create().set("id", 1L).set("val", 11L);
final Tuple newTuple = Tuple.create().set("id", 1L).set("val", 22L);
final Tuple nonExistedTuple = Tuple.create().set("id", 2L);
assertNull(tbl.get(null, Tuple.create().set("id", 1L)));
// Insert new tuple.
assertTrue(tbl.insert(null, tuple));
assertEqualsRows(schema, tuple, tbl.get(null, Tuple.create().set("id", 1L)));
// Ignore insert operation for exited row.
assertFalse(tbl.insert(null, newTuple));
assertEqualsRows(schema, tuple, tbl.get(null, Tuple.create().set("id", 1L)));
assertNull(tbl.get(null, nonExistedTuple));
}
Aggregations