use of org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes in project ignite-3 by apache.
the class KeyValueViewOperationsTest method removeExact.
@Test
public void removeExact() {
final TestKeyObject key = TestKeyObject.randomObject(rnd);
final TestKeyObject key2 = TestKeyObject.randomObject(rnd);
final TestObjectWithAllTypes obj = TestObjectWithAllTypes.randomObject(rnd);
final TestObjectWithAllTypes obj2 = TestObjectWithAllTypes.randomObject(rnd);
KeyValueView<TestKeyObject, TestObjectWithAllTypes> tbl = kvView();
// Put KV pair.
tbl.put(null, key, obj);
assertEquals(obj, tbl.get(null, key));
// Fails to delete KV pair with unexpected value.
assertFalse(tbl.remove(null, key, obj2));
assertEquals(obj, tbl.get(null, key));
// Delete KV pair with expected value.
assertTrue(tbl.remove(null, key, obj));
assertNull(tbl.get(null, key));
// Once again.
assertFalse(tbl.remove(null, key, obj));
assertNull(tbl.get(null, key));
// Try to remove non-existed key.
assertFalse(tbl.remove(null, key, obj));
assertNull(tbl.get(null, key));
// Put KV pair.
tbl.put(null, key, obj2);
assertEquals(obj2, tbl.get(null, key));
// Check null value ignored.
assertThrows(Throwable.class, () -> tbl.remove(null, key, null));
assertEquals(obj2, tbl.get(null, key));
// Delete KV pair with expected value.
assertTrue(tbl.remove(null, key, obj2));
assertNull(tbl.get(null, key));
assertFalse(tbl.remove(null, key2, obj2));
assertNull(tbl.get(null, key2));
}
use of org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes in project ignite-3 by apache.
the class KeyValueViewOperationsTest method replace.
@Test
public void replace() {
final TestKeyObject key = TestKeyObject.randomObject(rnd);
final TestKeyObject key2 = TestKeyObject.randomObject(rnd);
final TestObjectWithAllTypes obj = TestObjectWithAllTypes.randomObject(rnd);
final TestObjectWithAllTypes obj2 = TestObjectWithAllTypes.randomObject(rnd);
final TestObjectWithAllTypes obj3 = TestObjectWithAllTypes.randomObject(rnd);
KeyValueView<TestKeyObject, TestObjectWithAllTypes> tbl = kvView();
// Ignore replace operation for non-existed KV pair.
assertFalse(tbl.replace(null, key, obj));
assertNull(tbl.get(null, key));
tbl.put(null, key, obj);
// Replace existed KV pair.
assertTrue(tbl.replace(null, key, obj2));
assertEquals(obj2, tbl.get(null, key));
// Try remove existed KV pair.
assertThrows(Throwable.class, () -> tbl.replace(null, key, null));
assertNotNull(tbl.get(null, key));
tbl.remove(null, key);
// Ignore replace operation for non-existed KV pair.
assertFalse(tbl.replace(null, key, obj3));
assertNull(tbl.get(null, key));
tbl.put(null, key, obj3);
assertEquals(obj3, tbl.get(null, key));
// Trye remove non-existed KV pair.
assertThrows(Throwable.class, () -> tbl.replace(null, key2, null));
assertNull(tbl.get(null, key2));
}
use of org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes in project ignite-3 by apache.
the class KeyValueViewOperationsTest method putIfAbsent.
@Test
public void putIfAbsent() {
final TestKeyObject key = TestKeyObject.randomObject(rnd);
final TestObjectWithAllTypes obj = TestObjectWithAllTypes.randomObject(rnd);
final TestObjectWithAllTypes obj2 = TestObjectWithAllTypes.randomObject(rnd);
KeyValueView<TestKeyObject, TestObjectWithAllTypes> tbl = kvView();
assertNull(tbl.get(null, key));
// Insert new KV pair.
assertTrue(tbl.putIfAbsent(null, key, obj));
assertEquals(obj, tbl.get(null, key));
// Update KV pair.
assertFalse(tbl.putIfAbsent(null, key, obj2));
assertEquals(obj, tbl.get(null, key));
}
use of org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes in project ignite-3 by apache.
the class KeyValueViewOperationsTest method replaceExact.
@Test
public void replaceExact() {
final TestKeyObject key = TestKeyObject.randomObject(rnd);
final TestKeyObject key2 = TestKeyObject.randomObject(rnd);
final TestObjectWithAllTypes obj = TestObjectWithAllTypes.randomObject(rnd);
final TestObjectWithAllTypes obj2 = TestObjectWithAllTypes.randomObject(rnd);
KeyValueView<TestKeyObject, TestObjectWithAllTypes> tbl = kvView();
// Insert KV pair.
assertThrows(Throwable.class, () -> tbl.replace(null, key, null, obj));
tbl.put(null, key, obj);
assertEquals(obj, tbl.get(null, key));
assertNull(tbl.get(null, key2));
// Ignore replace operation for non-existed KV pair.
assertFalse(tbl.replace(null, key2, obj, obj2));
assertNull(tbl.get(null, key2));
// Replace existed KV pair.
assertTrue(tbl.replace(null, key, obj, obj2));
assertEquals(obj2, tbl.get(null, key));
// try remove existed KV pair.
assertThrows(Throwable.class, () -> tbl.replace(null, key, obj2, null));
assertNotNull(tbl.get(null, key));
}
use of org.apache.ignite.internal.schema.testobjects.TestObjectWithAllTypes in project ignite-3 by apache.
the class KeyValueViewOperationsTest method kvView.
/**
* Creates key-value view.
*/
private KeyValueViewImpl<TestKeyObject, TestObjectWithAllTypes> kvView() {
ClusterService clusterService = Mockito.mock(ClusterService.class, RETURNS_DEEP_STUBS);
Mockito.when(clusterService.topologyService().localMember().address()).thenReturn(DummyInternalTableImpl.ADDR);
TxManager txManager = new TxManagerImpl(clusterService, new HeapLockManager());
MessagingService messagingService = MessagingServiceTestUtils.mockMessagingService(txManager);
Mockito.when(clusterService.messagingService()).thenReturn(messagingService);
DummyInternalTableImpl table = new DummyInternalTableImpl(new VersionedRowStore(new ConcurrentHashMapPartitionStorage(), txManager), txManager);
Mapper<TestKeyObject> keyMapper = Mapper.of(TestKeyObject.class);
Mapper<TestObjectWithAllTypes> valMapper = Mapper.of(TestObjectWithAllTypes.class);
Column[] valCols = { new Column("primitiveByteCol".toUpperCase(), INT8, false), new Column("primitiveShortCol".toUpperCase(), INT16, false), new Column("primitiveIntCol".toUpperCase(), INT32, false), new Column("primitiveLongCol".toUpperCase(), INT64, false), new Column("primitiveFloatCol".toUpperCase(), FLOAT, false), new Column("primitiveDoubleCol".toUpperCase(), DOUBLE, false), new Column("byteCol".toUpperCase(), INT8, true), new Column("shortCol".toUpperCase(), INT16, true), new Column("intCol".toUpperCase(), INT32, true), new Column("longCol".toUpperCase(), INT64, true), new Column("nullLongCol".toUpperCase(), INT64, true), new Column("floatCol".toUpperCase(), FLOAT, true), new Column("doubleCol".toUpperCase(), DOUBLE, true), new Column("dateCol".toUpperCase(), DATE, true), new Column("timeCol".toUpperCase(), time(), true), new Column("dateTimeCol".toUpperCase(), datetime(), true), new Column("timestampCol".toUpperCase(), timestamp(), true), new Column("uuidCol".toUpperCase(), NativeTypes.UUID, true), new Column("bitmaskCol".toUpperCase(), NativeTypes.bitmaskOf(42), true), new Column("stringCol".toUpperCase(), STRING, true), new Column("nullBytesCol".toUpperCase(), BYTES, true), new Column("bytesCol".toUpperCase(), BYTES, true), new Column("numberCol".toUpperCase(), NativeTypes.numberOf(12), true), new Column("decimalCol".toUpperCase(), NativeTypes.decimalOf(19, 3), true) };
SchemaDescriptor schema = new SchemaDescriptor(1, new Column[] { new Column("id".toUpperCase(), NativeTypes.INT64, false) }, valCols);
// Validate all types are tested.
Set<NativeTypeSpec> testedTypes = Arrays.stream(valCols).map(c -> c.type().spec()).collect(Collectors.toSet());
Set<NativeTypeSpec> missedTypes = Arrays.stream(NativeTypeSpec.values()).filter(t -> !testedTypes.contains(t)).collect(Collectors.toSet());
assertEquals(Collections.emptySet(), missedTypes);
return new KeyValueViewImpl<>(table, new DummySchemaManagerImpl(schema), keyMapper, valMapper);
}
Aggregations