Skip to content

Commit d93304c

Browse files
committed
[JBTM-3985] Adding the waitForCallbacks implementation
1 parent 1ebe5fe commit d93304c

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

rts/lra/test/arquillian-extension/src/main/java/io/narayana/lra/arquillian/spi/NarayanaLRARecovery.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
package io.narayana.lra.arquillian.spi;
2424

2525
import io.narayana.lra.LRAConstants;
26+
27+
import org.eclipse.microprofile.config.Config;
28+
import org.eclipse.microprofile.config.ConfigProvider;
2629
import org.eclipse.microprofile.lra.tck.service.spi.LRARecoveryService;
2730
import org.jboss.logging.Logger;
2831

@@ -36,15 +39,30 @@
3639

3740
public class NarayanaLRARecovery implements LRARecoveryService {
3841
private static final Logger log = Logger.getLogger(NarayanaLRARecovery.class);
42+
private static final long WAIT_CALLBACK_TIMEOUT = initWaitForCallbackTimeout();
43+
private static final String WAIT_CALLBACK_TIMEOUT_PROPERTY = "lra.tck.callback.timeout";
3944

45+
/*
46+
* Wait for the participant to return the callback. This method does not
47+
* guarantee callbacks to finish. The Participant status is not immediately
48+
* reflected to the LRA status, but only after a recovery scan which executes an
49+
* enlistment. The waiting time can be configurable by
50+
* LRAConstants.WAIT_CALLBACK_TIMEOUT property.
51+
*/
4052
@Override
4153
public void waitForCallbacks(URI lraId) {
42-
// no action needed
54+
log.trace("waitForCallbacks for: " + lraId.toASCIIString());
55+
try {
56+
Thread.sleep(WAIT_CALLBACK_TIMEOUT);
57+
}
58+
catch (InterruptedException e) {
59+
log.error("waitForCallbacks interrupted by " + e.getMessage());
60+
}
4361
}
4462

4563
@Override
4664
public boolean waitForEndPhaseReplay(URI lraId) {
47-
log.info("waitForEndPhaseReplay for: " + lraId.toASCIIString());
65+
log.trace("waitForEndPhaseReplay for: " + lraId.toASCIIString());
4866
if (!recoverLRAs(lraId)) {
4967
// first recovery scan probably collided with periodic recovery which started
5068
// before the test execution so try once more
@@ -84,4 +102,19 @@ private boolean recoverLRAs(URI lraId) {
84102
recoveryCoordinatorClient.close();
85103
}
86104
}
105+
106+
private static Integer initWaitForCallbackTimeout() {
107+
Config config = ConfigProvider.getConfig();
108+
int defaultValue = 1000;
109+
if (config != null) {
110+
try {
111+
return config.getOptionalValue(WAIT_CALLBACK_TIMEOUT_PROPERTY, Integer.class).orElse(defaultValue);
112+
}
113+
catch (IllegalArgumentException e) {
114+
log.error("property " + WAIT_CALLBACK_TIMEOUT_PROPERTY + " not set correctly, using the default value: "
115+
+ defaultValue);
116+
}
117+
}
118+
return defaultValue;
119+
}
87120
}

0 commit comments

Comments
 (0)