Package net.greghaines.jesque.worker

Examples of net.greghaines.jesque.worker.WorkerImpl


    @Test
    public void testAdminAndWorkerPool() {
        final WorkerPool workerPool = new WorkerPool(new Callable<WorkerImpl>() {
            public WorkerImpl call() {
                return new WorkerImpl(config, set(testQueue),
                        new MapBasedJobFactory(map(entry("TestAction", TestAction.class))));
            }
        }, 2);
        final Admin admin = new AdminImpl(config);
        admin.setWorker(workerPool);
View Full Code Here


        }
    }

    @Test
    public void testPauseAndShutdownCommands() {
        final Worker worker = new WorkerImpl(config, set(testQueue),
                new MapBasedJobFactory(map(entry("TestAction", TestAction.class))));
        final Admin admin = new AdminImpl(config);
        admin.setWorker(worker);

        final Thread workerThread = new Thread(worker);
        workerThread.start();
        final Thread adminThread = new Thread(admin);
        adminThread.start();

        Assert.assertFalse(worker.isPaused());

        try {
            final AdminClient adminClient = new AdminClientImpl(config);
            try {
                adminClient.togglePausedWorkers(true);
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException ie) {
                }
                Assert.assertTrue(worker.isPaused());

                Assert.assertFalse(worker.isShutdown());
                adminClient.shutdownWorkers(true);
                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException ie) {
                }
                Assert.assertTrue(worker.isShutdown());
            } finally {
                adminClient.end();
            }
        } finally {
            TestUtils.stopWorker(admin, adminThread);
View Full Code Here

        templateValues.put("email", "mail@gmail.com");
        templateValues.put("url", "http://localhost:90/confir");
        templateValues.put("fName", "RANGANATHAN");
        final Job job = new Job("SendMailJob", null, "mail@gmail.com", "REGISTRATION_MAIL_SUBJECT", true,
                "REGISTRATION_MAIL", templateValues);
        final Worker worker = new WorkerImpl(CONFIG, Arrays.asList(TEST_QUEUE),
                new MapBasedJobFactory(map(entry("SendMailJob", SendMailJob.class))));
        final Thread workerThread = new Thread(worker);
        workerThread.start();
        try {
            TestUtils.enqueueJobs(TEST_QUEUE, Arrays.asList(job), CONFIG);
View Full Code Here

    @Test
    @Ignore
    public void issue28() throws InterruptedException {
        changeRedisTimeout(10);
        TestUtils.enqueueJobs("longRunning", Arrays.asList(new Job("LongRunningAction", 20 * 1000L)), config);
        final Worker worker2 = new WorkerImpl(config, Arrays.asList("longRunning"),
                new MapBasedJobFactory(map(entry("LongRunningAction", LongRunningAction.class))));
        final AtomicBoolean successRef = new AtomicBoolean(false);
        worker2.getWorkerEventEmitter().addListener(new WorkerListener() {
            @Override
            public void onEvent(final WorkerEvent event, final Worker worker, final String queue, final Job job,
                    final Object runner, final Object result, final Throwable t) {
                successRef.set(true);
                log.info("SUCCCESS: {}", job);
            }
        }, WorkerEvent.JOB_SUCCESS);
        final Thread workerThread2 = new Thread(worker2);
        workerThread2.start();
        sleepTight(1000);
        worker2.end(false);
        workerThread2.join();

        Assert.assertTrue("Success callback should have been called", successRef.get());
        changeRedisTimeout(0);
    }
View Full Code Here

        } finally {
            jedis.quit();
        }

        // Create and start worker
        final Worker worker = new WorkerImpl(config, Arrays.asList(testQueue),
                new MapBasedJobFactory(map(entry("TestAction", TestAction.class))));
        final Thread workerThread = new Thread(worker);
        workerThread.start();
        try { // Wait a bit to ensure the worker had time to process the job
            Thread.sleep(500);
View Full Code Here

        }
    }

    private static void doWork(final List<Job> jobs, final Map<String, ? extends Class<? extends Runnable>> jobTypes,
            final WorkerListener listener, final WorkerEvent... events) {
        final Worker worker = new WorkerImpl(CONFIG, Arrays.asList(TEST_QUEUE), new MapBasedJobFactory(jobTypes));
        if (listener != null && events.length > 0) {
            worker.getWorkerEventEmitter().addListener(listener, events);
        }
        final Thread workerThread = new Thread(worker);
        workerThread.start();
        try {
            TestUtils.enqueueJobs(TEST_QUEUE, jobs, CONFIG);
View Full Code Here

            for (int j = 0; j < 5; j++) {
                jobs.add(new Job("FailAction"));
            }
            TestUtils.enqueueJobs("bar", jobs, config);
        }
        final Worker worker = new WorkerImpl(config, Arrays.asList("foo0", "bar", "baz"),
                new MapBasedJobFactory(map(entry("TestAction", TestAction.class),
                        entry("FailAction", FailAction.class))));
        final Thread workerThread = new Thread(worker);
        workerThread.start();

        TestUtils.enqueueJobs("inf", Arrays.asList(new Job("InfiniteAction")), config);
        final Worker worker2 = new WorkerImpl(config, Arrays.asList("inf"),
                new MapBasedJobFactory(map(entry("InfiniteAction", InfiniteAction.class))));
        final Thread workerThread2 = new Thread(worker2);
        workerThread2.start();
        worker2.togglePause(true);

        workerThread.join();
    }
View Full Code Here

    }

    @Test
    @Ignore
    public void issue6() throws InterruptedException {
        final Worker worker = new WorkerImpl(config, Arrays.asList("foo"),
                new MapBasedJobFactory(map(entry("TestAction", TestAction.class),
                        entry("FailAction", FailAction.class))));
        final Thread workerThread = new Thread(worker);
        workerThread.start();
View Full Code Here

        } finally {
            jedis.quit();
        }

        // Create and start worker
        final Worker worker = new WorkerImpl(config, Arrays.asList(delayTestQueue),
                new MapBasedJobFactory(map(entry("TestAction", TestAction.class))));
        final Thread workerThread = new Thread(worker);
        workerThread.start();

        // start second thread
        final Worker worker2 = new WorkerImpl(config, Arrays.asList(testQueue),
                new MapBasedJobFactory(map(entry("TestAction", TestAction.class))));
        final Thread workerThread2 = new Thread(worker2);
        workerThread2.start();

        try { // Wait a bit to ensure the worker had time to process the job
View Full Code Here

    @Test
    public void testNotInterrupted() throws InterruptedException, JsonProcessingException {
        final String queue = "foo";
        TestUtils.enqueueJobs(queue, Arrays.asList(sleepJob), config);

        final Worker worker = new WorkerImpl(config, Arrays.asList(queue),
                new MapBasedJobFactory(JesqueUtils.map(JesqueUtils.entry("SleepAction", SleepAction.class))));
        final Thread workerThread = new Thread(worker);
        workerThread.start();

        Thread.sleep(1000);
View Full Code Here

TOP

Related Classes of net.greghaines.jesque.worker.WorkerImpl

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.