Search in sources :

Example 6 with FullSpec

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

the class FastJobStorageTest method fixedDataDatabase.

private JobDatabase fixedDataDatabase(List<FullSpec> fullSpecs) {
    JobDatabase database = mock(JobDatabase.class);
    when(database.getAllJobSpecs()).thenReturn(Stream.of(fullSpecs).map(FullSpec::getJobSpec).toList());
    when(database.getAllConstraintSpecs()).thenReturn(Stream.of(fullSpecs).map(FullSpec::getConstraintSpecs).flatMap(Stream::of).toList());
    when(database.getAllDependencySpecs()).thenReturn(Stream.of(fullSpecs).map(FullSpec::getDependencySpecs).flatMap(Stream::of).toList());
    return database;
}
Also used : JobDatabase(org.thoughtcrime.securesms.database.JobDatabase) FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) Stream(com.annimon.stream.Stream)

Example 7 with FullSpec

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

the class FastJobStorageTest method getPendingJobsWithNoDependenciesInCreatedOrder_singleEligibleJobInMixedList.

@Test
public void getPendingJobsWithNoDependenciesInCreatedOrder_singleEligibleJobInMixedList() {
    FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, -1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList());
    FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 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("2", 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 8 with FullSpec

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

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)

Example 9 with FullSpec

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

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 10 with FullSpec

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

the class FastJobStorageTest method updateJobAfterRetry_stateUpdated.

@Test
public void updateJobAfterRetry_stateUpdated() {
    FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 3, -1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList());
    FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Collections.singletonList(fullSpec)));
    subject.init();
    subject.updateJobAfterRetry("1", false, 1, 10, "a");
    JobSpec job = subject.getJobSpec("1");
    assertNotNull(job);
    assertFalse(job.isRunning());
    assertEquals(1, job.getRunAttempt());
    assertEquals(10, job.getNextRunAttemptTime());
    assertEquals("a", job.getSerializedData());
}
Also used : FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) Test(org.junit.Test)

Aggregations

FullSpec (org.thoughtcrime.securesms.jobmanager.persistence.FullSpec)42 JobSpec (org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)38 Test (org.junit.Test)32 Stream (com.annimon.stream.Stream)6 DependencySpec (org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec)6 Application (android.app.Application)4 NonNull (androidx.annotation.NonNull)4 Nullable (androidx.annotation.Nullable)4 WorkerThread (androidx.annotation.WorkerThread)4 Collectors (com.annimon.stream.Collectors)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 Map (java.util.Map)4 Set (java.util.Set)4 Log (org.signal.core.util.logging.Log)4