Skip to content

Commit

Permalink
JBTM-3966 fix crash tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgopen committed Jan 2, 2025
1 parent 039bb20 commit 2e6a47f
Showing 1 changed file with 15 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> containerDeploymentMap = new HashMap<>();

@Rule
Expand Down Expand Up @@ -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<String, String> entry : containerDeploymentMap.entrySet()) {
startContainer(entry.getKey(), entry.getValue());
}

// Cleans Object Store in case there are transactions from previous tests
clearRecoveryLogFromObjectStore();
clearRecoveryLogFromFS();

}

@After
Expand All @@ -128,11 +128,12 @@ public void after() {

// Cleans Object Store in case there are still active transactions
clearRecoveryLogFromObjectStore();
clearRecoveryLogFromFS();

for (Map.Entry<String, String> entry : containerDeploymentMap.entrySet()) {
stopContainer(entry.getKey(), entry.getValue());
}
clearRecoveryLogFromFS();

}

/**
Expand All @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 2e6a47f

Please sign in to comment.