Skip to content

Commit

Permalink
DT-1194: Fix issue where using Awaitility was causing code to run on …
Browse files Browse the repository at this point in the history
…a different thread (#1903)

* Fix issue where using Awaitility was causing code to run on a different thread

* Allow retries on CannotAcquireLockException and other TransientDataAccessExceptions
  • Loading branch information
pshapiro4broad authored Feb 10, 2025
1 parent 4d662cb commit da71fcc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.TransientDataAccessException;
import org.springframework.transaction.TransactionSystemException;

public class CreateDatasetGetOrCreateBucketStep implements Step {
Expand Down Expand Up @@ -80,7 +81,7 @@ public StepResult doStep(FlightContext context) throws InterruptedException {
googleProjectResource.getServiceAccount());

workingMap.put(FileMapKeys.BUCKET_INFO, bucketForFile);
} catch (BucketLockException | TransactionSystemException e) {
} catch (BucketLockException | TransientDataAccessException | TransactionSystemException e) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
} catch (GoogleResourceNamingException ex) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import bio.terra.common.auth.Users;
import bio.terra.common.category.Integration;
import bio.terra.common.configuration.TestConfiguration;
import bio.terra.common.configuration.TestConfiguration.User;
import bio.terra.common.fixtures.JsonLoader;
import bio.terra.common.fixtures.Names;
import bio.terra.integration.DataRepoFixtures;
Expand Down Expand Up @@ -55,7 +55,7 @@ class SecureMonitoringIntegrationTest {
private UUID snapshotId;
private UUID profileId;

private TestConfiguration.User steward() {
private User steward() {
return testUsers.steward();
}

Expand Down Expand Up @@ -118,10 +118,11 @@ void testDatasetWithSecureMonitoring() throws Exception {
"Snapshot summary denotes secure monitoring enabled",
snapshotSummary.isSecureMonitoringEnabled());

User steward = steward();
SnapshotModel snapshot =
Awaitility.waitAtMost(Duration.ofSeconds(10))
.until(
() -> dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId(), null),
() -> dataRepoFixtures.getSnapshot(steward, snapshotSummary.getId(), null),
Objects::nonNull);

assertThat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,11 @@ void snapshotRowIdsHappyPathTest() throws Exception {
dataRepoFixtures.createSnapshotWithRequest(
steward(), dataset.getName(), profileId, requestModel);
createdSnapshotId.set(snapshotSummary.getId());
User steward = steward();
SnapshotModel snapshot =
Awaitility.waitAtMost(Duration.ofSeconds(10))
.until(
() -> dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId(), null),
() -> dataRepoFixtures.getSnapshot(steward, snapshotSummary.getId(), null),
Objects::nonNull);
assertThat("new snapshot has been created", snapshot.getName(), is(requestModel.getName()));
assertThat(
Expand Down Expand Up @@ -216,10 +217,11 @@ void snapshotByQueryHappyPathTest() throws Exception {
dataRepoFixtures.createSnapshotWithRequest(
steward(), dataset.getName(), profileId, requestModel);
createdSnapshotId.set(snapshotSummary.getId());
User steward = steward();
SnapshotModel snapshot =
Awaitility.waitAtMost(Duration.ofSeconds(10))
.until(
() -> dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId(), null),
() -> dataRepoFixtures.getSnapshot(steward, snapshotSummary.getId(), null),
Objects::nonNull);
assertThat("new snapshot has been created", snapshot.getName(), is(requestModel.getName()));
}
Expand All @@ -238,10 +240,11 @@ void snapshotByAssetHappyPathTest() throws Exception {
dataRepoFixtures.createSnapshotWithRequest(
steward(), dataset.getName(), profileId, requestModel);
createdSnapshotId.set(snapshotSummary.getId());
User steward = steward();
SnapshotModel snapshot =
Awaitility.waitAtMost(Duration.ofSeconds(10))
.until(
() -> dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId(), null),
() -> dataRepoFixtures.getSnapshot(steward, snapshotSummary.getId(), null),
Objects::nonNull);
assertThat("new snapshot has been created", snapshot.getName(), is(requestModel.getName()));
}
Expand All @@ -255,9 +258,9 @@ void deleteAssetWithSnapshotTest() throws Exception {
SnapshotSummaryModel snapshotSummary =
dataRepoFixtures.createSnapshotWithRequest(
steward(), dataset.getName(), profileId, requestModel);
User steward = steward();
Awaitility.waitAtMost(Duration.ofSeconds(10))
.until(
() -> dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId(), null) != null);
.until(() -> dataRepoFixtures.getSnapshot(steward, snapshotSummary.getId(), null) != null);
ErrorModel errorModel =
dataRepoFixtures.deleteDatasetAssetExpectFailure(
steward(), dataset.getId(), "sample_centric");
Expand Down Expand Up @@ -338,10 +341,11 @@ void retrieveRowCountAndSnapshotByFullViewTest() throws Exception {
SnapshotSummaryModel snapshotSummary =
dataRepoFixtures.createSnapshotWithRequest(steward(), datasetName, profileId, requestModel);
createdSnapshotId.set(snapshotSummary.getId());
User steward = steward();
SnapshotModel snapshot =
Awaitility.waitAtMost(Duration.ofSeconds(10))
.until(
() -> dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId(), null),
() -> dataRepoFixtures.getSnapshot(steward, snapshotSummary.getId(), null),
Objects::nonNull);
assertThat("new snapshot has been created", snapshot.getName(), is(requestModel.getName()));
assertThat("the relationship comes through", snapshot.getRelationships(), hasSize(1));
Expand Down Expand Up @@ -415,10 +419,11 @@ void snapshotByFullViewAndPetServiceAccountHappyPathTest() throws Exception {
dataRepoFixtures.createSnapshotWithRequest(
steward(), datasetName, profileId, requestModel, true, true);
createdSnapshotId.set(snapshotSummary.getId());
User steward = steward();
SnapshotModel snapshot =
Awaitility.waitAtMost(Duration.ofSeconds(10))
.until(
() -> dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId(), null),
() -> dataRepoFixtures.getSnapshot(steward, snapshotSummary.getId(), null),
Objects::nonNull);
assertThat("new snapshot has been created", snapshot.getName(), is(requestModel.getName()));
assertThat("the relationship comes through", snapshot.getRelationships(), hasSize(1));
Expand Down Expand Up @@ -471,9 +476,9 @@ void testCreateSnapshotWithPolicies() throws Exception {
dataRepoFixtures.createSnapshotWithRequest(steward(), datasetName, profileId, requestModel);
UUID snapshotId = snapshotSummary.getId();
createdSnapshotId.set(snapshotId);
User steward = steward();
Awaitility.waitAtMost(Duration.ofSeconds(10))
.until(
() -> dataRepoFixtures.getSnapshot(steward(), snapshotSummary.getId(), null) != null);
.until(() -> dataRepoFixtures.getSnapshot(steward, snapshotSummary.getId(), null) != null);

Map<String, List<String>> rolesToPolicies =
dataRepoFixtures.retrieveSnapshotPolicies(steward(), snapshotId).getPolicies().stream()
Expand Down

0 comments on commit da71fcc

Please sign in to comment.