|
23 | 23 | package io.narayana.lra.arquillian.spi; |
24 | 24 |
|
25 | 25 | import io.narayana.lra.LRAConstants; |
| 26 | + |
| 27 | +import org.eclipse.microprofile.config.Config; |
| 28 | +import org.eclipse.microprofile.config.ConfigProvider; |
26 | 29 | import org.eclipse.microprofile.lra.tck.service.spi.LRARecoveryService; |
27 | 30 | import org.jboss.logging.Logger; |
28 | 31 |
|
|
36 | 39 |
|
37 | 40 | public class NarayanaLRARecovery implements LRARecoveryService { |
38 | 41 | 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"; |
39 | 44 |
|
| 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 | + */ |
40 | 52 | @Override |
41 | 53 | 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 | + } |
43 | 61 | } |
44 | 62 |
|
45 | 63 | @Override |
46 | 64 | public boolean waitForEndPhaseReplay(URI lraId) { |
47 | | - log.info("waitForEndPhaseReplay for: " + lraId.toASCIIString()); |
| 65 | + log.trace("waitForEndPhaseReplay for: " + lraId.toASCIIString()); |
48 | 66 | if (!recoverLRAs(lraId)) { |
49 | 67 | // first recovery scan probably collided with periodic recovery which started |
50 | 68 | // before the test execution so try once more |
@@ -84,4 +102,19 @@ private boolean recoverLRAs(URI lraId) { |
84 | 102 | recoveryCoordinatorClient.close(); |
85 | 103 | } |
86 | 104 | } |
| 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 | + } |
87 | 120 | } |
0 commit comments