Search in sources :

Example 1 with Job

use of org.apache.sling.jobs.Job in project sling by apache.

the class InMemoryJobStorageTest method testRemove.

@Test
public void testRemove() throws Exception {
    Job removed = jobStorage.remove(job);
    assertNotNull(removed);
    assertEquals(job.getId(), removed.getId());
    assertNull(jobStorage.get(jobId));
}
Also used : Job(org.apache.sling.jobs.Job) Test(org.junit.Test)

Example 2 with Job

use of org.apache.sling.jobs.Job in project sling by apache.

the class JobManagerTestComponent method activate.

@Activate
public void activate(Map<String, Object> props) {
    for (int i = 0; i < 10; i++) {
        Job job = jobManager.newJobBuilder(Types.jobQueue(TOPIC), Types.jobType(AsyncJobConsumer.JOB_TYPE)).addProperties(Collections.singletonMap("jobtest", (Object) "jobtest")).add();
        assertNotNull(job);
        LOGGER.info("Started Job {} ", job.getId());
    }
    // then start 10 sync jobs.
    for (int i = 0; i < 10; i++) {
        Job job = jobManager.newJobBuilder(Types.jobQueue(TOPIC), Types.jobType(FullySyncJob.JOB_TYPE)).addProperties(Collections.singletonMap("jobtest", (Object) "jobtest")).add();
        assertNotNull(job);
        LOGGER.info("Started Job {} ", job.getId());
    }
}
Also used : Job(org.apache.sling.jobs.Job) Activate(org.apache.felix.scr.annotations.Activate)

Example 3 with Job

use of org.apache.sling.jobs.Job in project sling by apache.

the class InMemoryJobStorage method remove.

@Nullable
@Override
public Job remove(@Nonnull String jobId) {
    check();
    Job j = store.get(jobId);
    store.remove(jobId);
    return j;
}
Also used : Job(org.apache.sling.jobs.Job) Nullable(javax.annotation.Nullable)

Example 4 with Job

use of org.apache.sling.jobs.Job in project sling by apache.

the class JobBuilderImplTest method testAddJob.

@Test
public void testAddJob() {
    long start = System.currentTimeMillis();
    Map<String, Object> testMap = new HashMap<String, Object>();
    testMap.put("job.name", "Jobname");
    Job queuedJob = new JobBuilderImpl(jobStarter, Types.jobQueue("testtopic"), Types.jobType("testtype")).addProperties(testMap).add();
    assertEquals(1, queue.size());
    Job fromQueue = queue.remove();
    assertEquals(queuedJob, fromQueue);
    assertEquals(Types.jobQueue("testtopic"), fromQueue.getQueue());
    assertEquals("Jobname", fromQueue.getProperties().get("job.name"));
    assertNotNull(fromQueue.getId());
    long now = System.currentTimeMillis();
    assertTrue(fromQueue.getCreated() >= start);
    assertTrue(fromQueue.getCreated() <= now);
    assertEquals(Job.JobState.CREATED, fromQueue.getJobState());
    assertNull(fromQueue.getController());
    fromQueue.setJobController(jobController);
    assertEquals(jobController, fromQueue.getController());
    fromQueue.removeJobController();
    assertNull(fromQueue.getController());
    assertEquals("", fromQueue.getResultMessage());
    assertEquals(0, fromQueue.getFinished());
    assertEquals(0, fromQueue.getStarted());
    assertEquals(0, fromQueue.getNumberOfRetries());
    assertEquals(0, fromQueue.getRetryCount());
}
Also used : HashMap(java.util.HashMap) Job(org.apache.sling.jobs.Job) Test(org.junit.Test)

Example 5 with Job

use of org.apache.sling.jobs.Job in project sling by apache.

the class ManagerSubscriberTest method test.

@Test
public void test() {
    // fake up a remote send.
    Map<String, Object> properties = new HashMap<String, Object>();
    String testId = "testGetJobById" + System.currentTimeMillis();
    properties.put("testid", testId);
    properties.put("job.name", "Jobname");
    String jobId = Utils.generateId();
    Job job = new JobImpl(Types.jobQueue("testtopic"), jobId, Types.jobType("testtype"), properties);
    JobUpdateImpl jobUpdate = new JobUpdateImpl(job, JobUpdate.JobUpdateCommand.START_JOB, job.getProperties());
    Map<String, Object> message = Utils.toMapValue(jobUpdate);
    // pump the topic message into the managerSubscriber and check that the job can be found.
    managerSubscriber.onMessage(org.apache.sling.mom.Types.topicName("testtopic"), message);
    Job searchedJob = jobManager.getJobById(jobId);
    assertNotNull(searchedJob);
    assertEquals(job.getId(), searchedJob.getId());
    assertEquals(testId, searchedJob.getProperties().get("testid"));
}
Also used : HashMap(java.util.HashMap) Job(org.apache.sling.jobs.Job) Test(org.junit.Test)

Aggregations

Job (org.apache.sling.jobs.Job)8 Test (org.junit.Test)5 HashMap (java.util.HashMap)2 Nullable (javax.annotation.Nullable)1 Activate (org.apache.felix.scr.annotations.Activate)1 JobCallback (org.apache.sling.jobs.JobCallback)1 JobConsumer (org.apache.sling.jobs.JobConsumer)1 JobUpdate (org.apache.sling.jobs.JobUpdate)1 JobUpdateListener (org.apache.sling.jobs.JobUpdateListener)1