use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.
the class FastJobStorageTest method updateJobs_memoryOnly_doesNotWriteToDatabase.
@Test
public void updateJobs_memoryOnly_doesNotWriteToDatabase() {
JobDatabase database = fixedDataDatabase(DataSetMemory.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, times(0)).updateJobs(jobs);
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.
the class FastJobStorageTest method getPendingJobsWithNoDependenciesInCreatedOrder_migrationJobTakesPrecedence.
@Test
public void getPendingJobsWithNoDependenciesInCreatedOrder_migrationJobTakesPrecedence() {
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, false, false), Collections.emptyList(), Collections.emptyList());
FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Arrays.asList(plainSpec, migrationSpec)));
subject.init();
List<JobSpec> jobs = subject.getPendingJobsWithNoDependenciesInCreatedOrder(10);
assertEquals(1, jobs.size());
assertEquals("2", jobs.get(0).getId());
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.
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();
}
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.
the class JobDatabase method updateJobs.
public synchronized void updateJobs(@NonNull List<JobSpec> jobs) {
if (Stream.of(jobs).allMatch(JobSpec::isMemoryOnly)) {
return;
}
SQLiteDatabase db = getWritableDatabase();
db.beginTransaction();
try {
Stream.of(jobs).filterNot(JobSpec::isMemoryOnly).forEach(job -> {
ContentValues values = new ContentValues();
values.put(Jobs.JOB_SPEC_ID, job.getId());
values.put(Jobs.FACTORY_KEY, job.getFactoryKey());
values.put(Jobs.QUEUE_KEY, job.getQueueKey());
values.put(Jobs.CREATE_TIME, job.getCreateTime());
values.put(Jobs.NEXT_RUN_ATTEMPT_TIME, job.getNextRunAttemptTime());
values.put(Jobs.RUN_ATTEMPT, job.getRunAttempt());
values.put(Jobs.MAX_ATTEMPTS, job.getMaxAttempts());
values.put(Jobs.LIFESPAN, job.getLifespan());
values.put(Jobs.SERIALIZED_DATA, job.getSerializedData());
values.put(Jobs.SERIALIZED_INPUT_DATA, job.getSerializedInputData());
values.put(Jobs.IS_RUNNING, job.isRunning() ? 1 : 0);
String query = Jobs.JOB_SPEC_ID + " = ?";
String[] args = new String[] { job.getId() };
db.update(Jobs.TABLE_NAME, values, query, args);
});
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.
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);
}
}
}
Aggregations