Skip to content

Commit 6c33337

Browse files
authored
Merge pull request quarkusio#51015 from marcosgopen/flaky-recovery-lra
Fix flaky recovery lra
2 parents 3c42793 + ca533d5 commit 6c33337

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

tcks/microprofile-lra/src/main/java/io/quarkus/tck/lra/NarayanaLRARecovery.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,34 @@
3232
import jakarta.ws.rs.core.Response;
3333
import jakarta.ws.rs.core.UriBuilder;
3434

35+
import org.eclipse.microprofile.config.Config;
36+
import org.eclipse.microprofile.config.ConfigProvider;
3537
import org.eclipse.microprofile.lra.tck.service.spi.LRARecoveryService;
3638
import org.jboss.logging.Logger;
3739

3840
import io.narayana.lra.LRAConstants;
3941

4042
public class NarayanaLRARecovery implements LRARecoveryService {
4143
private static final Logger log = Logger.getLogger(NarayanaLRARecovery.class);
44+
private static final long WAIT_CALLBACK_TIMEOUT = initWaitForCallbackTimeout();
45+
private static final String WAIT_CALLBACK_TIMEOUT_PROPERTY = "lra.tck.callback.timeout";
46+
private static final int DEFAULT_CALLBACK_TIMEOUT = 1000;
4247

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

4865
@Override
@@ -83,4 +100,17 @@ private boolean recoverLRAs(URI lraId) {
83100
recoveryCoordinatorClient.close();
84101
}
85102
}
103+
104+
private static Integer initWaitForCallbackTimeout() {
105+
Config config = ConfigProvider.getConfig();
106+
if (config != null) {
107+
try {
108+
return config.getOptionalValue(WAIT_CALLBACK_TIMEOUT_PROPERTY, Integer.class).orElse(DEFAULT_CALLBACK_TIMEOUT);
109+
} catch (IllegalArgumentException e) {
110+
log.error("property " + WAIT_CALLBACK_TIMEOUT_PROPERTY + " not set correctly, using the default value: "
111+
+ DEFAULT_CALLBACK_TIMEOUT);
112+
}
113+
}
114+
return DEFAULT_CALLBACK_TIMEOUT;
115+
}
86116
}

0 commit comments

Comments
 (0)