Search in sources :

Example 46 with SchemaDescriptor

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 47 with SchemaDescriptor

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 48 with SchemaDescriptor

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 49 with SchemaDescriptor

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Example 50 with SchemaDescriptor

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));
}
Also used : SchemaDescriptor(org.apache.ignite.internal.schema.SchemaDescriptor) Column(org.apache.ignite.internal.schema.Column) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test)

Aggregations

SchemaDescriptor (org.apache.ignite.internal.schema.SchemaDescriptor)105 Column (org.apache.ignite.internal.schema.Column)78 Test (org.junit.jupiter.api.Test)48 Tuple (org.apache.ignite.table.Tuple)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 Row (org.apache.ignite.internal.schema.row.Row)32 MethodSource (org.junit.jupiter.params.provider.MethodSource)30 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)22 TestObjectWithAllTypes (org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes)11 DummySchemaManagerImpl (org.apache.ignite.internal.table.impl.DummySchemaManagerImpl)11 TupleMarshaller (org.apache.ignite.internal.schema.marshaller.TupleMarshaller)10 TupleMarshallerImpl (org.apache.ignite.internal.schema.marshaller.TupleMarshallerImpl)10 List (java.util.List)9 ArrayList (java.util.ArrayList)8 NotNull (org.jetbrains.annotations.NotNull)8 UUID (java.util.UUID)7 Collectors (java.util.stream.Collectors)7 TableImpl (org.apache.ignite.internal.table.TableImpl)7 Random (java.util.Random)6 Map (java.util.Map)5