|
53 | 53 | import java.util.Set; |
54 | 54 | import java.util.UUID; |
55 | 55 | import java.util.concurrent.ConcurrentHashMap; |
| 56 | +import java.util.concurrent.CountDownLatch; |
56 | 57 | import java.util.concurrent.atomic.AtomicReference; |
57 | 58 | import java.util.stream.Collectors; |
58 | 59 |
|
@@ -296,20 +297,40 @@ public void testCreateUserSessionsParallel() throws InterruptedException { |
296 | 297 | (usMapStorageProvider == null || ConcurrentHashMapStorageProviderFactory.PROVIDER_ID.equals(usMapStorageProvider))); |
297 | 298 |
|
298 | 299 | Set<String> userSessionIds = Collections.newSetFromMap(new ConcurrentHashMap<>()); |
| 300 | + CountDownLatch latch = new CountDownLatch(4); |
299 | 301 |
|
300 | | - inIndependentFactories(4, 30, () -> withRealm(realmId, (session, realm) -> { |
301 | | - UserModel user = session.users().getUserByUsername(realm, "user1"); |
302 | | - UserSessionModel userSession = session.sessions().createUserSession(realm, user, "user1", "", "", false, null, null); |
303 | | - userSessionIds.add(userSession.getId()); |
| 302 | + inIndependentFactories(4, 30, () -> { |
| 303 | + withRealm(realmId, (session, realm) -> { |
| 304 | + UserModel user = session.users().getUserByUsername(realm, "user1"); |
| 305 | + UserSessionModel userSession = session.sessions().createUserSession(realm, user, "user1", "", "", false, null, null); |
| 306 | + userSessionIds.add(userSession.getId()); |
304 | 307 |
|
305 | | - return null; |
306 | | - })); |
| 308 | + latch.countDown(); |
| 309 | + |
| 310 | + return null; |
| 311 | + }); |
| 312 | + |
| 313 | + // wait for other nodes to finish |
| 314 | + try { |
| 315 | + latch.await(); |
| 316 | + } catch (InterruptedException e) { |
| 317 | + throw new RuntimeException(e); |
| 318 | + } |
307 | 319 |
|
308 | | - assertThat(userSessionIds, Matchers.iterableWithSize(4)); |
| 320 | + assertThat(userSessionIds, Matchers.iterableWithSize(4)); |
309 | 321 |
|
310 | | - withRealm(realmId, (session, realm) -> { |
311 | | - userSessionIds.forEach(id -> Assert.assertNotNull(session.sessions().getUserSession(realm, id))); |
312 | | - return null; |
| 322 | + // wait a bit to allow replication |
| 323 | + try { |
| 324 | + Thread.sleep(1000); |
| 325 | + } catch (InterruptedException e) { |
| 326 | + throw new RuntimeException(e); |
| 327 | + } |
| 328 | + |
| 329 | + withRealm(realmId, (session, realm) -> { |
| 330 | + userSessionIds.forEach(id -> Assert.assertNotNull(session.sessions().getUserSession(realm, id))); |
| 331 | + |
| 332 | + return null; |
| 333 | + }); |
313 | 334 | }); |
314 | 335 | } |
315 | 336 | } |
0 commit comments