Search in sources :

Example 31 with JobSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.

the class FastJobStorageTest method updateJobs_writesToDatabase.

@Test
public void updateJobs_writesToDatabase() {
    JobDatabase database = fixedDataDatabase(DataSet1.FULL_SPECS);
    FastJobStorage subject = new FastJobStorage(database);
    List<JobSpec> jobs = Collections.singletonList(new JobSpec("id1", "f1", null, 1, 1, 1, 1, 1, EMPTY_DATA, null, false, false));
    subject.init();
    subject.updateJobs(jobs);
    verify(database).updateJobs(jobs);
}
Also used : JobDatabase(org.thoughtcrime.securesms.database.JobDatabase) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) Test(org.junit.Test)

Example 32 with JobSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.

the class FastJobStorageTest method getPendingJobsWithNoDependenciesInCreatedOrder_firstItemInQueue.

@Test
public void getPendingJobsWithNoDependenciesInCreatedOrder_firstItemInQueue() {
    FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList());
    FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList());
    FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Arrays.asList(fullSpec1, fullSpec2)));
    subject.init();
    List<JobSpec> jobs = subject.getPendingJobsWithNoDependenciesInCreatedOrder(10);
    assertEquals(1, jobs.size());
    assertEquals("1", jobs.get(0).getId());
}
Also used : FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) Test(org.junit.Test)

Example 33 with JobSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by WhisperSystems.

the class JobMigratorTest method simpleJobStorage.

private static JobStorage simpleJobStorage() {
    JobStorage jobStorage = mock(JobStorage.class);
    when(jobStorage.getAllJobSpecs()).thenReturn(new ArrayList<>(Collections.singletonList(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, "", null, false, false))));
    return jobStorage;
}
Also used : JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) JobStorage(org.thoughtcrime.securesms.jobmanager.persistence.JobStorage)

Example 34 with JobSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by WhisperSystems.

the class FastJobStorage method updateJobs.

@Override
public void updateJobs(@NonNull List<JobSpec> jobSpecs) {
    List<JobSpec> durable = new ArrayList<>(jobSpecs.size());
    for (JobSpec update : jobSpecs) {
        JobSpec found = getJobById(update.getId());
        if (found == null || !found.isMemoryOnly()) {
            durable.add(update);
        }
    }
    if (durable.size() > 0) {
        jobDatabase.updateJobs(durable);
    }
    Map<String, JobSpec> updates = Stream.of(jobSpecs).collect(Collectors.toMap(JobSpec::getId));
    ListIterator<JobSpec> iter = jobs.listIterator();
    while (iter.hasNext()) {
        JobSpec existing = iter.next();
        JobSpec update = updates.get(existing.getId());
        if (update != null) {
            iter.set(update);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)

Example 35 with JobSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by WhisperSystems.

the class FastJobStorage method deleteJobs.

@Override
public synchronized void deleteJobs(@NonNull List<String> jobIds) {
    List<String> durableIds = new ArrayList<>(jobIds.size());
    for (String id : jobIds) {
        JobSpec job = getJobById(id);
        if (job == null || !job.isMemoryOnly()) {
            durableIds.add(id);
        }
    }
    if (durableIds.size() > 0) {
        jobDatabase.deleteJobs(durableIds);
    }
    Set<String> deleteIds = new HashSet<>(jobIds);
    Iterator<JobSpec> jobIter = jobs.iterator();
    while (jobIter.hasNext()) {
        if (deleteIds.contains(jobIter.next().getId())) {
            jobIter.remove();
        }
    }
    for (String jobId : jobIds) {
        constraintsByJobId.remove(jobId);
        dependenciesByJobId.remove(jobId);
        for (Map.Entry<String, List<DependencySpec>> entry : dependenciesByJobId.entrySet()) {
            Iterator<DependencySpec> depedencyIter = entry.getValue().iterator();
            while (depedencyIter.hasNext()) {
                if (depedencyIter.next().getDependsOnJobId().equals(jobId)) {
                    depedencyIter.remove();
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) DependencySpec(org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

JobSpec (org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)66 FullSpec (org.thoughtcrime.securesms.jobmanager.persistence.FullSpec)38 Test (org.junit.Test)36 WorkerThread (androidx.annotation.WorkerThread)10 DependencySpec (org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec)10 ArrayList (java.util.ArrayList)8 LinkedList (java.util.LinkedList)8 ConstraintSpec (org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec)8 Nullable (androidx.annotation.Nullable)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Map (java.util.Map)6 JobStorage (org.thoughtcrime.securesms.jobmanager.persistence.JobStorage)6 Application (android.app.Application)4 NonNull (androidx.annotation.NonNull)4 Collectors (com.annimon.stream.Collectors)4 Stream (com.annimon.stream.Stream)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4