Search in sources :

Example 1 with FileSystemBasedJobService

use of io.automatiko.engine.addons.persistence.filesystem.job.FileSystemBasedJobService in project automatiko-engine by automatiko-io.

the class FileSystemBasedJobServiceTest method testScheduleJobsForProcessInstanceAndCance.

@Test
public void testScheduleJobsForProcessInstanceAndCance() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    lenient().when(processes.processById("processId_1")).then(i -> {
        return process;
    });
    lenient().when(processes.processIds()).then(i -> {
        return Collections.singletonList("processId_1");
    });
    lenient().when(process.instances()).then(i -> {
        latch.countDown();
        return Mockito.mock(ProcessInstances.class);
    });
    FileSystemBasedJobService jobs = new FileSystemBasedJobService("target/jobs", 1, processes, application);
    ProcessInstanceJobDescription processInstanceJobDescription = ProcessInstanceJobDescription.of(123, DurationExpirationTime.after(500), "processInstanceId", "processId", "1");
    jobs.scheduleProcessInstanceJob(processInstanceJobDescription);
    jobs.cancelJob(processInstanceJobDescription.id());
    boolean achieved = latch.await(1, TimeUnit.SECONDS);
    assertThat(achieved).isFalse();
    verify(processes, times(0)).processById(eq("processId"));
}
Also used : CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) ProcessInstanceJobDescription(io.automatiko.engine.api.jobs.ProcessInstanceJobDescription) FileSystemBasedJobService(io.automatiko.engine.addons.persistence.filesystem.job.FileSystemBasedJobService) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) Test(org.junit.jupiter.api.Test)

Example 2 with FileSystemBasedJobService

use of io.automatiko.engine.addons.persistence.filesystem.job.FileSystemBasedJobService in project automatiko-engine by automatiko-io.

the class FileSystemBasedJobServiceTest method testScheduleJobsForProcessInstanceReload.

@Test
public void testScheduleJobsForProcessInstanceReload() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    when(processes.processById("processId_1")).then(i -> {
        return process;
    });
    when(processes.processIds()).then(i -> {
        return Collections.singletonList("processId_1");
    });
    when(process.instances()).then(i -> {
        latch.countDown();
        return Mockito.mock(ProcessInstances.class);
    });
    FileSystemBasedJobService jobs = new FileSystemBasedJobService("target/jobs", 1, processes, application);
    ProcessInstanceJobDescription processInstanceJobDescription = ProcessInstanceJobDescription.of(123, DurationExpirationTime.after(100), "processInstanceId", "processId", "1");
    jobs.scheduleProcessInstanceJob(processInstanceJobDescription);
    jobs.shutown(null);
    jobs = new FileSystemBasedJobService("target/jobs", 1, processes, application);
    jobs.scheduleOnLoad(null);
    boolean achieved = latch.await(2, TimeUnit.SECONDS);
    assertThat(achieved).isTrue();
}
Also used : CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) ProcessInstanceJobDescription(io.automatiko.engine.api.jobs.ProcessInstanceJobDescription) FileSystemBasedJobService(io.automatiko.engine.addons.persistence.filesystem.job.FileSystemBasedJobService) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) Test(org.junit.jupiter.api.Test)

Example 3 with FileSystemBasedJobService

use of io.automatiko.engine.addons.persistence.filesystem.job.FileSystemBasedJobService in project automatiko-engine by automatiko-io.

the class FileSystemBasedJobServiceTest method testScheduleJobsForProcessInstance.

@Test
public void testScheduleJobsForProcessInstance() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    when(processes.processById("processId_1")).then(i -> {
        return process;
    });
    when(processes.processIds()).then(i -> {
        return Collections.singletonList("processId_1");
    });
    when(process.instances()).then(i -> {
        latch.countDown();
        return Mockito.mock(ProcessInstances.class);
    });
    FileSystemBasedJobService jobs = new FileSystemBasedJobService("target/jobs", 1, processes, application);
    ProcessInstanceJobDescription processInstanceJobDescription = ProcessInstanceJobDescription.of(123, DurationExpirationTime.after(500), "processInstanceId", "processId", "1");
    jobs.scheduleProcessInstanceJob(processInstanceJobDescription);
    boolean achieved = latch.await(2, TimeUnit.SECONDS);
    assertThat(achieved).isTrue();
    verify(process, times(1)).instances();
}
Also used : CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) ProcessInstanceJobDescription(io.automatiko.engine.api.jobs.ProcessInstanceJobDescription) FileSystemBasedJobService(io.automatiko.engine.addons.persistence.filesystem.job.FileSystemBasedJobService) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) Test(org.junit.jupiter.api.Test)

Aggregations

FileSystemBasedJobService (io.automatiko.engine.addons.persistence.filesystem.job.FileSystemBasedJobService)3 ProcessInstanceJobDescription (io.automatiko.engine.api.jobs.ProcessInstanceJobDescription)3 CollectingUnitOfWorkFactory (io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory)3 DefaultUnitOfWorkManager (io.automatiko.engine.services.uow.DefaultUnitOfWorkManager)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.jupiter.api.Test)3