Search in sources :

Example 16 with JobQueue

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

Example 17 with JobQueue

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

the class JobQueueTestBase method testDelayUntilWithUnmeteredNetworkRequirementAndRegularDelayedJob3.

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

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

the class JobQueueTestBase method testDelayUntilWithUnmeteredNetworkRequirementAndRegularDelayedJob2.

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

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

the class JobQueueTestBase method testDelayUntilWithUnmeteredNetworkRequirementAndRegularDelayedJob4.

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

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

the class JobQueueTestBase method testDelayUntil.

@Test
public void testDelayUntil() throws Exception {
    JobQueue jobQueue = createNewJobQueue();
    long now = mockTimer.nanoTime();
    JobHolder networkJobHolder = createNewJobHolderWithDelayUntil(new Params(0).requireNetwork(), now + 2);
    JobHolder noNetworkJobHolder = createNewJobHolderWithDelayUntil(new Params(0), now + 5);
    jobQueue.insert(networkJobHolder);
    jobQueue.insert(noNetworkJobHolder);
    TestConstraint constraint = new TestConstraint(mockTimer);
    constraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
    assertThat("if there is no network, delay until should be provided for no network job", jobQueue.getNextJobDelayUntilNs(constraint), equalTo(noNetworkJobHolder.getDelayUntilNs()));
    constraint.clear();
    constraint.setMaxNetworkType(NetworkUtil.UNMETERED);
    assertThat("if there is network, delay until should be provided for network job because it is " + "sooner", jobQueue.getNextJobDelayUntilNs(constraint), equalTo(networkJobHolder.getDelayUntilNs()));
    JobHolder noNetworkJobHolder2 = createNewJobHolderWithDelayUntil(new Params(0), now + 1);
    jobQueue.insert(noNetworkJobHolder2);
    assertThat("if there is network, any job's delay until should be returned", jobQueue.getNextJobDelayUntilNs(constraint), equalTo(noNetworkJobHolder2.getDelayUntilNs()));
}
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