parent
f11b049e52
commit
64cbbde7cf
2 changed files with 27 additions and 4 deletions
|
@ -59,6 +59,7 @@ import java.util.Set;
|
|||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
@ -331,7 +332,27 @@ public abstract class KeycloakModelTest {
|
|||
public static void inIndependentFactories(int numThreads, int timeoutSeconds, Runnable task) throws InterruptedException {
|
||||
ExecutorService es = Executors.newFixedThreadPool(numThreads);
|
||||
try {
|
||||
Callable<?> independentTask = () -> inIndependentFactory(() -> { task.run(); return null; });
|
||||
/*
|
||||
workaround for Infinispan 12.1.7.Final to prevent an internal Infinispan NullPointerException
|
||||
when multiple nodes tried to join at the same time by starting them sequentially with 1 sec delay.
|
||||
Already fixed in Infinispan 13.
|
||||
https://issues.redhat.com/browse/ISPN-13231
|
||||
*/
|
||||
Semaphore sem = new Semaphore(1);
|
||||
Callable<?> independentTask = () -> {
|
||||
try {
|
||||
sem.acquire();
|
||||
return inIndependentFactory(() -> {
|
||||
Thread.sleep(1000);
|
||||
sem.release();
|
||||
task.run();
|
||||
return null;
|
||||
});
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Thread terminated with an exception", ex);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
es.invokeAll(
|
||||
IntStream.range(0, numThreads)
|
||||
.mapToObj(i -> independentTask)
|
||||
|
@ -339,7 +360,9 @@ public abstract class KeycloakModelTest {
|
|||
timeoutSeconds, TimeUnit.SECONDS
|
||||
);
|
||||
} finally {
|
||||
es.shutdownNow();
|
||||
LOG.debugf("waiting for threads to shutdown to avoid that one test pollutes another test");
|
||||
es.shutdown();
|
||||
LOG.debugf("shutdown of threads complete");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ public class CacheExpirationTest extends KeycloakModelTest {
|
|||
InfinispanConnectionProvider provider = session.getProvider(InfinispanConnectionProvider.class);
|
||||
Cache<String, Object> cache = provider.getCache(InfinispanConnectionProvider.WORK_CACHE_NAME);
|
||||
do {
|
||||
try { Thread.sleep(1000); } catch (InterruptedException ex) {}
|
||||
try { Thread.sleep(1000); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new RuntimeException(ex); }
|
||||
} while (! cache.getAdvancedCache().getDistributionManager().isJoinComplete());
|
||||
cache.keySet().forEach(s -> {});
|
||||
});
|
||||
|
@ -102,7 +102,7 @@ public class CacheExpirationTest extends KeycloakModelTest {
|
|||
|
||||
// Wait for at most 3 minutes which is much more than 15 seconds expiration set in DefaultInfinispanConnectionProviderFactory
|
||||
for (int i = 0; i < 3 * 60; i++) {
|
||||
try { Thread.sleep(1000); } catch (InterruptedException ex) {}
|
||||
try { Thread.sleep(1000); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new RuntimeException(ex); }
|
||||
if (getNumberOfInstancesOfClass(AuthenticationSessionAuthNoteUpdateEvent.class) == 0) {
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue