use of com.birbit.android.jobqueue.ConsumerManager.Consumer in project android-priority-jobqueue by yigit.
the class ConsumerTest method runJobMessage.
@Test
public void runJobMessage() {
MessageFactory factory = new MessageFactory();
PriorityMessageQueue pmq = new PriorityMessageQueue(timer, factory);
setRunning(pmq);
SafeMessageQueue mq = new SafeMessageQueue(timer, factory, "test");
setRunning(mq);
timer.setNow(2001);
Consumer consumer = new Consumer(pmq, mq, factory, timer);
RunJobMessage rjm = factory.obtain(RunJobMessage.class);
JobHolder mockHolder = mock(JobHolder.class);
when(mockHolder.safeRun(0, timer)).thenReturn(JobHolder.RUN_RESULT_SUCCESS);
rjm.setJobHolder(mockHolder);
timer.setNow(3001);
consumer.queueConsumer.handleMessage(rjm);
Message message = pmq.next(dummyConsumer);
assertThat(message, CoreMatchers.instanceOf(RunJobResultMessage.class));
RunJobResultMessage result = (RunJobResultMessage) message;
assertThat(result.getResult(), CoreMatchers.is(JobHolder.RUN_RESULT_SUCCESS));
assertThat(result.getJobHolder(), CoreMatchers.is(mockHolder));
assertThat(consumer.lastJobCompleted, CoreMatchers.is(3001L));
}
use of com.birbit.android.jobqueue.ConsumerManager.Consumer in project android-priority-jobqueue by yigit.
the class ConsumerTest method removePokesAfterJobTest.
@Test
public void removePokesAfterJobTest() {
MessageFactory factory = new MessageFactory();
PriorityMessageQueue pmq = new PriorityMessageQueue(timer, factory);
setRunning(pmq);
SafeMessageQueue mq = spy(new SafeMessageQueue(timer, factory, "test"));
setRunning(mq);
timer.setNow(2001);
Consumer consumer = new Consumer(pmq, mq, factory, timer);
RunJobMessage rjm = factory.obtain(RunJobMessage.class);
JobHolder mockHolder = mock(JobHolder.class);
when(mockHolder.safeRun(0, new MockTimer())).thenReturn(JobHolder.RUN_RESULT_SUCCESS);
rjm.setJobHolder(mockHolder);
timer.setNow(3001);
verify(mq, times(0)).cancelMessages(Consumer.pokeMessagePredicate);
consumer.queueConsumer.handleMessage(rjm);
verify(mq, times(1)).cancelMessages(Consumer.pokeMessagePredicate);
}
use of com.birbit.android.jobqueue.ConsumerManager.Consumer in project android-priority-jobqueue by yigit.
the class ConsumerTest method init.
@Test
public void init() {
PriorityMessageQueue pmq = mock(PriorityMessageQueue.class);
SafeMessageQueue mq = mock(SafeMessageQueue.class);
Consumer consumer = new Consumer(pmq, mq, factory, timer);
consumer.run();
verify(mq).consume(any(MessageQueueConsumer.class));
}
use of com.birbit.android.jobqueue.ConsumerManager.Consumer in project android-priority-jobqueue by yigit.
the class ConsumerTest method idleMessage.
@Test
public void idleMessage() {
MessageFactory factory = new MessageFactory();
PriorityMessageQueue pmq = new PriorityMessageQueue(timer, factory);
SafeMessageQueue mq = new SafeMessageQueue(timer, factory, "test");
setRunning(pmq);
setRunning(mq);
timer.setNow(2001);
Consumer consumer = new Consumer(pmq, mq, factory, timer);
consumer.queueConsumer.onIdle();
Message message = pmq.next(dummyConsumer);
assertThat(message, CoreMatchers.instanceOf(JobConsumerIdleMessage.class));
assertThat(((JobConsumerIdleMessage) message).getLastJobCompleted(), CoreMatchers.is(2001L));
}
Aggregations