Search in sources :

Example 21 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class SnapshotConnectedTest method testOverlappingDeletes.

@Test
public void testOverlappingDeletes() throws Exception {
    // create a snapshot
    SnapshotSummaryModel summaryModel = connectedOperations.createSnapshot(datasetSummary, "snapshot-test-snapshot.json", "_d2_");
    // NO ASSERTS inside the block below where hang is enabled to reduce chance of failing before disabling the hang
    // ====================================================
    // enable hang in DeleteSnapshotPrimaryDataStep
    configService.setFault(ConfigEnum.SNAPSHOT_DELETE_LOCK_CONFLICT_STOP_FAULT.name(), true);
    // try to delete the snapshot
    MvcResult result1 = mvc.perform(delete("/api/repository/v1/snapshots/" + summaryModel.getId())).andReturn();
    // try to delete the snapshot again, this should fail with a lock exception
    // note: asserts are below outside the hang block
    MvcResult result2 = mvc.perform(delete("/api/repository/v1/snapshots/" + summaryModel.getId())).andReturn();
    // disable hang in DeleteSnapshotPrimaryDataStep
    configService.setFault(ConfigEnum.SNAPSHOT_DELETE_LOCK_CONFLICT_CONTINUE_FAULT.name(), true);
    // ====================================================
    // check the response from the first delete request
    MockHttpServletResponse response1 = connectedOperations.validateJobModelAndWait(result1);
    DeleteResponseModel deleteResponseModel = connectedOperations.handleSuccessCase(response1, DeleteResponseModel.class);
    assertEquals("First delete returned successfully", DeleteResponseModel.ObjectStateEnum.DELETED, deleteResponseModel.getObjectState());
    // check the response from the second delete request
    MockHttpServletResponse response2 = connectedOperations.validateJobModelAndWait(result2);
    ErrorModel errorModel2 = connectedOperations.handleFailureCase(response2, HttpStatus.INTERNAL_SERVER_ERROR);
    assertThat("delete failed on lock exception", errorModel2.getMessage(), startsWith("Failed to lock the snapshot"));
    // confirm deleted
    connectedOperations.getSnapshotExpectError(summaryModel.getId(), HttpStatus.NOT_FOUND);
}
Also used : SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) ErrorModel(bio.terra.model.ErrorModel) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) DeleteResponseModel(bio.terra.model.DeleteResponseModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 22 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class SnapshotConnectedTest method testBadData.

@Test
public void testBadData() throws Exception {
    SnapshotRequestModel badDataRequest = makeSnapshotTestRequest(datasetSummary, "snapshot-test-snapshot-baddata.json");
    MockHttpServletResponse response = performCreateSnapshot(badDataRequest, "_baddata_");
    ErrorModel errorModel = handleCreateSnapshotFailureCase(response);
    assertThat(errorModel.getMessage(), containsString("Fred"));
}
Also used : ErrorModel(bio.terra.model.ErrorModel) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 23 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class SnapshotConnectedTest method testDuplicateName.

@Test
public void testDuplicateName() throws Exception {
    // create a snapshot
    SnapshotRequestModel snapshotRequest = makeSnapshotTestRequest(datasetSummary, "snapshot-test-snapshot.json");
    MockHttpServletResponse response = performCreateSnapshot(snapshotRequest, "_dup_");
    SnapshotSummaryModel summaryModel = validateSnapshotCreated(snapshotRequest, response);
    // fetch the snapshot and confirm the metadata matches the request
    SnapshotModel snapshotModel = getTestSnapshot(summaryModel.getId(), snapshotRequest, datasetSummary);
    assertNotNull("fetched snapshot successfully after creation", snapshotModel);
    // check that the snapshot metadata row is unlocked
    String exclusiveLock = snapshotDao.getExclusiveLockState(UUID.fromString(snapshotModel.getId()));
    assertNull("snapshot row is unlocked", exclusiveLock);
    // try to create the same snapshot again and check that it fails
    snapshotRequest.setName(snapshotModel.getName());
    response = performCreateSnapshot(snapshotRequest, null);
    ErrorModel errorModel = handleCreateSnapshotFailureCase(response);
    assertThat(response.getStatus(), equalTo(HttpStatus.BAD_REQUEST.value()));
    assertThat("error message includes name conflict", errorModel.getMessage(), containsString("Snapshot name already exists"));
    // delete and confirm deleted
    connectedOperations.deleteTestSnapshot(snapshotModel.getId());
    connectedOperations.getSnapshotExpectError(snapshotModel.getId(), HttpStatus.NOT_FOUND);
}
Also used : SnapshotSummaryModel(bio.terra.model.SnapshotSummaryModel) ErrorModel(bio.terra.model.ErrorModel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SnapshotRequestModel(bio.terra.model.SnapshotRequestModel) SnapshotModel(bio.terra.model.SnapshotModel) EnumerateSnapshotModel(bio.terra.model.EnumerateSnapshotModel) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 24 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class FileOperationTest method multiFileLoadBadLineTest.

@Test
public void multiFileLoadBadLineTest() throws Exception {
    // part 1: test that we exit with the bad line error when we have fewer than the max
    BulkLoadRequestModel loadRequest = makeBulkFileLoad("multiFileLoadBadLineSuccess", 0, 3, false, new boolean[] { true, false, true, false });
    loadRequest.maxFailedFileLoads(4);
    ErrorModel errorModel = connectedOperations.ingestBulkFileFailure(datasetSummary.getId(), loadRequest);
    assertThat("Expected error", errorModel.getMessage(), containsString("bad lines in the control file"));
    assertThat("Expected error", errorModel.getMessage(), containsString("There were"));
    assertThat("Expected number of error details", errorModel.getErrorDetail().size(), equalTo(3));
    // part 2: test that we exit with bad line error when we have more than the max
    loadRequest = makeBulkFileLoad("multiFileLoadBadLineSuccess", 0, 6, false, new boolean[] { true, true, true, true });
    loadRequest.maxFailedFileLoads(4);
    errorModel = connectedOperations.ingestBulkFileFailure(datasetSummary.getId(), loadRequest);
    assertThat("Expected error", errorModel.getMessage(), containsString("bad lines in the control file"));
    assertThat("Expected error", errorModel.getMessage(), containsString("More than"));
    assertThat("Expected number of error details", errorModel.getErrorDetail().size(), greaterThan(5));
}
Also used : BulkLoadRequestModel(bio.terra.model.BulkLoadRequestModel) ErrorModel(bio.terra.model.ErrorModel) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 25 with ErrorModel

use of bio.terra.model.ErrorModel in project jade-data-repo by DataBiosphere.

the class DatasetValidationsTest method testInvalidRelationshipTermTableColumn.

@Test
public void testInvalidRelationshipTermTableColumn() throws Exception {
    // participant_id is part of the sample table, not participant
    RelationshipTermModel mismatchedTerm = new RelationshipTermModel().table("participant").column("participant_id");
    RelationshipModel mismatchedRelationship = new RelationshipModel().name("participant_sample").from(mismatchedTerm).to(buildSampleTerm());
    DatasetRequestModel req = buildDatasetRequest();
    req.getSchema().relationships(Collections.singletonList(mismatchedRelationship));
    ErrorModel errorModel = expectBadDatasetCreateRequest(req);
    checkValidationErrorModel(errorModel, new String[] { "InvalidRelationshipTermTableColumn" });
}
Also used : RelationshipTermModel(bio.terra.model.RelationshipTermModel) DatasetRequestModel(bio.terra.model.DatasetRequestModel) RelationshipModel(bio.terra.model.RelationshipModel) ErrorModel(bio.terra.model.ErrorModel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ErrorModel (bio.terra.model.ErrorModel)48 Test (org.junit.Test)38 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)38 DatasetRequestModel (bio.terra.model.DatasetRequestModel)21 AssetTableModel (bio.terra.model.AssetTableModel)16 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)16 MvcResult (org.springframework.test.web.servlet.MvcResult)14 TableModel (bio.terra.model.TableModel)13 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)13 ColumnModel (bio.terra.model.ColumnModel)8 IntPartitionOptionsModel (bio.terra.model.IntPartitionOptionsModel)6 AssetModel (bio.terra.model.AssetModel)5 FileModel (bio.terra.model.FileModel)5 DatePartitionOptionsModel (bio.terra.model.DatePartitionOptionsModel)4 IngestRequestModel (bio.terra.model.IngestRequestModel)4 DatasetSummaryModel (bio.terra.model.DatasetSummaryModel)3 DeleteResponseModel (bio.terra.model.DeleteResponseModel)3 FileLoadModel (bio.terra.model.FileLoadModel)3 SnapshotSummaryModel (bio.terra.model.SnapshotSummaryModel)3 Blob (com.google.cloud.storage.Blob)3