Search in sources :

Example 6 with SchedulerConstraint

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

the class BatchingSchedulerTest method testTwoWithDeadlinesAndBatch.

@Test
public void testTwoWithDeadlinesAndBatch() {
    SchedulerConstraint constraint = createConstraint(NetworkUtil.METERED, 0, 10L);
    bs.request(constraint);
    SchedulerConstraint constraint2 = createConstraint(NetworkUtil.METERED, 0, 20L);
    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));
    MatcherAssert.assertThat(constraint.getOverrideDeadlineInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
}
Also used : SchedulerConstraint(com.birbit.android.jobqueue.scheduling.SchedulerConstraint) Test(org.junit.Test)

Example 7 with SchedulerConstraint

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

the class BatchingSchedulerTest method testAddTwoOfTheSameWithEnoughDeadline.

@Test
public void testAddTwoOfTheSameWithEnoughDeadline() {
    SchedulerConstraint constraint = createConstraint(NetworkUtil.METERED, 0, 0L);
    bs.request(constraint);
    SchedulerConstraint constraint2 = createConstraint(NetworkUtil.METERED, 0, BatchingScheduler.DEFAULT_BATCHING_PERIOD_IN_MS);
    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(constraint.getOverrideDeadlineInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
    MatcherAssert.assertThat(constraint2.getOverrideDeadlineInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS * 2));
}
Also used : SchedulerConstraint(com.birbit.android.jobqueue.scheduling.SchedulerConstraint) Test(org.junit.Test)

Example 8 with SchedulerConstraint

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

the class BatchingSchedulerTest method testAddTwoOfTheSameWithDelayWithTimeDiff.

@Test
public void testAddTwoOfTheSameWithDelayWithTimeDiff() {
    SchedulerConstraint constraint = createConstraint(NetworkUtil.METERED, 0);
    bs.request(constraint);
    timer.incrementMs(DEFAULT_BATCHING_PERIOD_IN_MS - 101);
    SchedulerConstraint constraint2 = createConstraint(NetworkUtil.METERED, 100);
    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 9 with SchedulerConstraint

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

the class BatchingSchedulerTest method testAddTwoOfTheSameWithDelay.

@Test
public void testAddTwoOfTheSameWithDelay() {
    SchedulerConstraint constraint = createConstraint(NetworkUtil.METERED, 0);
    bs.request(constraint);
    SchedulerConstraint constraint2 = createConstraint(NetworkUtil.METERED, 100);
    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 10 with SchedulerConstraint

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

the class BatchingSchedulerTest method testAddTwoOfTheSameWithEnoughDelay.

@Test
public void testAddTwoOfTheSameWithEnoughDelay() {
    SchedulerConstraint constraint = createConstraint(NetworkUtil.METERED, 0);
    bs.request(constraint);
    SchedulerConstraint constraint2 = createConstraint(NetworkUtil.METERED, BatchingScheduler.DEFAULT_BATCHING_PERIOD_IN_MS);
    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 * 2));
}
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