/** * Attempts to schedule the provided Job. * * <p>Returns one of the SCHEDULE_RESULT_ constants. */ @ScheduleResult public int schedule(@NonNull Job job) { if (!driver.isAvailable()) { return SCHEDULE_RESULT_NO_DRIVER_AVAILABLE; } return driver.schedule(job); }
@Override public int schedule(@NonNull Job job) { return this.wrappedDriver.schedule(job); }
@Override public int schedule(@NonNull Job job) { Log.i("TrackingBackend", "beginning schedule loop"); synchronized (mStore) { final Iterator<JobHistory> it = mStore.iterator(); while (it.hasNext()) { JobParameters j = it.next().job; if (j.getTag().equals(job.getTag()) && j.getService().equals(job.getService())) { it.remove(); } } mStore.add(new JobHistory(job)); } Log.i("TrackingBackend", "ending schedule loop"); return mDriver.schedule(job); }
@Test public void testMustSchedule_success() throws Exception { when(driver.schedule(null)).thenReturn(FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS); /* assert no exception is thrown */ dispatcher.mustSchedule(null); }
@Test public void testSchedule_passThrough() throws Exception { final int[] possibleResults = { FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS, FirebaseJobDispatcher.SCHEDULE_RESULT_NO_DRIVER_AVAILABLE, FirebaseJobDispatcher.SCHEDULE_RESULT_BAD_SERVICE, FirebaseJobDispatcher.SCHEDULE_RESULT_UNKNOWN_ERROR, FirebaseJobDispatcher.SCHEDULE_RESULT_UNSUPPORTED_TRIGGER }; for (int result : possibleResults) { when(driver.schedule(null)).thenReturn(result); assertEquals(result, dispatcher.schedule(null)); } verify(driver, times(possibleResults.length)).schedule(null); }
@Test public void testMustSchedule_failure() throws Exception { final int[] possibleErrors = { FirebaseJobDispatcher.SCHEDULE_RESULT_NO_DRIVER_AVAILABLE, FirebaseJobDispatcher.SCHEDULE_RESULT_BAD_SERVICE, FirebaseJobDispatcher.SCHEDULE_RESULT_UNKNOWN_ERROR, FirebaseJobDispatcher.SCHEDULE_RESULT_UNSUPPORTED_TRIGGER }; for (int scheduleError : possibleErrors) { when(driver.schedule(null)).thenReturn(scheduleError); try { dispatcher.mustSchedule(null); fail("Expected mustSchedule() with error code " + scheduleError + " to fail"); } catch (ScheduleFailedException expected) { /* expected */ } } verify(driver, times(possibleErrors.length)).schedule(null); }
private void reschedule(JobInvocation jobInvocation) { Job job = new Builder(getValidationEnforcer(), jobInvocation).setReplaceCurrent(true).build(); getGooglePlayDriver().schedule(job); }
@Test public void testSchedule_unavailable() throws Exception { setDriverAvailability(false); assertEquals( FirebaseJobDispatcher.SCHEDULE_RESULT_NO_DRIVER_AVAILABLE, dispatcher.schedule(null)); verify(driver, never()).schedule(null); }
@Test public void onJobFinished_successRecurringContentJob_reschedule() { JobInvocation jobInvocation = receiver.prepareJob(callbackMock, getBundleForContentJobExecutionRecurring()); receiver.onJobFinished(jobInvocation, JobService.RESULT_SUCCESS); verify(driverMock).schedule(jobArgumentCaptor.capture()); // No need to callback when job finished. // Reschedule request is treated as two events: completion of old job and scheduling of new // job with the same parameters. verifyZeroInteractions(callbackMock); Job rescheduledJob = jobArgumentCaptor.getValue(); TestUtil.assertJobsEqual(jobInvocation, rescheduledJob); }