|
29 | 29 | importstaticorg.assertj.core.api.Assertions.assertThatThrownBy; |
30 | 30 | importstaticorg.lmdbjava.ByteArrayProxy.PROXY_BA; |
31 | 31 | importstaticorg.lmdbjava.ByteBufferProxy.PROXY_OPTIMAL; |
32 | | -importstaticorg.lmdbjava.DbiFlags.MDB_CREATE; |
33 | | -importstaticorg.lmdbjava.DbiFlags.MDB_DUPSORT; |
34 | | -importstaticorg.lmdbjava.DbiFlags.MDB_INTEGERKEY; |
35 | | -importstaticorg.lmdbjava.DbiFlags.MDB_REVERSEKEY; |
| 32 | +importstaticorg.lmdbjava.DbiFlags.*; |
36 | 33 | importstaticorg.lmdbjava.Env.create; |
37 | 34 | importstaticorg.lmdbjava.EnvFlags.MDB_NOSUBDIR; |
38 | 35 | importstaticorg.lmdbjava.GetOp.MDB_SET_KEY; |
39 | 36 | importstaticorg.lmdbjava.KeyRange.atMost; |
40 | 37 | importstaticorg.lmdbjava.PutFlags.MDB_NODUPDATA; |
41 | 38 | importstaticorg.lmdbjava.PutFlags.MDB_NOOVERWRITE; |
42 | | -importstaticorg.lmdbjava.TestUtils.DB_1; |
43 | | -importstaticorg.lmdbjava.TestUtils.ba; |
44 | | -importstaticorg.lmdbjava.TestUtils.bb; |
45 | | -importstaticorg.lmdbjava.TestUtils.fromBa; |
| 39 | +importstaticorg.lmdbjava.TestUtils.*; |
46 | 40 |
|
47 | 41 | importjava.nio.ByteBuffer; |
48 | 42 | importjava.nio.file.Path; |
49 | 43 | importjava.util.ArrayList; |
50 | 44 | importjava.util.Comparator; |
51 | 45 | importjava.util.Iterator; |
52 | 46 | importjava.util.List; |
53 | | -importjava.util.concurrent.ExecutionException; |
54 | | -importjava.util.concurrent.ExecutorService; |
55 | | -importjava.util.concurrent.Executors; |
56 | | -importjava.util.concurrent.Future; |
57 | | -importjava.util.concurrent.TimeoutException; |
| 47 | +importjava.util.concurrent.*; |
58 | 48 | importjava.util.concurrent.atomic.AtomicBoolean; |
59 | 49 | importjava.util.function.BiConsumer; |
60 | 50 | importjava.util.function.Function; |
@@ -197,44 +187,43 @@ private <T> void doDbiWithComparatorThreadSafety( |
197 | 187 |
|
198 | 188 | finalList<Integer>keys =range(0,1_000).boxed().collect(toList()); |
199 | 189 |
|
200 | | -try (finalExecutorServicepool =Executors.newCachedThreadPool()) { |
201 | | -finalAtomicBooleanproceed =newAtomicBoolean(true); |
202 | | -finalFuture<?>reader = |
203 | | -pool.submit( |
204 | | - () -> { |
205 | | -while (proceed.get()) { |
206 | | -try (Txn<T>txn =env.txnRead()) { |
207 | | -db.get(txn,serializer.apply(50)); |
208 | | - } |
| 190 | +finalExecutorServicepool =Executors.newCachedThreadPool(); |
| 191 | +finalAtomicBooleanproceed =newAtomicBoolean(true); |
| 192 | +finalFuture<?>reader = |
| 193 | +pool.submit( |
| 194 | + () -> { |
| 195 | +while (proceed.get()) { |
| 196 | +try (Txn<T>txn =env.txnRead()) { |
| 197 | +db.get(txn,serializer.apply(50)); |
209 | 198 | } |
210 | | - }); |
| 199 | + } |
| 200 | + }); |
211 | 201 |
|
212 | | -for (finalIntegerkey :keys) { |
213 | | -try (Txn<T>txn =env.txnWrite()) { |
214 | | -db.put(txn,serializer.apply(key),serializer.apply(3)); |
215 | | -txn.commit(); |
216 | | - } |
| 202 | +for (finalIntegerkey :keys) { |
| 203 | +try (Txn<T>txn =env.txnWrite()) { |
| 204 | +db.put(txn,serializer.apply(key),serializer.apply(3)); |
| 205 | +txn.commit(); |
217 | 206 | } |
| 207 | + } |
218 | 208 |
|
219 | | -try (Txn<T>txn =env.txnRead(); |
220 | | -CursorIterable<T>ci =db.iterate(txn)) { |
221 | | -finalIterator<KeyVal<T>>iter =ci.iterator(); |
222 | | -finalList<Integer>result =newArrayList<>(); |
223 | | -while (iter.hasNext()) { |
224 | | -result.add(deserializer.applyAsInt(iter.next().key())); |
225 | | - } |
226 | | - |
227 | | -assertThat(result).contains(keys.toArray(newInteger[0])); |
| 209 | +try (Txn<T>txn =env.txnRead(); |
| 210 | +CursorIterable<T>ci =db.iterate(txn)) { |
| 211 | +finalIterator<KeyVal<T>>iter =ci.iterator(); |
| 212 | +finalList<Integer>result =newArrayList<>(); |
| 213 | +while (iter.hasNext()) { |
| 214 | +result.add(deserializer.applyAsInt(iter.next().key())); |
228 | 215 | } |
229 | 216 |
|
230 | | -proceed.set(false); |
231 | | -try { |
232 | | -reader.get(1,SECONDS); |
233 | | -pool.shutdown(); |
234 | | -pool.awaitTermination(1,SECONDS); |
235 | | - }catch (ExecutionException |InterruptedException |TimeoutExceptione) { |
236 | | -thrownewIllegalStateException(e); |
237 | | - } |
| 217 | +assertThat(result).contains(keys.toArray(newInteger[0])); |
| 218 | + } |
| 219 | + |
| 220 | +proceed.set(false); |
| 221 | +try { |
| 222 | +reader.get(1,SECONDS); |
| 223 | +pool.shutdown(); |
| 224 | +pool.awaitTermination(1,SECONDS); |
| 225 | + }catch (ExecutionException |InterruptedException |TimeoutExceptione) { |
| 226 | +thrownewIllegalStateException(e); |
238 | 227 | } |
239 | 228 | } |
240 | 229 |
|
|