Search in sources :

Example 46 with JobSpec

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

the class FastJobStorageTest method getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenAllJobsAreRunning.

@Test
public void getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenAllJobsAreRunning() {
    FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList());
    FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Collections.singletonList(fullSpec)));
    subject.init();
    assertEquals(0, subject.getPendingJobsWithNoDependenciesInCreatedOrder(10).size());
}
Also used : FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) Test(org.junit.Test)

Example 47 with JobSpec

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

the class JobDatabase method insertJobs.

public synchronized void insertJobs(@NonNull List<FullSpec> fullSpecs) {
    if (Stream.of(fullSpecs).map(FullSpec::getJobSpec).allMatch(JobSpec::isMemoryOnly)) {
        return;
    }
    SQLiteDatabase db = getWritableDatabase();
    db.beginTransaction();
    try {
        for (FullSpec fullSpec : fullSpecs) {
            insertJobSpec(db, fullSpec.getJobSpec());
            insertConstraintSpecs(db, fullSpec.getConstraintSpecs());
            insertDependencySpecs(db, fullSpec.getDependencySpecs());
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}
Also used : SQLiteDatabase(net.zetetic.database.sqlcipher.SQLiteDatabase) FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)

Example 48 with JobSpec

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

the class FastJobStorageTest method updateJobs_updatesAllFields.

@Test
public void updateJobs_updatesAllFields() {
    FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList());
    FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 1, 1, 1, 1, 1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList());
    FullSpec fullSpec3 = new FullSpec(new JobSpec("3", "f3", null, 1, 1, 1, 1, 1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList());
    FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Arrays.asList(fullSpec1, fullSpec2, fullSpec3)));
    JobSpec update1 = new JobSpec("1", "g1", "q1", 2, 2, 2, 2, 2, "abc", null, true, false);
    JobSpec update2 = new JobSpec("2", "g2", "q2", 3, 3, 3, 3, 3, "def", "ghi", true, false);
    subject.init();
    subject.updateJobs(Arrays.asList(update1, update2));
    assertEquals(update1, subject.getJobSpec("1"));
    assertEquals(update2, subject.getJobSpec("2"));
    assertEquals(fullSpec3.getJobSpec(), subject.getJobSpec("3"));
}
Also used : FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) Test(org.junit.Test)

Example 49 with JobSpec

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

the class FastJobStorageTest method updateAllJobsToBePending_allArePending.

@Test
public void updateAllJobsToBePending_allArePending() {
    FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList());
    FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 1, 1, 1, 1, 1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList());
    FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Arrays.asList(fullSpec1, fullSpec2)));
    subject.init();
    subject.updateAllJobsToBePending();
    assertFalse(subject.getJobSpec("1").isRunning());
    assertFalse(subject.getJobSpec("2").isRunning());
}
Also used : FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) Test(org.junit.Test)

Example 50 with JobSpec

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

the class FastJobStorageTest method getPendingJobsWithNoDependenciesInCreatedOrder_runningMigrationBlocksNormalJobs.

@Test
public void getPendingJobsWithNoDependenciesInCreatedOrder_runningMigrationBlocksNormalJobs() {
    FullSpec plainSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList());
    FullSpec migrationSpec = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, -1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList());
    FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Arrays.asList(plainSpec, migrationSpec)));
    subject.init();
    List<JobSpec> jobs = subject.getPendingJobsWithNoDependenciesInCreatedOrder(10);
    assertEquals(0, jobs.size());
}
Also used : FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) Test(org.junit.Test)

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