Search in sources :

Example 1 with JobData

use of org.thoughtcrime.securesms.jobmanager.JobMigration.JobData in project Signal-Android by WhisperSystems.

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;
}
Also used : JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) SuppressLint(android.annotation.SuppressLint)

Example 2 with JobData

use of org.thoughtcrime.securesms.jobmanager.JobMigration.JobData in project Signal-Android by WhisperSystems.

the class RecipientIdJobMigrationTest method migrate_pushGroupUpdateJob.

@Test
public void migrate_pushGroupUpdateJob() throws Exception {
    JobData testData = new JobData("PushGroupUpdateJob", null, new Data.Builder().putString("source", "+16101234567").putString("group_id", "__textsecure_group__!abcdef0123456789abcdef0123456789").build());
    mockRecipientResolve("+16101234567", 1);
    RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
    JobData converted = subject.migrate(testData);
    assertEquals("PushGroupUpdateJob", converted.getFactoryKey());
    assertNull(converted.getQueueKey());
    assertEquals("1", converted.getData().getString("source"));
    assertEquals("__textsecure_group__!abcdef0123456789abcdef0123456789", converted.getData().getString("group_id"));
    new PushGroupUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Also used : JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) PushGroupUpdateJob(org.thoughtcrime.securesms.jobs.PushGroupUpdateJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with JobData

use of org.thoughtcrime.securesms.jobmanager.JobMigration.JobData in project Signal-Android by WhisperSystems.

the class RecipientIdJobMigrationTest method migrate_pushGroupSendJob_nonNull.

@Test
public void migrate_pushGroupSendJob_nonNull() throws Exception {
    JobData testData = new JobData("PushGroupSendJob", "someGroupId", new Data.Builder().putString("filter_address", "+16101234567").putLong("message_id", 123).build());
    mockRecipientResolve("+16101234567", 1);
    mockRecipientResolve("someGroupId", 5);
    RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
    JobData converted = subject.migrate(testData);
    assertEquals("PushGroupSendJob", converted.getFactoryKey());
    assertEquals(RecipientId.from(5).toQueueKey(), converted.getQueueKey());
    assertEquals("1", converted.getData().getString("filter_recipient"));
    assertFalse(converted.getData().hasString("filter_address"));
    new PushGroupSendJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Also used : PushGroupSendJob(org.thoughtcrime.securesms.jobs.PushGroupSendJob) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with JobData

use of org.thoughtcrime.securesms.jobmanager.JobMigration.JobData in project Signal-Android by WhisperSystems.

the class RecipientIdJobMigrationTest method migrate_pushTextSendJob.

@Test
public void migrate_pushTextSendJob() throws Exception {
    JobData testData = new JobData("PushTextSendJob", "+16101234567", new Data.Builder().putLong("message_id", 1).build());
    mockRecipientResolve("+16101234567", 1);
    RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
    JobData converted = subject.migrate(testData);
    assertEquals("PushTextSendJob", converted.getFactoryKey());
    assertEquals(RecipientId.from(1).toQueueKey(), converted.getQueueKey());
    assertEquals(1, converted.getData().getLong("message_id"));
    new PushTextSendJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Also used : JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Data(org.thoughtcrime.securesms.jobmanager.Data) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) PushTextSendJob(org.thoughtcrime.securesms.jobs.PushTextSendJob) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with JobData

use of org.thoughtcrime.securesms.jobmanager.JobMigration.JobData in project Signal-Android by WhisperSystems.

the class RecipientIdJobMigrationTest method migrate_retrieveProfileAvatarJob.

@Test
public void migrate_retrieveProfileAvatarJob() throws Exception {
    JobData testData = new JobData("RetrieveProfileAvatarJob", "RetrieveProfileAvatarJob+16101234567", new Data.Builder().putString("address", "+16101234567").putString("profile_avatar", "abc").build());
    mockRecipientResolve("+16101234567", 1);
    RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
    JobData converted = subject.migrate(testData);
    assertEquals("RetrieveProfileAvatarJob", converted.getFactoryKey());
    assertEquals("RetrieveProfileAvatarJob::" + RecipientId.from(1).toQueueKey(), converted.getQueueKey());
    assertEquals("1", converted.getData().getString("recipient"));
    new RetrieveProfileAvatarJob.Factory().create(mock(Job.Parameters.class), converted.getData());
}
Also used : RetrieveProfileAvatarJob(org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob) JobData(org.thoughtcrime.securesms.jobmanager.JobMigration.JobData) Application(android.app.Application) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

JobData (org.thoughtcrime.securesms.jobmanager.JobMigration.JobData)22 Test (org.junit.Test)21 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 Application (android.app.Application)17 Data (org.thoughtcrime.securesms.jobmanager.Data)9 NewSerializableSyncMessageId (org.thoughtcrime.securesms.jobmanager.migrations.RecipientIdJobMigration.NewSerializableSyncMessageId)2 OldSerializableSyncMessageId (org.thoughtcrime.securesms.jobmanager.migrations.RecipientIdJobMigration.OldSerializableSyncMessageId)2 DirectoryRefreshJob (org.thoughtcrime.securesms.jobs.DirectoryRefreshJob)2 FailingJob (org.thoughtcrime.securesms.jobs.FailingJob)2 MultiDeviceReadUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob)2 PushGroupSendJob (org.thoughtcrime.securesms.jobs.PushGroupSendJob)2 RequestGroupInfoJob (org.thoughtcrime.securesms.jobs.RequestGroupInfoJob)2 SendDeliveryReceiptJob (org.thoughtcrime.securesms.jobs.SendDeliveryReceiptJob)2 SmsSendJob (org.thoughtcrime.securesms.jobs.SmsSendJob)2 SuppressLint (android.annotation.SuppressLint)1 JobSpec (org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)1 MultiDeviceContactUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob)1 MultiDeviceVerifiedUpdateJob (org.thoughtcrime.securesms.jobs.MultiDeviceVerifiedUpdateJob)1 MultiDeviceViewOnceOpenJob (org.thoughtcrime.securesms.jobs.MultiDeviceViewOnceOpenJob)1 PushGroupUpdateJob (org.thoughtcrime.securesms.jobs.PushGroupUpdateJob)1