use of com.birbit.android.jobqueue.JobManager in project android-priority-jobqueue by yigit.
the class PriorityTest method testPriority.
@Test
public void testPriority() throws Exception {
JobManager jobManager = createJobManager(new Configuration.Builder(RuntimeEnvironment.application).maxConsumerCount(1).timer(mockTimer));
testPriority(jobManager, false);
}
use of com.birbit.android.jobqueue.JobManager in project android-priority-jobqueue by yigit.
the class RetryLogicTest method testChangePriorityAndObserveExecutionOrder.
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public void testChangePriorityAndObserveExecutionOrder(boolean persistent) throws InterruptedException {
cancelLatch = new CountDownLatch(2);
RetryJob job1 = new RetryJob(new Params(10).setPersistent(persistent).groupBy("group"));
job1.identifier = "1";
RetryJob job2 = new RetryJob(new Params(5).setPersistent(persistent).groupBy("group"));
job2.identifier = "2";
JobManager jobManager = createJobManager();
jobManager.stop();
jobManager.addJob(job1);
jobManager.addJob(job2);
retryProvider = new RetryProvider() {
@Override
public RetryConstraint build(Job job, Throwable throwable, int runCount, int maxRunCount) {
RetryJob retryJob = (RetryJob) job;
if ("1".equals(retryJob.identifier)) {
if (retryJob.getPriority() == 1) {
return RetryConstraint.CANCEL;
}
RetryConstraint retryConstraint = new RetryConstraint(true);
retryConstraint.setNewPriority(1);
return retryConstraint;
} else {
return RetryConstraint.CANCEL;
}
}
};
final List<String> runOrder = new ArrayList<>();
onRunCallback = new Callback() {
@Override
public void on(Job job) {
runOrder.add(((RetryJob) job).identifier);
}
};
canRun = true;
jobManager.start();
assertThat("both jobs should be canceled eventually", cancelLatch.await(3, TimeUnit.MINUTES), is(true));
assertThat("jobs should run a total of 3 times", runCount, is(3));
final List<String> expectedRunOrder = Arrays.asList("1", "2", "1");
assertThat("expected run order count should match", runOrder.size(), is(expectedRunOrder.size()));
for (int i = 0; i < expectedRunOrder.size(); i++) {
assertThat("at iteration " + i + ", this job should run", runOrder.get(i), is(expectedRunOrder.get(i)));
}
}
use of com.birbit.android.jobqueue.JobManager in project android-priority-jobqueue by yigit.
the class SingleIdTest method testSingleIdRunning.
private void testSingleIdRunning(boolean persistent) throws InterruptedException {
JobManager jobManager = createJobManager();
String singleId = "dorks";
CountDownLatch latchWait = new CountDownLatch(1);
CountDownLatch latchRunning = new CountDownLatch(1);
DummyJob dummyJob1 = new SerializableDummyTwoLatchJob(new Params(0).setPersistent(persistent).setSingleId(singleId).setGroupId(singleId), latchWait, latchRunning);
addJob(jobManager, dummyJob1);
jobManager.start();
//let job1 start running
latchRunning.await(5, TimeUnit.SECONDS);
jobManager.stop();
assertThat("should not be marked ready", jobManager.count(), is(0));
CountDownLatch latchRunning2 = new CountDownLatch(1);
DummyJob dummyJob2 = new SerializableDummyLatchJob(new Params(0).setPersistent(persistent).setSingleId(singleId).setGroupId(singleId), latchRunning2);
addJob(jobManager, dummyJob2);
assertThat("should add new job if first job was running", jobManager.count(), is(1));
DummyJob dummyJob3 = new DummyJob(new Params(0).setPersistent(persistent).setSingleId(singleId).setGroupId(singleId));
addJob(jobManager, dummyJob3);
assertThat("should not add new job if already queued", jobManager.count(), is(1));
//let job1 finish
latchWait.countDown();
jobManager.start();
//wait until job2 runs
assertThat("job should have run", latchRunning2.await(5, TimeUnit.SECONDS), is(true));
jobManager.stopAndWaitUntilConsumersAreFinished();
assertThat("job should not have run", dummyJob3.getOnRunCnt(), is(0));
assertThat("should have called onCancel", dummyJob3.getOnCancelCnt(), is(1));
DummyJob dummyJob4 = new DummyJob(new Params(0).setPersistent(persistent).setSingleId(singleId).setGroupId(singleId));
addJob(jobManager, dummyJob4);
assertThat("should be added if all others have run", jobManager.count(), is(1));
}
use of com.birbit.android.jobqueue.JobManager in project android-priority-jobqueue by yigit.
the class SlowOnAddedTest method testPersistent.
@Test
public void testPersistent() throws InterruptedException {
JobManager jobManager = createJobManager();
MyDummyPersistentJob.persistentJobLatch = new CountDownLatch(1);
for (int i = 0; i < 50; i++) {
jobManager.addJob(new DummyJob(new Params(1).persist()));
}
jobManager.addJob(new MyDummyPersistentJob(2));
MyDummyPersistentJob.persistentJobLatch.await();
assertThat("even if job is persistent, onAdded should be called b4 onRun", MyDummyPersistentJob.onAddedCountWhenOnRun, equalTo(1));
}
use of com.birbit.android.jobqueue.JobManager in project android-priority-jobqueue by yigit.
the class AddedCountTest method testAddedCount.
private void testAddedCount(DummyJob dummyJob) {
JobManager jobManager = createJobManager();
jobManager.stop();
jobManager.addJob(dummyJob);
MatcherAssert.assertThat(1, equalTo(dummyJob.getOnAddedCnt()));
}
Aggregations