Search in sources :

Example 11 with SchedulerConstraint

use of com.birbit.android.jobqueue.scheduling.SchedulerConstraint in project android-priority-jobqueue by yigit.

the class JobManagerThread method invokeSchedulersIfIdle.

private void invokeSchedulersIfIdle() {
    if (scheduler == null || pendingSchedulerCallbacks == null || pendingSchedulerCallbacks.isEmpty() || !consumerManager.areAllConsumersIdle()) {
        return;
    }
    for (int i = pendingSchedulerCallbacks.size() - 1; i >= 0; i--) {
        SchedulerConstraint constraint = pendingSchedulerCallbacks.remove(i);
        boolean reschedule = hasJobsWithSchedulerConstraint(constraint);
        scheduler.onFinished(constraint, reschedule);
    }
}
Also used : SchedulerConstraint(com.birbit.android.jobqueue.scheduling.SchedulerConstraint) SchedulerConstraint(com.birbit.android.jobqueue.scheduling.SchedulerConstraint)

Example 12 with SchedulerConstraint

use of com.birbit.android.jobqueue.scheduling.SchedulerConstraint in project android-priority-jobqueue by yigit.

the class BatchingSchedulerTest method createConstraint.

private static SchedulerConstraint createConstraint(int networkStatus, long delay, Long deadline) {
    SchedulerConstraint constraint = new SchedulerConstraint("abc");
    constraint.setDelayInMs(delay);
    constraint.setNetworkStatus(networkStatus);
    constraint.setOverrideDeadlineInMs(deadline);
    return constraint;
}
Also used : SchedulerConstraint(com.birbit.android.jobqueue.scheduling.SchedulerConstraint)

Example 13 with SchedulerConstraint

use of com.birbit.android.jobqueue.scheduling.SchedulerConstraint in project android-priority-jobqueue by yigit.

the class BatchingSchedulerTest method testAddTwoOfTheSameWithTimeDiff.

@Test
public void testAddTwoOfTheSameWithTimeDiff() {
    SchedulerConstraint constraint = createConstraint(NetworkUtil.METERED, 0);
    bs.request(constraint);
    timer.incrementMs(DEFAULT_BATCHING_PERIOD_IN_MS - 10);
    SchedulerConstraint constraint2 = createConstraint(NetworkUtil.METERED, 0);
    bs.request(constraint2);
    verify(scheduler, times(1)).request(constraint);
    verify(scheduler, times(0)).request(constraint2);
    MatcherAssert.assertThat(constraint.getDelayInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
}
Also used : SchedulerConstraint(com.birbit.android.jobqueue.scheduling.SchedulerConstraint) Test(org.junit.Test)

Example 14 with SchedulerConstraint

use of com.birbit.android.jobqueue.scheduling.SchedulerConstraint in project android-priority-jobqueue by yigit.

the class BatchingSchedulerTest method testSecondWithDeadline.

@Test
public void testSecondWithDeadline() {
    SchedulerConstraint constraint = createConstraint(NetworkUtil.METERED, 0);
    bs.request(constraint);
    SchedulerConstraint constraint2 = createConstraint(NetworkUtil.METERED, 0, 10L);
    bs.request(constraint2);
    verify(scheduler, times(1)).request(constraint);
    verify(scheduler, times(1)).request(constraint2);
    MatcherAssert.assertThat(constraint.getDelayInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
    MatcherAssert.assertThat(constraint2.getDelayInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
    MatcherAssert.assertThat(constraint2.getOverrideDeadlineInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
}
Also used : SchedulerConstraint(com.birbit.android.jobqueue.scheduling.SchedulerConstraint) Test(org.junit.Test)

Example 15 with SchedulerConstraint

use of com.birbit.android.jobqueue.scheduling.SchedulerConstraint in project android-priority-jobqueue by yigit.

the class BatchingSchedulerTest method testAddTwoOfTheSame.

@Test
public void testAddTwoOfTheSame() {
    SchedulerConstraint constraint = createConstraint(NetworkUtil.METERED, 0);
    bs.request(constraint);
    SchedulerConstraint constraint2 = createConstraint(NetworkUtil.METERED, 0);
    bs.request(constraint2);
    verify(scheduler, times(1)).request(constraint);
    verify(scheduler, times(0)).request(constraint2);
    MatcherAssert.assertThat(constraint.getDelayInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
}
Also used : SchedulerConstraint(com.birbit.android.jobqueue.scheduling.SchedulerConstraint) Test(org.junit.Test)

Aggregations

SchedulerConstraint (com.birbit.android.jobqueue.scheduling.SchedulerConstraint)18 Test (org.junit.Test)14 JobManager (com.birbit.android.jobqueue.JobManager)1 Params (com.birbit.android.jobqueue.Params)1 Configuration (com.birbit.android.jobqueue.config.Configuration)1 Scheduler (com.birbit.android.jobqueue.scheduling.Scheduler)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1