FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver); Job syncSunshineJob = dispatcher.newJobBuilder() dispatcher.schedule(syncSunshineJob);
@Test public void testMustSchedule_success() throws Exception { when(driver.schedule(null)).thenReturn(FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS); /* assert no exception is thrown */ dispatcher.mustSchedule(null); }
private static void initLocked(Context ctx) { sStore = new JobStore(); sDispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(ctx)); sInitialized = true; }
.newJobBuilder() .setConstraints(Constraint.DEVICE_CHARGING) .setService(TestJobService.class) "Expected schedule() request to succeed", FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS, dispatcher.schedule(job));
private Job.Builder jobBuilder() { return new FirebaseJobDispatcher(new Driver() { @Override public int schedule(Job job) { return true; }).newJobBuilder();
public static void scheduleFirebaseBackgroundUpload(Context context) { FirebaseJobDispatcher jobDispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context)); jobDispatcher.mustSchedule( jobDispatcher.newJobBuilder() .setTag(BACKGROUND_UPLOAD_JOB_TAG) .setService(FirebaseJobService.class) .setConstraints( Constraint.ON_UNMETERED_NETWORK, Constraint.DEVICE_CHARGING) .setTrigger(Trigger.executionWindow( 0, // can start immediately (int) TimeUnit.DAYS.toSeconds(1))) // wait at most a day .build()); }
final Builder builder = jobDispatcher .newJobBuilder() .setTag(form.tag.get()) .setRecurring(form.recurring.get()) .setReplaceCurrent(form.replaceCurrent.get()) .setRetryStrategy( jobDispatcher.newRetryStrategy( form.retryStrategy.get(), form.getInitialBackoffSeconds(), jobDispatcher.mustSchedule(builder.build());
static Job createJob(FirebaseJobDispatcher dispatcher, String gcmSenderId) { Bundle extras = new Bundle(); extras.putString(KEY_GCM_SENDER_ID, gcmSenderId); return dispatcher.newJobBuilder() .setExtras(extras) .setRecurring(false) .setReplaceCurrent(true) // retry with exponential backoff .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL) .setConstraints( // only run on a network Constraint.ON_ANY_NETWORK ) .setService(ParseGCMJobService.class) // the JobService that will be called .setTag(JOB_TAG_REGISTER) // uniquely identifies the job .build(); }
/** * Register your app to start receiving GCM pushes * * @param context context */ public static void register(@NonNull Context context) { //kicks off the background job PLog.d(TAG, "Scheduling job to register Parse GCM"); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context.getApplicationContext())); Job job = ParseGCMJobService.createJob(dispatcher, gcmSenderFromManifest(context)); dispatcher.mustSchedule(job); }
myExtrasBundle.putString(MyJobService.EXTRAS_CITY, CITY); Job myJob = mDispatcher.newJobBuilder() .build(); mDispatcher.mustSchedule(myJob);
/** * Attempts to schedule the provided Job, throwing an exception if it fails. * * @throws ScheduleFailedException */ public void mustSchedule(@NonNull Job job) { if (schedule(job) != SCHEDULE_RESULT_SUCCESS) { throw new ScheduleFailedException(); } }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(driver.getValidator()).thenReturn(validator); dispatcher = new FirebaseJobDispatcher(driver); setDriverAvailability(true); }
@Test public void testSchedule_failsWhenPlayServicesIsUnavailable() throws Exception { markBackendUnavailable(); mockPackageManagerInfo(); Job job = null; try { job = dispatcher .newJobBuilder() .setService(TestJobService.class) .setTag("foobar") .setConstraints(Constraint.DEVICE_CHARGING) .setTrigger(Trigger.executionWindow(0, 60)) .build(); } catch (ValidationEnforcer.ValidationException ve) { fail(TextUtils.join("\n", ve.getErrors())); } assertEquals( "Expected schedule() request to fail when backend is unavailable", FirebaseJobDispatcher.SCHEDULE_RESULT_NO_DRIVER_AVAILABLE, dispatcher.schedule(job)); }
private @NonNull Job.Builder createBuilder(BackupType backupType) { return firebaseJobDispatcher.newJobBuilder() .setReplaceCurrent(true) .setService(SmsJobService.class) .setTag(backupType.name()) .setRetryStrategy(defaultRetryStrategy()) .setConstraints(jobConstraints(backupType)); }
/** * You can call this manually if you are overriding the {@link com.google.firebase.iid.FirebaseInstanceIdService} * * @param context context */ public static void register(Context context) { //kicks off the background job PLog.d(TAG, "Scheduling job to register Parse FCM"); FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(context.getApplicationContext())); Job job = ParseFirebaseJobService.createJob(dispatcher); dispatcher.mustSchedule(job); } }
final Bundle extras = OnExitJobService.buildExtras(beacon, this.beaconExitTimeoutInMillis, this.targetService); this.dispatcher.mustSchedule(this.dispatcher.newJobBuilder() .setExtras(extras) .setLifetime(Lifetime.FOREVER)
@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); }
FirebaseJobDispatcher dispatcher = new FirebaseJobDispatcher(driver); Job syncSunshineJob = dispatcher.newJobBuilder() dispatcher.schedule(syncSunshineJob);
@Before public void setUp() { MockitoAnnotations.initMocks(this); googlePlayDriver = new GooglePlayDriver(mMockContext); driver = new TestJobDriver(googlePlayDriver); dispatcher = new FirebaseJobDispatcher(driver); when(mMockContext.getPackageName()).thenReturn("foo.bar.whatever"); when(constraintCheckerMock.areConstraintsSatisfied(any(JobInvocation.class))).thenReturn(true); }
static Job createJob(FirebaseJobDispatcher dispatcher) { return dispatcher.newJobBuilder() .setRecurring(false) .setReplaceCurrent(true) // retry with exponential backoff .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL) .setConstraints( // only run on a network Constraint.ON_ANY_NETWORK ) .setService(ParseFirebaseJobService.class) // the JobService that will be called .setTag(JOB_TAG_UPLOAD_TOKEN) // uniquely identifies the job .build(); }