Search in sources :

Example 1 with StepExecutionEntity

use of edu.harvard.iq.dataverse.batch.entities.StepExecutionEntity in project dataverse by IQSS.

the class FileRecordJobIT method testNewEditor.

@Test
@Ignore
public void testNewEditor() {
    try {
        // create contributor user
        String contribUser = UUID.randomUUID().toString().substring(0, 8);
        String contribToken = given().body("{" + "   \"userName\": \"" + contribUser + "\"," + "   \"firstName\": \"" + contribUser + "\"," + "   \"lastName\": \"" + contribUser + "\"," + "   \"email\": \"" + contribUser + "@mailinator.com\"" + "}").contentType(ContentType.JSON).request().post("/api/builtin-users/secret/" + props.getProperty("builtin.user.key")).then().assertThat().statusCode(200).extract().jsonPath().getString("data.apiToken");
        Response grantRole = UtilIT.grantRoleOnDataverse(testName, DataverseRole.EDITOR.toString(), "@" + contribUser, token);
        // grantRole.prettyPrint();
        // create a single test file and put it in two places
        String file1 = "testfile.txt";
        String file2 = "subdir/testfile.txt";
        File file = createTestFile(dsDir, file1, 0.25);
        if (file != null) {
            FileUtils.copyFile(file, new File(dsDir + file2));
        } else {
            System.out.println("Unable to copy file: " + dsDir + file2);
            fail();
        }
        // mock the checksum manifest
        String checksum1 = "asfdasdfasdfasdf";
        String checksum2 = "sgsdgdsgfsdgsdgf";
        if (file1 != null && file2 != null) {
            PrintWriter pw = new PrintWriter(new FileWriter(dsDir + "/files.sha"));
            pw.write(checksum1 + " " + file1);
            pw.write("\n");
            pw.write(checksum2 + " " + file2);
            pw.write("\n");
            pw.close();
        } else {
            fail();
        }
        // validate job
        JobExecutionEntity job = getJobWithToken(contribToken);
        assertEquals(job.getSteps().size(), 1);
        StepExecutionEntity step1 = job.getSteps().get(0);
        Map<String, Long> metrics = step1.getMetrics();
        assertEquals(job.getExitStatus(), BatchStatus.COMPLETED.name());
        assertEquals(job.getStatus(), BatchStatus.COMPLETED);
        assertEquals(step1.getExitStatus(), BatchStatus.COMPLETED.name());
        assertEquals(step1.getStatus(), BatchStatus.COMPLETED);
        assertEquals(step1.getName(), "import-files");
        assertEquals((long) metrics.get("write_skip_count"), 0);
        assertEquals((long) metrics.get("commit_count"), 1);
        assertEquals((long) metrics.get("process_skip_count"), 0);
        assertEquals((long) metrics.get("read_skip_count"), 0);
        assertEquals((long) metrics.get("write_count"), 2);
        assertEquals((long) metrics.get("rollback_count"), 0);
        assertEquals((long) metrics.get("filter_count"), 0);
        assertEquals((long) metrics.get("read_count"), 2);
        assertEquals(step1.getPersistentUserData(), null);
        // confirm data files were imported
        updateDatasetJsonPath();
        List<String> storageIds = new ArrayList<>();
        storageIds.add(dsPath.getString("data.latestVersion.files[0].dataFile.storageIdentifier"));
        storageIds.add(dsPath.getString("data.latestVersion.files[1].dataFile.storageIdentifier"));
        assert (storageIds.contains(file1));
        assert (storageIds.contains(file2));
        // test the reporting apis
        given().header(API_TOKEN_HTTP_HEADER, contribToken).get(props.getProperty("job.status.api") + job.getId()).then().assertThat().body("status", equalTo("COMPLETED"));
        List<Integer> ids = given().header(API_TOKEN_HTTP_HEADER, contribToken).get(props.getProperty("job.status.api")).then().extract().jsonPath().getList("jobs.id");
        assertTrue(ids.contains((int) job.getId()));
    } catch (Exception e) {
        System.out.println("Error testNewEditor: " + e.getMessage());
        e.printStackTrace();
        fail();
    }
}
Also used : FileWriter(java.io.FileWriter) JobExecutionEntity(edu.harvard.iq.dataverse.batch.entities.JobExecutionEntity) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Response(com.jayway.restassured.response.Response) StepExecutionEntity(edu.harvard.iq.dataverse.batch.entities.StepExecutionEntity) File(java.io.File) PrintWriter(java.io.PrintWriter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with StepExecutionEntity

use of edu.harvard.iq.dataverse.batch.entities.StepExecutionEntity in project dataverse by IQSS.

the class FileRecordJobIT method testFileInChecksumManifestDoesntExist.

@Test
@Ignore
public /**
 * Checksum manifest references a file that isn't present, it should return failed status and detailed
 * message in persistentUserData
 */
void testFileInChecksumManifestDoesntExist() {
    try {
        // create test files and checksum manifest with record that doesn't exist
        File file1 = createTestFile(dsDir, "testfile1.txt", 0.25);
        File file2 = createTestFile(dsDir, "testfile2.txt", 0.25);
        String checksum1 = "aorjsonaortargj848";
        String checksum2 = "ldgklrrshfdsnosri4948";
        if (file1 != null && file2 != null) {
            PrintWriter pw = new PrintWriter(new FileWriter(dsDir + "/files.sha"));
            pw.write(checksum1 + " " + file1.getName());
            pw.write("\n");
            pw.write(checksum2 + " " + file2.getName());
            pw.write("\n");
            pw.write("asdfae34034asfaf9r3  fileThatDoesntExist.txt");
            pw.write("\n");
            pw.close();
        } else {
            fail();
        }
        JobExecutionEntity job = getJob();
        assertEquals(job.getSteps().size(), 1);
        StepExecutionEntity step1 = job.getSteps().get(0);
        Map<String, Long> metrics1 = step1.getMetrics();
        // check job status
        assertEquals(job.getExitStatus(), BatchStatus.COMPLETED.name());
        assertEquals(job.getStatus(), BatchStatus.COMPLETED);
        // check step 1 status and name
        assertEquals(step1.getExitStatus(), BatchStatus.COMPLETED.name());
        assertEquals(step1.getStatus(), BatchStatus.COMPLETED);
        assertEquals(step1.getName(), "import-files");
        // verify step 1 metrics
        assertEquals((long) metrics1.get("write_skip_count"), 0);
        assertEquals((long) metrics1.get("commit_count"), 1);
        assertEquals((long) metrics1.get("process_skip_count"), 0);
        assertEquals((long) metrics1.get("read_skip_count"), 0);
        assertEquals((long) metrics1.get("write_count"), 2);
        assertEquals((long) metrics1.get("rollback_count"), 0);
        assertEquals((long) metrics1.get("filter_count"), 0);
        assertEquals((long) metrics1.get("read_count"), 2);
        // should be no user data (error messages)
        assertEquals(step1.getPersistentUserData(), null);
        // confirm files were imported
        updateDatasetJsonPath();
        List<String> filenames = new ArrayList<>();
        filenames.add(dsPath.getString("data.latestVersion.files[0].dataFile.filename"));
        filenames.add(dsPath.getString("data.latestVersion.files[1].dataFile.filename"));
        assert (filenames.contains("testfile1.txt"));
        assert (filenames.contains("testfile2.txt"));
        // confirm checksums were imported
        List<String> checksums = new ArrayList<>();
        checksums.add(dsPath.getString("data.latestVersion.files[0].dataFile.checksum.value"));
        checksums.add(dsPath.getString("data.latestVersion.files[1].dataFile.checksum.value"));
        assert (checksums.contains(checksum1));
        assert (checksums.contains(checksum2));
    } catch (Exception e) {
        System.out.println("Error testChecksumImport: " + e.getMessage());
        e.printStackTrace();
        fail();
    }
}
Also used : StepExecutionEntity(edu.harvard.iq.dataverse.batch.entities.StepExecutionEntity) FileWriter(java.io.FileWriter) JobExecutionEntity(edu.harvard.iq.dataverse.batch.entities.JobExecutionEntity) ArrayList(java.util.ArrayList) File(java.io.File) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with StepExecutionEntity

use of edu.harvard.iq.dataverse.batch.entities.StepExecutionEntity in project dataverse by IQSS.

the class FileRecordJobIT method testSameFileInDifferentDirectories.

/**
 * Import the same file in different directories, in the same dataset.
 * This is not permitted via HTTP file upload since identical checksums are not allowed in the same dataset.
 * Ignores failed checksum manifest import.
 */
@Test
@Ignore
public void testSameFileInDifferentDirectories() {
    try {
        // create a single test file and put it in two places
        String file1 = "testfile.txt";
        String file2 = "subdir/testfile.txt";
        File file = createTestFile(dsDir, file1, 0.25);
        if (file != null) {
            FileUtils.copyFile(file, new File(dsDir + file2));
        } else {
            System.out.println("Unable to copy file: " + dsDir + file2);
            fail();
        }
        // mock the checksum manifest
        String checksum1 = "asfdasdfasdfasdf";
        String checksum2 = "sgsdgdsgfsdgsdgf";
        if (file1 != null && file2 != null) {
            PrintWriter pw = new PrintWriter(new FileWriter(dsDir + "/files.sha"));
            pw.write(checksum1 + " " + file1);
            pw.write("\n");
            pw.write(checksum2 + " " + file2);
            pw.write("\n");
            pw.close();
        } else {
            fail();
        }
        // validate job
        JobExecutionEntity job = getJob();
        assertEquals(job.getSteps().size(), 1);
        StepExecutionEntity step1 = job.getSteps().get(0);
        Map<String, Long> metrics = step1.getMetrics();
        assertEquals(job.getExitStatus(), BatchStatus.COMPLETED.name());
        assertEquals(job.getStatus(), BatchStatus.COMPLETED);
        assertEquals(step1.getExitStatus(), BatchStatus.COMPLETED.name());
        assertEquals(step1.getStatus(), BatchStatus.COMPLETED);
        assertEquals(step1.getName(), "import-files");
        assertEquals((long) metrics.get("write_skip_count"), 0);
        assertEquals((long) metrics.get("commit_count"), 1);
        assertEquals((long) metrics.get("process_skip_count"), 0);
        assertEquals((long) metrics.get("read_skip_count"), 0);
        assertEquals((long) metrics.get("write_count"), 2);
        assertEquals((long) metrics.get("rollback_count"), 0);
        assertEquals((long) metrics.get("filter_count"), 0);
        assertEquals((long) metrics.get("read_count"), 2);
        assertEquals(step1.getPersistentUserData(), null);
        // confirm data files were imported
        updateDatasetJsonPath();
        List<String> storageIds = new ArrayList<>();
        storageIds.add(dsPath.getString("data.latestVersion.files[0].dataFile.storageIdentifier"));
        storageIds.add(dsPath.getString("data.latestVersion.files[1].dataFile.storageIdentifier"));
        assert (storageIds.contains(file1));
        assert (storageIds.contains(file2));
        // test the reporting apis
        given().header(API_TOKEN_HTTP_HEADER, token).get(props.getProperty("job.status.api") + job.getId()).then().assertThat().body("status", equalTo("COMPLETED"));
        List<Integer> ids = given().header(API_TOKEN_HTTP_HEADER, token).get(props.getProperty("job.status.api")).then().extract().jsonPath().getList("jobs.id");
        assertTrue(ids.contains((int) job.getId()));
    } catch (Exception e) {
        System.out.println("Error testIdenticalFilesInDifferentDirectories: " + e.getMessage());
        e.printStackTrace();
        fail();
    }
}
Also used : FileWriter(java.io.FileWriter) JobExecutionEntity(edu.harvard.iq.dataverse.batch.entities.JobExecutionEntity) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StepExecutionEntity(edu.harvard.iq.dataverse.batch.entities.StepExecutionEntity) File(java.io.File) PrintWriter(java.io.PrintWriter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with StepExecutionEntity

use of edu.harvard.iq.dataverse.batch.entities.StepExecutionEntity in project dataverse by IQSS.

the class FileRecordJobIT method testFilesWithoutChecksumManifest.

@Test
@Ignore
public /**
 * No checksum manifest found
 */
void testFilesWithoutChecksumManifest() {
    try {
        // create test files and NO checksum manifest
        createTestFile(dsDir, "testfile1.txt", 0.25);
        createTestFile(dsDir, "testfile2.txt", 0.25);
        JobExecutionEntity job = getJob();
        assertEquals(job.getSteps().size(), 1);
        StepExecutionEntity step1 = job.getSteps().get(0);
        Map<String, Long> metrics1 = step1.getMetrics();
        // check job status
        assertEquals(job.getExitStatus(), BatchStatus.FAILED.name());
        assertEquals(job.getStatus(), BatchStatus.FAILED);
        // check step 1 status and name
        assertEquals(step1.getExitStatus(), BatchStatus.FAILED.name());
        assertEquals(step1.getStatus(), BatchStatus.FAILED);
        assertEquals(step1.getName(), "import-files");
        // verify step 1 metrics
        assertEquals((long) metrics1.get("write_skip_count"), 0);
        assertEquals((long) metrics1.get("commit_count"), 0);
        assertEquals((long) metrics1.get("process_skip_count"), 0);
        assertEquals((long) metrics1.get("read_skip_count"), 0);
        assertEquals((long) metrics1.get("write_count"), 0);
        assertEquals((long) metrics1.get("rollback_count"), 0);
        assertEquals((long) metrics1.get("filter_count"), 0);
        assertEquals((long) metrics1.get("read_count"), 0);
        // should be no user data (error messages)
        assertEquals(step1.getPersistentUserData(), null);
        // confirm files were imported and checksums unknown
        updateDatasetJsonPath();
        List<String> filenames = new ArrayList<>();
        filenames.add(dsPath.getString("data.latestVersion.files[0].dataFile.filename"));
        filenames.add(dsPath.getString("data.latestVersion.files[1].dataFile.filename"));
        assert (filenames.contains("testfile1.txt"));
        assert (filenames.contains("testfile2.txt"));
        assert (dsPath.getString("data.latestVersion.files[0].dataFile.checksum.value").equalsIgnoreCase("unknown"));
        assert (dsPath.getString("data.latestVersion.files[1].dataFile.checksum.value").equalsIgnoreCase("unknown"));
    } catch (Exception e) {
        System.out.println("Error testChecksumImportMissingManifest: " + e.getMessage());
        e.printStackTrace();
        fail();
    }
}
Also used : StepExecutionEntity(edu.harvard.iq.dataverse.batch.entities.StepExecutionEntity) JobExecutionEntity(edu.harvard.iq.dataverse.batch.entities.JobExecutionEntity) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with StepExecutionEntity

use of edu.harvard.iq.dataverse.batch.entities.StepExecutionEntity in project dataverse by IQSS.

the class FileRecordJobIT method testAddingFilesInMergeMode.

// @Test
// /**
// * Delete a file in REPLACE mode
// */
// public void testDeleteFileInReplaceMode() {
// 
// try {
// 
// // create a single test file and put it in two places
// String file1 =  "testfile.txt";
// String file2 = "subdir/testfile.txt";
// File file = createTestFile(dsDir, file1, 0.25);
// if (file != null) {
// FileUtils.copyFile(file, new File(dsDir + file2));
// } else {
// System.out.println("Unable to copy file: " + dsDir + file2);
// fail();
// }
// 
// // mock the checksum manifest
// String checksum1 = "asfdasdfasdfasdf";
// String checksum2 = "sgsdgdsgfsdgsdgf";
// if (file1 != null && file2 != null) {
// PrintWriter pw = new PrintWriter(new FileWriter(dsDir + "/files.sha"));
// pw.write(checksum1 + " " + file1);
// pw.write("\n");
// pw.write(checksum2 + " " + file2);
// pw.write("\n");
// pw.close();
// } else {
// fail();
// }
// 
// // validate job
// JobExecutionEntity job = getJob();
// assertEquals(job.getSteps().size(), 2);
// StepExecutionEntity step1 = job.getSteps().get(0);
// Map<String, Long> metrics = step1.getMetrics();
// assertEquals(job.getExitStatus(), BatchStatus.COMPLETED.name());
// assertEquals(job.getStatus(), BatchStatus.COMPLETED);
// assertEquals(step1.getExitStatus(), BatchStatus.COMPLETED.name());
// assertEquals(step1.getStatus(), BatchStatus.COMPLETED);
// assertEquals(step1.getName(), "import-files");
// assertEquals((long) metrics.get("write_skip_count"), 0);
// assertEquals((long) metrics.get("commit_count"), 1);
// assertEquals((long) metrics.get("process_skip_count"), 0);
// assertEquals((long) metrics.get("read_skip_count"), 0);
// assertEquals((long) metrics.get("write_count"), 2);
// assertEquals((long) metrics.get("rollback_count"), 0);
// assertEquals((long) metrics.get("filter_count"), 0);
// assertEquals((long) metrics.get("read_count"), 2);
// assertEquals(step1.getPersistentUserData(), null);
// 
// // confirm data files were imported
// updateDatasetJsonPath();
// List<String> storageIds = new ArrayList<>();
// storageIds.add(dsPath.getString("data.latestVersion.files[0].dataFile.storageIdentifier"));
// storageIds.add(dsPath.getString("data.latestVersion.files[1].dataFile.storageIdentifier"));
// assert(storageIds.contains(file1));
// assert(storageIds.contains(file2));
// 
// // test the reporting apis
// given()
// .header(API_TOKEN_HTTP_HEADER, token)
// .get(props.getProperty("job.status.api") + job.getId())
// .then().assertThat()
// .body("status", equalTo("COMPLETED"));
// List<Integer> ids =  given()
// .header(API_TOKEN_HTTP_HEADER, token)
// .get(props.getProperty("job.status.api"))
// .then().extract().jsonPath()
// .getList("jobs.id");
// assertTrue(ids.contains((int)job.getId()));
// 
// 
// // delete one file and run the job again
// file.delete();
// 
// // mock the checksum manifest
// if (file1 != null) {
// PrintWriter pw = new PrintWriter(new FileWriter(dsDir + "/files.sha"));
// pw.write(checksum1 + " " + file1);
// pw.write("\n");
// pw.close();
// } else {
// fail();
// }
// 
// // validate job again
// JobExecutionEntity newJob = getJobWithMode("REPLACE");
// assertEquals(newJob.getSteps().size(), 2);
// StepExecutionEntity newSteps = newJob.getSteps().get(0);
// Map<String, Long> newMetrics = newSteps.getMetrics();
// assertEquals(newJob.getExitStatus(), BatchStatus.COMPLETED.name());
// assertEquals(newJob.getStatus(), BatchStatus.COMPLETED);
// assertEquals(newSteps.getExitStatus(), BatchStatus.COMPLETED.name());
// assertEquals(newSteps.getStatus(), BatchStatus.COMPLETED);
// assertEquals(newSteps.getName(), "import-files");
// assertEquals(0, (long) newMetrics.get("write_skip_count"));
// assertEquals(1, (long) newMetrics.get("commit_count"));
// assertEquals(0, (long) newMetrics.get("process_skip_count"));
// assertEquals(0, (long) newMetrics.get("read_skip_count"));
// assertEquals(1, (long) newMetrics.get("write_count"));
// assertEquals(0, (long) newMetrics.get("rollback_count"));
// assertEquals(0, (long) newMetrics.get("filter_count"));
// assertEquals(1, (long) newMetrics.get("read_count"));
// assertEquals(newSteps.getPersistentUserData(), null);
// 
// // confirm data files were imported
// updateDatasetJsonPath();
// //System.out.println("DATASET JSON: " + dsPath.prettyPrint());
// List<String> newStorageIds = new ArrayList<>();
// newStorageIds.add(dsPath.getString("data.latestVersion.files[0].dataFile.storageIdentifier"));
// assert(newStorageIds.contains(file2)); // should contain subdir/testfile.txt still
// 
// // test the reporting apis
// given()
// .header(API_TOKEN_HTTP_HEADER, token)
// .get(props.getProperty("job.status.api") + newJob.getId())
// .then().assertThat()
// .body("status", equalTo("COMPLETED"));
// List<Integer> newIds =  given()
// .header(API_TOKEN_HTTP_HEADER, token)
// .get(props.getProperty("job.status.api"))
// .then().extract().jsonPath()
// .getList("jobs.id");
// assertTrue(newIds.contains((int)job.getId()));
// 
// } catch (Exception e) {
// System.out.println("Error testIdenticalFilesInDifferentDirectories: " + e.getMessage());
// e.printStackTrace();
// fail();
// }
// }
@Test
@Ignore
public /**
 * Add a file in MERGE mode (default), should only need to commit the new file
 */
void testAddingFilesInMergeMode() {
    try {
        // create a single test file and put it in two places
        String file1 = "testfile.txt";
        String file2 = "subdir/testfile.txt";
        File file = createTestFile(dsDir, file1, 0.25);
        if (file != null) {
            FileUtils.copyFile(file, new File(dsDir + file2));
        } else {
            System.out.println("Unable to copy file: " + dsDir + file2);
            fail();
        }
        // mock the checksum manifest
        String checksum1 = "asfdasdfasdfasdf";
        String checksum2 = "sgsdgdsgfsdgsdgf";
        if (file1 != null && file2 != null) {
            PrintWriter pw = new PrintWriter(new FileWriter(dsDir + "/files.sha"));
            pw.write(checksum1 + " " + file1);
            pw.write("\n");
            pw.write(checksum2 + " " + file2);
            pw.write("\n");
            pw.close();
        } else {
            fail();
        }
        // validate job
        JobExecutionEntity job = getJob();
        assertEquals(job.getSteps().size(), 1);
        StepExecutionEntity step1 = job.getSteps().get(0);
        Map<String, Long> metrics = step1.getMetrics();
        assertEquals(job.getExitStatus(), BatchStatus.COMPLETED.name());
        assertEquals(job.getStatus(), BatchStatus.COMPLETED);
        assertEquals(step1.getExitStatus(), BatchStatus.COMPLETED.name());
        assertEquals(step1.getStatus(), BatchStatus.COMPLETED);
        assertEquals(step1.getName(), "import-files");
        assertEquals((long) metrics.get("write_skip_count"), 0);
        assertEquals((long) metrics.get("commit_count"), 1);
        assertEquals((long) metrics.get("process_skip_count"), 0);
        assertEquals((long) metrics.get("read_skip_count"), 0);
        assertEquals((long) metrics.get("write_count"), 2);
        assertEquals((long) metrics.get("rollback_count"), 0);
        assertEquals((long) metrics.get("filter_count"), 0);
        assertEquals((long) metrics.get("read_count"), 2);
        assertEquals(step1.getPersistentUserData(), null);
        // confirm data files were imported
        updateDatasetJsonPath();
        List<String> storageIds = new ArrayList<>();
        storageIds.add(dsPath.getString("data.latestVersion.files[0].dataFile.storageIdentifier"));
        storageIds.add(dsPath.getString("data.latestVersion.files[1].dataFile.storageIdentifier"));
        assert (storageIds.contains(file1));
        assert (storageIds.contains(file2));
        // test the reporting apis
        given().header(API_TOKEN_HTTP_HEADER, token).get(props.getProperty("job.status.api") + job.getId()).then().assertThat().body("status", equalTo("COMPLETED"));
        List<Integer> ids = given().header(API_TOKEN_HTTP_HEADER, token).get(props.getProperty("job.status.api")).then().extract().jsonPath().getList("jobs.id");
        assertTrue(ids.contains((int) job.getId()));
        // add a new file and run the job again
        String file3 = "addedfile.txt";
        File addedFile = createTestFile(dsDir, file3, 0.25);
        // mock the checksum manifest
        String checksum3 = "asfdasdfasdfasdf";
        if (file1 != null && file2 != null && file3 != null) {
            PrintWriter pw = new PrintWriter(new FileWriter(dsDir + "/files.sha"));
            pw.write(checksum1 + " " + file1);
            pw.write("\n");
            pw.write(checksum2 + " " + file2);
            pw.write("\n");
            pw.write(checksum3 + " " + file3);
            pw.write("\n");
            pw.close();
        } else {
            fail();
        }
        // validate job again
        JobExecutionEntity newJob = getJobWithMode("MERGE");
        assertEquals(newJob.getSteps().size(), 1);
        StepExecutionEntity newSteps = newJob.getSteps().get(0);
        Map<String, Long> newMetrics = newSteps.getMetrics();
        assertEquals(newJob.getExitStatus(), BatchStatus.COMPLETED.name());
        assertEquals(newJob.getStatus(), BatchStatus.COMPLETED);
        assertEquals(newSteps.getExitStatus(), BatchStatus.COMPLETED.name());
        assertEquals(newSteps.getStatus(), BatchStatus.COMPLETED);
        assertEquals(newSteps.getName(), "import-files");
        assertEquals(0, (long) newMetrics.get("write_skip_count"));
        assertEquals(1, (long) newMetrics.get("commit_count"));
        assertEquals(0, (long) newMetrics.get("process_skip_count"));
        assertEquals(0, (long) newMetrics.get("read_skip_count"));
        assertEquals(1, (long) newMetrics.get("write_count"));
        assertEquals(0, (long) newMetrics.get("rollback_count"));
        assertEquals(2, (long) newMetrics.get("filter_count"));
        assertEquals(3, (long) newMetrics.get("read_count"));
        assertEquals(newSteps.getPersistentUserData(), null);
        // confirm data files were imported
        updateDatasetJsonPath();
        List<String> newStorageIds = new ArrayList<>();
        newStorageIds.add(dsPath.getString("data.latestVersion.files[0].dataFile.storageIdentifier"));
        newStorageIds.add(dsPath.getString("data.latestVersion.files[1].dataFile.storageIdentifier"));
        newStorageIds.add(dsPath.getString("data.latestVersion.files[2].dataFile.storageIdentifier"));
        assert (newStorageIds.contains(file1));
        assert (newStorageIds.contains(file2));
        assert (newStorageIds.contains(file3));
        // test the reporting apis
        given().header(API_TOKEN_HTTP_HEADER, token).get(props.getProperty("job.status.api") + newJob.getId()).then().assertThat().body("status", equalTo("COMPLETED"));
        List<Integer> newIds = given().header(API_TOKEN_HTTP_HEADER, token).get(props.getProperty("job.status.api")).then().extract().jsonPath().getList("jobs.id");
        assertTrue(newIds.contains((int) job.getId()));
    } catch (Exception e) {
        System.out.println("Error testIdenticalFilesInDifferentDirectories: " + e.getMessage());
        e.printStackTrace();
        fail();
    }
}
Also used : FileWriter(java.io.FileWriter) JobExecutionEntity(edu.harvard.iq.dataverse.batch.entities.JobExecutionEntity) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StepExecutionEntity(edu.harvard.iq.dataverse.batch.entities.StepExecutionEntity) File(java.io.File) PrintWriter(java.io.PrintWriter) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

JobExecutionEntity (edu.harvard.iq.dataverse.batch.entities.JobExecutionEntity)7 StepExecutionEntity (edu.harvard.iq.dataverse.batch.entities.StepExecutionEntity)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 Ignore (org.junit.Ignore)7 Test (org.junit.Test)7 File (java.io.File)6 FileWriter (java.io.FileWriter)6 PrintWriter (java.io.PrintWriter)6 Response (com.jayway.restassured.response.Response)1