use of org.apache.ignite.lang.ByteArray in project ignite-3 by apache.
the class AbstractKeyValueStorageTest method removeAll.
@Test
public void removeAll() {
byte[] key1 = key(1);
byte[] val1 = keyValue(1, 1);
final byte[] key2 = key(2);
final byte[] val2_1 = keyValue(2, 21);
final byte[] val2_2 = keyValue(2, 22);
final byte[] key3 = key(3);
final byte[] val3_1 = keyValue(3, 31);
final byte[] key4 = key(4);
assertEquals(0, storage.revision());
assertEquals(0, storage.updateCounter());
// Regular put.
storage.put(key1, val1);
// Rewrite.
storage.put(key2, val2_1);
storage.put(key2, val2_2);
// Remove. Tombstone must not be removed again.
storage.put(key3, val3_1);
storage.remove(key3);
assertEquals(5, storage.revision());
assertEquals(5, storage.updateCounter());
storage.removeAll(List.of(key1, key2, key3, key4));
assertEquals(6, storage.revision());
// Only two keys are updated.
assertEquals(7, storage.updateCounter());
Collection<Entry> entries = storage.getAll(List.of(key1, key2, key3, key4));
assertEquals(4, entries.size());
Map<ByteArray, Entry> map = entries.stream().collect(Collectors.toMap(e -> new ByteArray(e.key()), identity()));
// Test regular put value.
Entry e1 = map.get(new ByteArray(key1));
assertNotNull(e1);
assertEquals(6, e1.revision());
assertEquals(6, e1.updateCounter());
assertTrue(e1.tombstone());
assertFalse(e1.empty());
// Test rewritten value.
Entry e2 = map.get(new ByteArray(key2));
assertNotNull(e2);
assertEquals(6, e2.revision());
assertEquals(7, e2.updateCounter());
assertTrue(e2.tombstone());
assertFalse(e2.empty());
// Test removed value.
Entry e3 = map.get(new ByteArray(key3));
assertNotNull(e3);
assertEquals(5, e3.revision());
assertEquals(5, e3.updateCounter());
assertTrue(e3.tombstone());
assertFalse(e3.empty());
// Test empty value.
Entry e4 = map.get(new ByteArray(key4));
assertNotNull(e4);
assertFalse(e4.tombstone());
assertTrue(e4.empty());
}
use of org.apache.ignite.lang.ByteArray in project ignite-3 by apache.
the class AbstractKeyValueStorageTest method getAllWithRevisionBound.
@Test
void getAllWithRevisionBound() {
byte[] key1 = key(1);
byte[] val1 = keyValue(1, 1);
final byte[] key2 = key(2);
final byte[] val2_1 = keyValue(2, 21);
final byte[] val2_2 = keyValue(2, 22);
final byte[] key3 = key(3);
final byte[] val3 = keyValue(3, 3);
final byte[] key4 = key(4);
assertEquals(0, storage.revision());
assertEquals(0, storage.updateCounter());
// Regular put.
storage.put(key1, val1);
// Rewrite.
storage.put(key2, val2_1);
storage.put(key2, val2_2);
// Remove.
storage.put(key3, val3);
storage.remove(key3);
assertEquals(5, storage.revision());
assertEquals(5, storage.updateCounter());
// Bounded by revision 2.
Collection<Entry> entries = storage.getAll(List.of(key1, key2, key3, key4), 2);
assertEquals(4, entries.size());
Map<ByteArray, Entry> map = entries.stream().collect(Collectors.toMap(e -> new ByteArray(e.key()), identity()));
// Test regular put value.
Entry e1 = map.get(new ByteArray(key1));
assertNotNull(e1);
assertEquals(1, e1.revision());
assertEquals(1, e1.updateCounter());
assertFalse(e1.tombstone());
assertFalse(e1.empty());
assertArrayEquals(val1, e1.value());
// Test while not rewritten value.
Entry e2 = map.get(new ByteArray(key2));
assertNotNull(e2);
assertEquals(2, e2.revision());
assertEquals(2, e2.updateCounter());
assertFalse(e2.tombstone());
assertFalse(e2.empty());
assertArrayEquals(val2_1, e2.value());
// Values with larger revision don't exist yet.
Entry e3 = map.get(new ByteArray(key3));
assertNotNull(e3);
assertTrue(e3.empty());
Entry e4 = map.get(new ByteArray(key4));
assertNotNull(e4);
assertTrue(e4.empty());
// Bounded by revision 4.
entries = storage.getAll(List.of(key1, key2, key3, key4), 4);
assertEquals(4, entries.size());
map = entries.stream().collect(Collectors.toMap(e -> new ByteArray(e.key()), identity()));
// Test regular put value.
e1 = map.get(new ByteArray(key1));
assertNotNull(e1);
assertEquals(1, e1.revision());
assertEquals(1, e1.updateCounter());
assertFalse(e1.tombstone());
assertFalse(e1.empty());
assertArrayEquals(val1, e1.value());
// Test rewritten value.
e2 = map.get(new ByteArray(key2));
assertNotNull(e2);
assertEquals(3, e2.revision());
assertEquals(3, e2.updateCounter());
assertFalse(e2.tombstone());
assertFalse(e2.empty());
assertArrayEquals(val2_2, e2.value());
// Test not removed value.
e3 = map.get(new ByteArray(key3));
assertNotNull(e3);
assertEquals(4, e3.revision());
assertEquals(4, e3.updateCounter());
assertFalse(e3.tombstone());
assertFalse(e3.empty());
assertArrayEquals(val3, e3.value());
// Value with larger revision doesn't exist yet.
e4 = map.get(new ByteArray(key4));
assertNotNull(e4);
assertTrue(e4.empty());
}
use of org.apache.ignite.lang.ByteArray in project ignite-3 by apache.
the class AbstractKeyValueStorageTest method getAndPutAll.
@Test
public void getAndPutAll() {
final byte[] key1 = key(1);
final byte[] val1 = keyValue(1, 1);
byte[] key2 = key(2);
byte[] val21 = keyValue(2, 21);
final byte[] val2_2 = keyValue(2, 22);
final byte[] key3 = key(3);
final byte[] val3_1 = keyValue(3, 31);
final byte[] val3_2 = keyValue(3, 32);
final byte[] key4 = key(4);
assertEquals(0, storage.revision());
assertEquals(0, storage.updateCounter());
// Must be rewritten.
storage.put(key2, val21);
// Remove. Tombstone must be replaced by new value.
storage.put(key3, val3_1);
storage.remove(key3);
assertEquals(3, storage.revision());
assertEquals(3, storage.updateCounter());
Collection<Entry> entries = storage.getAndPutAll(List.of(key1, key2, key3), List.of(val1, val2_2, val3_2));
assertEquals(4, storage.revision());
assertEquals(6, storage.updateCounter());
assertEquals(3, entries.size());
Map<ByteArray, Entry> map = entries.stream().collect(Collectors.toMap(e -> new ByteArray(e.key()), identity()));
// Test regular put value.
Entry e1 = map.get(new ByteArray(key1));
assertNotNull(e1);
assertEquals(0, e1.revision());
assertEquals(0, e1.updateCounter());
assertFalse(e1.tombstone());
assertTrue(e1.empty());
// Test rewritten value.
Entry e2 = map.get(new ByteArray(key2));
assertNotNull(e2);
assertEquals(1, e2.revision());
assertEquals(1, e2.updateCounter());
assertFalse(e2.tombstone());
assertFalse(e2.empty());
assertArrayEquals(val21, e2.value());
// Test removed value.
Entry e3 = map.get(new ByteArray(key3));
assertNotNull(e3);
assertEquals(3, e3.revision());
assertEquals(3, e3.updateCounter());
assertTrue(e3.tombstone());
assertFalse(e3.empty());
// Test state after putAll.
entries = storage.getAll(List.of(key1, key2, key3, key4));
assertEquals(4, entries.size());
map = entries.stream().collect(Collectors.toMap(e -> new ByteArray(e.key()), identity()));
// Test regular put value.
e1 = map.get(new ByteArray(key1));
assertNotNull(e1);
assertEquals(4, e1.revision());
assertEquals(4, e1.updateCounter());
assertFalse(e1.tombstone());
assertFalse(e1.empty());
assertArrayEquals(val1, e1.value());
// Test rewritten value.
e2 = map.get(new ByteArray(key2));
assertNotNull(e2);
assertEquals(4, e2.revision());
assertEquals(5, e2.updateCounter());
assertFalse(e2.tombstone());
assertFalse(e2.empty());
assertArrayEquals(val2_2, e2.value());
// Test removed value.
e3 = map.get(new ByteArray(key3));
assertNotNull(e3);
assertEquals(4, e3.revision());
assertEquals(6, e3.updateCounter());
assertFalse(e3.tombstone());
assertFalse(e3.empty());
// Test empty value.
Entry e4 = map.get(new ByteArray(key4));
assertNotNull(e4);
assertFalse(e4.tombstone());
assertTrue(e4.empty());
}
use of org.apache.ignite.lang.ByteArray in project ignite-3 by apache.
the class AbstractKeyValueStorageTest method getAndRemoveAll.
@Test
public void getAndRemoveAll() {
byte[] key1 = key(1);
byte[] val1 = keyValue(1, 1);
final byte[] key2 = key(2);
final byte[] val2_1 = keyValue(2, 21);
final byte[] val2_2 = keyValue(2, 22);
final byte[] key3 = key(3);
final byte[] val3_1 = keyValue(3, 31);
final byte[] key4 = key(4);
assertEquals(0, storage.revision());
assertEquals(0, storage.updateCounter());
// Regular put.
storage.put(key1, val1);
// Rewrite.
storage.put(key2, val2_1);
storage.put(key2, val2_2);
// Remove. Tombstone must not be removed again.
storage.put(key3, val3_1);
storage.remove(key3);
assertEquals(5, storage.revision());
assertEquals(5, storage.updateCounter());
Collection<Entry> entries = storage.getAndRemoveAll(List.of(key1, key2, key3, key4));
assertEquals(6, storage.revision());
// Only two keys are updated.
assertEquals(7, storage.updateCounter());
assertEquals(4, entries.size());
Map<ByteArray, Entry> map = entries.stream().collect(Collectors.toMap(e -> new ByteArray(e.key()), identity()));
// Test regular put value.
Entry e1 = map.get(new ByteArray(key1));
assertNotNull(e1);
assertEquals(1, e1.revision());
assertEquals(1, e1.updateCounter());
assertFalse(e1.tombstone());
assertFalse(e1.empty());
// Test rewritten value.
Entry e2 = map.get(new ByteArray(key2));
assertNotNull(e2);
assertEquals(3, e2.revision());
assertEquals(3, e2.updateCounter());
assertFalse(e2.tombstone());
assertFalse(e2.empty());
// Test removed value.
Entry e3 = map.get(new ByteArray(key3));
assertNotNull(e3);
assertEquals(5, e3.revision());
assertEquals(5, e3.updateCounter());
assertTrue(e3.tombstone());
assertFalse(e3.empty());
// Test empty value.
Entry e4 = map.get(new ByteArray(key4));
assertNotNull(e4);
assertFalse(e4.tombstone());
assertTrue(e4.empty());
// Test state after getAndRemoveAll.
entries = storage.getAll(List.of(key1, key2, key3, key4));
assertEquals(4, entries.size());
map = entries.stream().collect(Collectors.toMap(e -> new ByteArray(e.key()), identity()));
// Test regular put value.
e1 = map.get(new ByteArray(key1));
assertNotNull(e1);
assertEquals(6, e1.revision());
assertEquals(6, e1.updateCounter());
assertTrue(e1.tombstone());
assertFalse(e1.empty());
// Test rewritten value.
e2 = map.get(new ByteArray(key2));
assertNotNull(e2);
assertEquals(6, e2.revision());
assertEquals(7, e2.updateCounter());
assertTrue(e2.tombstone());
assertFalse(e2.empty());
// Test removed value.
e3 = map.get(new ByteArray(key3));
assertNotNull(e3);
assertEquals(5, e3.revision());
assertEquals(5, e3.updateCounter());
assertTrue(e3.tombstone());
assertFalse(e3.empty());
// Test empty value.
e4 = map.get(new ByteArray(key4));
assertNotNull(e4);
assertFalse(e4.tombstone());
assertTrue(e4.empty());
}
use of org.apache.ignite.lang.ByteArray in project ignite-3 by apache.
the class ItMetaStorageServiceTest method testGetAndRemove.
/**
* Tests {@link MetaStorageService#getAndRemove(ByteArray)}.
*
* @throws Exception If failed.
*/
@Test
public void testGetAndRemove() throws Exception {
EntryImpl expRes = new EntryImpl(new ByteArray(new byte[] { 1 }), new byte[] { 3 }, 10, 2);
when(mockStorage.getAndRemove(expRes.key().bytes())).thenReturn(new org.apache.ignite.internal.metastorage.server.Entry(expRes.key().bytes(), expRes.value(), expRes.revision(), expRes.updateCounter()));
assertEquals(expRes, metaStorageSvc.getAndRemove(expRes.key()).get());
}
Aggregations