Search in sources :

Example 1 with InMemoryJobStorage

use of org.apache.sling.jobs.impl.storage.InMemoryJobStorage in project sling by apache.

the class ManagerSubscriberTest method setUp.

@Before
public void setUp() throws Exception {
    topicQueues = new HashMap<org.apache.sling.mom.Types.TopicName, Queue<QueueEntry>>();
    messageQueues = new HashMap<org.apache.sling.mom.Types.QueueName, Queue<QueueEntry>>();
    //noinspection unchecked
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            org.apache.sling.mom.Types.TopicName topic = (org.apache.sling.mom.Types.TopicName) invocationOnMock.getArguments()[0];
            org.apache.sling.mom.Types.CommandName command = (org.apache.sling.mom.Types.CommandName) invocationOnMock.getArguments()[1];
            @SuppressWarnings("unchecked") Map<String, Object> properties = (Map<String, Object>) invocationOnMock.getArguments()[2];
            Queue<QueueEntry> queue = topicQueues.get(topic);
            if (queue == null) {
                queue = new ArrayBlockingQueue<QueueEntry>(100);
                topicQueues.put(topic, queue);
            }
            queue.add(new QueueEntry(command, properties));
            return null;
        }
    }).when(topicManager).publish(Mockito.any(org.apache.sling.mom.Types.TopicName.class), Mockito.any(org.apache.sling.mom.Types.CommandName.class), Mockito.any(Map.class));
    //noinspection unchecked
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            org.apache.sling.mom.Types.QueueName topic = (org.apache.sling.mom.Types.QueueName) invocationOnMock.getArguments()[0];
            @SuppressWarnings("unchecked") Map<String, Object> properties = (Map<String, Object>) invocationOnMock.getArguments()[1];
            Queue<QueueEntry> queue = messageQueues.get(topic);
            if (queue == null) {
                queue = new ArrayBlockingQueue<QueueEntry>(100);
                messageQueues.put(topic, queue);
            }
            queue.add(new QueueEntry(properties));
            return null;
        }
    }).when(queueManager).add(Mockito.any(org.apache.sling.mom.Types.QueueName.class), Mockito.any(Map.class));
    messageSender = new OutboundJobUpdateListener(topicManager, queueManager);
    jobStorage = new InMemoryJobStorage();
    jobManager = new JobManagerImpl(jobStorage, messageSender);
    managerSubscriber = new ManagerSubscriber();
    Field f = managerSubscriber.getClass().getDeclaredField("jobManager");
    f.setAccessible(true);
    f.set(managerSubscriber, jobManager);
}
Also used : Types(org.apache.sling.jobs.Types) Field(java.lang.reflect.Field) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Queue(java.util.Queue) InvocationOnMock(org.mockito.invocation.InvocationOnMock) InMemoryJobStorage(org.apache.sling.jobs.impl.storage.InMemoryJobStorage) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Example 2 with InMemoryJobStorage

use of org.apache.sling.jobs.impl.storage.InMemoryJobStorage in project sling by apache.

the class JobSubsystem method activate.

@Activate
public synchronized void activate() {
    jobStorage = new InMemoryJobStorage();
    messageSender = new OutboundJobUpdateListener(topicManager, queueManager);
    manager = new JobManagerImpl(jobStorage, messageSender);
}
Also used : InMemoryJobStorage(org.apache.sling.jobs.impl.storage.InMemoryJobStorage) Activate(org.osgi.service.component.annotations.Activate)

Example 3 with InMemoryJobStorage

use of org.apache.sling.jobs.impl.storage.InMemoryJobStorage in project sling by apache.

the class JobManagerImplTest method setUp.

@Before
public void setUp() throws Exception {
    topicQueues = new HashMap<org.apache.sling.mom.Types.TopicName, Queue<QueueEntry>>();
    messageQueues = new HashMap<org.apache.sling.mom.Types.QueueName, Queue<QueueEntry>>();
    //noinspection unchecked
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            org.apache.sling.mom.Types.TopicName topic = (org.apache.sling.mom.Types.TopicName) invocationOnMock.getArguments()[0];
            org.apache.sling.mom.Types.CommandName command = (org.apache.sling.mom.Types.CommandName) invocationOnMock.getArguments()[1];
            @SuppressWarnings("unchecked") Map<String, Object> properties = (Map<String, Object>) invocationOnMock.getArguments()[2];
            LOGGER.info("Topic Manager publish {} {} {} ", new Object[] { topic, command, properties });
            Queue<QueueEntry> queue = topicQueues.get(topic);
            if (queue == null) {
                queue = new ArrayBlockingQueue<QueueEntry>(100);
                topicQueues.put(topic, queue);
            }
            queue.add(new QueueEntry(command, properties));
            return null;
        }
    }).when(topicManager).publish(Mockito.any(org.apache.sling.mom.Types.TopicName.class), Mockito.any(org.apache.sling.mom.Types.CommandName.class), Mockito.any(Map.class));
    //noinspection unchecked
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            org.apache.sling.mom.Types.QueueName topic = (org.apache.sling.mom.Types.QueueName) invocationOnMock.getArguments()[0];
            @SuppressWarnings("unchecked") Map<String, Object> properties = (Map<String, Object>) invocationOnMock.getArguments()[1];
            LOGGER.info("Queue Manager add {} {} {} ", new Object[] { topic, properties });
            Queue<QueueEntry> queue = messageQueues.get(topic);
            if (queue == null) {
                queue = new ArrayBlockingQueue<QueueEntry>(100);
                messageQueues.put(topic, queue);
            }
            queue.add(new QueueEntry(properties));
            return null;
        }
    }).when(queueManager).add(Mockito.any(org.apache.sling.mom.Types.QueueName.class), Mockito.any(Map.class));
    messageSender = new OutboundJobUpdateListener(topicManager, queueManager);
    jobStorage = new InMemoryJobStorage();
    jobManager = new JobManagerImpl(jobStorage, messageSender);
}
Also used : Types(org.apache.sling.jobs.Types) org.apache.sling.mom(org.apache.sling.mom) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) InvocationOnMock(org.mockito.invocation.InvocationOnMock) InMemoryJobStorage(org.apache.sling.jobs.impl.storage.InMemoryJobStorage) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Queue(java.util.Queue) HashMap(java.util.HashMap) Map(java.util.Map) Before(org.junit.Before)

Aggregations

InMemoryJobStorage (org.apache.sling.jobs.impl.storage.InMemoryJobStorage)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Queue (java.util.Queue)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 Types (org.apache.sling.jobs.Types)2 Before (org.junit.Before)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Field (java.lang.reflect.Field)1 org.apache.sling.mom (org.apache.sling.mom)1 Activate (org.osgi.service.component.annotations.Activate)1