use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method assertTags.
private void assertTags(String msg, JobQueue jobQueue, JobHolder holder) {
Set<JobHolder> result;
String wrongTag;
final String id = holder.getId();
boolean found;
Matcher allTagsMatcher = CoreMatchers.hasItems(holder.getTags().toArray(new String[holder.getTags().size()]));
do {
wrongTag = UUID.randomUUID().toString();
found = false;
if (holder.getTags() != null) {
for (String tag : holder.getTags()) {
if (tag.equals(wrongTag)) {
found = true;
break;
}
}
}
} while (found);
result = jobQueue.findJobs(forTags(mockTimer, ANY, Collections.<String>emptyList(), wrongTag));
found = false;
for (JobHolder received : result) {
if (received.getId().equals(holder.getId())) {
found = true;
}
}
assertThat(msg + " when wrong tag is given, our job should not return", found, is(false));
if (holder.getTags() == null) {
// done
return;
}
Collection<String> exclude = Arrays.asList(holder.getId());
for (String[] tags : combinations(holder.getTags())) {
result = jobQueue.findJobs(forTags(mockTimer, TagConstraint.ANY, Collections.<String>emptyList(), tags));
if (tags.length == 0) {
assertThat(msg + " empty tag list, should return 0 jobs", result.size(), is(0));
} else {
assertThat(msg + " any combinations: when correct tag is given, it should return one", result.size(), is(1));
assertThat(msg + " any combinations: returned job should be the correct one", result.iterator().next().getId(), is(id));
assertThat(msg + " returned holder should have all tags:", result.iterator().next().getTags(), allTagsMatcher);
}
result = jobQueue.findJobs(forTags(mockTimer, TagConstraint.ANY, exclude, tags));
assertThat(msg + " when excluded, holder should not show up in results", result.size(), is(0));
}
for (String[] tags : combinations(holder.getTags())) {
result = jobQueue.findJobs(forTags(mockTimer, ALL, Collections.<String>emptyList(), tags));
if (tags.length == 0) {
assertThat(msg + " empty tag list, should return 0 jobs", result.size(), is(0));
} else {
assertThat(msg + " all combinations: when correct tag is given, it should return one", result.size(), is(1));
assertThat(msg + " all combinations: returned job should be the correct one", result.iterator().next().getId(), is(id));
assertThat(msg + " returned holder should have all tags:", result.iterator().next().getTags(), allTagsMatcher);
}
result = jobQueue.findJobs(forTags(mockTimer, ALL, exclude, tags));
assertThat(msg + " when excluded, holder should not show up in results", result.size(), is(0));
}
for (String[] tags : combinations(holder.getTags())) {
String[] tagsWithAdditional = new String[tags.length + 1];
System.arraycopy(tags, 0, tagsWithAdditional, 0, tags.length);
tagsWithAdditional[tags.length] = wrongTag;
result = jobQueue.findJobs(forTags(mockTimer, TagConstraint.ANY, Collections.<String>emptyList(), tagsWithAdditional));
if (tags.length == 0) {
assertThat(msg + " empty tag list, should return 0 jobs", result.size(), is(0));
} else {
assertThat(msg + " any combinations with wrong tag: when correct tag is given, it should return one", result.size(), is(1));
assertThat(msg + " any combinations with wrong tag: returned job should be the correct one", result.iterator().next().getId(), is(id));
assertThat(msg + " returned holder should have all tags:", result.iterator().next().getTags(), allTagsMatcher);
}
result = jobQueue.findJobs(forTags(mockTimer, ALL, Collections.<String>emptyList(), tagsWithAdditional));
assertThat(msg + " all combinations with wrong tag: when an additional wrong tag is given, it should return 0", result.size(), is(0));
result = jobQueue.findJobs(forTags(mockTimer, ALL, exclude, tagsWithAdditional));
assertThat(msg + " when excluded, holder should not show up in results", result.size(), is(0));
}
}
use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDelayUntilWithNetworkRequirement.
@Test
public void testDelayUntilWithNetworkRequirement() {
JobQueue jobQueue = createNewJobQueue();
JobHolder holder1 = createNewJobHolder(new Params(2).requireNetwork().overrideDeadlineToRunInMs(1000));
jobQueue.insert(holder1);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setMaxNetworkType(NetworkUtil.DISCONNECTED);
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(1000000000L));
}
use of com.birbit.android.jobqueue.JobHolder in project android-priority-jobqueue by yigit.
the class JobQueueTestBase method testDeadlineDoesNotAffectExcludeRunning.
@Test
public void testDeadlineDoesNotAffectExcludeRunning() {
JobQueue jobQueue = createNewJobQueue();
JobHolder jobHolder = createNewJobHolder(new Params(0).overrideDeadlineToRunInMs(10));
jobQueue.insert(jobHolder);
TestConstraint testConstraint = new TestConstraint(mockTimer);
assertThat(jobQueue.nextJobAndIncRunCount(testConstraint).getId(), is(jobHolder.getId()));
mockTimer.incrementMs(100);
TestConstraint constraint = new TestConstraint(mockTimer);
constraint.setExcludeRunning(true);
assertThat(jobQueue.findJobs(constraint), is(Collections.EMPTY_SET));
assertThat(jobQueue.getNextJobDelayUntilNs(constraint), is(nullValue()));
}
use of com.birbit.android.jobqueue.JobHolder 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);
}
use of com.birbit.android.jobqueue.JobHolder 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()));
}
Aggregations