Package org.apache.sling.event.jobs

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


            jobManager.addJob("sling/orderedtest/start", properties);
            assertTrue("No event received in the given time.", cb.block(5));
            cb.reset();

            // get the queue
            final Queue q = jobManager.getQueue("orderedtest");
            assertNotNull("Queue 'orderedtest' should exist!", q);

            // suspend it
            q.suspend();

            final int NUM_JOBS = 30;

            // we start "some" jobs:
            for(int i = 0; i < NUM_JOBS; i++ ) {
                final String subTopic = "sling/orderedtest/sub" + (i % 10);
                properties.clear();
                properties.put("counter", i);
                jobManager.addJob(subTopic, properties);
            }
            // start the queue
            q.resume();
            while ( count.get() < NUM_JOBS +1 ) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ie) {
                    // ignore
                }
            }
            // we started one event before the test, so add one
            assertEquals("Finished count", NUM_JOBS + 1, count.get());
            assertEquals("Finished count", NUM_JOBS + 1, jobManager.getStatistics().getNumberOfFinishedJobs());
            assertEquals("Finished count", NUM_JOBS + 1, q.getStatistics().getNumberOfFinishedJobs());
            assertEquals("Failed count", NUM_JOBS / 10, q.getStatistics().getNumberOfFailedJobs());
            assertEquals("Cancelled count", 0, q.getStatistics().getNumberOfCancelledJobs());
        } finally {
            jcReg.unregister();
            ehReg.unregister();
        }
    }
View Full Code Here


            jobManager.addJob(TOPIC + "/start", null);
            assertTrue("No event received in the given time.", cb.block(5));
            cb.reset();

            // get the queue
            final Queue q = jobManager.getQueue(QUEUE_NAME);
            assertNotNull("Queue '" + QUEUE_NAME + "' should exist!", q);

            // suspend it
            q.suspend();

            // we start "some" jobs:
            // first jobs without id
            for(int i = 0; i < NUM_JOBS; i++ ) {
                final String subTopic = TOPIC + "/sub" + (i % 10);
                jobManager.addJob(subTopic, null);
            }
            // second jobs with id
            for(int i = 0; i < NUM_JOBS; i++ ) {
                final String subTopic = TOPIC + "/sub" + (i % 10);
                jobManager.addJob(subTopic, "id" + i, null);
            }
            // start the queue
            q.resume();
            while ( count.get() < 2 * NUM_JOBS  + 1 ) {
                assertEquals("Failed count", 0, q.getStatistics().getNumberOfFailedJobs());
                assertEquals("Cancelled count", 0, q.getStatistics().getNumberOfCancelledJobs());
                sleep(500);
            }
            // we started one event before the test, so add one
            assertEquals("Finished count", 2 * NUM_JOBS + 1, count.get());
            assertEquals("Finished count", 2 * NUM_JOBS + 1, jobManager.getStatistics().getNumberOfFinishedJobs());
            assertEquals("Finished count", 2 * NUM_JOBS + 1, q.getStatistics().getNumberOfFinishedJobs());
            assertEquals("Failed count", 0, q.getStatistics().getNumberOfFailedJobs());
            assertEquals("Cancelled count", 0, q.getStatistics().getNumberOfCancelledJobs());
        } finally {
            jc1Reg.unregister();
            jcReg.unregister();
            ehReg.unregister();
        }
View Full Code Here

    protected void doPost(final HttpServletRequest req, final HttpServletResponse resp)
    throws ServletException, IOException {
        String msg = null;
        final String cmd = req.getParameter("action");
        if ( "suspend".equals(cmd) ) {
            final Queue q = this.getQueue(req);
            if ( q != null ) {
                q.suspend();
            } else {
                msg = this.getQueueErrorMessage(req, "suspend");
            }
        } else if ( "resume".equals(cmd) ) {
            final Queue q = this.getQueue(req);
            if ( q != null ) {
                q.resume();
            } else {
                msg = this.getQueueErrorMessage(req, "resume");
            }
        } else if ( "clear".equals(cmd) ) {
            final Queue q = this.getQueue(req);
            if ( q != null ) {
                q.clear();
            } else {
                msg = this.getQueueErrorMessage(req, "clear");
            }
        } else if ( "reset".equals(cmd) ) {
            if ( req.getParameter(PAR_QUEUE) == null || req.getParameter(PAR_QUEUE).length() == 0 ) {
                this.jobManager.getStatistics().reset();
            } else {
                final Queue q = this.getQueue(req);
                if ( q != null ) {
                    q.getStatistics().reset();
                } else {
                    msg = this.getQueueErrorMessage(req, "reset");
                }
            }
        } else if ( "test".equals(cmd) ) {
            this.startTestJob();
        } else if ( "dropall".equals(cmd) ) {
            final Queue q = this.getQueue(req);
            if ( q != null ) {
                q.removeAll();
            } else {
                msg = this.getQueueErrorMessage(req, "drop all");
            }
        } else {
            msg = "Unknown command";
View Full Code Here

    public void testAddQueue() {
        addQueue();
    }

    public Queue addQueue() {
        Queue queue = Mockito.mock(Queue.class, Mockito.withSettings().extraInterfaces(Statistics.class));
        mockStatistics((Statistics) queue);
        Mockito.when(queue.getName()).thenReturn("queue-name");
        Mockito.when(bundleContext.registerService(Mockito.anyString(), Mockito.any(StatisticsMBean.class), Mockito.any(Dictionary.class))).thenReturn(serviceRegistration);
        mbean.sendEvent(new QueueStatusEvent(queue,null));
        Mockito.verify(bundleContext, Mockito.only()).registerService(serviceClass.capture(), serviceObject.capture(), serviceProperties.capture());
        Assert.assertEquals("Expected bean to be registerd as a StatisticsMBean ", StatisticsMBean.class.getName(), serviceClass.getValue());
        Assert.assertTrue("Expected service to be an instance of SatisticsMBean", serviceObject.getValue() instanceof StatisticsMBean);
View Full Code Here

    }


    @Test
    public void updateQueue() {
        Queue firstQueue = addQueue();
        Queue queue = Mockito.mock(Queue.class, Mockito.withSettings().extraInterfaces(Statistics.class));
        Mockito.when(queue.getName()).thenReturn("queue-name-changed");
        Mockito.reset(bundleContext);
        mbean.sendEvent(new QueueStatusEvent(queue,firstQueue));
        Mockito.verify(bundleContext, Mockito.never()).registerService(serviceClass.capture(), serviceObject.capture(), serviceProperties.capture());
    }
View Full Code Here

        Mockito.verify(bundleContext, Mockito.never()).registerService(serviceClass.capture(), serviceObject.capture(), serviceProperties.capture());
    }

    @Test
    public void removeQueue() {
        Queue firstQueue = addQueue();
        mbean.sendEvent(new QueueStatusEvent(null,firstQueue));
        Mockito.verify(serviceRegistration, Mockito.only()).unregister();

    }
View Full Code Here

    /**
     * @see org.apache.sling.event.JobStatusProvider#wakeUpJobQueue(java.lang.String)
     */
    @Override
    public void wakeUpJobQueue(final String jobQueueName) {
        final Queue q = this.jobManager.getQueue(jobQueueName);
        if ( q != null ) {
            q.resume();
        }
    }
View Full Code Here

TOP

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

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.