use of org.haiku.haikudepotserver.job.model.TestNumberedLinesJobSpecification in project haikudepotserver by haiku.
the class LocalJobServiceIT method testHappyDays.
/**
* <p>This will be a bit of an unstable test (non-repeatable) because it is
* going to drive jobs into the job service and see them all run correctly.
* It introduces some random delays.</p>
*/
@Test
public void testHappyDays() {
// -------------------------
List<String> guids = IntStream.of(1, 2, 3, 4).mapToObj((i) -> new TestNumberedLinesJobSpecification(3, 500L)).map((spec) -> jobService.submit(spec, JobSnapshot.COALESCE_STATUSES_NONE)).collect(Collectors.toList());
String immediateGuid = jobService.immediate(new TestNumberedLinesJobSpecification(3, 500L), false);
// -------------------------
Stream.concat(guids.stream(), Stream.of(immediateGuid)).forEach((guid) -> {
jobService.awaitJobFinishedUninterruptibly(guid, TimeUnit.SECONDS.toMillis(15));
try {
Optional<? extends JobSnapshot> jobSnapshotOptional = jobService.tryGetJob(guid);
Assertions.assertThat(jobSnapshotOptional.isPresent()).isTrue();
Assertions.assertThat(jobSnapshotOptional.get().getStatus()).isEqualTo(JobSnapshot.Status.FINISHED);
Set<String> dataGuids = jobSnapshotOptional.get().getGeneratedDataGuids();
Assertions.assertThat(dataGuids.size()).isEqualTo(1);
String dataGuid = dataGuids.iterator().next();
Optional<JobDataWithByteSource> jobDataOptional = jobService.tryObtainData(dataGuid);
Assertions.assertThat(jobDataOptional.isPresent()).isTrue();
try (InputStream inputStream = jobDataOptional.get().getByteSource().openStream();
Reader reader = new InputStreamReader(inputStream, Charsets.UTF_8)) {
Assertions.assertThat(CharStreams.toString(reader)).isEqualTo("0\n1\n2\n");
}
} catch (IOException ioe) {
new UncheckedIOException(ioe);
}
});
}
Aggregations