Search in sources :

Example 46 with Params

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

the class SqliteJobQueueTest method testClearTags.

@Test
public void testClearTags() throws Throwable {
    SqliteJobQueue queue = (SqliteJobQueue) createNewJobQueue();
    JobHolder vh1 = createNewJobHolder(new Params(1).addTags("a", "b", "c"));
    JobHolder vh2 = createNewJobHolder(new Params(1).addTags("a", "b", "x"));
    queue.insert(vh1);
    queue.insert(vh2);
    assertTags(queue, new TagInfo(0, vh1.getId(), "a"), new TagInfo(0, vh1.getId(), "b"), new TagInfo(0, vh1.getId(), "c"), new TagInfo(0, vh2.getId(), "a"), new TagInfo(0, vh2.getId(), "b"), new TagInfo(0, vh2.getId(), "x"));
    queue.remove(vh2);
    assertTags(queue, new TagInfo(0, vh1.getId(), "a"), new TagInfo(0, vh1.getId(), "b"), new TagInfo(0, vh1.getId(), "c"));
    queue.clear();
    assertTags(queue);
}
Also used : JobHolder(com.birbit.android.jobqueue.JobHolder) SqliteJobQueue(com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue) Params(com.birbit.android.jobqueue.Params) Test(org.junit.Test)

Example 47 with Params

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

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

the class JobQueueTestBase method testDeadline.

private void testDeadline(boolean cancel) throws Exception {
    JobQueue jobQueue = createNewJobQueue();
    Params params = new Params(0).requireNetwork();
    if (cancel) {
        params.overrideDeadlineToCancelInMs(100);
    } else {
        params.overrideDeadlineToRunInMs(100);
    }
    JobHolder requireNetwork = createNewJobHolder(params);
    jobQueue.insert(requireNetwork);
    TestConstraint testConstraint = new TestConstraint(mockTimer);
    testConstraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
    assertThat("when a job w/ a deadline is given, it should not be returned if not ready", jobQueue.nextJobAndIncRunCount(testConstraint), is(nullValue()));
    assertThat("when a job w/ a deadline is given, it should show up in next job ready query", jobQueue.getNextJobDelayUntilNs(testConstraint), is(100 * JobManager.NS_PER_MS));
    mockTimer.incrementMs(100);
    JobHolder nextJob = jobQueue.nextJobAndIncRunCount(testConstraint);
    assertThat("when a job reaches deadline, it should be returned", nextJob, is(notNullValue()));
    assertThat("when a job reaches deadline, it should be returned", nextJob.getId(), is(requireNetwork.getId()));
    assertThat(nextJob.shouldCancelOnDeadline(), is(cancel));
}
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)

Example 49 with Params

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

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

Aggregations

Params (com.birbit.android.jobqueue.Params)95 Test (org.junit.Test)75 JobManager (com.birbit.android.jobqueue.JobManager)47 JobHolder (com.birbit.android.jobqueue.JobHolder)46 DummyJob (com.birbit.android.jobqueue.test.jobs.DummyJob)41 JobQueue (com.birbit.android.jobqueue.JobQueue)40 TestConstraint (com.birbit.android.jobqueue.TestConstraint)37 Job (com.birbit.android.jobqueue.Job)31 CountDownLatch (java.util.concurrent.CountDownLatch)31 Configuration (com.birbit.android.jobqueue.config.Configuration)17 RetryConstraint (com.birbit.android.jobqueue.RetryConstraint)12 TargetApi (android.annotation.TargetApi)9 CancelResult (com.birbit.android.jobqueue.CancelResult)9 Constraint (com.birbit.android.jobqueue.Constraint)8 TagConstraint (com.birbit.android.jobqueue.TagConstraint)8 JobManagerCallbackAdapter (com.birbit.android.jobqueue.callback.JobManagerCallbackAdapter)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 ArrayList (java.util.ArrayList)6 JobManagerCallback (com.birbit.android.jobqueue.callback.JobManagerCallback)4 SqliteJobQueue (com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue)3