use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.
the class JobMigrator method migrate.
/**
* @return The version that has been migrated to.
*/
int migrate(@NonNull JobStorage jobStorage, @NonNull Data.Serializer dataSerializer) {
List<JobSpec> jobSpecs = jobStorage.getAllJobSpecs();
for (int i = lastSeenVersion; i < currentVersion; i++) {
Log.i(TAG, "Migrating from " + i + " to " + (i + 1));
ListIterator<JobSpec> iter = jobSpecs.listIterator();
JobMigration migration = migrations.get(i + 1);
assert migration != null;
while (iter.hasNext()) {
JobSpec jobSpec = iter.next();
Data data = dataSerializer.deserialize(jobSpec.getSerializedData());
JobData originalJobData = new JobData(jobSpec.getFactoryKey(), jobSpec.getQueueKey(), data);
JobData updatedJobData = migration.migrate(originalJobData);
JobSpec updatedJobSpec = new JobSpec(jobSpec.getId(), updatedJobData.getFactoryKey(), updatedJobData.getQueueKey(), jobSpec.getCreateTime(), jobSpec.getNextRunAttemptTime(), jobSpec.getRunAttempt(), jobSpec.getMaxAttempts(), jobSpec.getLifespan(), dataSerializer.serialize(updatedJobData.getData()), jobSpec.getSerializedInputData(), jobSpec.isRunning(), jobSpec.isMemoryOnly());
iter.set(updatedJobSpec);
}
}
jobStorage.updateJobs(jobSpecs);
return currentVersion;
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.
the class FastJobStorageTest method getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenEarlierItemInQueueInRunning.
@Test
public void getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenEarlierItemInQueueInRunning() {
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, true, 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();
assertEquals(0, subject.getPendingJobsWithNoDependenciesInCreatedOrder(1).size());
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.
the class FastJobStorageTest method getPendingJobsWithNoDependenciesInCreatedOrder_onlyReturnFirstEligibleMigrationJob.
@Test
public void getPendingJobsWithNoDependenciesInCreatedOrder_onlyReturnFirstEligibleMigrationJob() {
FullSpec migrationSpec1 = new FullSpec(new JobSpec("1", "f1", Job.Parameters.MIGRATION_QUEUE_KEY, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList());
FullSpec migrationSpec2 = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList());
FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Arrays.asList(migrationSpec1, migrationSpec2)));
subject.init();
List<JobSpec> jobs = subject.getPendingJobsWithNoDependenciesInCreatedOrder(10);
assertEquals(1, jobs.size());
assertEquals("1", jobs.get(0).getId());
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.
the class FastJobStorageTest method getPendingJobsWithNoDependenciesInCreatedOrder_runningMigrationBlocksLaterMigrationJobs.
@Test
public void getPendingJobsWithNoDependenciesInCreatedOrder_runningMigrationBlocksLaterMigrationJobs() {
FullSpec migrationSpec1 = new FullSpec(new JobSpec("1", "f1", Job.Parameters.MIGRATION_QUEUE_KEY, 0, 0, 0, 0, -1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList());
FullSpec migrationSpec2 = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList());
FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Arrays.asList(migrationSpec1, migrationSpec2)));
subject.init();
List<JobSpec> jobs = subject.getPendingJobsWithNoDependenciesInCreatedOrder(10);
assertEquals(0, jobs.size());
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.
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());
}
Aggregations