Search in sources :

Example 11 with JobQueue

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

the class JobQueueTestBase method testFindByTags.

@Test
public void testFindByTags() {
    JobQueue jobQueue = createNewJobQueue();
    assertThat("empty queue should return 0", jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), "abc")).size(), is(0));
    jobQueue.insert(createNewJobHolder());
    Set<JobHolder> result = jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), "blah"));
    assertThat("if job does not have a tag, it should return 0", result.size(), is(0));
    final String tag1 = UUID.randomUUID().toString();
    JobHolder holder = createNewJobHolder(new Params(0).addTags(tag1));
    jobQueue.insert(holder);
    assertTags("holder with 1 tag", jobQueue, holder);
    jobQueue.insertOrReplace(holder);
    assertTags("holder with 1 tag reinserted", jobQueue, holder);
    jobQueue.remove(holder);
    assertThat("when job is removed, it should return none", jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), tag1)).size(), is(0));
    JobHolder holder2 = createNewJobHolder(new Params(0).addTags(tag1));
    jobQueue.insert(holder2);
    assertThat("it should return the job", jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), tag1)).size(), is(1));
    jobQueue.onJobCancelled(holder2);
    assertThat("when queried w/ exclude cancelled, it should not return the job", jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), tag1)).size(), is(0));
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) JobQueue(com.birbit.android.jobqueue.JobQueue) Params(com.birbit.android.jobqueue.Params) Test(org.junit.Test)

Example 12 with JobQueue

use of com.birbit.android.jobqueue.JobQueue 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 13 with JobQueue

use of com.birbit.android.jobqueue.JobQueue 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 14 with JobQueue

use of com.birbit.android.jobqueue.JobQueue 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 15 with JobQueue

use of com.birbit.android.jobqueue.JobQueue 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)

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