use of gov.cms.ab2d.common.dto.StaleJob in project ab2d by CMSgov.
the class FileDeletionServiceTest method testDontCleanOutDir.
@Test
void testDontCleanOutDir(@TempDir File tmpDir) throws IOException {
AuditMockJob newJob = new AuditMockJob(new StaleJob(UUID.randomUUID().toString(), job.getOrganization()), SUCCESSFUL, OffsetDateTime.now().minusDays(1));
jobAuditClientMock.update(job);
ReflectionTestUtils.setField(fileDeletionService, "efsMount", tmpDir.getAbsolutePath());
String jobId = newJob.getJobUuid();
String miscString = "Hello";
// Create the directories
List<Path> files = new ArrayList<>();
Path jobDir = Files.createDirectory(Path.of(tmpDir.getAbsolutePath(), jobId));
Path finishedDir = Files.createDirectory(Path.of(tmpDir.getAbsolutePath(), jobId, "finished"));
Path streamDir = Files.createDirectory(Path.of(tmpDir.getAbsolutePath(), jobId, "streaming"));
// Create the files
files.add(Files.createFile(Path.of(tmpDir.getAbsolutePath(), jobId, "tstfile.ndjson")));
files.add(Files.createFile(Path.of(tmpDir.getAbsolutePath(), jobId, "tstfile.txt")));
files.add(Files.createFile(Path.of(tmpDir.getAbsolutePath(), jobId, "finished", "tstfile.ndjson")));
files.add(Files.createFile(Path.of(tmpDir.getAbsolutePath(), jobId, "streaming", "tstfile.ndjson")));
files.add(Files.createFile(Path.of(tmpDir.getAbsolutePath(), jobId, "streaming", "tstfile.txt")));
// Write data to the files
for (Path file : files) {
Files.writeString(file, miscString);
}
files.add(jobDir);
files.add(finishedDir);
files.add(streamDir);
fileDeletionService.deleteFiles();
List<Path> remaining = files.stream().filter(f -> f.toFile().exists()).collect(Collectors.toList());
remaining.forEach(System.out::println);
assertEquals(8, remaining.size());
assertEquals(3, remaining.stream().filter(f -> f.toFile().isDirectory()).count());
assertEquals(2, remaining.stream().filter(f -> f.toFile().isFile()).filter(f -> f.toFile().getName().equals("tstfile.txt")).count());
}
use of gov.cms.ab2d.common.dto.StaleJob in project ab2d by CMSgov.
the class FileDeletionServiceTest method init.
@BeforeEach
public void init() {
pathsToDelete = new ArrayList<>();
PdpClient pdpClient = dataSetup.setupPdpClient(List.of());
// Connected to a job that is finished and has expired
job = new AuditMockJob(new StaleJob(UUID.randomUUID().toString(), pdpClient.getOrganization()), SUCCESSFUL, OffsetDateTime.now().minusDays(4));
jobAuditClientMock.update(job);
// Connected to a job, but in progress
jobInProgress = new AuditMockJob(new StaleJob(UUID.randomUUID().toString(), pdpClient.getOrganization()), IN_PROGRESS, null);
jobAuditClientMock.update(jobInProgress);
// Connected to a job that is finished where the file has yet to expire
jobNotExpiredYet = new AuditMockJob(new StaleJob(UUID.randomUUID().toString(), pdpClient.getOrganization()), SUCCESSFUL, OffsetDateTime.now().minusHours(55));
jobAuditClientMock.update(jobNotExpiredYet);
jobCancelled = new AuditMockJob(new StaleJob(UUID.randomUUID().toString(), pdpClient.getOrganization()), CANCELLED, null);
jobAuditClientMock.update(jobCancelled);
jobFailed = new AuditMockJob(new StaleJob(UUID.randomUUID().toString(), pdpClient.getOrganization()), FAILED, null);
jobAuditClientMock.update(jobFailed);
efsMount = tmpDirFolder.toPath().toString();
ReflectionTestUtils.setField(fileDeletionService, "efsMount", efsMount);
}
use of gov.cms.ab2d.common.dto.StaleJob in project ab2d by CMSgov.
the class JobServiceTest method checkForExpirations.
@Test
void checkForExpirations() {
Job job = createJobAllContracts(NDJSON_FIRE_CONTENT_TYPE);
job.setStatus(FAILED);
jobRepository.save(job);
dataSetup.queueForCleanup(job);
List<StaleJob> staleJobs = jobService.checkForExpiration(of(job.getJobUuid()), 1);
assertFalse(staleJobs.isEmpty());
assertEquals(1, staleJobs.size());
staleJobs = jobService.checkForExpiration(Collections.emptyList(), 1);
assertTrue(staleJobs.isEmpty());
}
use of gov.cms.ab2d.common.dto.StaleJob in project ab2d by CMSgov.
the class EventUtilsTest method buildStaleFileEvent.
/*
* A trivial test to get Sonar happy.
*/
@Test
void buildStaleFileEvent() {
StaleJob staleJob = new StaleJob("job_uuid", "bogus incorporated");
FileEvent fileEvent = EventUtils.getStaleFileEvent(staleJob, null, null);
assertNotNull(fileEvent);
}
use of gov.cms.ab2d.common.dto.StaleJob in project ab2d by CMSgov.
the class FileDeletionServiceTest method testCleanOutDir.
@Test
void testCleanOutDir(@TempDir File tmpDir) throws IOException {
ReflectionTestUtils.setField(fileDeletionService, "efsMount", tmpDir.getAbsolutePath());
String jobId = job.getJobUuid();
String miscString = "Hello";
// Create the directories
List<Path> files = new ArrayList<>();
Path jobDir = Files.createDirectory(Path.of(tmpDir.getAbsolutePath(), jobId));
Path finishedDir = Files.createDirectory(Path.of(tmpDir.getAbsolutePath(), jobId, "finished"));
Path streamDir = Files.createDirectory(Path.of(tmpDir.getAbsolutePath(), jobId, "streaming"));
// Create the files
files.add(Files.createFile(Path.of(tmpDir.getAbsolutePath(), jobId, "tstfile.ndjson")));
files.add(Files.createFile(Path.of(tmpDir.getAbsolutePath(), jobId, "tstfile.txt")));
files.add(Files.createFile(Path.of(tmpDir.getAbsolutePath(), jobId, "finished", "tstfile.ndjson")));
files.add(Files.createFile(Path.of(tmpDir.getAbsolutePath(), jobId, "streaming", "tstfile.ndjson")));
files.add(Files.createFile(Path.of(tmpDir.getAbsolutePath(), jobId, "streaming", "tstfile.txt")));
// Write data to the files
for (Path file : files) {
Files.writeString(file, miscString);
changeFileCreationDate(file);
}
files.add(jobDir);
files.add(finishedDir);
files.add(streamDir);
StaleJob staleJob = new StaleJob(job.getJobUuid(), job.getOrganization());
fileDeletionService.deleteNdjsonFilesAndDirectory(staleJob, jobDir);
List<Path> remaining = files.stream().filter(f -> f.toFile().exists()).collect(Collectors.toList());
// There should be 4 remaining path - the top job directory, the streaming dir, the top level txt file and the s
// streaming txt file
assertEquals(4, remaining.size());
assertEquals(2, remaining.stream().filter(f -> f.toFile().isDirectory()).count());
assertEquals(2, remaining.stream().filter(f -> f.toFile().isFile()).filter(f -> f.toFile().getName().equals("tstfile.txt")).count());
remaining.forEach(System.out::println);
}
Aggregations