Search in sources :

Example 21 with JobQueue

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

the class JobQueueTestBase method testDelayUntilWithNetworkRequirementAndRegularDelayedJob3.

@Test
public void testDelayUntilWithNetworkRequirementAndRegularDelayedJob3() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(500).requireNetwork());
    JobHolder holder2 = createNewJobHolder(new Params(2).delayInMs(1000));
    jobQueue.insert(holder1);
    jobQueue.insert(holder2);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
    assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(500000000L));
}
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 22 with JobQueue

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

the class JobQueueTestBase method testDelayUntilWithNetworkRequirement.

@Test
public void testDelayUntilWithNetworkRequirement() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder holder1 = createNewJobHolder(new Params(2).requireNetwork().overrideDeadlineToRunInMs(1000));
    jobQueue.insert(holder1);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
    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 23 with JobQueue

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

the class JobQueueTestBase method testDeadlineDoesNotAffectExcludeRunning.

@Test
public void testDeadlineDoesNotAffectExcludeRunning() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder jobHolder = createNewJobHolder(new Params(0).overrideDeadlineToRunInMs(10));
    jobQueue.insert(jobHolder);
    TestConstraint testConstraint = new TestConstraint(mockTimer);
    assertThat(jobQueue.nextJobAndIncRunCount(testConstraint).getId(), is(jobHolder.getId()));
    mockTimer.incrementMs(100);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setExcludeRunning(true);
    assertThat(jobQueue.findJobs(constraint), is(Collections.EMPTY_SET));
    assertThat(jobQueue.getNextJobDelayUntilNs(constraint), 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 24 with JobQueue

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

the class JobQueueTestBase method testDeadlineDoesNotAffectExcludeGroupQuery.

@Test
public void testDeadlineDoesNotAffectExcludeGroupQuery() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder jobHolder = createNewJobHolder(new Params(0).groupBy("g1").overrideDeadlineToRunInMs(10));
    jobQueue.insert(jobHolder);
    mockTimer.incrementMs(100);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setExcludeGroups(Arrays.asList("g1"));
    assertThat(jobQueue.findJobs(constraint), is(Collections.EMPTY_SET));
    assertThat(jobQueue.getNextJobDelayUntilNs(constraint), 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 25 with JobQueue

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

the class JobQueueTestBase method testDelayUntilWithRunningJobs.

@Test
public void testDelayUntilWithRunningJobs() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder holder = createNewJobHolder();
    jobQueue.insert(holder);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setMaxNetworkType(NetworkUtil.METERED);
    constraint.setExcludeRunning(true);
    assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(JobManager.NOT_DELAYED_JOB_DELAY));
    JobHolder nextJob = jobQueue.nextJobAndIncRunCount(constraint);
    assertThat(nextJob, is(notNullValue()));
    assertThat(nextJob.getId(), is(holder.getId()));
    assertThat(jobQueue.getNextJobDelayUntilNs(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)

Aggregations

JobQueue (com.birbit.android.jobqueue.JobQueue)45 Test (org.junit.Test)44 JobHolder (com.birbit.android.jobqueue.JobHolder)42 TestConstraint (com.birbit.android.jobqueue.TestConstraint)41 Params (com.birbit.android.jobqueue.Params)40 Constraint (com.birbit.android.jobqueue.Constraint)9 TagConstraint (com.birbit.android.jobqueue.TagConstraint)8 SuppressLint (android.annotation.SuppressLint)1 Job (com.birbit.android.jobqueue.Job)1 JobManager (com.birbit.android.jobqueue.JobManager)1 QueueFactory (com.birbit.android.jobqueue.QueueFactory)1 Configuration (com.birbit.android.jobqueue.config.Configuration)1 SimpleInMemoryPriorityQueue (com.birbit.android.jobqueue.inMemoryQueue.SimpleInMemoryPriorityQueue)1 SqliteJobQueue (com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue)1 DummyJob (com.birbit.android.jobqueue.test.jobs.DummyJob)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1