Search in sources :

Example 26 with TestConstraint

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

the class JobQueueTestBase method testNoDeadline.

@Test
public void testNoDeadline() throws Exception {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder requireNetwork = createNewJobHolder(new Params(0).requireNetwork());
    jobQueue.insert(requireNetwork);
    TestConstraint testConstraint = new TestConstraint(mockTimer);
    testConstraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
    assertThat("when a job w/o a deadline is given, it should not be returned if not ready", jobQueue.nextJobAndIncRunCount(testConstraint), is(nullValue()));
    assertThat("when a job w/o a deadline is given, it should not be returned in next ready", jobQueue.getNextJobDelayUntilNs(testConstraint), is(nullValue()));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) TestConstraint(com.birbit.android.jobqueue.TestConstraint) JobQueue(com.birbit.android.jobqueue.JobQueue) Params(com.birbit.android.jobqueue.Params) Test(org.junit.Test)

Example 27 with TestConstraint

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

the class JobQueueTestBase method testDelayUntilWithUnmeteredNetworkRequirement4.

@Test
public void testDelayUntilWithUnmeteredNetworkRequirement4() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(3000).requireUnmeteredNetwork().delayInMs(2000));
    jobQueue.insert(holder1);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setMaxNetworkType(NetworkUtil.UNMETERED);
    assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(2000000000L));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) TestConstraint(com.birbit.android.jobqueue.TestConstraint) JobQueue(com.birbit.android.jobqueue.JobQueue) Params(com.birbit.android.jobqueue.Params) Test(org.junit.Test)

Example 28 with TestConstraint

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

the class JobQueueTestBase method testRemove.

@Test
public void testRemove() throws Exception {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder holder = createNewJobHolder();
    jobQueue.insert(holder);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setExcludeRunning(true);
    assertThat(jobQueue.nextJobAndIncRunCount(constraint).getId(), equalTo(holder.getId()));
    assertThat(jobQueue.nextJobAndIncRunCount(constraint), is(nullValue()));
    jobQueue.remove(holder);
    assertThat(jobQueue.nextJobAndIncRunCount(constraint), is(nullValue()));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) TestConstraint(com.birbit.android.jobqueue.TestConstraint) JobQueue(com.birbit.android.jobqueue.JobQueue) Test(org.junit.Test)

Example 29 with TestConstraint

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

the class JobQueueTestBase method testDelayUntilWithNetworkRequirement3.

@Test
public void testDelayUntilWithNetworkRequirement3() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(2000).delayInMs(1000).requireNetwork());
    jobQueue.insert(holder1);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setMaxNetworkType(NetworkUtil.UNMETERED);
    assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(1000000000L));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) TestConstraint(com.birbit.android.jobqueue.TestConstraint) JobQueue(com.birbit.android.jobqueue.JobQueue) Params(com.birbit.android.jobqueue.Params) Test(org.junit.Test)

Example 30 with TestConstraint

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

the class JobQueueTestBase method testDelayUntilWithNetworkRequirement2.

@Test
public void testDelayUntilWithNetworkRequirement2() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(3000).delayInMs(2000).requireNetwork());
    jobQueue.insert(holder1);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
    assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(3000000000L));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) TestConstraint(com.birbit.android.jobqueue.TestConstraint) JobQueue(com.birbit.android.jobqueue.JobQueue) Params(com.birbit.android.jobqueue.Params) Test(org.junit.Test)

Aggregations

TestConstraint (com.birbit.android.jobqueue.TestConstraint)39 JobQueue (com.birbit.android.jobqueue.JobQueue)38 Test (org.junit.Test)38 JobHolder (com.birbit.android.jobqueue.JobHolder)37 Params (com.birbit.android.jobqueue.Params)35 Constraint (com.birbit.android.jobqueue.Constraint)5 TagConstraint (com.birbit.android.jobqueue.TagConstraint)5 Job (com.birbit.android.jobqueue.Job)1 SqliteJobQueue (com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue)1 CountDownLatch (java.util.concurrent.CountDownLatch)1