|
32 | 32 | import java.util.Map; |
33 | 33 | import java.util.Random; |
34 | 34 | import java.util.concurrent.atomic.AtomicBoolean; |
| 35 | +import java.util.concurrent.atomic.AtomicLong; |
35 | 36 | import java.util.concurrent.atomic.AtomicReference; |
| 37 | +import java.util.function.Consumer; |
36 | 38 |
|
37 | 39 | import static org.awaitility.Awaitility.await; |
38 | 40 | import static org.hamcrest.Matchers.notNullValue; |
@@ -80,15 +82,16 @@ public void shouldThrowExceptionWhenInsertWithTTL() { |
80 | 82 |
|
81 | 83 | @Test |
82 | 84 | public void shouldThrowExceptionWhenInsertWithTTLWithCallback() { |
83 | | - assertThrows(UnsupportedOperationException.class, () -> entityManager.insert(getEntity(), Duration.ofSeconds(10), r -> {})); |
| 85 | + assertThrows(UnsupportedOperationException.class, () -> entityManager.insert(getEntity(), Duration.ofSeconds(10), r -> { |
| 86 | + })); |
84 | 87 | } |
85 | 88 |
|
86 | 89 | @Test |
87 | 90 | public void shouldUpdateAsync() throws InterruptedException { |
88 | 91 |
|
89 | 92 | Random random = new Random(); |
90 | 93 | long id = random.nextLong(); |
91 | | - |
| 94 | + |
92 | 95 | AtomicBoolean condition = new AtomicBoolean(false); |
93 | 96 | AtomicReference<DocumentEntity> reference = new AtomicReference<>(); |
94 | 97 | DocumentEntity entity = getEntity(); |
@@ -192,6 +195,23 @@ public void shouldRemoveEntity() { |
192 | 195 | entityManager.delete(deleteQuery); |
193 | 196 | } |
194 | 197 |
|
| 198 | + @Test |
| 199 | + public void shouldCount() throws InterruptedException { |
| 200 | + AtomicBoolean condition = new AtomicBoolean(false); |
| 201 | + AtomicLong value = new AtomicLong(0); |
| 202 | + DocumentEntity entity = getEntity(); |
| 203 | + entityManager.insert(entity, c -> condition.set(true)); |
| 204 | + await().untilTrue(condition); |
| 205 | + condition.set(false); |
| 206 | + Consumer<Long> callback = l -> { |
| 207 | + condition.set(true); |
| 208 | + value.set(l); |
| 209 | + }; |
| 210 | + entityManager.count(COLLECTION_NAME, callback); |
| 211 | + await().untilTrue(condition); |
| 212 | + assertTrue(value.get() > 0); |
| 213 | + } |
| 214 | + |
195 | 215 | private DocumentEntity getEntity() { |
196 | 216 | DocumentEntity entity = DocumentEntity.of(COLLECTION_NAME); |
197 | 217 | Map<String, Object> map = new HashMap<>(); |
|
0 commit comments