From 2e6a47f5a768deeb5b44a5a55a9a06c8cc2cf08e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Sapp=C3=A9=20Griot?= Date: Thu, 2 Jan 2025 12:23:18 +0100 Subject: [PATCH] JBTM-3966 fix crash tests --- .../arquillian/LRACoordinatorRecoveryIT.java | 69 ++++--------------- 1 file changed, 15 insertions(+), 54 deletions(-) diff --git a/test/crash/src/test/java/io/narayana/lra/arquillian/LRACoordinatorRecoveryIT.java b/test/crash/src/test/java/io/narayana/lra/arquillian/LRACoordinatorRecoveryIT.java index 8dbcd2f..8b830cc 100644 --- a/test/crash/src/test/java/io/narayana/lra/arquillian/LRACoordinatorRecoveryIT.java +++ b/test/crash/src/test/java/io/narayana/lra/arquillian/LRACoordinatorRecoveryIT.java @@ -74,7 +74,7 @@ public class LRACoordinatorRecoveryIT extends UnmanagedTestBase { private static Path storeDir; private static final Long LONG_TIMEOUT = 600000L; // 10 minutes - private static final Long SHORT_TIMEOUT = 10000L; // 10 seconds + private static final Long SHORT_TIMEOUT = 1000L; // 1 seconds private static final Map containerDeploymentMap = new HashMap<>(); @Rule @@ -110,14 +110,14 @@ public void before() { client = ClientBuilder.newClient(); lraClient = new NarayanaLRAClient(); - + // Cleans Object Store in case there are transactions from previous tests + clearRecoveryLogFromFS(); for (Map.Entry entry : containerDeploymentMap.entrySet()) { startContainer(entry.getKey(), entry.getValue()); } - // Cleans Object Store in case there are transactions from previous tests clearRecoveryLogFromObjectStore(); - clearRecoveryLogFromFS(); + } @After @@ -128,11 +128,12 @@ public void after() { // Cleans Object Store in case there are still active transactions clearRecoveryLogFromObjectStore(); - clearRecoveryLogFromFS(); for (Map.Entry entry : containerDeploymentMap.entrySet()) { stopContainer(entry.getKey(), entry.getValue()); } + clearRecoveryLogFromFS(); + } /** @@ -150,57 +151,23 @@ public static WebArchive deploy() { public void lraCoordinatorShortTimeoutLRA(@ArquillianResource @OperateOnDeployment(LRA_PARTICIPANT_DEPLOYMENT_QUALIFIER) URL baseURL) throws URISyntaxException { - String lraId; - URI lraListenerURI = UriBuilder.fromUri(baseURL.toURI()).path(LRAListener.LRA_LISTENER_PATH).build(); - - // Starts an LRA with a short time limit by invoking a resource annotated with @LRA. The time limit is - // defined as LRAListener.LRA_SHORT_TIMELIMIT - Response response = client - .target(lraListenerURI) - .path(LRAListener.LRA_LISTENER_ACTION) - .request() - .put(null); - - Assert.assertEquals("LRA participant action", 200, response.getStatus()); + URI shortLRA = lraClient.startLRA(null, "Short Timeout Recovery Test", SHORT_TIMEOUT, ChronoUnit.MILLIS); + assertNotNull("A new LRA should have been added to the object store before the JVM was halted.", shortLRA); + // The LRA transaction could have been started via lraClient but it is useful to + // test the filters as well // Restarts lra-coordinator to simulate a crash restartContainer(LRA_COORDINATOR_CONTAINER_QUALIFIER); // Waits for a period of time longer than the timeout of the LRA Transaction - doWait((LRAListener.LRA_SHORT_TIMELIMIT + 1L) * 1000); - - // The LRA transaction could have been started via lraClient but it is useful to test the filters as well - lraId = getFirstLRAFromFS(); - assertNotNull("A new LRA should have been added to the object store before the JVM was halted.", lraId); - lraId = String.format("%s/%s", lraClient.getCoordinatorUrl(), lraId); - - // Waits for a period of time longer than the timeout of the LRA Transaction - doWait((LRAListener.LRA_SHORT_TIMELIMIT + 1L) * 1000); - - // Checks recovery - LRAStatus status = getStatus(new URI(lraId)); - - LRALogger.logger.infof("%s: Status after restart is %s%n", status == null ? "GONE" : status.name()); - - if (status == null || status == LRAStatus.Cancelling) { - int sc = recover(); - - if (sc != 0) { - recover(); - } - } + doWait(SHORT_TIMEOUT + 5000L); // LRA with short timeout should have timed out and cancelled - status = getStatus(new URI(lraId)); - - Assert.assertTrue(String.format("LRA %s should have cancelled", lraId), - status == null || status == LRAStatus.Cancelled); + LRAStatus status = getStatus(shortLRA); - // Verifies that the resource was notified that the LRA finished - String listenerStatus = getStatusFromListener(lraListenerURI); + Assert.assertTrue(String.format("LRA %s should have cancelled", shortLRA.toString()), + status == null || status == LRAStatus.Cancelled || status == LRAStatus.Cancelling); - assertEquals(String.format("The service lra-listener should have been told that the final state of the LRA %s was cancelled", lraId), - LRAStatus.Cancelled.name(), listenerStatus); } @Test @@ -218,13 +185,7 @@ public void lraCoordinatorRecoveryTwoLRAs(@ArquillianResource @OperateOnDeployme restartContainer(LRA_COORDINATOR_CONTAINER_QUALIFIER); // Waits for a period of time longer than the timeout of the short LRA transaction - doWait((LRAListener.LRA_SHORT_TIMELIMIT + 1L) * 1000); - - int sc = recover(); - - if (sc != 0) { - recover(); - } + doWait(SHORT_TIMEOUT + 5000L); LRAStatus longStatus = getStatus(longLRA); LRAStatus shortStatus = getStatus(shortLRA);