-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tests): client retries requests that require synchronization
- workaround for the problem that client and broker are not synchronized, i.e. the client is not aware when a the broker has reached a certain state that is able to serve the next request related to #23, #30
- Loading branch information
1 parent
75ed978
commit 94548f8
Showing
2 changed files
with
80 additions
and
23 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
qa/integration-tests/src/test/java/org/camunda/bpm/broker/it/TestUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.camunda.bpm.broker.it; | ||
|
||
import java.util.concurrent.Callable; | ||
import java.util.function.Function; | ||
|
||
import uk.co.real_logic.agrona.LangUtil; | ||
|
||
public class TestUtil | ||
{ | ||
|
||
public static final int MAX_RETRIES = 5; | ||
|
||
public static <T> Invocation<T> doRepeatedly(Callable<T> callable) | ||
{ | ||
return new Invocation<>(callable); | ||
} | ||
|
||
public static class Invocation<T> | ||
{ | ||
protected Callable<T> callable; | ||
|
||
public Invocation(Callable<T> callable) | ||
{ | ||
this.callable = callable; | ||
} | ||
|
||
public T until(Function<T, Boolean> condition) | ||
{ | ||
int numTries = 0; | ||
|
||
T result = null; | ||
|
||
do | ||
{ | ||
try | ||
{ | ||
if (numTries > 0) | ||
{ | ||
Thread.sleep(100L); | ||
} | ||
|
||
result = callable.call(); | ||
} | ||
catch (Exception e) | ||
{ | ||
LangUtil.rethrowUnchecked(e); | ||
} | ||
numTries++; | ||
} | ||
while (numTries < MAX_RETRIES && !condition.apply(result)); | ||
|
||
return result; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters