use of com.birbit.android.jobqueue.messaging.message.CommandMessage in project android-priority-jobqueue by yigit.
the class MessageQueueTestBase method recycleOnCancel.
@Test
public void recycleOnCancel() {
MessageFactory factory = spy(new MessageFactory());
MockTimer mockTimer = new MockTimer();
final T mq = createMessageQueue(mockTimer, factory);
final CommandMessage cm = factory.obtain(CommandMessage.class);
cm.set(CommandMessage.POKE);
mq.post(cm);
final CommandMessage cm2 = factory.obtain(CommandMessage.class);
cm2.set(CommandMessage.POKE);
mq.post(cm2);
mq.cancelMessages(new MessagePredicate() {
@Override
public boolean onMessage(Message message) {
return message == cm;
}
});
verify(factory).release(cm);
verify(factory, times(0)).release(cm2);
}
use of com.birbit.android.jobqueue.messaging.message.CommandMessage in project android-priority-jobqueue by yigit.
the class MessageQueueTestBase method postWhileIdle.
@Test
public void postWhileIdle() throws InterruptedException {
final MockTimer timer = new MockTimer();
final MessageQueue mq = createMessageQueue(timer, new MessageFactory());
final CountDownLatch idleEnterLatch = new CountDownLatch(1);
final CountDownLatch idleExitLatch = new CountDownLatch(1);
final CountDownLatch handleMessage = new CountDownLatch(1);
final CommandMessage cm = new CommandMessage();
cm.set(CommandMessage.POKE);
final MessageQueueConsumer consumer = new MessageQueueConsumer() {
@Override
public void handleMessage(Message message) {
if (message == cm) {
handleMessage.countDown();
}
}
@Override
public void onIdle() {
idleEnterLatch.countDown();
try {
idleExitLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
mq.consume(consumer);
}
});
thread.start();
MatcherAssert.assertThat(idleEnterLatch.await(30, TimeUnit.SECONDS), CoreMatchers.is(true));
mq.post(cm);
idleExitLatch.countDown();
MatcherAssert.assertThat(handleMessage.await(30, TimeUnit.SECONDS), CoreMatchers.is(true));
mq.stop();
thread.join(5000);
assertThat(thread.isAlive(), CoreMatchers.is(false));
}
use of com.birbit.android.jobqueue.messaging.message.CommandMessage in project android-priority-jobqueue by yigit.
the class MessageQueueTestBase method recycleOnConsume.
@Test
public void recycleOnConsume() {
MessageFactory factory = spy(new MessageFactory());
MockTimer mockTimer = new MockTimer();
final T mq = createMessageQueue(mockTimer, factory);
CommandMessage cm = factory.obtain(CommandMessage.class);
cm.set(CommandMessage.POKE);
mq.post(cm);
mq.consume(new MessageQueueConsumer() {
@Override
public void handleMessage(Message message) {
mq.stop();
}
@Override
public void onIdle() {
}
});
verify(factory).release(cm);
}
use of com.birbit.android.jobqueue.messaging.message.CommandMessage in project android-priority-jobqueue by yigit.
the class PriorityMessageQueueTest method test1.
@Test
public void test1() {
CommandMessage mC1 = new CommandMessage();
CommandMessage mC2 = new CommandMessage();
AddJobMessage aj1 = new AddJobMessage();
AddJobMessage aj2 = new AddJobMessage();
mq.post(mC1);
mq.post(mC2);
mq.post(aj1);
mq.post(aj2);
final List<Message> expectedOrder = Arrays.asList(aj1, aj2, mC1, mC2);
mq.consume(new MessageQueueConsumer() {
int index;
@Override
public void handleMessage(Message message) {
assertThat(message, is(expectedOrder.get(index++)));
if (index == expectedOrder.size()) {
mq.stop();
}
}
@Override
public void onIdle() {
}
});
}
use of com.birbit.android.jobqueue.messaging.message.CommandMessage in project android-priority-jobqueue by yigit.
the class UnsafeMessageQueueTest method simplePost.
@Test
public void simplePost() {
Message m = new CommandMessage();
Message m2 = new CommandMessage();
Message m3 = new CommandMessage();
mq.post(m);
mq.post(m2);
mq.post(m3);
assertThat(mq.next(), is(m));
assertThat(mq.next(), is(m2));
assertThat(mq.next(), is(m3));
}
Aggregations