Search in sources :

Example 6 with MockTimer

use of com.birbit.android.jobqueue.test.timer.MockTimer in project android-priority-jobqueue by yigit.

the class RunningJobSetTest method testAddWithTimeout.

@Test
public void testAddWithTimeout() {
    MockTimer timer = new MockTimer();
    set = new RunningJobSet(timer);
    set.addGroupUntil("g1", 10L);
    timer.setNow(5);
    assertList("g1");
    timer.setNow(11);
    assertList();
    timer.setNow(3);
    // should've pruned the list
    assertList();
}
Also used : MockTimer(com.birbit.android.jobqueue.test.timer.MockTimer) RunningJobSet(com.birbit.android.jobqueue.RunningJobSet) Test(org.junit.Test)

Example 7 with MockTimer

use of com.birbit.android.jobqueue.test.timer.MockTimer in project android-priority-jobqueue by yigit.

the class RunningJobSetTest method testAddMultipleGroupTimeouts.

@Test
public void testAddMultipleGroupTimeouts() {
    MockTimer timer = new MockTimer();
    set = new RunningJobSet(timer);
    set.addGroupUntil("g1", 10L);
    set.addGroupUntil("g2", 20L);
    timer.setNow(5);
    assertList("g1", "g2");
    timer.setNow(11);
    assertList("g2");
    timer.setNow(21);
    assertList();
}
Also used : MockTimer(com.birbit.android.jobqueue.test.timer.MockTimer) RunningJobSet(com.birbit.android.jobqueue.RunningJobSet) Test(org.junit.Test)

Example 8 with MockTimer

use of com.birbit.android.jobqueue.test.timer.MockTimer in project android-priority-jobqueue by yigit.

the class BatchingSchedulerTest method testCustomDuration.

@Test
public void testCustomDuration() {
    scheduler = mock(Scheduler.class);
    timer = new MockTimer();
    bs = new BatchingScheduler(scheduler, timer, 123);
    MatcherAssert.assertThat(bs.batchingDurationInMs, CoreMatchers.is(123L));
    MatcherAssert.assertThat(bs.batchingDurationInNs, CoreMatchers.is(123000000L));
}
Also used : MockTimer(com.birbit.android.jobqueue.test.timer.MockTimer) BatchingScheduler(com.birbit.android.jobqueue.BatchingScheduler) Scheduler(com.birbit.android.jobqueue.scheduling.Scheduler) BatchingScheduler(com.birbit.android.jobqueue.BatchingScheduler) Test(org.junit.Test)

Example 9 with MockTimer

use of com.birbit.android.jobqueue.test.timer.MockTimer in project android-priority-jobqueue by yigit.

the class BatchingSchedulerTest method init.

@Before
public void init() {
    scheduler = mock(Scheduler.class);
    timer = new MockTimer();
    bs = new BatchingScheduler(scheduler, timer);
    Context context = mock(Context.class);
    when(context.getApplicationContext()).thenReturn(mock(Context.class));
    bs.init(context, mock(Scheduler.Callback.class));
}
Also used : Context(android.content.Context) MockTimer(com.birbit.android.jobqueue.test.timer.MockTimer) BatchingScheduler(com.birbit.android.jobqueue.BatchingScheduler) Scheduler(com.birbit.android.jobqueue.scheduling.Scheduler) BatchingScheduler(com.birbit.android.jobqueue.BatchingScheduler) Before(org.junit.Before)

Example 10 with MockTimer

use of com.birbit.android.jobqueue.test.timer.MockTimer in project android-priority-jobqueue by yigit.

the class JobParamsTest method assertParamsUnderstood.

@Test
public void assertParamsUnderstood() {
    MockTimer mockTimer = new MockTimer();
    JobHolder j1 = JobQueueTestBase.createNewJobHolder(new Params(1).requireNetwork(), mockTimer);
    assertThat("require network param should be understood properly", j1.getRequiredNetworkType(), equalTo(NetworkUtil.METERED));
    JobHolder j2 = JobQueueTestBase.createNewJobHolder(new Params(1).groupBy("blah"), mockTimer);
    assertThat("group param should be understood properly", j2.getGroupId(), equalTo("blah"));
    assertThat("require network param should be understood properly", j2.getRequiredNetworkType(), equalTo(NetworkUtil.DISCONNECTED));
    JobHolder j3 = JobQueueTestBase.createNewJobHolder(new Params(1).persist(), mockTimer);
    assertThat("persist param should be understood properly", j3.persistent, equalTo(true));
    JobHolder j4 = JobQueueTestBase.createNewJobHolder(new Params(1).setPersistent(false).setRequiresNetwork(false).setGroupId(null).setSingleId(null), mockTimer);
    assertThat("persist param should be understood properly", j4.persistent, equalTo(false));
    assertThat("require network param should be understood properly", j4.getRequiredNetworkType(), equalTo(NetworkUtil.DISCONNECTED));
    assertThat("group param should be understood properly", j4.groupId, nullValue());
    assertThat("single param should be understood properly", j4.getSingleInstanceId(), nullValue());
    mockTimer.incrementMs(2);
    DummyJob j15 = new DummyJob(new Params(1).singleInstanceBy("bloop"));
    assertThat("single param should be understood properly", j15.getSingleInstanceId(), endsWith("bloop"));
    assertThat("group param should be automatically set if single instance", j15.getRunGroupId(), notNullValue());
    mockTimer.setNow(150);
    JobHolder j6 = JobQueueTestBase.createNewJobHolder(new Params(1), mockTimer);
    assertThat("no deadline", j6.getDeadlineNs(), is(Params.FOREVER));
    JobHolder j7 = JobQueueTestBase.createNewJobHolder(new Params(1).overrideDeadlineToCancelInMs(100), mockTimer);
    assertThat("100 ms deadline", j7.getDeadlineNs(), is(100000150L));
    assertThat("100 ms deadline", j7.shouldCancelOnDeadline(), is(true));
    JobHolder j13 = JobQueueTestBase.createNewJobHolder(new Params(1).overrideDeadlineToCancelInMs(200), mockTimer);
    assertThat("100 ms deadline", j13.getDeadlineNs(), is(200000150L));
    assertThat("100 ms deadline", j7.shouldCancelOnDeadline(), is(true));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) MockTimer(com.birbit.android.jobqueue.test.timer.MockTimer) DummyJob(com.birbit.android.jobqueue.test.jobs.DummyJob) Params(com.birbit.android.jobqueue.Params) Test(org.junit.Test)

Aggregations

MockTimer (com.birbit.android.jobqueue.test.timer.MockTimer)14 Test (org.junit.Test)12 CommandMessage (com.birbit.android.jobqueue.messaging.message.CommandMessage)7 CountDownLatch (java.util.concurrent.CountDownLatch)4 RunningJobSet (com.birbit.android.jobqueue.RunningJobSet)3 BatchingScheduler (com.birbit.android.jobqueue.BatchingScheduler)2 JobHolder (com.birbit.android.jobqueue.JobHolder)2 Scheduler (com.birbit.android.jobqueue.scheduling.Scheduler)2 Context (android.content.Context)1 Consumer (com.birbit.android.jobqueue.ConsumerManager.Consumer)1 Params (com.birbit.android.jobqueue.Params)1 MessageFactory (com.birbit.android.jobqueue.messaging.MessageFactory)1 MessageQueueConsumer (com.birbit.android.jobqueue.messaging.MessageQueueConsumer)1 PriorityMessageQueue (com.birbit.android.jobqueue.messaging.PriorityMessageQueue)1 SafeMessageQueue (com.birbit.android.jobqueue.messaging.SafeMessageQueue)1 RunJobMessage (com.birbit.android.jobqueue.messaging.message.RunJobMessage)1 DummyJob (com.birbit.android.jobqueue.test.jobs.DummyJob)1 AssertionFailedError (junit.framework.AssertionFailedError)1 Before (org.junit.Before)1