Skip to content
This repository was archived by the owner on Feb 11, 2023. It is now read-only.

Commit 445ae39

Browse files
author
Alexander Krasnoschekov
committed
Fixes tarantool#31
Adds Iterator enum with values copied from Tarantool sources; Adds overloaded select method that accepts Iterator instead of int; Adds tests on JUnit5 and Mockito.
1 parent 9eb519d commit 445ae39

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@
5252
<version>4.12</version>
5353
<scope>test</scope>
5454
</dependency>
55+
<dependency>
56+
<groupId>org.junit.jupiter</groupId>
57+
<artifactId>junit-jupiter-api</artifactId>
58+
<version>5.2.0</version>
59+
<scope>test</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.mockito</groupId>
63+
<artifactId>mockito-all</artifactId>
64+
<version>1.9.5</version>
65+
<scope>test</scope>
66+
</dependency>
5567
</dependencies>
5668

5769
<parent>

src/main/java/org/tarantool/AbstractTarantoolOps.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ public abstract class AbstractTarantoolOps<Space, Tuple, Operation, Result> impl
66

77
public abstract Result exec(Code code, Object... args);
88

9+
public Result select(Space space, Space index, Tuple key, int offset, int limit, Iterator iterator) {
10+
return exec(Code.SELECT, Key.SPACE, space, Key.INDEX, index, Key.KEY, key, Key.ITERATOR, iterator.ordinal(), Key.LIMIT, limit, Key.OFFSET, offset);
11+
}
12+
913
public Result select(Space space, Space index, Tuple key, int offset, int limit, int iterator) {
1014
return exec(Code.SELECT, Key.SPACE, space, Key.INDEX, index, Key.KEY, key, Key.ITERATOR, iterator, Key.LIMIT, limit, Key.OFFSET, offset);
1115
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.tarantool;
2+
3+
// Iterator info was taken from here https://github.com/tarantool/tarantool/blob/f66584c3bcdffe61d6d99a4868a9b72d62338a11/src/box/iterator_type.h#L62
4+
public enum Iterator {
5+
EQ, // key == x ASC order
6+
REQ, // key == x DESC order
7+
ALL, // all tuples
8+
LT, // key < x
9+
LE, // key <= x
10+
GE, // key >= x
11+
GT, // key > x
12+
BITS_ALL_SET, // all bits from x are set in key
13+
BITS_ANY_SET, // at least one x's bit is set
14+
BITS_ALL_NOT_SET, // all bits are not set
15+
OVERLAPS, // key overlaps x
16+
NEIGHBOR // tuples in distance ascending order from specified point
17+
}

src/main/java/org/tarantool/TarantoolClientOps.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
public interface TarantoolClientOps<T,O,P,R> {
55
R select(T space, T index, O key, int offset, int limit, int iterator);
66

7+
R select(T space, T index, O key, int offset, int limit, Iterator iterator);
8+
79
R insert(T space, O tuple);
810

911
R replace(T space, O tuple);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.tarantool;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.mockito.Mockito.*;
10+
11+
12+
class IteratorTest {
13+
protected class MockOps extends AbstractTarantoolOps<Integer, List<?>, Object, List<?>> {
14+
15+
@Override
16+
public List exec(Code code, Object... args) {
17+
return null;
18+
}
19+
20+
@Override
21+
public void close() {
22+
throw new UnsupportedOperationException();
23+
}
24+
}
25+
26+
@Test
27+
void testSelectWithIteratorInsteadOfInteger() {
28+
final int iteratorNumber = 0;
29+
30+
assertEquals(Iterator.EQ.ordinal(), iteratorNumber);
31+
32+
MockOps ops = new MockOps();
33+
MockOps spyOps = spy(ops);
34+
spyOps.select(1,1,new ArrayList<Integer>(),0,1,Iterator.EQ);
35+
36+
verify(spyOps, times(1)).exec(
37+
Code.SELECT,
38+
Key.SPACE,1,
39+
Key.INDEX,1,
40+
Key.KEY, new ArrayList<Integer>(),
41+
Key.ITERATOR,iteratorNumber,
42+
Key.LIMIT,1,
43+
Key.OFFSET,0
44+
);
45+
}
46+
}

0 commit comments

Comments
 (0)