Search in sources :

Example 11 with ByteArray

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

the class ConcurrentHashMapPartitionStorage method removeAll.

/**
 * {@inheritDoc}
 */
@Override
public Collection<SearchRow> removeAll(List<? extends SearchRow> keys) {
    var skippedRows = new ArrayList<SearchRow>(keys.size());
    for (SearchRow key : keys) {
        byte[] keyBytes = key.keyBytes();
        byte[] removedValueBytes = map.remove(new ByteArray(keyBytes));
        if (removedValueBytes == null) {
            skippedRows.add(key);
        }
    }
    return skippedRows;
}
Also used : ArrayList(java.util.ArrayList) ByteArray(org.apache.ignite.lang.ByteArray) SearchRow(org.apache.ignite.internal.storage.SearchRow)

Example 12 with ByteArray

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

the class ConcurrentHashMapPartitionStorage method snapshot.

/**
 * {@inheritDoc}
 */
@Override
@NotNull
public CompletableFuture<Void> snapshot(Path snapshotPath) {
    return CompletableFuture.runAsync(() -> {
        try (OutputStream out = Files.newOutputStream(snapshotPath.resolve(SNAPSHOT_FILE));
            ObjectOutputStream objOut = new ObjectOutputStream(out)) {
            objOut.writeObject(map.keySet().stream().map(ByteArray::bytes).collect(toList()));
            objOut.writeObject(new ArrayList<>(map.values()));
        } catch (Exception e) {
            throw new IgniteInternalException(e);
        }
    });
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) ByteArray(org.apache.ignite.lang.ByteArray) ObjectOutputStream(java.io.ObjectOutputStream) StorageException(org.apache.ignite.internal.storage.StorageException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ByteArray

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

the class WatchAggregatorTest method testTwoEqualCollectionCriteriaUnion.

@Test
public void testTwoEqualCollectionCriteriaUnion() {
    var watchAggregator = new WatchAggregator();
    watchAggregator.add(Arrays.asList(new ByteArray("key1"), new ByteArray("key2")), null);
    watchAggregator.add(Arrays.asList(new ByteArray("key1"), new ByteArray("key2")), null);
    var keyCriterion = watchAggregator.watch(0, null).get().keyCriterion();
    var expKeyCriterion = new KeyCriterion.CollectionCriterion(new HashSet<>(Arrays.asList(new ByteArray("key1"), 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 14 with ByteArray

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

the class WatchAggregatorTest method testTwoExactCriteriaUnion.

@Test
public void testTwoExactCriteriaUnion() {
    var watchAggregator = new WatchAggregator();
    watchAggregator.add(new ByteArray("key1"), null);
    watchAggregator.add(new ByteArray("key2"), null);
    var keyCriterion = watchAggregator.watch(0, null).get().keyCriterion();
    var expKeyCriterion = new KeyCriterion.CollectionCriterion(new HashSet<>(Arrays.asList(new ByteArray("key1"), 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 15 with ByteArray

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

the class WatchAggregatorTest method testEventsRouting.

@Test
public void testEventsRouting() {
    var watchAggregator = new WatchAggregator();
    var lsnr1 = mock(WatchListener.class);
    var lsnr2 = mock(WatchListener.class);
    watchAggregator.add(new ByteArray("1"), lsnr1);
    watchAggregator.add(new ByteArray("2"), lsnr2);
    var entryEvt1 = new EntryEvent(entry("1", "value1", 1, 1), entry("1", "value1n", 1, 1));
    var entryEvt2 = new EntryEvent(entry("2", "value2", 1, 1), entry("2", "value2n", 1, 1));
    watchAggregator.watch(1, (v1, v2) -> {
    }).get().listener().onUpdate(new WatchEvent(List.of(entryEvt1, entryEvt2)));
    var watchEvt1Res = ArgumentCaptor.forClass(WatchEvent.class);
    verify(lsnr1).onUpdate(watchEvt1Res.capture());
    assertEquals(List.of(entryEvt1), watchEvt1Res.getValue().entryEvents());
    var watchEvt2Res = ArgumentCaptor.forClass(WatchEvent.class);
    verify(lsnr2).onUpdate(watchEvt2Res.capture());
    assertEquals(List.of(entryEvt2), watchEvt2Res.getValue().entryEvents());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) WatchEvent(org.apache.ignite.internal.metastorage.client.WatchEvent) WatchListener(org.apache.ignite.internal.metastorage.client.WatchListener) ByteArray(org.apache.ignite.lang.ByteArray) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ArgumentCaptor(org.mockito.ArgumentCaptor) KeyCriterion(org.apache.ignite.internal.metastorage.watch.KeyCriterion) WatchAggregator(org.apache.ignite.internal.metastorage.watch.WatchAggregator) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EntryEvent(org.apache.ignite.internal.metastorage.client.EntryEvent) NotNull(org.jetbrains.annotations.NotNull) Mockito.mock(org.mockito.Mockito.mock) Entry(org.apache.ignite.internal.metastorage.client.Entry) EntryEvent(org.apache.ignite.internal.metastorage.client.EntryEvent) ByteArray(org.apache.ignite.lang.ByteArray) WatchEvent(org.apache.ignite.internal.metastorage.client.WatchEvent) WatchAggregator(org.apache.ignite.internal.metastorage.watch.WatchAggregator) Test(org.junit.jupiter.api.Test)

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