| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2fb1c02 commit 05314e8
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,32 +29,22 @@ | |||
| 29 | 29 | import static org.assertj.core.api.Assertions.assertThatThrownBy; | |
| 30 | 30 | import static org.lmdbjava.ByteArrayProxy.PROXY_BA; | |
| 31 | 31 | import static org.lmdbjava.ByteBufferProxy.PROXY_OPTIMAL; | |
| 32 | - import static org.lmdbjava.DbiFlags.MDB_CREATE; | ||
| 33 | - import static org.lmdbjava.DbiFlags.MDB_DUPSORT; | ||
| 34 | - import static org.lmdbjava.DbiFlags.MDB_INTEGERKEY; | ||
| 35 | - import static org.lmdbjava.DbiFlags.MDB_REVERSEKEY; | ||
| 32 | + import static org.lmdbjava.DbiFlags.*; | ||
| 36 | 33 | import static org.lmdbjava.Env.create; | |
| 37 | 34 | import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR; | |
| 38 | 35 | import static org.lmdbjava.GetOp.MDB_SET_KEY; | |
| 39 | 36 | import static org.lmdbjava.KeyRange.atMost; | |
| 40 | 37 | import static org.lmdbjava.PutFlags.MDB_NODUPDATA; | |
| 41 | 38 | import static org.lmdbjava.PutFlags.MDB_NOOVERWRITE; | |
| 42 | - import static org.lmdbjava.TestUtils.DB_1; | ||
| 43 | - import static org.lmdbjava.TestUtils.ba; | ||
| 44 | - import static org.lmdbjava.TestUtils.bb; | ||
| 45 | - import static org.lmdbjava.TestUtils.fromBa; | ||
| 39 | + import static org.lmdbjava.TestUtils.*; | ||
| 46 | 40 | ||
| 47 | 41 | import java.nio.ByteBuffer; | |
| 48 | 42 | import java.nio.file.Path; | |
| 49 | 43 | import java.util.ArrayList; | |
| 50 | 44 | import java.util.Comparator; | |
| 51 | 45 | import java.util.Iterator; | |
| 52 | 46 | import java.util.List; | |
| 53 | - import java.util.concurrent.ExecutionException; | ||
| 54 | - import java.util.concurrent.ExecutorService; | ||
| 55 | - import java.util.concurrent.Executors; | ||
| 56 | - import java.util.concurrent.Future; | ||
| 57 | - import java.util.concurrent.TimeoutException; | ||
| 47 | + import java.util.concurrent.*; | ||
| 58 | 48 | import java.util.concurrent.atomic.AtomicBoolean; | |
| 59 | 49 | import java.util.function.BiConsumer; | |
| 60 | 50 | import java.util.function.Function; | |
@@ -197,44 +187,43 @@ private <T> void doDbiWithComparatorThreadSafety( | |||
| 197 | 187 | ||
| 198 | 188 | final List<Integer> keys = range(0, 1_000).boxed().collect(toList()); | |
| 199 | 189 | ||
| 200 | - try (final ExecutorService pool = Executors.newCachedThreadPool()) { | ||
| 201 | - final AtomicBoolean proceed = new AtomicBoolean(true); | ||
| 202 | - final Future<?> 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 | + final ExecutorService pool = Executors.newCachedThreadPool(); | ||
| 191 | + final AtomicBoolean proceed = new AtomicBoolean(true); | ||
| 192 | + final Future<?> 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 (final Integer key : keys) { | ||
| 213 | - try (Txn<T> txn = env.txnWrite()) { | ||
| 214 | - db.put(txn, serializer.apply(key), serializer.apply(3)); | ||
| 215 | - txn.commit(); | ||
| 216 | - } | ||
| 202 | + for (final Integer key : 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 | - final Iterator<KeyVal<T>> iter = ci.iterator(); | ||
| 222 | - final List<Integer> result = new ArrayList<>(); | ||
| 223 | - while (iter.hasNext()) { | ||
| 224 | - result.add(deserializer.applyAsInt(iter.next().key())); | ||
| 225 | - } | ||
| 226 | - | ||
| 227 | - assertThat(result).contains(keys.toArray(new Integer[0])); | ||
| 209 | + try (Txn<T> txn = env.txnRead(); | ||
| 210 | + CursorIterable<T> ci = db.iterate(txn)) { | ||
| 211 | + final Iterator<KeyVal<T>> iter = ci.iterator(); | ||
| 212 | + final List<Integer> result = new ArrayList<>(); | ||
| 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 | TimeoutException e) { | ||
| 236 | - throw new IllegalStateException(e); | ||
| 237 | - } | ||
| 217 | + assertThat(result).contains(keys.toArray(new Integer[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 | TimeoutException e) { | ||
| 226 | + throw new IllegalStateException(e); | ||
| 238 | 227 | } | |
| 239 | 228 | } | |
| 240 | 229 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments