Search in sources :

Example 21 with JobHolder

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

the class JobQueueTestBase method testSessionId.

@Test
public void testSessionId() throws Exception {
    long sessionId = (long) (Math.random() * 100000);
    JobQueue jobQueue = createNewJobQueueWithSessionId(sessionId);
    JobHolder jobHolder = createNewJobHolder();
    jobQueue.insert(jobHolder);
    jobHolder = jobQueue.nextJobAndIncRunCount(new TestConstraint(mockTimer));
    assertThat("session id should be attached to next job", jobHolder.getRunningSessionId(), equalTo(sessionId));
}
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 22 with JobHolder

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

the class JobQueueTestBase method testDelayUntilWithNetworkRequirementAndRegularDelayedJob4.

@Test
public void testDelayUntilWithNetworkRequirementAndRegularDelayedJob4() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(500).requireNetwork());
    JobHolder holder2 = createNewJobHolder(new Params(2).delayInMs(1000));
    jobQueue.insert(holder2);
    jobQueue.insert(holder1);
    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 23 with JobHolder

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

the class JobQueueTestBase method testDeadlineDoesNotAffectIdQuery.

@Test
public void testDeadlineDoesNotAffectIdQuery() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder jobHolder = createNewJobHolder(new Params(0).overrideDeadlineToRunInMs(10));
    jobQueue.insert(jobHolder);
    mockTimer.incrementMs(100);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setExcludeJobIds(Collections.singletonList(jobHolder.getId()));
    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 JobHolder

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

the class JobQueueTestBase method testDelayUntilWithUnmeteredNetworkRequirement3.

@Test
public void testDelayUntilWithUnmeteredNetworkRequirement3() {
    JobQueue jobQueue = createNewJobQueue();
    JobHolder holder1 = createNewJobHolder(new Params(2).overrideDeadlineToRunInMs(2000).requireUnmeteredNetwork().delayInMs(1000));
    jobQueue.insert(holder1);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setMaxNetworkType(NetworkUtil.METERED);
    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 25 with JobHolder

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

the class JobQueueTestBase method testDelayUntilWithNetworkRequirement5.

@Test
public void testDelayUntilWithNetworkRequirement5() {
    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.METERED);
    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)

Aggregations

JobHolder (com.birbit.android.jobqueue.JobHolder)62 Test (org.junit.Test)50 Params (com.birbit.android.jobqueue.Params)46 JobQueue (com.birbit.android.jobqueue.JobQueue)42 TestConstraint (com.birbit.android.jobqueue.TestConstraint)39 Constraint (com.birbit.android.jobqueue.Constraint)8 TagConstraint (com.birbit.android.jobqueue.TagConstraint)7 DummyJob (com.birbit.android.jobqueue.test.jobs.DummyJob)7 JobManager (com.birbit.android.jobqueue.JobManager)6 Job (com.birbit.android.jobqueue.Job)4 Cursor (android.database.Cursor)2 Consumer (com.birbit.android.jobqueue.ConsumerManager.Consumer)2 Configuration (com.birbit.android.jobqueue.config.Configuration)2 MessageFactory (com.birbit.android.jobqueue.messaging.MessageFactory)2 MessageQueueConsumer (com.birbit.android.jobqueue.messaging.MessageQueueConsumer)2 PriorityMessageQueue (com.birbit.android.jobqueue.messaging.PriorityMessageQueue)2 SafeMessageQueue (com.birbit.android.jobqueue.messaging.SafeMessageQueue)2 RunJobMessage (com.birbit.android.jobqueue.messaging.message.RunJobMessage)2 MockTimer (com.birbit.android.jobqueue.test.timer.MockTimer)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2