1818
1919import static java .nio .ByteBuffer .allocateDirect ;
2020import static org .assertj .core .api .Assertions .assertThat ;
21- import static org .lmdbjava .DbiFlags .MDB_CREATE ;
22- import static org .lmdbjava .DbiFlags .MDB_DUPSORT ;
23- import static org .lmdbjava .DbiFlags .MDB_INTEGERKEY ;
2421import static org .lmdbjava .Env .create ;
25- import static org .lmdbjava .EnvFlags .MDB_NOSUBDIR ;
2622import static org .lmdbjava .TestUtils .DB_1 ;
27- import static org .lmdbjava .TestUtils .POSIX_MODE ;
2823import static org .lmdbjava .TestUtils .bb ;
2924
3025import java .io .File ;
4136import java .util .function .Function ;
4237import org .junit .jupiter .params .ParameterizedTest ;
4338import org .junit .jupiter .params .provider .CsvFileSource ;
44- import org .lmdbjava .ByteBufferProxy .AbstractByteBufferProxy ;
4539import org .lmdbjava .CursorIterable .KeyVal ;
4640
4741/** Test {@link CursorIterable}. */
4842public final class CursorIterableRangeTest {
4943
50- private static final DbiFlagSet CREATE_AND_DUPSORT = DbiFlagSet .of (MDB_CREATE , MDB_DUPSORT );
51- private static final DbiFlagSet CREATE_AND_INTEGERKEY = DbiFlagSet .of (MDB_CREATE , MDB_INTEGERKEY );
44+ private static final DbiFlagSet FLAGSET_DUPSORT =
45+ DbiFlagSet .of (DbiFlags .MDB_CREATE , DbiFlags .MDB_DUPSORT );
46+ private static final DbiFlagSet FLAGSET_REVERSEKEY =
47+ DbiFlagSet .of (DbiFlags .MDB_CREATE , DbiFlags .MDB_REVERSEKEY );
48+ private static final DbiFlagSet FLAGSET_INTEGERKEY =
49+ DbiFlagSet .of (DbiFlags .MDB_CREATE , DbiFlags .MDB_INTEGERKEY );
50+ private static final DbiFlagSet FLAGSET_REVERSE_INTEGERKEY =
51+ DbiFlagSet .of (DbiFlags .MDB_CREATE , DbiFlags .MDB_INTEGERKEY , DbiFlags .MDB_REVERSEKEY );
5252
5353 @ ParameterizedTest (name = "{index} => {0}: ({1}, {2})" )
5454 @ CsvFileSource (resources = "/CursorIterableRangeTest/testSignedComparator.csv" )
@@ -57,7 +57,7 @@ void testSignedComparator(
5757 testCSV (
5858 builder -> builder .withCallbackComparator (ignored -> ByteBuffer ::compareTo ),
5959 createBasicDBPopulator (),
60- MDB_CREATE ,
60+ DbiFlags . MDB_CREATE ,
6161 keyType ,
6262 startKey ,
6363 stopKey ,
@@ -68,16 +68,21 @@ void testSignedComparator(
6868 @ CsvFileSource (resources = "/CursorIterableRangeTest/testUnsignedComparator.csv" )
6969 void testUnsignedComparator (
7070 final String keyType , final String startKey , final String stopKey , final String expectedKV ) {
71- testCSV (
72- builder ->
73- builder .withIteratorComparator (
74- ignored -> AbstractByteBufferProxy ::compareLexicographically ),
75- createBasicDBPopulator (),
76- MDB_CREATE ,
77- keyType ,
78- startKey ,
79- stopKey ,
80- expectedKV );
71+ testCSV (createBasicDBPopulator (), DbiFlags .MDB_CREATE , keyType , startKey , stopKey , expectedKV );
72+ }
73+
74+ @ ParameterizedTest (name = "{index} => {0}: ({1}, {2})" )
75+ @ CsvFileSource (resources = "/CursorIterableRangeTest/testUnsignedComparator.csv" )
76+ void testUnsignedComparator_Iterator (
77+ final String keyType , final String startKey , final String stopKey , final String expectedKV ) {
78+ testCSV (createBasicDBPopulator (), DbiFlags .MDB_CREATE , keyType , startKey , stopKey , expectedKV );
79+ }
80+
81+ @ ParameterizedTest (name = "{index} => {0}: ({1}, {2})" )
82+ @ CsvFileSource (resources = "/CursorIterableRangeTest/testUnsignedComparator.csv" )
83+ void testUnsignedComparator_Callback (
84+ final String keyType , final String startKey , final String stopKey , final String expectedKV ) {
85+ testCSV (createBasicDBPopulator (), DbiFlags .MDB_CREATE , keyType , startKey , stopKey , expectedKV );
8186 }
8287
8388 @ ParameterizedTest (name = "{index} => {0}: ({1}, {2})" )
@@ -87,7 +92,7 @@ void testSignedComparatorDupsort(
8792 testCSV (
8893 builder -> builder .withCallbackComparator (ignored -> ByteBuffer ::compareTo ),
8994 createMultiDBPopulator (2 ),
90- CREATE_AND_DUPSORT ,
95+ FLAGSET_DUPSORT ,
9196 keyType ,
9297 startKey ,
9398 stopKey ,
@@ -98,28 +103,16 @@ void testSignedComparatorDupsort(
98103 @ CsvFileSource (resources = "/CursorIterableRangeTest/testUnsignedComparatorDupsort.csv" )
99104 void testUnsignedComparatorDupsort (
100105 final String keyType , final String startKey , final String stopKey , final String expectedKV ) {
101- testCSV (
102- builder ->
103- builder .withIteratorComparator (
104- ignored -> AbstractByteBufferProxy ::compareLexicographically ),
105- createMultiDBPopulator (2 ),
106- CREATE_AND_DUPSORT ,
107- keyType ,
108- startKey ,
109- stopKey ,
110- expectedKV );
106+ testCSV (createMultiDBPopulator (2 ), FLAGSET_DUPSORT , keyType , startKey , stopKey , expectedKV );
111107 }
112108
113109 @ ParameterizedTest (name = "{index} => {0}: ({1}, {2})" )
114110 @ CsvFileSource (resources = "/CursorIterableRangeTest/testIntegerKey.csv" )
115111 void testIntegerKey (
116112 final String keyType , final String startKey , final String stopKey , final String expectedKV ) {
117113 testCSV (
118- builder ->
119- builder .withIteratorComparator (
120- ignored -> AbstractByteBufferProxy ::compareAsIntegerKeys ),
121114 createIntegerDBPopulator (),
122- DbiFlagSet . of ( MDB_CREATE , MDB_INTEGERKEY ) ,
115+ FLAGSET_INTEGERKEY ,
123116 keyType ,
124117 startKey ,
125118 stopKey ,
@@ -133,11 +126,8 @@ void testIntegerKey(
133126 void testLongKey (
134127 final String keyType , final String startKey , final String stopKey , final String expectedKV ) {
135128 testCSV (
136- builder ->
137- builder .withIteratorComparator (
138- ignored -> AbstractByteBufferProxy ::compareAsIntegerKeys ),
139129 createLongDBPopulator (),
140- CREATE_AND_INTEGERKEY ,
130+ FLAGSET_INTEGERKEY ,
141131 keyType ,
142132 startKey ,
143133 stopKey ,
@@ -166,6 +156,58 @@ private void testCSV(
166156 ByteOrder .BIG_ENDIAN );
167157 }
168158
159+ private void testCSV (
160+ final BiConsumer <Env <ByteBuffer >, Dbi <ByteBuffer >> dbPopulator ,
161+ final DbiFlagSet dbiFlags ,
162+ final String keyType ,
163+ final String startKey ,
164+ final String stopKey ,
165+ final String expectedKV ) {
166+ testCSV (
167+ dbPopulator ,
168+ dbiFlags ,
169+ keyType ,
170+ startKey ,
171+ stopKey ,
172+ expectedKV ,
173+ Integer .BYTES ,
174+ ByteOrder .BIG_ENDIAN );
175+ }
176+
177+ private void testCSV (
178+ final BiConsumer <Env <ByteBuffer >, Dbi <ByteBuffer >> dbPopulator ,
179+ final DbiFlagSet dbiFlags ,
180+ final String keyType ,
181+ final String startKey ,
182+ final String stopKey ,
183+ final String expectedKV ,
184+ final int keyLen ,
185+ final ByteOrder byteOrder ) {
186+ // First test with our default iterator comparator
187+ testCSV (
188+ DbiBuilder .Stage2 ::withDefaultComparator ,
189+ dbPopulator ,
190+ dbiFlags ,
191+ keyType ,
192+ startKey ,
193+ stopKey ,
194+ expectedKV ,
195+ keyLen ,
196+ byteOrder );
197+
198+ // Now test with mdp_cmp doing all comparisons, should be the same
199+ testCSV (
200+ DbiBuilder .Stage2 ::withNativeComparator ,
201+ dbPopulator ,
202+ dbiFlags ,
203+ keyType ,
204+ startKey ,
205+ stopKey ,
206+ expectedKV ,
207+ keyLen ,
208+ byteOrder );
209+ }
210+
169211 private void testCSV (
170212 final Function <DbiBuilder .Stage2 <ByteBuffer >, DbiBuilder .Stage3 <ByteBuffer >> comparatorFunc ,
171213 final BiConsumer <Env <ByteBuffer >, Dbi <ByteBuffer >> dbPopulator ,
@@ -183,8 +225,7 @@ private void testCSV(
183225 .setMapSize (256 , ByteUnit .KIBIBYTES )
184226 .setMaxReaders (1 )
185227 .setMaxDbs (1 )
186- .setFilePermissions (POSIX_MODE )
187- .setEnvFlags (MDB_NOSUBDIR )
228+ .setEnvFlags (EnvFlags .MDB_NOSUBDIR )
188229 .open (file )) {
189230
190231 final DbiBuilder .Stage2 <ByteBuffer > builderStage2 = env .createDbi ().setDbName (DB_1 );
0 commit comments