JobManager { @NonNull JobStorage getJobStorage() { if (mJobStorage == null) { try { mJobStorageLatch.await(20, TimeUnit.SECONDS); } catch (InterruptedException e) { throw new RuntimeException(e); } } if (mJobStorage == null) { throw new IllegalStateException("Job storage shouldn't be null"); } return mJobStorage; } private  JobManager(final Context context); static JobManager create(@NonNull Context context); static JobManager instance(); synchronized void schedule(@NonNull JobRequest request); JobRequest getJobRequest(int jobId); @NonNull Set<JobRequest> getAllJobRequests(); Set<JobRequest> getAllJobRequestsForTag(@NonNull String tag); Job getJob(int jobId); @NonNull Set<Job> getAllJobs(); @NonNull Set<Job> getAllJobsForTag(@NonNull String tag); @NonNull SparseArray<Job.Result> getAllJobResults(); boolean cancel(int jobId); int cancelAll(); int cancelAllForTag(@NonNull String tag); void addJobCreator(JobCreator jobCreator); void removeJobCreator(JobCreator jobCreator);  }
@Test public void testJobIdRollover() throws Exception { JobConfig.setJobIdOffset(10); context().getSharedPreferences(JobStorage.PREF_FILE_NAME, Context.MODE_PRIVATE).edit() .putInt(JobStorage.JOB_ID_COUNTER, JobIdsInternal.RESERVED_JOB_ID_RANGE_START - 2) .apply(); assertThat(manager().getJobStorage().nextJobId()).isEqualTo(JobIdsInternal.RESERVED_JOB_ID_RANGE_START - 1); assertThat(manager().getJobStorage().nextJobId()).isEqualTo(11); assertThat(manager().getJobStorage().nextJobId()).isEqualTo(12); }