Search in sources :

Example 1 with ByteArray

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

the class ItMetaStorageServiceTest method testRangeWitKeyTo.

/**
 * Tests {@link MetaStorageService#range(ByteArray, ByteArray, long)}} with not null keyTo.
 *
 * @throws Exception If failed.
 */
@Test
public void testRangeWitKeyTo() throws Exception {
    ByteArray expKeyFrom = new ByteArray(new byte[] { 1 });
    ByteArray expKeyTo = new ByteArray(new byte[] { 3 });
    when(mockStorage.range(expKeyFrom.bytes(), expKeyTo.bytes())).thenReturn(mock(Cursor.class));
    metaStorageSvc.range(expKeyFrom, expKeyTo).close();
}
Also used : ByteArray(org.apache.ignite.lang.ByteArray) Cursor(org.apache.ignite.internal.util.Cursor) Test(org.junit.jupiter.api.Test)

Example 2 with ByteArray

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

the class ItMetaStorageServiceTest method testRangeWitKeyToAndUpperBound.

/**
 * Tests {@link MetaStorageService#range(ByteArray, ByteArray, long)}} with not null keyTo and explicit revUpperBound.
 *
 * @throws Exception If failed.
 */
@Test
public void testRangeWitKeyToAndUpperBound() throws Exception {
    ByteArray expKeyFrom = new ByteArray(new byte[] { 1 });
    ByteArray expKeyTo = new ByteArray(new byte[] { 3 });
    long expRevUpperBound = 10;
    when(mockStorage.range(expKeyFrom.bytes(), expKeyTo.bytes(), expRevUpperBound)).thenReturn(mock(Cursor.class));
    metaStorageSvc.range(expKeyFrom, expKeyTo, expRevUpperBound).close();
}
Also used : ByteArray(org.apache.ignite.lang.ByteArray) Cursor(org.apache.ignite.internal.util.Cursor) Test(org.junit.jupiter.api.Test)

Example 3 with ByteArray

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

the class ItMetaStorageServiceTest method testRangeClose.

/**
 * Tests {@link MetaStorageService#range(ByteArray, ByteArray, long)}} close.
 *
 * @throws Exception If failed.
 */
@Test
public void testRangeClose() throws Exception {
    ByteArray expKeyFrom = new ByteArray(new byte[] { 1 });
    Cursor cursorMock = mock(Cursor.class);
    when(mockStorage.range(expKeyFrom.bytes(), null)).thenReturn(cursorMock);
    Cursor<Entry> cursor = metaStorageSvc.range(expKeyFrom, null);
    cursor.close();
    verify(cursorMock, times(1)).close();
}
Also used : ByteArray(org.apache.ignite.lang.ByteArray) Cursor(org.apache.ignite.internal.util.Cursor) Test(org.junit.jupiter.api.Test)

Example 4 with ByteArray

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

the class ItMetaStorageServiceTest method testRemove.

/**
 * Tests {@link MetaStorageService#remove(ByteArray)}.
 *
 * @throws Exception If failed.
 */
@Test
public void testRemove() throws Exception {
    ByteArray expKey = new ByteArray(new byte[] { 1 });
    doNothing().when(mockStorage).remove(expKey.bytes());
    metaStorageSvc.remove(expKey).get();
}
Also used : ByteArray(org.apache.ignite.lang.ByteArray) Test(org.junit.jupiter.api.Test)

Example 5 with ByteArray

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

the class ItMetaStorageServiceTest method testMultiInvoke.

@Test
public void testMultiInvoke() throws Exception {
    ByteArray key1 = new ByteArray(new byte[] { 1 });
    ByteArray key2 = new ByteArray(new byte[] { 2 });
    ByteArray key3 = new ByteArray(new byte[] { 3 });
    var val1 = new byte[] { 4 };
    var val2 = new byte[] { 5 };
    var rval1 = new byte[] { 6 };
    var rval2 = new byte[] { 7 };
    /*
        if (key1.value == val1 || key2.value != val2)
            if (key3.revision == 3 || key2.value > val1 || key1.value >= val2):
                put(key1, rval1)
                return true
            else
                if (key2.value < val1 && key1.value <= val2):
                    put(key1, rval1)
                    remove(key2, rval2)
                    return false
                else
                    return true
        else
            put(key2, rval2)
            return false
         */
    var iif = If.iif(or(value(key1).eq(val1), value(key2).ne(val2)), iif(or(revision(key3).eq(3), or(value(key2).gt(val1), value(key1).ge(val2))), ops(put(key1, rval1)).yield(true), iif(and(value(key2).lt(val1), value(key1).le(val2)), ops(put(key1, rval1), remove(key2)).yield(false), ops().yield(true))), ops(put(key2, rval2)).yield(false));
    var ifCaptor = ArgumentCaptor.forClass(org.apache.ignite.internal.metastorage.server.If.class);
    when(mockStorage.invoke(any())).thenReturn(new StatementResult(true));
    assertTrue(metaStorageSvc.invoke(iif).get().getAsBoolean());
    verify(mockStorage).invoke(ifCaptor.capture());
    var resultIf = ifCaptor.getValue();
    assertThat(resultIf.cond(), cond(new OrCondition(new ValueCondition(Type.EQUAL, key1.bytes(), val1), new ValueCondition(Type.NOT_EQUAL, key2.bytes(), val2))));
    assertThat(resultIf.andThen().iif().cond(), cond(new OrCondition(new RevisionCondition(RevisionCondition.Type.EQUAL, key3.bytes(), 3), new OrCondition(new ValueCondition(ValueCondition.Type.GREATER, key2.bytes(), val1), new ValueCondition(Type.GREATER_OR_EQUAL, key1.bytes(), val2)))));
    assertThat(resultIf.andThen().iif().orElse().iif().cond(), cond(new AndCondition(new ValueCondition(ValueCondition.Type.LESS, key2.bytes(), val1), new ValueCondition(Type.LESS_OR_EQUAL, key1.bytes(), val2))));
    assertThat(resultIf.andThen().iif().andThen().update(), upd(new Update(List.of(new org.apache.ignite.internal.metastorage.server.Operation(OperationType.PUT, key1.bytes(), rval1)), new StatementResult(true))));
    assertThat(resultIf.andThen().iif().orElse().iif().andThen().update(), upd(new Update(Arrays.asList(new org.apache.ignite.internal.metastorage.server.Operation(OperationType.PUT, key1.bytes(), rval1), new org.apache.ignite.internal.metastorage.server.Operation(OperationType.REMOVE, key2.bytes(), null)), new StatementResult(false))));
    assertThat(resultIf.andThen().iif().orElse().iif().orElse().update(), upd(new Update(Collections.emptyList(), new StatementResult(true))));
    assertThat(resultIf.orElse().update(), upd(new Update(List.of(new org.apache.ignite.internal.metastorage.server.Operation(OperationType.PUT, key2.bytes(), rval2)), new StatementResult(false))));
}
Also used : StatementResult(org.apache.ignite.internal.metastorage.server.StatementResult) Update(org.apache.ignite.internal.metastorage.server.Update) AndCondition(org.apache.ignite.internal.metastorage.server.AndCondition) ByteArray(org.apache.ignite.lang.ByteArray) ValueCondition(org.apache.ignite.internal.metastorage.server.ValueCondition) OrCondition(org.apache.ignite.internal.metastorage.server.OrCondition) RevisionCondition(org.apache.ignite.internal.metastorage.server.RevisionCondition) 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