Set<JobRequest> requests = new HashSet<>(manager.getAllJobRequestsForTag(builder.mTag)); for (JobRequest request : requests) { if (!request.isExact() || request.getStartMs() != JobRequest.START_NOW) {
@Test public void verifyNotFoundJobCanceledDailyJob() { final String tag = "something"; int jobId = DailyJob.schedule(new JobRequest.Builder(tag), TimeUnit.HOURS.toMillis(5), TimeUnit.HOURS.toMillis(6)); assertThat(manager().getAllJobRequestsForTag(tag)).hasSize(1); executeJob(jobId, Job.Result.FAILURE); assertThat(manager().getAllJobRequestsForTag(tag)).isEmpty(); }
@Test public void verifyNotFoundJobCanceledOneOff() { final String tag = "something"; final int jobId = new JobRequest.Builder(tag) .setExecutionWindow(TimeUnit.HOURS.toMillis(4), TimeUnit.HOURS.toMillis(5)) .build() .schedule(); assertThat(manager().getAllJobRequestsForTag(tag)).hasSize(1); executeJob(jobId, Job.Result.FAILURE); assertThat(manager().getAllJobRequestsForTag(tag)).isEmpty(); }
@Test @Config(sdk = Build.VERSION_CODES.M) public void verifyNotFoundJobCanceledPeriodicFlexSupport() { final String tag = "something"; final int jobId = new JobRequest.Builder(tag) .setPeriodic(TimeUnit.HOURS.toMillis(4)) .build() .schedule(); assertThat(manager().getAllJobRequestsForTag(tag)).hasSize(1); executeJob(jobId, Job.Result.FAILURE); assertThat(manager().getAllJobRequestsForTag(tag)).isEmpty(); } }
@Test public void verifyNotFoundJobCanceledExact() { final String tag = "something"; final int jobId = new JobRequest.Builder(tag) .setExact(TimeUnit.HOURS.toMillis(4)) .build() .schedule(); assertThat(manager().getAllJobRequestsForTag(tag)).hasSize(1); executeJob(jobId, Job.Result.FAILURE); assertThat(manager().getAllJobRequestsForTag(tag)).isEmpty(); }
@Test public void verifyNotFoundJobCanceledPeriodic() { final String tag = "something"; final int jobId = new JobRequest.Builder(tag) .setPeriodic(TimeUnit.HOURS.toMillis(4)) .build() .schedule(); assertThat(manager().getAllJobRequestsForTag(tag)).hasSize(1); executeJob(jobId, Job.Result.FAILURE); assertThat(manager().getAllJobRequestsForTag(tag)).isEmpty(); }
@Test public void testPeriodicJob() throws Exception { int jobId = DummyJobs.createBuilder(DummyJobs.SuccessJob.class) .setPeriodic(TimeUnit.MINUTES.toMillis(15)) .build() .schedule(); executeJob(jobId, Job.Result.SUCCESS); // make sure job request is still around assertThat(manager().getAllJobRequestsForTag(DummyJobs.SuccessJob.TAG)).hasSize(1); }
@Override public void onCreate() { super.onCreate(); JobManager.create(this).addJobCreator(new HookFetchJobCreator()); int noOfJobRequests = JobManager.instance().getAllJobRequestsForTag(HookFetchJob.TAG).size(); // No of Job Requests for HookFetchJob would be greater than 1 for older version of // application because of rescheduling of job again and again, causing large no. of wakelocks if (noOfJobRequests > 1) { JobManager.instance().cancelAllForTag(HookFetchJob.TAG); noOfJobRequests = 0; } if (noOfJobRequests == 0) { HookFetchJob.scheduleJob(); } }
Set<JobRequest> requests = new HashSet<>(manager.getAllJobRequestsForTag(builder.mTag)); for (JobRequest request : requests) { if (!request.isExact() || request.getStartMs() != JobRequest.START_NOW) {