Search in sources :

Example 1 with TestNumberedLinesJobSpecification

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);
        }
    });
}
Also used : IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) JobSnapshot(org.haiku.haikudepotserver.job.model.JobSnapshot) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) TestLockableJobSpecification(org.haiku.haikudepotserver.job.model.TestLockableJobSpecification) TestNumberedLinesJobSpecification(org.haiku.haikudepotserver.job.model.TestNumberedLinesJobSpecification) CharStreams(com.google.common.io.CharStreams) JobDataWithByteSource(org.haiku.haikudepotserver.job.model.JobDataWithByteSource) JobService(org.haiku.haikudepotserver.job.model.JobService) TestConfig(org.haiku.haikudepotserver.config.TestConfig) Charsets(com.google.common.base.Charsets) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Assertions(org.fest.assertions.Assertions) Resource(javax.annotation.Resource) Set(java.util.Set) IOException(java.io.IOException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) UncheckedIOException(java.io.UncheckedIOException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Lock(java.util.concurrent.locks.Lock) Stream(java.util.stream.Stream) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Optional(java.util.Optional) InputStream(java.io.InputStream) JobDataWithByteSource(org.haiku.haikudepotserver.job.model.JobDataWithByteSource) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) TestNumberedLinesJobSpecification(org.haiku.haikudepotserver.job.model.TestNumberedLinesJobSpecification) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Charsets (com.google.common.base.Charsets)1 CharStreams (com.google.common.io.CharStreams)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 UncheckedIOException (java.io.UncheckedIOException)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Stream (java.util.stream.Stream)1 Resource (javax.annotation.Resource)1 Assertions (org.fest.assertions.Assertions)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 TestConfig (org.haiku.haikudepotserver.config.TestConfig)1