ibessonov commented on code in PR #1464:
URL: https://github.com/apache/ignite-3/pull/1464#discussion_r1056198696
##########
modules/core/src/testFixtures/java/org/apache/ignite/internal/testframework/IgniteTestUtils.java:
##########
@@ -766,4 +771,57 @@ public static <T> T await(CompletionStage<T> stage, long
timeout, TimeUnit unit)
public static <T> T await(CompletionStage<T> stage) {
return await(stage, TIMEOUT_SEC, TimeUnit.SECONDS);
}
+
+ /**
+ * {@link #runRace(long, RunnableX...)} with default timeout of 10 seconds.
+ */
+ public static void runRace(RunnableX... actions) {
+ runRace(TimeUnit.SECONDS.toMillis(10), actions);
+ }
+
+ /**
+ * Runs all actions, each in a separate thread, having a {@link
CyclicBarrier} before calling {@link RunnableX#run()}.
+ * Waits for threads completion or fails with the assertion if timeout
exceeded.
+ */
+ public static void runRace(long timeoutMillis, RunnableX... actions) {
+ int length = actions.length;
+
+ CyclicBarrier barrier = new CyclicBarrier(length);
+
+ Set<Throwable> throwables = ConcurrentHashMap.newKeySet();
+
+ Thread[] threads = IntStream.range(0, length).mapToObj(i -> new
Thread(() -> {
+ try {
+ barrier.await();
+
+ actions[i].run();
+ } catch (Throwable e) {
+ throwables.add(e);
+ }
+ })).toArray(Thread[]::new);
+
+ Stream.of(threads).forEach(Thread::start);
+
+ try {
+ for (Thread thread : threads) {
+ thread.join(timeoutMillis);
+ }
+ } catch (InterruptedException e) {
+ for (Thread thread : threads) {
+ thread.interrupt();
+ }
+
+ fail("Race operations took too long.");
+ }
+
+ if (!throwables.isEmpty()) {
+ AssertionError assertionError = new AssertionError("One or several
threads have failed.");
Review Comment:
Ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]