use of androidx.work.WorkInfo in project android-job by evernote.
the class PlatformWorkManagerTest method testCancel.
@Test
@SuppressWarnings("ConstantConditions")
public void testCancel() {
int jobId = new JobRequest.Builder(TAG).setExecutionWindow(TimeUnit.HOURS.toMillis(4), TimeUnit.HOURS.toMillis(5)).build().schedule();
JobRequest request = mWorkManagerRule.getManager().getJobRequest(jobId);
JobProxyWorkManager jobProxyWorkManager = new JobProxyWorkManager(ApplicationProvider.getApplicationContext());
assertThat(jobProxyWorkManager.isPlatformJobScheduled(request)).isTrue();
String tag = JobProxyWorkManager.createTag(jobId);
List<WorkInfo> statuses = mWorkManagerRule.getWorkStatus(tag);
assertThat(statuses).isNotNull().hasSize(1);
assertThat(statuses.get(0).getState()).isEqualTo(WorkInfo.State.ENQUEUED);
mWorkManagerRule.getManager().cancel(jobId);
assertThat(mWorkManagerRule.getWorkStatus(tag).get(0).getState()).isEqualTo(WorkInfo.State.CANCELLED);
assertThat(jobProxyWorkManager.isPlatformJobScheduled(request)).isFalse();
}
use of androidx.work.WorkInfo in project fdroidclient by f-droid.
the class FDroidMetricsWorkerTest method testWorkRequest.
@Test
public void testWorkRequest() throws ExecutionException, InterruptedException {
OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(FDroidMetricsWorker.class).build();
workManagerTestRule.workManager.enqueue(request).getResult();
ListenableFuture<WorkInfo> workInfo = workManagerTestRule.workManager.getWorkInfoById(request.getId());
assertEquals(WorkInfo.State.SUCCEEDED, workInfo.get().getState());
}
use of androidx.work.WorkInfo in project collect by opendatakit.
the class InstanceUploaderListActivity method updateAutoSendStatus.
/**
* Updates whether an auto-send job is ongoing.
*/
private void updateAutoSendStatus() {
// This shouldn't use WorkManager directly but it's likely this code will be removed when
// we eventually move sending forms to a Foreground Service (rather than a blocking AsyncTask)
String tag = ((FormUpdateAndInstanceSubmitScheduler) instanceSubmitScheduler).getAutoSendTag(currentProjectProvider.getCurrentProject().getUuid());
LiveData<List<WorkInfo>> statuses = WorkManager.getInstance().getWorkInfosForUniqueWorkLiveData(tag);
statuses.observe(this, workStatuses -> {
if (workStatuses != null) {
for (WorkInfo status : workStatuses) {
if (status.getState().equals(WorkInfo.State.RUNNING)) {
autoSendOngoing = true;
return;
}
}
autoSendOngoing = false;
}
});
}
use of androidx.work.WorkInfo in project fdroidclient by f-droid.
the class CleanCacheWorkerTest method testWorkRequest.
@Test
public void testWorkRequest() throws ExecutionException, InterruptedException {
OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(CleanCacheWorker.class).build();
workManagerTestRule.workManager.enqueue(request).getResult();
ListenableFuture<WorkInfo> workInfo = workManagerTestRule.workManager.getWorkInfoById(request.getId());
assertEquals(WorkInfo.State.SUCCEEDED, workInfo.get().getState());
}
Aggregations