Search in sources :

Example 46 with ByteArray

use of org.apache.ignite.lang.ByteArray in project ignite-3 by apache.

the class WatchAggregatorTest method testTwoEqualExactCriteriaUnion.

@Test
public void testTwoEqualExactCriteriaUnion() {
    var watchAggregator = new WatchAggregator();
    watchAggregator.add(new ByteArray("key1"), null);
    watchAggregator.add(new ByteArray("key1"), null);
    var keyCriterion = watchAggregator.watch(0, null).get().keyCriterion();
    assertEquals(keyCriterion, keyCriterion);
}
Also used : ByteArray(org.apache.ignite.lang.ByteArray) WatchAggregator(org.apache.ignite.internal.metastorage.watch.WatchAggregator) Test(org.junit.jupiter.api.Test)

Example 47 with ByteArray

use of org.apache.ignite.lang.ByteArray in project ignite-3 by apache.

the class WatchAggregatorTest method testNullKeyAsStartOfRangeCriterion.

@Test
public void testNullKeyAsStartOfRangeCriterion() {
    var watchAggregator = new WatchAggregator();
    watchAggregator.add(new ByteArray("key0"), null);
    watchAggregator.add(null, new ByteArray("key2"), null);
    var keyCriterion = watchAggregator.watch(0, null).get().keyCriterion();
    var expKeyCriterion = new KeyCriterion.RangeCriterion(null, new ByteArray("key2"));
    assertEquals(expKeyCriterion, keyCriterion);
}
Also used : ByteArray(org.apache.ignite.lang.ByteArray) WatchAggregator(org.apache.ignite.internal.metastorage.watch.WatchAggregator) Test(org.junit.jupiter.api.Test)

Example 48 with ByteArray

use of org.apache.ignite.lang.ByteArray in project ignite-3 by apache.

the class MetaStorageServiceImpl method multipleEntryResult.

private static Map<ByteArray, Entry> multipleEntryResult(Object obj) {
    MultipleEntryResponse resp = (MultipleEntryResponse) obj;
    Map<ByteArray, Entry> res = new HashMap<>();
    for (SingleEntryResponse e : resp.entries()) {
        ByteArray key = new ByteArray(e.key());
        res.put(key, new EntryImpl(key, e.value(), e.revision(), e.updateCounter()));
    }
    return res;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ByteArray(org.apache.ignite.lang.ByteArray) MultipleEntryResponse(org.apache.ignite.internal.metastorage.common.command.MultipleEntryResponse) SingleEntryResponse(org.apache.ignite.internal.metastorage.common.command.SingleEntryResponse)

Example 49 with ByteArray

use of org.apache.ignite.lang.ByteArray in project ignite-3 by apache.

the class ConcurrentHashMapPartitionStorage method removeAllExact.

/**
 * {@inheritDoc}
 */
@Override
public Collection<DataRow> removeAllExact(List<? extends DataRow> keyValues) {
    var skippedRows = new ArrayList<DataRow>(keyValues.size());
    for (DataRow row : keyValues) {
        var key = new ByteArray(row.keyBytes());
        byte[] existingValueBytes = map.get(key);
        if (Arrays.equals(existingValueBytes, row.valueBytes())) {
            map.remove(key);
        } else {
            skippedRows.add(row);
        }
    }
    return skippedRows;
}
Also used : ArrayList(java.util.ArrayList) ByteArray(org.apache.ignite.lang.ByteArray) DataRow(org.apache.ignite.internal.storage.DataRow)

Example 50 with ByteArray

use of org.apache.ignite.lang.ByteArray in project ignite-3 by apache.

the class ConcurrentHashMapPartitionStorage method invoke.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public <T> T invoke(SearchRow key, InvokeClosure<T> clo) throws StorageException {
    byte[] keyBytes = key.keyBytes();
    ByteArray mapKey = new ByteArray(keyBytes);
    byte[] existingDataBytes = map.get(mapKey);
    clo.call(existingDataBytes == null ? null : new SimpleDataRow(keyBytes, existingDataBytes));
    switch(clo.operationType()) {
        case WRITE:
            DataRow newRow = clo.newRow();
            assert newRow != null;
            map.put(mapKey, newRow.valueBytes());
            break;
        case REMOVE:
            map.remove(mapKey);
            break;
        case NOOP:
            break;
        default:
            throw new UnsupportedOperationException(String.valueOf(clo.operationType()));
    }
    return clo.result();
}
Also used : ByteArray(org.apache.ignite.lang.ByteArray) DataRow(org.apache.ignite.internal.storage.DataRow) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ByteArray (org.apache.ignite.lang.ByteArray)51 Test (org.junit.jupiter.api.Test)35 Cursor (org.apache.ignite.internal.util.Cursor)13 List (java.util.List)12 WatchAggregator (org.apache.ignite.internal.metastorage.watch.WatchAggregator)12 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)11 Map (java.util.Map)10 NotNull (org.jetbrains.annotations.NotNull)9 Collection (java.util.Collection)8 Iterator (java.util.Iterator)8 Collectors (java.util.stream.Collectors)8 AfterEach (org.junit.jupiter.api.AfterEach)8 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)8 Assertions.fail (org.junit.jupiter.api.Assertions.fail)8 BeforeEach (org.junit.jupiter.api.BeforeEach)8 ByteBuffer (java.nio.ByteBuffer)7 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)7 ArrayList (java.util.ArrayList)7 NoSuchElementException (java.util.NoSuchElementException)7 Function.identity (java.util.function.Function.identity)7