Skip to content

Commit 451f0fa

Browse files
Merge pull request #33 from hypersolid/issue-31
Fixes #31
2 parents 9eb519d + 833f952 commit 451f0fa

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

Diff for: pom.xml

+12
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>

Diff for: src/main/java/org/tarantool/AbstractTarantoolOps.java

+4
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 select(space, index, key, offset, limit, iterator.getValue());
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
}

Diff for: src/main/java/org/tarantool/Iterator.java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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(0), // key == x ASC order
6+
REQ(1), // key == x DESC order
7+
ALL(2), // all tuples
8+
LT(3), // key < x
9+
LE(4), // key <= x
10+
GE(5), // key >= x
11+
GT(6), // key > x
12+
BITS_ALL_SET(7), // all bits from x are set in key
13+
BITS_ANY_SET(8), // at least one x's bit is set
14+
BITS_ALL_NOT_SET(9), // all bits are not set
15+
OVERLAPS(10), // key overlaps x
16+
NEIGHBOR(11); // tuples in distance ascending order from specified point
17+
18+
private final int value;
19+
20+
Iterator(int value) {
21+
this.value = value;
22+
}
23+
24+
public int getValue() {
25+
return value;
26+
}
27+
}

Diff for: src/main/java/org/tarantool/TarantoolClientOps.java

+2
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);

Diff for: src/test/java/org/tarantool/IteratorTest.java

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.mockito.Mockito.*;
9+
10+
11+
class IteratorTest {
12+
protected class MockOps extends AbstractTarantoolOps<Integer, List<?>, Object, List<?>> {
13+
14+
@Override
15+
public List exec(Code code, Object... args) {
16+
return null;
17+
}
18+
19+
@Override
20+
public void close() {
21+
throw new UnsupportedOperationException();
22+
}
23+
}
24+
25+
@Test
26+
void testSelectWithIteratorInsteadOfInteger() {
27+
MockOps ops = new MockOps();
28+
MockOps spyOps = spy(ops);
29+
30+
spyOps.select(1, 1, new ArrayList<Integer>(), 0, 1, Iterator.EQ);
31+
32+
verify(spyOps, times(1)).select(1, 1, new ArrayList<Integer>(), 0, 1, 0);
33+
}
34+
}

0 commit comments

Comments
 (0)