use of com.birbit.android.jobqueue.TagConstraint in project android-priority-jobqueue by yigit.
the class CancelFailingJobsTest method testCancelWithoutNetwork.
public void testCancelWithoutNetwork(boolean async, TagConstraint constraint) throws InterruptedException {
final int jobCount = 30;
JobManager jobManager = createJobManager(new Configuration.Builder(RuntimeEnvironment.application).minConsumerCount(5).networkUtil(networkUtil).timer(mockTimer));
networkUtil.setNetworkStatus(NetworkUtil.DISCONNECTED, true);
for (int i = 0; i < jobCount; i++) {
jobManager.addJob(new FailingJob(new Params(i).groupBy("group").addTags("tag")));
}
final CancelResult[] result = new CancelResult[1];
if (async) {
final CountDownLatch cancelLatch = new CountDownLatch(1);
jobManager.cancelJobsInBackground(new CancelResult.AsyncCancelCallback() {
@Override
public void onCancelled(CancelResult cancelResult) {
result[0] = cancelResult;
cancelLatch.countDown();
}
}, constraint, "tag");
assertThat(cancelLatch.await(jobCount, TimeUnit.SECONDS), is(true));
} else {
result[0] = jobManager.cancelJobs(TagConstraint.ANY, "tag");
}
assertThat("all jobs should be cancelled", result[0].getCancelledJobs().size(), is(jobCount));
assertThat("no jobs should fail to cancel", result[0].getFailedToCancel().size(), is(0));
final CountDownLatch runLatch = new CountDownLatch(1);
jobManager.addJob(new DummyJob(new Params(1).groupBy("group").addTags("tag")) {
@Override
public void onRun() throws Throwable {
super.onRun();
runLatch.countDown();
}
});
networkUtil.setNetworkStatus(NetworkUtil.UNMETERED, true);
assertThat("new job should run w/o any issues", runLatch.await(2, TimeUnit.SECONDS), is(true));
}
Aggregations