mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-26 12:44:38 +00:00
Store Job data as bytes.
This commit is contained in:
@@ -53,7 +53,7 @@ public class JobMigratorTest {
|
||||
JobMigration migration2 = spy(new EmptyMigration(3));
|
||||
|
||||
JobMigrator subject = new JobMigrator(1, 3, Arrays.asList(migration1, migration2));
|
||||
int version = subject.migrate(simpleJobStorage(), mock(Data.Serializer.class));
|
||||
int version = subject.migrate(simpleJobStorage());
|
||||
|
||||
assertEquals(3, version);
|
||||
verify(migration1).migrate(any());
|
||||
@@ -66,7 +66,7 @@ public class JobMigratorTest {
|
||||
JobMigration migration2 = spy(new EmptyMigration(3));
|
||||
|
||||
JobMigrator subject = new JobMigrator(2, 3, Arrays.asList(migration1, migration2));
|
||||
int version = subject.migrate(simpleJobStorage(), mock(Data.Serializer.class));
|
||||
int version = subject.migrate(simpleJobStorage());
|
||||
|
||||
assertEquals(3, version);
|
||||
verify(migration1, never()).migrate(any());
|
||||
@@ -79,7 +79,7 @@ public class JobMigratorTest {
|
||||
JobMigration migration2 = spy(new EmptyMigration(3));
|
||||
|
||||
JobMigrator subject = new JobMigrator(3, 3, Arrays.asList(migration1, migration2));
|
||||
int version = subject.migrate(simpleJobStorage(), mock(Data.Serializer.class));
|
||||
int version = subject.migrate(simpleJobStorage());
|
||||
|
||||
assertEquals(3, version);
|
||||
verify(migration1, never()).migrate(any());
|
||||
@@ -88,7 +88,7 @@ public class JobMigratorTest {
|
||||
|
||||
private static JobStorage simpleJobStorage() {
|
||||
JobStorage jobStorage = mock(JobStorage.class);
|
||||
when(jobStorage.getAllJobSpecs()).thenReturn(new ArrayList<>(Collections.singletonList(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, "", null, false, false))));
|
||||
when(jobStorage.getAllJobSpecs()).thenReturn(new ArrayList<>(Collections.singletonList(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, null, null, false, false))));
|
||||
return jobStorage;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.thoughtcrime.securesms.jobmanager.impl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.signal.core.util.StreamUtil;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -11,13 +11,13 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public final class JsonDataSerializerTest {
|
||||
public final class JsonJobDataTest {
|
||||
|
||||
private static final float FloatDelta = 0.00001f;
|
||||
|
||||
@Test
|
||||
public void deserialize_dataMatchesExpected() throws IOException {
|
||||
Data data = new JsonDataSerializer().deserialize(StreamUtil.readFullyAsString(ClassLoader.getSystemClassLoader().getResourceAsStream("data/data_serialized.json")));
|
||||
JsonJobData data = JsonJobData.deserialize(StreamUtil.readFully(ClassLoader.getSystemClassLoader().getResourceAsStream("data/data_serialized.json")));
|
||||
|
||||
assertEquals("s1 value", data.getString("s1"));
|
||||
assertEquals("s2 value", data.getString("s2"));
|
||||
@@ -6,7 +6,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobMigration.JobData;
|
||||
import org.thoughtcrime.securesms.jobs.FailingJob;
|
||||
@@ -30,26 +30,28 @@ public class RecipientIdFollowUpJobMigrationTest {
|
||||
|
||||
@Test
|
||||
public void migrate_sendDeliveryReceiptJob_good() throws Exception {
|
||||
JobData testData = new JobData("SendDeliveryReceiptJob", null, new Data.Builder().putString("recipient", "1")
|
||||
.putLong("message_id", 1)
|
||||
.putLong("timestamp", 2)
|
||||
.build());
|
||||
JobData testData = new JobData("SendDeliveryReceiptJob", null, new JsonJobData.Builder().putString("recipient", "1")
|
||||
.putLong("message_id", 1)
|
||||
.putLong("timestamp", 2)
|
||||
.serialize());
|
||||
RecipientIdFollowUpJobMigration subject = new RecipientIdFollowUpJobMigration();
|
||||
JobData converted = subject.migrate(testData);
|
||||
|
||||
assertEquals("SendDeliveryReceiptJob", converted.getFactoryKey());
|
||||
assertNull(converted.getQueueKey());
|
||||
assertEquals("1", converted.getData().getString("recipient"));
|
||||
assertEquals(1, converted.getData().getLong("message_id"));
|
||||
assertEquals(2, converted.getData().getLong("timestamp"));
|
||||
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
assertEquals("1", data.getString("recipient"));
|
||||
assertEquals(1, data.getLong("message_id"));
|
||||
assertEquals(2, data.getLong("timestamp"));
|
||||
|
||||
new SendDeliveryReceiptJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrate_sendDeliveryReceiptJob_bad() throws Exception {
|
||||
JobData testData = new JobData("SendDeliveryReceiptJob", null, new Data.Builder().putString("recipient", "1")
|
||||
.build());
|
||||
JobData testData = new JobData("SendDeliveryReceiptJob", null, new JsonJobData.Builder().putString("recipient", "1")
|
||||
.serialize());
|
||||
RecipientIdFollowUpJobMigration subject = new RecipientIdFollowUpJobMigration();
|
||||
JobData converted = subject.migrate(testData);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobMigration.JobData;
|
||||
import org.thoughtcrime.securesms.jobmanager.migrations.RecipientIdJobMigration.NewSerializableSyncMessageId;
|
||||
@@ -49,17 +49,18 @@ public class RecipientIdJobMigrationTest {
|
||||
|
||||
@Test
|
||||
public void migrate_multiDeviceContactUpdateJob() throws Exception {
|
||||
JobData testData = new JobData("MultiDeviceContactUpdateJob", "MultiDeviceContactUpdateJob", new Data.Builder().putBoolean("force_sync", false).putString("address", "+16101234567").build());
|
||||
JobData testData = new JobData("MultiDeviceContactUpdateJob", "MultiDeviceContactUpdateJob", new JsonJobData.Builder().putBoolean("force_sync", false).putString("address", "+16101234567").serialize());
|
||||
mockRecipientResolve("+16101234567", 1);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("MultiDeviceContactUpdateJob", converted.getFactoryKey());
|
||||
assertEquals("MultiDeviceContactUpdateJob", converted.getQueueKey());
|
||||
assertFalse(converted.getData().getBoolean("force_sync"));
|
||||
assertFalse(converted.getData().hasString("address"));
|
||||
assertEquals("1", converted.getData().getString("recipient"));
|
||||
assertFalse(data.getBoolean("force_sync"));
|
||||
assertFalse(data.hasString("address"));
|
||||
assertEquals("1", data.getString("recipient"));
|
||||
|
||||
new MultiDeviceContactUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
@@ -67,142 +68,150 @@ public class RecipientIdJobMigrationTest {
|
||||
@Test
|
||||
public void migrate_multiDeviceViewOnceOpenJob() throws Exception {
|
||||
OldSerializableSyncMessageId oldId = new OldSerializableSyncMessageId("+16101234567", 1);
|
||||
JobData testData = new JobData("MultiDeviceRevealUpdateJob", null, new Data.Builder().putString("message_id", JsonUtils.toJson(oldId)).build());
|
||||
JobData testData = new JobData("MultiDeviceRevealUpdateJob", null, new JsonJobData.Builder().putString("message_id", JsonUtils.toJson(oldId)).serialize());
|
||||
mockRecipientResolve("+16101234567", 1);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("MultiDeviceRevealUpdateJob", converted.getFactoryKey());
|
||||
assertNull(converted.getQueueKey());
|
||||
assertEquals(JsonUtils.toJson(new NewSerializableSyncMessageId("1", 1)), converted.getData().getString("message_id"));
|
||||
assertEquals(JsonUtils.toJson(new NewSerializableSyncMessageId("1", 1)), data.getString("message_id"));
|
||||
|
||||
new MultiDeviceViewOnceOpenJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrate_sendDeliveryReceiptJob() throws Exception {
|
||||
JobData testData = new JobData("SendDeliveryReceiptJob", null, new Data.Builder().putString("address", "+16101234567")
|
||||
.putLong("message_id", 1)
|
||||
.putLong("timestamp", 2)
|
||||
.build());
|
||||
JobData testData = new JobData("SendDeliveryReceiptJob", null, new JsonJobData.Builder().putString("address", "+16101234567")
|
||||
.putLong("message_id", 1)
|
||||
.putLong("timestamp", 2)
|
||||
.serialize());
|
||||
mockRecipientResolve("+16101234567", 1);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("SendDeliveryReceiptJob", converted.getFactoryKey());
|
||||
assertNull(converted.getQueueKey());
|
||||
assertEquals("1", converted.getData().getString("recipient"));
|
||||
assertEquals(1, converted.getData().getLong("message_id"));
|
||||
assertEquals(2, converted.getData().getLong("timestamp"));
|
||||
assertEquals("1", data.getString("recipient"));
|
||||
assertEquals(1, data.getLong("message_id"));
|
||||
assertEquals(2, data.getLong("timestamp"));
|
||||
|
||||
new SendDeliveryReceiptJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrate_multiDeviceVerifiedUpdateJob() throws Exception {
|
||||
JobData testData = new JobData("MultiDeviceVerifiedUpdateJob", "__MULTI_DEVICE_VERIFIED_UPDATE__", new Data.Builder().putString("destination", "+16101234567")
|
||||
.putString("identity_key", "abcd")
|
||||
.putInt("verified_status", 1)
|
||||
.putLong("timestamp", 123)
|
||||
.build());
|
||||
JobData testData = new JobData("MultiDeviceVerifiedUpdateJob", "__MULTI_DEVICE_VERIFIED_UPDATE__", new JsonJobData.Builder().putString("destination", "+16101234567")
|
||||
.putString("identity_key", "abcd")
|
||||
.putInt("verified_status", 1)
|
||||
.putLong("timestamp", 123)
|
||||
.serialize());
|
||||
mockRecipientResolve("+16101234567", 1);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("MultiDeviceVerifiedUpdateJob", converted.getFactoryKey());
|
||||
assertEquals("__MULTI_DEVICE_VERIFIED_UPDATE__", converted.getQueueKey());
|
||||
assertEquals("abcd", converted.getData().getString("identity_key"));
|
||||
assertEquals(1, converted.getData().getInt("verified_status"));
|
||||
assertEquals(123, converted.getData().getLong("timestamp"));
|
||||
assertEquals("1", converted.getData().getString("destination"));
|
||||
assertEquals("abcd", data.getString("identity_key"));
|
||||
assertEquals(1, data.getInt("verified_status"));
|
||||
assertEquals(123, data.getLong("timestamp"));
|
||||
assertEquals("1", data.getString("destination"));
|
||||
|
||||
new MultiDeviceVerifiedUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrate_pushGroupSendJob_null() throws Exception {
|
||||
JobData testData = new JobData("PushGroupSendJob", "someGroupId", new Data.Builder().putString("filter_address", null)
|
||||
.putLong("message_id", 123)
|
||||
.build());
|
||||
JobData testData = new JobData("PushGroupSendJob", "someGroupId", new JsonJobData.Builder().putString("filter_address", null)
|
||||
.putLong("message_id", 123)
|
||||
.serialize());
|
||||
mockRecipientResolve("someGroupId", 5);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("PushGroupSendJob", converted.getFactoryKey());
|
||||
assertEquals(RecipientId.from(5).toQueueKey(), converted.getQueueKey());
|
||||
assertNull(converted.getData().getString("filter_recipient"));
|
||||
assertFalse(converted.getData().hasString("filter_address"));
|
||||
assertNull(data.getString("filter_recipient"));
|
||||
assertFalse(data.hasString("filter_address"));
|
||||
|
||||
new PushGroupSendJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
|
||||
@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());
|
||||
JobData testData = new JobData("PushGroupSendJob", "someGroupId", new JsonJobData.Builder().putString("filter_address", "+16101234567")
|
||||
.putLong("message_id", 123)
|
||||
.serialize());
|
||||
mockRecipientResolve("+16101234567", 1);
|
||||
mockRecipientResolve("someGroupId", 5);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("PushGroupSendJob", converted.getFactoryKey());
|
||||
assertEquals(RecipientId.from(5).toQueueKey(), converted.getQueueKey());
|
||||
assertEquals("1", converted.getData().getString("filter_recipient"));
|
||||
assertFalse(converted.getData().hasString("filter_address"));
|
||||
assertEquals("1", data.getString("filter_recipient"));
|
||||
assertFalse(data.hasString("filter_address"));
|
||||
|
||||
new PushGroupSendJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrate_directoryRefreshJob_null() throws Exception {
|
||||
JobData testData = new JobData("DirectoryRefreshJob", "DirectoryRefreshJob", new Data.Builder().putString("address", null).putBoolean("notify_of_new_users", true).build());
|
||||
JobData testData = new JobData("DirectoryRefreshJob", "DirectoryRefreshJob", new JsonJobData.Builder().putString("address", null).putBoolean("notify_of_new_users", true).serialize());
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("DirectoryRefreshJob", converted.getFactoryKey());
|
||||
assertEquals("DirectoryRefreshJob", converted.getQueueKey());
|
||||
assertNull(converted.getData().getString("recipient"));
|
||||
assertTrue(converted.getData().getBoolean("notify_of_new_users"));
|
||||
assertFalse(converted.getData().hasString("address"));
|
||||
assertNull(data.getString("recipient"));
|
||||
assertTrue(data.getBoolean("notify_of_new_users"));
|
||||
assertFalse(data.hasString("address"));
|
||||
|
||||
new DirectoryRefreshJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrate_directoryRefreshJob_nonNull() throws Exception {
|
||||
JobData testData = new JobData("DirectoryRefreshJob", "DirectoryRefreshJob", new Data.Builder().putString("address", "+16101234567").putBoolean("notify_of_new_users", true).build());
|
||||
JobData testData = new JobData("DirectoryRefreshJob", "DirectoryRefreshJob", new JsonJobData.Builder().putString("address", "+16101234567").putBoolean("notify_of_new_users", true).serialize());
|
||||
mockRecipientResolve("+16101234567", 1);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("DirectoryRefreshJob", converted.getFactoryKey());
|
||||
assertEquals("DirectoryRefreshJob", converted.getQueueKey());
|
||||
assertTrue(converted.getData().getBoolean("notify_of_new_users"));
|
||||
assertEquals("1", converted.getData().getString("recipient"));
|
||||
assertFalse(converted.getData().hasString("address"));
|
||||
assertTrue(data.getBoolean("notify_of_new_users"));
|
||||
assertEquals("1", data.getString("recipient"));
|
||||
assertFalse(data.hasString("address"));
|
||||
|
||||
new DirectoryRefreshJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
|
||||
@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());
|
||||
JobData testData = new JobData("RetrieveProfileAvatarJob", "RetrieveProfileAvatarJob+16101234567", new JsonJobData.Builder().putString("address", "+16101234567").putString("profile_avatar", "abc").serialize());
|
||||
mockRecipientResolve("+16101234567", 1);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("RetrieveProfileAvatarJob", converted.getFactoryKey());
|
||||
assertEquals("RetrieveProfileAvatarJob::" + RecipientId.from(1).toQueueKey(), converted.getQueueKey());
|
||||
assertEquals("1", converted.getData().getString("recipient"));
|
||||
assertEquals("1", data.getString("recipient"));
|
||||
|
||||
|
||||
new RetrieveProfileAvatarJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
@@ -210,14 +219,15 @@ public class RecipientIdJobMigrationTest {
|
||||
|
||||
@Test
|
||||
public void migrate_multiDeviceReadUpdateJob_empty() throws Exception {
|
||||
JobData testData = new JobData("MultiDeviceReadUpdateJob", null, new Data.Builder().putStringArray("message_ids", new String[0]).build());
|
||||
JobData testData = new JobData("MultiDeviceReadUpdateJob", null, new JsonJobData.Builder().putStringArray("message_ids", new String[0]).serialize());
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("MultiDeviceReadUpdateJob", converted.getFactoryKey());
|
||||
assertNull(converted.getQueueKey());
|
||||
assertEquals(0, converted.getData().getStringArray("message_ids").length);
|
||||
assertEquals(0, data.getStringArray("message_ids").length);
|
||||
|
||||
new MultiDeviceReadUpdateJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
@@ -227,17 +237,18 @@ public class RecipientIdJobMigrationTest {
|
||||
OldSerializableSyncMessageId id1 = new OldSerializableSyncMessageId("+16101234567", 1);
|
||||
OldSerializableSyncMessageId id2 = new OldSerializableSyncMessageId("+16101112222", 2);
|
||||
|
||||
JobData testData = new JobData("MultiDeviceReadUpdateJob", null, new Data.Builder().putStringArray("message_ids", new String[]{ JsonUtils.toJson(id1), JsonUtils.toJson(id2) }).build());
|
||||
JobData testData = new JobData("MultiDeviceReadUpdateJob", null, new JsonJobData.Builder().putStringArray("message_ids", new String[]{ JsonUtils.toJson(id1), JsonUtils.toJson(id2) }).serialize());
|
||||
mockRecipientResolve("+16101234567", 1);
|
||||
mockRecipientResolve("+16101112222", 2);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("MultiDeviceReadUpdateJob", converted.getFactoryKey());
|
||||
assertNull(converted.getQueueKey());
|
||||
|
||||
String[] updated = converted.getData().getStringArray("message_ids");
|
||||
String[] updated = data.getStringArray("message_ids");
|
||||
assertEquals(2, updated.length);
|
||||
|
||||
assertEquals(JsonUtils.toJson(new NewSerializableSyncMessageId("1", 1)), updated[0]);
|
||||
@@ -248,47 +259,50 @@ public class RecipientIdJobMigrationTest {
|
||||
|
||||
@Test
|
||||
public void migrate_pushMediaSendJob() throws Exception {
|
||||
JobData testData = new JobData("PushMediaSendJob", "+16101234567", new Data.Builder().putLong("message_id", 1).build());
|
||||
JobData testData = new JobData("PushMediaSendJob", "+16101234567", new JsonJobData.Builder().putLong("message_id", 1).serialize());
|
||||
mockRecipientResolve("+16101234567", 1);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("PushMediaSendJob", converted.getFactoryKey());
|
||||
assertEquals(RecipientId.from(1).toQueueKey(), converted.getQueueKey());
|
||||
assertEquals(1, converted.getData().getLong("message_id"));
|
||||
assertEquals(1, data.getLong("message_id"));
|
||||
|
||||
new IndividualSendJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrate_smsSendJob_nonNull() throws Exception {
|
||||
JobData testData = new JobData("SmsSendJob", "+16101234567", new Data.Builder().putLong("message_id", 1).putInt("run_attempt", 0).build());
|
||||
JobData testData = new JobData("SmsSendJob", "+16101234567", new JsonJobData.Builder().putLong("message_id", 1).putInt("run_attempt", 0).serialize());
|
||||
mockRecipientResolve("+16101234567", 1);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("SmsSendJob", converted.getFactoryKey());
|
||||
assertEquals(RecipientId.from(1).toQueueKey(), converted.getQueueKey());
|
||||
assertEquals(1, converted.getData().getLong("message_id"));
|
||||
assertEquals(0, converted.getData().getInt("run_attempt"));
|
||||
assertEquals(1, data.getLong("message_id"));
|
||||
assertEquals(0, data.getInt("run_attempt"));
|
||||
|
||||
new SmsSendJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void migrate_smsSendJob_null() throws Exception {
|
||||
JobData testData = new JobData("SmsSendJob", null, new Data.Builder().putLong("message_id", 1).putInt("run_attempt", 0).build());
|
||||
JobData testData = new JobData("SmsSendJob", null, new JsonJobData.Builder().putLong("message_id", 1).putInt("run_attempt", 0).serialize());
|
||||
mockRecipientResolve("+16101234567", 1);
|
||||
|
||||
RecipientIdJobMigration subject = new RecipientIdJobMigration(mock(Application.class));
|
||||
JobData converted = subject.migrate(testData);
|
||||
JsonJobData data = JsonJobData.deserialize(converted.getData());
|
||||
|
||||
assertEquals("SmsSendJob", converted.getFactoryKey());
|
||||
assertNull(converted.getQueueKey());
|
||||
assertEquals(1, converted.getData().getLong("message_id"));
|
||||
assertEquals(0, converted.getData().getInt("run_attempt"));
|
||||
assertEquals(1, data.getLong("message_id"));
|
||||
assertEquals(0, data.getInt("run_attempt"));
|
||||
|
||||
new SmsSendJob.Factory().create(mock(Job.Parameters.class), converted.getData());
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.thoughtcrime.securesms.jobmanager.migrations;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.thoughtcrime.securesms.database.MessageTable;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobMigration;
|
||||
import org.thoughtcrime.securesms.jobs.SendReadReceiptJob;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
@@ -26,20 +26,21 @@ public class SendReadReceiptsJobMigrationTest {
|
||||
SendReadReceiptJob job = new SendReadReceiptJob(1, RecipientId.from(2), new ArrayList<>(), new ArrayList<>());
|
||||
JobMigration.JobData jobData = new JobMigration.JobData(job.getFactoryKey(),
|
||||
"asdf",
|
||||
new Data.Builder()
|
||||
new JsonJobData.Builder()
|
||||
.putString("recipient", RecipientId.from(2).serialize())
|
||||
.putLongArray("message_ids", new long[]{1, 2, 3, 4, 5})
|
||||
.putLong("timestamp", 292837649).build());
|
||||
.putLong("timestamp", 292837649).serialize());
|
||||
when(mockDatabase.getThreadIdForMessage(anyLong())).thenReturn(1234L);
|
||||
|
||||
// WHEN
|
||||
JobMigration.JobData result = testSubject.migrate(jobData);
|
||||
JsonJobData data = JsonJobData.deserialize(result.getData());
|
||||
|
||||
// THEN
|
||||
assertEquals(1234L, result.getData().getLong("thread"));
|
||||
assertEquals(RecipientId.from(2).serialize(), result.getData().getString("recipient"));
|
||||
assertTrue(result.getData().hasLongArray("message_ids"));
|
||||
assertTrue(result.getData().hasLong("timestamp"));
|
||||
assertEquals(1234L, data.getLong("thread"));
|
||||
assertEquals(RecipientId.from(2).serialize(), data.getString("recipient"));
|
||||
assertTrue(data.hasLongArray("message_ids"));
|
||||
assertTrue(data.hasLong("timestamp"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -48,10 +49,10 @@ public class SendReadReceiptsJobMigrationTest {
|
||||
SendReadReceiptJob job = new SendReadReceiptJob(1, RecipientId.from(2), new ArrayList<>(), new ArrayList<>());
|
||||
JobMigration.JobData jobData = new JobMigration.JobData(job.getFactoryKey(),
|
||||
"asdf",
|
||||
new Data.Builder()
|
||||
new JsonJobData.Builder()
|
||||
.putString("recipient", RecipientId.from(2).serialize())
|
||||
.putLongArray("message_ids", new long[]{})
|
||||
.putLong("timestamp", 292837649).build());
|
||||
.putLong("timestamp", 292837649).serialize());
|
||||
when(mockDatabase.getThreadIdForMessage(anyLong())).thenReturn(-1L);
|
||||
|
||||
// WHEN
|
||||
@@ -77,7 +78,7 @@ public class SendReadReceiptsJobMigrationTest {
|
||||
@Test
|
||||
public void givenSomeOtherJobDataWithThreadId_whenIMigrate_thenIDoNotReplace() {
|
||||
// GIVEN
|
||||
JobMigration.JobData jobData = new JobMigration.JobData("SomeOtherJob", "asdf", new Data.Builder().putLong("thread", 1).build());
|
||||
JobMigration.JobData jobData = new JobMigration.JobData("SomeOtherJob", "asdf", new JsonJobData.Builder().putLong("thread", 1).serialize());
|
||||
|
||||
// WHEN
|
||||
JobMigration.JobData result = testSubject.migrate(jobData);
|
||||
@@ -89,7 +90,7 @@ public class SendReadReceiptsJobMigrationTest {
|
||||
@Test
|
||||
public void givenSomeOtherJobDataWithoutThreadId_whenIMigrate_thenIDoNotReplace() {
|
||||
// GIVEN
|
||||
JobMigration.JobData jobData = new JobMigration.JobData("SomeOtherJob", "asdf", new Data.Builder().build());
|
||||
JobMigration.JobData jobData = new JobMigration.JobData("SomeOtherJob", "asdf", new JsonJobData.Builder().serialize());
|
||||
|
||||
// WHEN
|
||||
JobMigration.JobData result = testSubject.migrate(jobData);
|
||||
|
||||
@@ -4,7 +4,7 @@ import org.junit.Test;
|
||||
import org.thoughtcrime.securesms.database.GroupTable;
|
||||
import org.thoughtcrime.securesms.database.model.GroupRecord;
|
||||
import org.thoughtcrime.securesms.groups.GroupId;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobMigration;
|
||||
import org.thoughtcrime.securesms.jobs.FailingJob;
|
||||
import org.thoughtcrime.securesms.jobs.SenderKeyDistributionSendJob;
|
||||
@@ -30,10 +30,10 @@ public class SenderKeyDistributionSendJobRecipientMigrationTest {
|
||||
// GIVEN
|
||||
JobMigration.JobData jobData = new JobMigration.JobData(SenderKeyDistributionSendJob.KEY,
|
||||
"asdf",
|
||||
new Data.Builder()
|
||||
new JsonJobData.Builder()
|
||||
.putString("recipient_id", RecipientId.from(1).serialize())
|
||||
.putBlobAsString("group_id", GROUP_ID.getDecodedId())
|
||||
.build());
|
||||
.serialize());
|
||||
|
||||
GroupRecord mockGroup = mock(GroupRecord.class);
|
||||
when(mockGroup.getRecipientId()).thenReturn(RecipientId.from(2));
|
||||
@@ -41,10 +41,11 @@ public class SenderKeyDistributionSendJobRecipientMigrationTest {
|
||||
|
||||
// WHEN
|
||||
JobMigration.JobData result = testSubject.migrate(jobData);
|
||||
JsonJobData data = JsonJobData.deserialize(result.getData());
|
||||
|
||||
// THEN
|
||||
assertEquals(RecipientId.from(1).serialize(), result.getData().getString("recipient_id"));
|
||||
assertEquals(RecipientId.from(2).serialize(), result.getData().getString("thread_recipient_id"));
|
||||
assertEquals(RecipientId.from(1).serialize(), data.getString("recipient_id"));
|
||||
assertEquals(RecipientId.from(2).serialize(), data.getString("thread_recipient_id"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,10 +53,10 @@ public class SenderKeyDistributionSendJobRecipientMigrationTest {
|
||||
// GIVEN
|
||||
JobMigration.JobData jobData = new JobMigration.JobData(SenderKeyDistributionSendJob.KEY,
|
||||
"asdf",
|
||||
new Data.Builder()
|
||||
new JsonJobData.Builder()
|
||||
.putString("recipient_id", RecipientId.from(1).serialize())
|
||||
.putBlobAsString("group_id", GROUP_ID.getDecodedId())
|
||||
.build());
|
||||
.serialize());
|
||||
|
||||
// WHEN
|
||||
JobMigration.JobData result = testSubject.migrate(jobData);
|
||||
@@ -69,9 +70,9 @@ public class SenderKeyDistributionSendJobRecipientMigrationTest {
|
||||
// GIVEN
|
||||
JobMigration.JobData jobData = new JobMigration.JobData(SenderKeyDistributionSendJob.KEY,
|
||||
"asdf",
|
||||
new Data.Builder()
|
||||
new JsonJobData.Builder()
|
||||
.putString("recipient_id", RecipientId.from(1).serialize())
|
||||
.build());
|
||||
.serialize());
|
||||
|
||||
// WHEN
|
||||
JobMigration.JobData result = testSubject.migrate(jobData);
|
||||
|
||||
@@ -6,9 +6,7 @@ import com.annimon.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.thoughtcrime.securesms.database.JobDatabase;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.JsonDataSerializer;
|
||||
import org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec;
|
||||
import org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec;
|
||||
import org.thoughtcrime.securesms.jobmanager.persistence.FullSpec;
|
||||
@@ -30,9 +28,6 @@ import static org.thoughtcrime.securesms.testutil.TestHelpers.setOf;
|
||||
|
||||
public class FastJobStorageTest {
|
||||
|
||||
private static final JsonDataSerializer serializer = new JsonDataSerializer();
|
||||
private static final String EMPTY_DATA = serializer.serialize(Data.EMPTY);
|
||||
|
||||
@Test
|
||||
public void init_allStoredDataAvailable() {
|
||||
FastJobStorage subject = new FastJobStorage(fixedDataDatabase(DataSet1.FULL_SPECS));
|
||||
@@ -97,10 +92,10 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void updateAllJobsToBePending_allArePending() {
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, EMPTY_DATA, null, true, false),
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, null, 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),
|
||||
FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 1, 1, 1, 1, 1, null, null, true, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -117,7 +112,7 @@ public class FastJobStorageTest {
|
||||
public void updateJobs_writesToDatabase() {
|
||||
JobDatabase database = fixedDataDatabase(DataSet1.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));
|
||||
List<JobSpec> jobs = Collections.singletonList(new JobSpec("id1", "f1", null, 1, 1, 1, 1, 1, null, null, false, false));
|
||||
|
||||
subject.init();
|
||||
subject.updateJobs(jobs);
|
||||
@@ -129,7 +124,7 @@ public class FastJobStorageTest {
|
||||
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));
|
||||
List<JobSpec> jobs = Collections.singletonList(new JobSpec("id1", "f1", null, 1, 1, 1, 1, 1, null, null, false, false));
|
||||
|
||||
subject.init();
|
||||
subject.updateJobs(jobs);
|
||||
@@ -139,20 +134,20 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void updateJobs_updatesAllFields() {
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, EMPTY_DATA, null, false, false),
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, null, 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),
|
||||
FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 1, 1, 1, 1, 1, null, 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),
|
||||
FullSpec fullSpec3 = new FullSpec(new JobSpec("3", "f3", null, 1, 1, 1, 1, 1, null, 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);
|
||||
JobSpec update1 = new JobSpec("1", "g1", "q1", 2, 2, 2, 2, 2, "abc".getBytes(), null, true, false);
|
||||
JobSpec update2 = new JobSpec("2", "g2", "q2", 3, 3, 3, 3, 3, "def".getBytes(), "ghi".getBytes(), true, false);
|
||||
|
||||
subject.init();
|
||||
subject.updateJobs(Arrays.asList(update1, update2));
|
||||
@@ -191,9 +186,9 @@ public class FastJobStorageTest {
|
||||
FastJobStorage subject = new FastJobStorage(database);
|
||||
|
||||
subject.init();
|
||||
subject.updateJobAfterRetry("id1", true, 1, 10, "a");
|
||||
subject.updateJobAfterRetry("id1", true, 1, 10, "a".getBytes());
|
||||
|
||||
verify(database).updateJobAfterRetry("id1", true, 1, 10, "a");
|
||||
verify(database).updateJobAfterRetry("id1", true, 1, 10, "a".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -202,21 +197,21 @@ public class FastJobStorageTest {
|
||||
FastJobStorage subject = new FastJobStorage(database);
|
||||
|
||||
subject.init();
|
||||
subject.updateJobAfterRetry("id1", true, 1, 10, "a");
|
||||
subject.updateJobAfterRetry("id1", true, 1, 10, "a".getBytes());
|
||||
|
||||
verify(database, times(0)).updateJobAfterRetry("id1", true, 1, 10, "a");
|
||||
verify(database, times(0)).updateJobAfterRetry("id1", true, 1, 10, "a".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateJobAfterRetry_stateUpdated() {
|
||||
FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 3, -1, EMPTY_DATA, null, true, false),
|
||||
FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 3, -1, null, null, true, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Collections.singletonList(fullSpec)));
|
||||
|
||||
subject.init();
|
||||
subject.updateJobAfterRetry("1", false, 1, 10, "a");
|
||||
subject.updateJobAfterRetry("1", false, 1, 10, "a".getBytes());
|
||||
|
||||
JobSpec job = subject.getJobSpec("1");
|
||||
|
||||
@@ -224,15 +219,15 @@ public class FastJobStorageTest {
|
||||
assertFalse(job.isRunning());
|
||||
assertEquals(1, job.getRunAttempt());
|
||||
assertEquals(10, job.getNextRunAttemptTime());
|
||||
assertEquals("a", job.getSerializedData());
|
||||
assertEquals("a", new String(job.getSerializedData()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenEarlierItemInQueueInRunning() {
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, true, false),
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, null, 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),
|
||||
FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", "q", 0, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -244,7 +239,7 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenAllJobsAreRunning() {
|
||||
FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, true, false),
|
||||
FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, null, null, true, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -256,7 +251,7 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenNextRunTimeIsAfterCurrentTime() {
|
||||
FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 10, 0, 0, -1, EMPTY_DATA, null, false, false),
|
||||
FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 10, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -268,10 +263,10 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenDependentOnAnotherJob() {
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, -1, EMPTY_DATA, null, true, false),
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, -1, null, 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),
|
||||
FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 0, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.singletonList(new DependencySpec("2", "1", false)));
|
||||
|
||||
@@ -284,7 +279,7 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void getPendingJobsWithNoDependenciesInCreatedOrder_singleEligibleJob() {
|
||||
FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false),
|
||||
FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -296,10 +291,10 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void getPendingJobsWithNoDependenciesInCreatedOrder_multipleEligibleJobs() {
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false),
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false),
|
||||
FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 0, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -312,10 +307,10 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void getPendingJobsWithNoDependenciesInCreatedOrder_singleEligibleJobInMixedList() {
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, -1, EMPTY_DATA, null, true, false),
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, -1, null, 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),
|
||||
FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 0, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -331,10 +326,10 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void getPendingJobsWithNoDependenciesInCreatedOrder_firstItemInQueue() {
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false),
|
||||
FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false),
|
||||
FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", "q", 0, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -350,10 +345,10 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void getPendingJobsWithNoDependenciesInCreatedOrder_migrationJobTakesPrecedence() {
|
||||
FullSpec plainSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false),
|
||||
FullSpec plainSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, null, 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),
|
||||
FullSpec migrationSpec = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -368,10 +363,10 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void getPendingJobsWithNoDependenciesInCreatedOrder_runningMigrationBlocksNormalJobs() {
|
||||
FullSpec plainSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false),
|
||||
FullSpec plainSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, -1, null, 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),
|
||||
FullSpec migrationSpec = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, -1, null, null, true, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -385,10 +380,10 @@ public class FastJobStorageTest {
|
||||
|
||||
@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),
|
||||
FullSpec migrationSpec1 = new FullSpec(new JobSpec("1", "f1", Job.Parameters.MIGRATION_QUEUE_KEY, 0, 0, 0, 0, -1, null, 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),
|
||||
FullSpec migrationSpec2 = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -402,10 +397,10 @@ public class FastJobStorageTest {
|
||||
|
||||
@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),
|
||||
FullSpec migrationSpec1 = new FullSpec(new JobSpec("1", "f1", Job.Parameters.MIGRATION_QUEUE_KEY, 0, 0, 0, 0, -1, null, 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),
|
||||
FullSpec migrationSpec2 = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -420,10 +415,10 @@ public class FastJobStorageTest {
|
||||
|
||||
@Test
|
||||
public void getPendingJobsWithNoDependenciesInCreatedOrder_onlyMigrationJobWithAppropriateNextRunTime() {
|
||||
FullSpec migrationSpec1 = new FullSpec(new JobSpec("1", "f1", Job.Parameters.MIGRATION_QUEUE_KEY, 0, 999, 0, 0, -1, EMPTY_DATA, null, false, false),
|
||||
FullSpec migrationSpec1 = new FullSpec(new JobSpec("1", "f1", Job.Parameters.MIGRATION_QUEUE_KEY, 0, 999, 0, 0, -1, null, 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),
|
||||
FullSpec migrationSpec2 = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, -1, null, null, false, false),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
|
||||
@@ -608,9 +603,9 @@ public class FastJobStorageTest {
|
||||
}
|
||||
|
||||
private static final class DataSet1 {
|
||||
static final JobSpec JOB_1 = new JobSpec("id1", "f1", "q1", 1, 2, 3, 4, 5, EMPTY_DATA, null, false, false);
|
||||
static final JobSpec JOB_2 = new JobSpec("id2", "f2", "q2", 1, 2, 3, 4, 5, EMPTY_DATA, null, false, false);
|
||||
static final JobSpec JOB_3 = new JobSpec("id3", "f3", "q3", 1, 2, 3, 4, 5, EMPTY_DATA, null, false, false);
|
||||
static final JobSpec JOB_1 = new JobSpec("id1", "f1", "q1", 1, 2, 3, 4, 5, null, null, false, false);
|
||||
static final JobSpec JOB_2 = new JobSpec("id2", "f2", "q2", 1, 2, 3, 4, 5, null, null, false, false);
|
||||
static final JobSpec JOB_3 = new JobSpec("id3", "f3", "q3", 1, 2, 3, 4, 5, null, null, false, false);
|
||||
static final ConstraintSpec CONSTRAINT_1 = new ConstraintSpec("id1", "f1", false);
|
||||
static final ConstraintSpec CONSTRAINT_2 = new ConstraintSpec("id2", "f2", false);
|
||||
static final DependencySpec DEPENDENCY_2 = new DependencySpec("id2", "id1", false);
|
||||
@@ -641,7 +636,7 @@ public class FastJobStorageTest {
|
||||
}
|
||||
|
||||
private static final class DataSetMemory {
|
||||
static final JobSpec JOB_1 = new JobSpec("id1", "f1", "q1", 1, 2, 3, 4, 5, EMPTY_DATA, null, false, true);
|
||||
static final JobSpec JOB_1 = new JobSpec("id1", "f1", "q1", 1, 2, 3, 4, 5, null, null, false, true);
|
||||
static final ConstraintSpec CONSTRAINT_1 = new ConstraintSpec("id1", "f1", true);
|
||||
static final FullSpec FULL_SPEC_1 = new FullSpec(JOB_1, Collections.singletonList(CONSTRAINT_1), Collections.emptyList());
|
||||
static final List<FullSpec> FULL_SPECS = Collections.singletonList(FULL_SPEC_1);
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.thoughtcrime.securesms.database.MessageTable;
|
||||
import org.thoughtcrime.securesms.database.model.MessageId;
|
||||
import org.thoughtcrime.securesms.database.model.StoryType;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.jobmanager.Data;
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData;
|
||||
import org.thoughtcrime.securesms.jobmanager.Job;
|
||||
import org.thoughtcrime.securesms.jobmanager.JobManager;
|
||||
import org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob;
|
||||
@@ -92,7 +92,7 @@ public class MarkReadReceiverTest {
|
||||
return;
|
||||
}
|
||||
|
||||
Data data = job.serialize();
|
||||
JsonJobData data = JsonJobData.deserialize(job.serialize());
|
||||
|
||||
long threadId = data.getLong("thread");
|
||||
String recipientId = data.getString("recipient");
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.thoughtcrime.securesms.attachments.DatabaseAttachment
|
||||
import org.thoughtcrime.securesms.database.AttachmentTable
|
||||
import org.thoughtcrime.securesms.jobmanager.Job
|
||||
import org.thoughtcrime.securesms.jobmanager.JobManager
|
||||
import org.thoughtcrime.securesms.jobmanager.JsonJobData
|
||||
import org.thoughtcrime.securesms.jobs.AttachmentCompressionJob
|
||||
import org.thoughtcrime.securesms.jobs.AttachmentCopyJob
|
||||
import org.thoughtcrime.securesms.jobs.AttachmentUploadJob
|
||||
@@ -211,8 +212,8 @@ class UploadDependencyGraphTest {
|
||||
if (expectedCopyDestinationCount > 0) {
|
||||
assertTrue(steps[3][0] is AttachmentCopyJob)
|
||||
|
||||
val uploadData = steps[2][0].serialize()
|
||||
val copyData = steps[3][0].serialize()
|
||||
val uploadData = JsonJobData.deserialize(steps[2][0].serialize())
|
||||
val copyData = JsonJobData.deserialize(steps[3][0].serialize())
|
||||
|
||||
val uploadAttachmentId = AttachmentId(uploadData.getLong("row_id"), uploadData.getLong("unique_id"))
|
||||
val copySourceAttachmentId = JsonUtils.fromJson(copyData.getString("source_id"), AttachmentId::class.java)
|
||||
|
||||
Reference in New Issue
Block a user