Search in sources :

Example 1 with DatasetDaoUtils

use of bio.terra.service.dataset.DatasetDaoUtils in project jade-data-repo by DataBiosphere.

the class ConnectedOperations method retryAcquireLockIngestFileSuccess.

public void retryAcquireLockIngestFileSuccess(boolean attemptRetry, String datasetId, FileLoadModel fileLoadModel, ConfigurationService configService, DatasetDao datasetDao) throws Exception {
    // Insert fault into shared lock
    ConfigEnum faultToInsert = attemptRetry ? ConfigEnum.FILE_INGEST_SHARED_LOCK_RETRY_FAULT : ConfigEnum.FILE_INGEST_SHARED_LOCK_FATAL_FAULT;
    configService.setFault(faultToInsert.name(), true);
    String jsonRequest = TestUtils.mapToJson(fileLoadModel);
    String url = "/api/repository/v1/datasets/" + datasetId + "/files";
    MvcResult result = mvc.perform(post(url).contentType(MediaType.APPLICATION_JSON).content(jsonRequest)).andReturn();
    // give the flight time to fail a couple of times
    TimeUnit.SECONDS.sleep(5);
    datasetDaoUtils = new DatasetDaoUtils();
    String[] sharedLocks = datasetDaoUtils.getSharedLocks(datasetDao, UUID.fromString(datasetId));
    // Remove insertion of shared lock fault
    configService.setFault(faultToInsert.name(), false);
    assertEquals("no shared locks after first call", 0, sharedLocks.length);
    MockHttpServletResponse response = validateJobModelAndWait(result);
    if (attemptRetry) {
        // Check if the flight successfully completed
        // Assume that if it successfully completed, then it was able to retry and acquire the shared lock
        FileModel fileModel = handleSuccessCase(response, FileModel.class);
        checkSuccessfulFileLoad(fileLoadModel, fileModel, datasetId);
    } else {
        handleFailureCase(response);
    }
}
Also used : FileModel(bio.terra.model.FileModel) DatasetDaoUtils(bio.terra.service.dataset.DatasetDaoUtils) ConfigEnum(bio.terra.service.configuration.ConfigEnum) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

FileModel (bio.terra.model.FileModel)1 ConfigEnum (bio.terra.service.configuration.ConfigEnum)1 DatasetDaoUtils (bio.terra.service.dataset.DatasetDaoUtils)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1