Package org.apache.sling.event.jobs

Examples of org.apache.sling.event.jobs.JobManager


        }
    }

    @Test(timeout=DURATION * 4000)
    public void testDoChaos() throws Exception {
        final JobManager jobManager = this.getJobManager();

        // setup added, created and finished map
        // added and finished are filled by notifications
        // created is filled by the threads starting jobs
        final Map<String, AtomicLong> added = new HashMap<String, AtomicLong>();
View Full Code Here


                        cb.block();
                        return JobResult.OK;
                    }
                });
        try {
            final JobManager jobManager = this.getJobManager();
            jobManager.addJob(TOPIC, "myid1", null);
            assertTrue("No event received in the given time.", cb.block(5));
            cb.reset();
            assertFalse("Unexpected event received in the given time.", cb.block(5));
        } finally {
            jcReg.unregister();
View Full Code Here

                        sleep(1000);
                        return JobResult.FAILED;
                    }
                });
        try {
            final JobManager jobManager = this.getJobManager();
            jobManager.addJob(TOPIC, "myid3", null);
            cb.block();

            assertEquals(1, jobManager.findJobs(JobManager.QueryType.ALL, "sling/test", -1, (Map<String, Object>[])null).size());
            // job is currently sleeping, but force cancel always waits!
            final Event e = jobManager.findJob("sling/test", Collections.singletonMap(JobUtil.PROPERTY_JOB_NAME, (Object)"myid3"));
            assertNotNull(e);
            jobManager.forceRemoveJob((String)e.getProperty(ResourceHelper.PROPERTY_JOB_ID));
            // the job is now removed
            assertEquals(0, jobManager.findJobs(JobManager.QueryType.ALL, "sling/test", -1, (Map<String, Object>[])null).size());
            final Collection<Job> col = jobManager.findJobs(JobManager.QueryType.HISTORY, "sling/test", -1, (Map<String, Object>[])null);
            try {
                assertEquals(1, col.size());
            } finally {
                for(final Job j : col) {
                    jobManager.removeJobById(j.getId());
                }
            }
        } finally {
            jcReg.unregister();
        }
View Full Code Here

*/
public class JobHandlingReplicationQueueProviderTest {

    @Test
    public void testGetOrCreateNamedQueue() throws Exception {
        JobManager jobManager = mock(JobManager.class);

        BundleContext context = mock(BundleContext.class);
        JobHandlingReplicationQueueProvider jobHandlingReplicationQueueProvider = new JobHandlingReplicationQueueProvider(
                jobManager, context);
        ReplicationQueue queue = jobHandlingReplicationQueueProvider.getInternalQueue("dummy-agent", "default");
View Full Code Here



    @Test
    public void testEnableQueueProcessing() throws Exception {
        JobManager jobManager = mock(JobManager.class);
        ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
        Configuration config = mock(Configuration.class);
        when(configAdmin.createFactoryConfiguration(QueueConfiguration.class.getName(), null)).thenReturn(config);
        BundleContext context = mock(BundleContext.class);
        JobHandlingReplicationQueueProvider jobHandlingReplicationQueueProvider = new JobHandlingReplicationQueueProvider(
View Full Code Here

        jobHandlingReplicationQueueProvider.enableQueueProcessing(agentName, queueProcessor);
    }

    @Test
    public void testDisableQueueProcessing() throws Exception {
        JobManager jobManager = mock(JobManager.class);
        ConfigurationAdmin configAdmin = mock(ConfigurationAdmin.class);
        Configuration config = mock(Configuration.class);
        when(configAdmin.createFactoryConfiguration(QueueConfiguration.class.getName(), null)).thenReturn(config);
        BundleContext context = mock(BundleContext.class);
        JobHandlingReplicationQueueProvider jobHandlingReplicationQueueProvider = new JobHandlingReplicationQueueProvider(
View Full Code Here

public class JobHandlingReplicationQueueTest {

    @SuppressWarnings("unchecked")
    @Test
    public void testPackageAddition() throws Exception {
        JobManager jobManager = mock(JobManager.class);
        JobBuilder builder = mock(JobBuilder.class);
        when(builder.properties(any(Map.class))).thenReturn(builder);
        Job job = mock(Job.class);
        when(job.getId()).thenReturn("id-123");
        when(builder.add()).thenReturn(job);
        String topic = JobHandlingReplicationQueue.REPLICATION_QUEUE_TOPIC + "/aname";
        when(jobManager.createJob(topic)).thenReturn(builder);
        when(jobManager.findJobs(JobManager.QueryType.ALL, topic, -1)).thenReturn(Collections.<Job>emptySet());
        when(builder.properties(any(Map.class))).thenReturn(builder);
        ReplicationQueue queue = new JobHandlingReplicationQueue("aname", topic, jobManager);
        ReplicationQueueItem pkg = mock(ReplicationQueueItem.class);
        assertTrue(queue.add(pkg));
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    @Test
    public void testPackageAdditionAndStatusCheck() throws Exception {
        JobManager jobManager = mock(JobManager.class);
        JobBuilder builder = mock(JobBuilder.class);
        when(builder.properties(any(Map.class))).thenReturn(builder);
        Job job = mock(Job.class);
        when(job.getId()).thenReturn("id-123");
        when(builder.add()).thenReturn(job);
        String topic = JobHandlingReplicationQueue.REPLICATION_QUEUE_TOPIC + "/aname";
        when(jobManager.createJob(topic)).thenReturn(builder);
        when(jobManager.findJobs(JobManager.QueryType.ALL, topic, -1)).thenReturn(Collections.<Job>emptySet());
        when(builder.properties(any(Map.class))).thenReturn(builder);
        ReplicationQueue queue = new JobHandlingReplicationQueue("aname", topic, jobManager);
        ReplicationQueueItem pkg = mock(ReplicationQueueItem.class);
        assertTrue(queue.add(pkg));
        ReplicationQueueItemState status = queue.getStatus(pkg);
View Full Code Here

                        cb2.block();
                        return JobResult.FAILED;
                    }
                });
        try {
            final JobManager jobManager = this.getJobManager();
            jobManager.addJob(TOPIC, Collections.singletonMap("id", (Object)"myid2"));
            cb.block();

            assertEquals(1, jobManager.findJobs(JobManager.QueryType.ALL, TOPIC, -1, (Map<String, Object>[])null).size());
            // job is currently waiting, therefore cancel fails
            final Job e1 = jobManager.getJob(TOPIC, Collections.singletonMap("id", (Object)"myid2"));
            assertNotNull(e1);
            cb2.block(); // and continue job

            sleep(200);

            // the job is now in the queue again
            final Job e2 = jobManager.getJob(TOPIC, Collections.singletonMap("id", (Object)"myid2"));
            assertNotNull(e2);
            assertTrue(jobManager.removeJobById(e2.getId()));
            assertEquals(0, jobManager.findJobs(JobManager.QueryType.ALL, TOPIC, -1, (Map<String, Object>[])null).size());
            final Collection<Job> col = jobManager.findJobs(JobManager.QueryType.HISTORY, TOPIC, -1, (Map<String, Object>[])null);
            try {
                assertEquals(1, col.size());
            } finally {
                for(final Job j : col) {
                    jobManager.removeJobById(j.getId());
                }
            }
        } finally {
            jcReg.unregister();
        }
View Full Code Here

                        cb2.block();
                        return JobResult.OK;
                    }
                });
        try {
            final JobManager jobManager = this.getJobManager();
            final Job j = jobManager.addJob(TOPIC, null);
            cb.block();

            assertNotNull(jobManager.getJob(TOPIC, null));

            cb2.block(); // and continue job

            jobManager.removeJobById(j.getId());
        } finally {
            jcReg.unregister();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.event.jobs.JobManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.