|
18 | 18 |
|
19 | 19 | package org.dizitart.no2; |
20 | 20 |
|
| 21 | +import lombok.AllArgsConstructor; |
| 22 | +import lombok.Data; |
| 23 | +import lombok.NoArgsConstructor; |
21 | 24 | import org.dizitart.no2.exceptions.NitriteIOException; |
| 25 | +import org.dizitart.no2.objects.Id; |
22 | 26 | import org.dizitart.no2.objects.ObjectRepository; |
23 | 27 | import org.junit.After; |
24 | 28 | import org.junit.Before; |
|
37 | 41 | import static org.dizitart.no2.DbTestOperations.getRandomTempDbFile; |
38 | 42 | import static org.dizitart.no2.Document.createDocument; |
39 | 43 | import static org.dizitart.no2.filters.Filters.ALL; |
| 44 | +import static org.dizitart.no2.objects.filters.ObjectFilters.eq; |
| 45 | +import static org.dizitart.no2.objects.filters.ObjectFilters.not; |
40 | 46 | import static org.junit.Assert.*; |
41 | 47 |
|
42 | 48 | public class NitriteTest { |
@@ -277,4 +283,53 @@ public void testIssue112() { |
277 | 283 | Nitrite db = Nitrite.builder().filePath("/tmp").openOrCreate(); |
278 | 284 | assertNull(db); |
279 | 285 | } |
| 286 | + |
| 287 | + @Test |
| 288 | + public void testIssue185() { |
| 289 | + final ObjectRepository<Receipt> repository = db.getRepository(Receipt.class); |
| 290 | + final Receipt receipt = new Receipt(); |
| 291 | + receipt.clientRef = "111-11111"; |
| 292 | + receipt.status = Receipt.Status.PREPARING; |
| 293 | + |
| 294 | + new Thread(new Runnable() { |
| 295 | + @Override |
| 296 | + public void run() { |
| 297 | + for (int i = 0; i < 1000; ++i) { |
| 298 | + repository.update(receipt, true); |
| 299 | + try { |
| 300 | + Thread.sleep(50); |
| 301 | + } catch (InterruptedException ignored) { |
| 302 | + } |
| 303 | + repository.remove(receipt); |
| 304 | + try { |
| 305 | + Thread.sleep(50); |
| 306 | + } catch (InterruptedException ignored) { |
| 307 | + } |
| 308 | + } |
| 309 | + } |
| 310 | + }).start(); |
| 311 | + |
| 312 | + for (int i = 0; i < 1000; ++i) { |
| 313 | + repository.find(not(eq("status", Receipt.Status.COMPLETED)), FindOptions.sort("createdTimestamp", SortOrder.Descending)).toList(); |
| 314 | + try { |
| 315 | + Thread.sleep(50); |
| 316 | + } catch (InterruptedException ignored) { |
| 317 | + } |
| 318 | + } |
| 319 | + } |
| 320 | + |
| 321 | + @Data |
| 322 | + @NoArgsConstructor |
| 323 | + @AllArgsConstructor |
| 324 | + public static class Receipt { |
| 325 | + public enum Status { |
| 326 | + COMPLETED, |
| 327 | + PREPARING, |
| 328 | + } |
| 329 | + |
| 330 | + private Status status; |
| 331 | + @Id |
| 332 | + private String clientRef; |
| 333 | + private Long createdTimestamp = System.currentTimeMillis(); |
| 334 | + } |
280 | 335 | } |
0 commit comments