Search in sources :

Example 1 with WorkInfo

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();
}
Also used : JobRequest(com.evernote.android.job.JobRequest) WorkInfo(androidx.work.WorkInfo) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 2 with WorkInfo

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());
}
Also used : WorkInfo(androidx.work.WorkInfo) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 3 with WorkInfo

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;
        }
    });
}
Also used : WorkInfo(androidx.work.WorkInfo) List(java.util.List) FormUpdateAndInstanceSubmitScheduler(org.odk.collect.android.backgroundwork.FormUpdateAndInstanceSubmitScheduler)

Example 4 with WorkInfo

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());
}
Also used : WorkInfo(androidx.work.WorkInfo) OneTimeWorkRequest(androidx.work.OneTimeWorkRequest) Test(org.junit.Test) FileCompatTest(org.fdroid.fdroid.compat.FileCompatTest) LargeTest(androidx.test.filters.LargeTest)

Aggregations

WorkInfo (androidx.work.WorkInfo)4 LargeTest (androidx.test.filters.LargeTest)3 Test (org.junit.Test)3 OneTimeWorkRequest (androidx.work.OneTimeWorkRequest)2 JobRequest (com.evernote.android.job.JobRequest)1 List (java.util.List)1 FileCompatTest (org.fdroid.fdroid.compat.FileCompatTest)1 FormUpdateAndInstanceSubmitScheduler (org.odk.collect.android.backgroundwork.FormUpdateAndInstanceSubmitScheduler)1