diff --git a/app/src/flipper/java/org/thoughtcrime/securesms/database/FlipperSqlCipherAdapter.java b/app/src/flipper/java/org/thoughtcrime/securesms/database/FlipperSqlCipherAdapter.java index 6e68db8a25..dd9d0dde12 100644 --- a/app/src/flipper/java/org/thoughtcrime/securesms/database/FlipperSqlCipherAdapter.java +++ b/app/src/flipper/java/org/thoughtcrime/securesms/database/FlipperSqlCipherAdapter.java @@ -45,13 +45,15 @@ public class FlipperSqlCipherAdapter extends DatabaseDriver fullSpecs) { @@ -94,7 +152,7 @@ public class JobDatabase extends Database { return; } - SQLiteDatabase db = databaseHelper.getWritableDatabase(); + SQLiteDatabase db = getWritableDatabase(); db.beginTransaction(); @@ -114,7 +172,7 @@ public class JobDatabase extends Database { public synchronized @NonNull List getAllJobSpecs() { List jobs = new LinkedList<>(); - try (Cursor cursor = databaseHelper.getReadableDatabase().query(Jobs.TABLE_NAME, null, null, null, null, null, Jobs.CREATE_TIME + ", " + Jobs.ID + " ASC")) { + try (Cursor cursor = getReadableDatabase().query(Jobs.TABLE_NAME, null, null, null, null, null, Jobs.CREATE_TIME + ", " + Jobs.ID + " ASC")) { while (cursor != null && cursor.moveToNext()) { jobs.add(jobSpecFromCursor(cursor)); } @@ -130,7 +188,7 @@ public class JobDatabase extends Database { String query = Jobs.JOB_SPEC_ID + " = ?"; String[] args = new String[]{ id }; - databaseHelper.getWritableDatabase().update(Jobs.TABLE_NAME, contentValues, query, args); + getWritableDatabase().update(Jobs.TABLE_NAME, contentValues, query, args); } public synchronized void updateJobAfterRetry(@NonNull String id, boolean isRunning, int runAttempt, long nextRunAttemptTime, @NonNull String serializedData) { @@ -143,14 +201,14 @@ public class JobDatabase extends Database { String query = Jobs.JOB_SPEC_ID + " = ?"; String[] args = new String[]{ id }; - databaseHelper.getWritableDatabase().update(Jobs.TABLE_NAME, contentValues, query, args); + getWritableDatabase().update(Jobs.TABLE_NAME, contentValues, query, args); } public synchronized void updateAllJobsToBePending() { ContentValues contentValues = new ContentValues(); contentValues.put(Jobs.IS_RUNNING, 0); - databaseHelper.getWritableDatabase().update(Jobs.TABLE_NAME, contentValues, null, null); + getWritableDatabase().update(Jobs.TABLE_NAME, contentValues, null, null); } public synchronized void updateJobs(@NonNull List jobs) { @@ -158,7 +216,7 @@ public class JobDatabase extends Database { return; } - SQLiteDatabase db = databaseHelper.getWritableDatabase(); + SQLiteDatabase db = getWritableDatabase(); db.beginTransaction(); @@ -175,7 +233,6 @@ public class JobDatabase extends Database { values.put(Jobs.RUN_ATTEMPT, job.getRunAttempt()); values.put(Jobs.MAX_ATTEMPTS, job.getMaxAttempts()); values.put(Jobs.MAX_BACKOFF, job.getMaxBackoff()); - values.put(Jobs.MAX_INSTANCES, job.getMaxInstancesForFactory()); values.put(Jobs.LIFESPAN, job.getLifespan()); values.put(Jobs.SERIALIZED_DATA, job.getSerializedData()); values.put(Jobs.SERIALIZED_INPUT_DATA, job.getSerializedInputData()); @@ -194,7 +251,7 @@ public class JobDatabase extends Database { } public synchronized void deleteJobs(@NonNull List jobIds) { - SQLiteDatabase db = databaseHelper.getWritableDatabase(); + SQLiteDatabase db = getWritableDatabase(); db.beginTransaction(); @@ -217,7 +274,7 @@ public class JobDatabase extends Database { public synchronized @NonNull List getAllConstraintSpecs() { List constraints = new LinkedList<>(); - try (Cursor cursor = databaseHelper.getReadableDatabase().query(Constraints.TABLE_NAME, null, null, null, null, null, null)) { + try (Cursor cursor = getReadableDatabase().query(Constraints.TABLE_NAME, null, null, null, null, null, null)) { while (cursor != null && cursor.moveToNext()) { constraints.add(constraintSpecFromCursor(cursor)); } @@ -229,7 +286,7 @@ public class JobDatabase extends Database { public synchronized @NonNull List getAllDependencySpecs() { List dependencies = new LinkedList<>(); - try (Cursor cursor = databaseHelper.getReadableDatabase().query(Dependencies.TABLE_NAME, null, null, null, null, null, null)) { + try (Cursor cursor = getReadableDatabase().query(Dependencies.TABLE_NAME, null, null, null, null, null, null)) { while (cursor != null && cursor.moveToNext()) { dependencies.add(dependencySpecFromCursor(cursor)); } @@ -252,7 +309,6 @@ public class JobDatabase extends Database { contentValues.put(Jobs.RUN_ATTEMPT, job.getRunAttempt()); contentValues.put(Jobs.MAX_ATTEMPTS, job.getMaxAttempts()); contentValues.put(Jobs.MAX_BACKOFF, job.getMaxBackoff()); - contentValues.put(Jobs.MAX_INSTANCES, job.getMaxInstancesForFactory()); contentValues.put(Jobs.LIFESPAN, job.getLifespan()); contentValues.put(Jobs.SERIALIZED_DATA, job.getSerializedData()); contentValues.put(Jobs.SERIALIZED_INPUT_DATA, job.getSerializedInputData()); @@ -293,7 +349,6 @@ public class JobDatabase extends Database { cursor.getInt(cursor.getColumnIndexOrThrow(Jobs.MAX_ATTEMPTS)), cursor.getLong(cursor.getColumnIndexOrThrow(Jobs.MAX_BACKOFF)), cursor.getLong(cursor.getColumnIndexOrThrow(Jobs.LIFESPAN)), - cursor.getInt(cursor.getColumnIndexOrThrow(Jobs.MAX_INSTANCES)), cursor.getString(cursor.getColumnIndexOrThrow(Jobs.SERIALIZED_DATA)), cursor.getString(cursor.getColumnIndexOrThrow(Jobs.SERIALIZED_INPUT_DATA)), cursor.getInt(cursor.getColumnIndexOrThrow(Jobs.IS_RUNNING)) == 1, @@ -311,4 +366,73 @@ public class JobDatabase extends Database { cursor.getString(cursor.getColumnIndexOrThrow(Dependencies.DEPENDS_ON_JOB_SPEC_ID)), false); } + + private @NonNull SQLiteDatabase getReadableDatabase() { + return getWritableDatabase(databaseSecret.asString()); + } + + private @NonNull SQLiteDatabase getWritableDatabase() { + return getWritableDatabase(databaseSecret.asString()); + } + + @Override + public @NonNull SQLiteDatabase getSqlCipherDatabase() { + return getWritableDatabase(); + } + + private void dropTableIfPresent(@NonNull String table) { + if (DatabaseFactory.getInstance(application).hasTable(table)) { + Log.i(TAG, "Dropping original " + table + " table from the main database."); + DatabaseFactory.getInstance(application).getRawDatabase().rawExecSQL("DROP TABLE " + table); + } + } + + private static void migrateJobSpecsFromPreviousDatabase(@NonNull SQLiteDatabase oldDb, @NonNull SQLiteDatabase newDb) { + try (Cursor cursor = oldDb.rawQuery("SELECT * FROM job_spec", null)) { + while (cursor.moveToNext()) { + ContentValues values = new ContentValues(); + + values.put(Jobs.JOB_SPEC_ID, CursorUtil.requireString(cursor, "job_spec_id")); + values.put(Jobs.FACTORY_KEY, CursorUtil.requireString(cursor, "factory_key")); + values.put(Jobs.QUEUE_KEY, CursorUtil.requireString(cursor, "queue_key")); + values.put(Jobs.CREATE_TIME, CursorUtil.requireLong(cursor, "create_time")); + values.put(Jobs.NEXT_RUN_ATTEMPT_TIME, CursorUtil.requireLong(cursor, "next_run_attempt_time")); + values.put(Jobs.RUN_ATTEMPT, CursorUtil.requireInt(cursor, "run_attempt")); + values.put(Jobs.MAX_ATTEMPTS, CursorUtil.requireInt(cursor, "max_attempts")); + values.put(Jobs.MAX_BACKOFF, CursorUtil.requireLong(cursor, "max_backoff")); + values.put(Jobs.LIFESPAN, CursorUtil.requireLong(cursor, "lifespan")); + values.put(Jobs.SERIALIZED_DATA, CursorUtil.requireString(cursor, "serialized_data")); + values.put(Jobs.SERIALIZED_INPUT_DATA, CursorUtil.requireString(cursor, "serialized_input_data")); + values.put(Jobs.IS_RUNNING, CursorUtil.requireInt(cursor, "is_running")); + + newDb.insert(Jobs.TABLE_NAME, null, values); + } + } + } + + private static void migrateConstraintSpecsFromPreviousDatabase(@NonNull SQLiteDatabase oldDb, @NonNull SQLiteDatabase newDb) { + try (Cursor cursor = oldDb.rawQuery("SELECT * FROM constraint_spec", null)) { + while (cursor.moveToNext()) { + ContentValues values = new ContentValues(); + + values.put(Constraints.JOB_SPEC_ID, CursorUtil.requireString(cursor, "job_spec_id")); + values.put(Constraints.FACTORY_KEY, CursorUtil.requireString(cursor, "factory_key")); + + newDb.insert(Constraints.TABLE_NAME, null, values); + } + } + } + + private static void migrateDependencySpecsFromPreviousDatabase(@NonNull SQLiteDatabase oldDb, @NonNull SQLiteDatabase newDb) { + try (Cursor cursor = oldDb.rawQuery("SELECT * FROM dependency_spec", null)) { + while (cursor.moveToNext()) { + ContentValues values = new ContentValues(); + + values.put(Dependencies.JOB_SPEC_ID, CursorUtil.requireString(cursor, "job_spec_id")); + values.put(Dependencies.DEPENDS_ON_JOB_SPEC_ID, CursorUtil.requireString(cursor, "depends_on_job_spec_id")); + + newDb.insert(Dependencies.TABLE_NAME, null, values); + } + } + } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java index 7ad1b0cf9c..367b716c16 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java @@ -201,7 +201,6 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper implements SignalDatab db.execSQL(StorageKeyDatabase.CREATE_TABLE); db.execSQL(MentionDatabase.CREATE_TABLE); executeStatements(db, SearchDatabase.CREATE_TABLE); - executeStatements(db, JobDatabase.CREATE_TABLE); executeStatements(db, RemappedRecordsDatabase.CREATE_TABLE); executeStatements(db, RecipientDatabase.CREATE_INDEXS); diff --git a/app/src/main/java/org/thoughtcrime/securesms/dependencies/ApplicationDependencyProvider.java b/app/src/main/java/org/thoughtcrime/securesms/dependencies/ApplicationDependencyProvider.java index 61ede78048..aae6fd5b74 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/dependencies/ApplicationDependencyProvider.java +++ b/app/src/main/java/org/thoughtcrime/securesms/dependencies/ApplicationDependencyProvider.java @@ -14,6 +14,7 @@ import org.thoughtcrime.securesms.components.TypingStatusSender; import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.DatabaseObserver; +import org.thoughtcrime.securesms.database.JobDatabase; import org.thoughtcrime.securesms.events.ReminderUpdateEvent; import org.thoughtcrime.securesms.jobmanager.Constraint; import org.thoughtcrime.securesms.jobmanager.ConstraintObserver; @@ -150,7 +151,7 @@ public class ApplicationDependencyProvider implements ApplicationDependencies.Pr .setJobFactories(JobManagerFactories.getJobFactories(context)) .setConstraintFactories(JobManagerFactories.getConstraintFactories(context)) .setConstraintObservers(JobManagerFactories.getConstraintObservers(context)) - .setJobStorage(new FastJobStorage(DatabaseFactory.getJobDatabase(context))) + .setJobStorage(new FastJobStorage(JobDatabase.getInstance(context))) .setJobMigrator(new JobMigrator(TextSecurePreferences.getJobManagerVersion(context), JobManager.CURRENT_VERSION, JobManagerFactories.getJobMigrations(context))) .addReservedJobRunner(new FactoryJobPredicate(PushDecryptMessageJob.KEY, PushProcessMessageJob.KEY, MarkerJob.KEY)) .addReservedJobRunner(new FactoryJobPredicate(PushTextSendJob.KEY, PushMediaSendJob.KEY, PushGroupSendJob.KEY, ReactionSendJob.KEY, TypingSendJob.KEY, GroupCallUpdateSendJob.KEY)) diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobController.java b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobController.java index 7abf59002a..1278bd0bf2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobController.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobController.java @@ -355,7 +355,6 @@ class JobController { job.getParameters().getMaxAttempts(), job.getParameters().getMaxBackoff(), job.getParameters().getLifespan(), - job.getParameters().getMaxInstancesForFactory(), dataSerializer.serialize(job.serialize()), null, false, @@ -469,7 +468,6 @@ class JobController { jobSpec.getMaxAttempts(), jobSpec.getMaxBackoff(), jobSpec.getLifespan(), - jobSpec.getMaxInstancesForFactory(), jobSpec.getSerializedData(), dataSerializer.serialize(inputData), jobSpec.isRunning(), diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobMigrator.java b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobMigrator.java index 6ac435777b..a37485be2a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobMigrator.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/JobMigrator.java @@ -71,7 +71,6 @@ public class JobMigrator { jobSpec.getMaxAttempts(), jobSpec.getMaxBackoff(), jobSpec.getLifespan(), - jobSpec.getMaxInstancesForFactory(), dataSerializer.serialize(updatedJobData.getData()), jobSpec.getSerializedInputData(), jobSpec.isRunning(), diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/persistence/JobSpec.java b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/persistence/JobSpec.java index dce8cbe482..3a1c0c7457 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/persistence/JobSpec.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/persistence/JobSpec.java @@ -18,7 +18,6 @@ public final class JobSpec { private final int maxAttempts; private final long maxBackoff; private final long lifespan; - private final int maxInstances; private final String serializedData; private final String serializedInputData; private final boolean isRunning; @@ -33,7 +32,6 @@ public final class JobSpec { int maxAttempts, long maxBackoff, long lifespan, - int maxInstances, @NonNull String serializedData, @Nullable String serializedInputData, boolean isRunning, @@ -48,7 +46,6 @@ public final class JobSpec { this.runAttempt = runAttempt; this.maxAttempts = maxAttempts; this.lifespan = lifespan; - this.maxInstances = maxInstances; this.serializedData = serializedData; this.serializedInputData = serializedInputData; this.isRunning = isRunning; @@ -87,10 +84,6 @@ public final class JobSpec { return maxBackoff; } - public int getMaxInstancesForFactory() { - return maxInstances; - } - public long getLifespan() { return lifespan; } @@ -122,7 +115,6 @@ public final class JobSpec { maxAttempts == jobSpec.maxAttempts && maxBackoff == jobSpec.maxBackoff && lifespan == jobSpec.lifespan && - maxInstances == jobSpec.maxInstances && isRunning == jobSpec.isRunning && memoryOnly == jobSpec.memoryOnly && Objects.equals(id, jobSpec.id) && @@ -134,13 +126,13 @@ public final class JobSpec { @Override public int hashCode() { - return Objects.hash(id, factoryKey, queueKey, createTime, nextRunAttemptTime, runAttempt, maxAttempts, maxBackoff, lifespan, maxInstances, serializedData, serializedInputData, isRunning, memoryOnly); + return Objects.hash(id, factoryKey, queueKey, createTime, nextRunAttemptTime, runAttempt, maxAttempts, maxBackoff, lifespan, serializedData, serializedInputData, isRunning, memoryOnly); } @SuppressLint("DefaultLocale") @Override public @NonNull String toString() { - return String.format("id: JOB::%s | factoryKey: %s | queueKey: %s | createTime: %d | nextRunAttemptTime: %d | runAttempt: %d | maxAttempts: %d | maxBackoff: %d | maxInstances: %d | lifespan: %d | isRunning: %b | memoryOnly: %b", - id, factoryKey, queueKey, createTime, nextRunAttemptTime, runAttempt, maxAttempts, maxBackoff, maxInstances, lifespan, isRunning, memoryOnly); + return String.format("id: JOB::%s | factoryKey: %s | queueKey: %s | createTime: %d | nextRunAttemptTime: %d | runAttempt: %d | maxAttempts: %d | maxBackoff: %d | lifespan: %d | isRunning: %b | memoryOnly: %b", + id, factoryKey, queueKey, createTime, nextRunAttemptTime, runAttempt, maxAttempts, maxBackoff, lifespan, isRunning, memoryOnly); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/workmanager/WorkManagerDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/workmanager/WorkManagerDatabase.java index 711f28c906..5414d91e68 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobmanager/workmanager/WorkManagerDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobmanager/workmanager/WorkManagerDatabase.java @@ -67,7 +67,6 @@ final class WorkManagerDatabase extends SQLiteOpenHelper { Job.Parameters.UNLIMITED, TimeUnit.SECONDS.toMillis(30), TimeUnit.DAYS.toMillis(1), - Job.Parameters.UNLIMITED, dataSerializer.serialize(DataMigrator.convert(data)), null, false, diff --git a/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.java b/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.java index a68bfde846..6c184beb6d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.java +++ b/app/src/main/java/org/thoughtcrime/securesms/jobs/FastJobStorage.java @@ -178,7 +178,6 @@ public class FastJobStorage implements JobStorage { existing.getMaxAttempts(), existing.getMaxBackoff(), existing.getLifespan(), - existing.getMaxInstancesForFactory(), existing.getSerializedData(), existing.getSerializedInputData(), isRunning, @@ -209,7 +208,6 @@ public class FastJobStorage implements JobStorage { existing.getMaxAttempts(), existing.getMaxBackoff(), existing.getLifespan(), - existing.getMaxInstancesForFactory(), serializedData, existing.getSerializedInputData(), isRunning, @@ -236,7 +234,6 @@ public class FastJobStorage implements JobStorage { existing.getMaxAttempts(), existing.getMaxBackoff(), existing.getLifespan(), - existing.getMaxInstancesForFactory(), existing.getSerializedData(), existing.getSerializedInputData(), false, diff --git a/app/src/test/java/org/thoughtcrime/securesms/jobmanager/JobMigratorTest.java b/app/src/test/java/org/thoughtcrime/securesms/jobmanager/JobMigratorTest.java index 9c160c33cb..2619c9942d 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/jobmanager/JobMigratorTest.java +++ b/app/src/test/java/org/thoughtcrime/securesms/jobmanager/JobMigratorTest.java @@ -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, 1, 1, "", null, false, false)))); + when(jobStorage.getAllJobSpecs()).thenReturn(new ArrayList<>(Collections.singletonList(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, 1, "", null, false, false)))); return jobStorage; } diff --git a/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.java b/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.java index 33f651a4a7..4ba1fd14af 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.java +++ b/app/src/test/java/org/thoughtcrime/securesms/jobs/FastJobStorageTest.java @@ -96,10 +96,10 @@ public class FastJobStorageTest { @Test public void updateAllJobsToBePending_allArePending() { - FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, 1, 1, EMPTY_DATA, null, true, false), + FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, 1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList()); - FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 1, 1, 1, 1, 1, 1, 1, EMPTY_DATA, null, true, false), + FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 1, 1, 1, 1, 1, 1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList()); @@ -116,7 +116,7 @@ public class FastJobStorageTest { public void updateJobs_writesToDatabase() { JobDatabase database = fixedDataDatabase(DataSet1.FULL_SPECS); FastJobStorage subject = new FastJobStorage(database); - List jobs = Collections.singletonList(new JobSpec("id1", "f1", null, 1, 1, 1, 1, 1, 1, 1, EMPTY_DATA, null, false, false)); + List jobs = Collections.singletonList(new JobSpec("id1", "f1", null, 1, 1, 1, 1, 1, 1, EMPTY_DATA, null, false, false)); subject.init(); subject.updateJobs(jobs); @@ -128,7 +128,7 @@ public class FastJobStorageTest { public void updateJobs_memoryOnly_doesNotWriteToDatabase() { JobDatabase database = fixedDataDatabase(DataSetMemory.FULL_SPECS); FastJobStorage subject = new FastJobStorage(database); - List jobs = Collections.singletonList(new JobSpec("id1", "f1", null, 1, 1, 1, 1, 1, 1, 1, EMPTY_DATA, null, false, false)); + List jobs = Collections.singletonList(new JobSpec("id1", "f1", null, 1, 1, 1, 1, 1, 1, EMPTY_DATA, null, false, false)); subject.init(); subject.updateJobs(jobs); @@ -138,20 +138,20 @@ public class FastJobStorageTest { @Test public void updateJobs_updatesAllFields() { - FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 1, 1, 1, 1, 1, 1, 1, EMPTY_DATA, null, false, false), + FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 1, 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, 1, 1, EMPTY_DATA, null, false, false), + FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 1, 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, 1, 1, EMPTY_DATA, null, false, false), + FullSpec fullSpec3 = new FullSpec(new JobSpec("3", "f3", null, 1, 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, 2, 2, "abc", null, true, false); - JobSpec update2 = new JobSpec("2", "g2", "q2", 3, 3, 3, 3, 3, 3, 3, "def", "ghi", true, false); + JobSpec update1 = new JobSpec("1", "g1", "q1", 2, 2, 2, 2, 2, 2, "abc", null, true, false); + JobSpec update2 = new JobSpec("2", "g2", "q2", 3, 3, 3, 3, 3, 3, "def", "ghi", true, false); subject.init(); subject.updateJobs(Arrays.asList(update1, update2)); @@ -208,7 +208,7 @@ public class FastJobStorageTest { @Test public void updateJobAfterRetry_stateUpdated() { - FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 3, 30000, -1, -1, EMPTY_DATA, null, true, false), + FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 3, 30000, -1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList()); @@ -228,10 +228,10 @@ public class FastJobStorageTest { @Test public void getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenEarlierItemInQueueInRunning() { - FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, 0, -1, -1, EMPTY_DATA, null, true, false), + FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", "q", 0, 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, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", "q", 0, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); @@ -243,7 +243,7 @@ public class FastJobStorageTest { @Test public void getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenAllJobsAreRunning() { - FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, 0, -1, -1, EMPTY_DATA, null, true, false), + FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, 0, -1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList()); @@ -255,7 +255,7 @@ public class FastJobStorageTest { @Test public void getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenNextRunTimeIsAfterCurrentTime() { - FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 10, 0, 0, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 10, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); @@ -267,10 +267,10 @@ public class FastJobStorageTest { @Test public void getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenDependentOnAnotherJob() { - FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, 0, -1, -1, EMPTY_DATA, null, true, false), + FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 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, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 0, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.singletonList(new DependencySpec("2", "1", false))); @@ -283,7 +283,7 @@ public class FastJobStorageTest { @Test public void getPendingJobsWithNoDependenciesInCreatedOrder_singleEligibleJob() { - FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec fullSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); @@ -295,10 +295,10 @@ public class FastJobStorageTest { @Test public void getPendingJobsWithNoDependenciesInCreatedOrder_multipleEligibleJobs() { - FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); - FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 0, 0, 0, 0, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 0, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); @@ -311,10 +311,10 @@ public class FastJobStorageTest { @Test public void getPendingJobsWithNoDependenciesInCreatedOrder_singleEligibleJobInMixedList() { - FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, 0, -1, -1, EMPTY_DATA, null, true, false), + FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 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, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 0, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); @@ -330,10 +330,10 @@ public class FastJobStorageTest { @Test public void getPendingJobsWithNoDependenciesInCreatedOrder_firstItemInQueue() { - FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); - FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", "q", 0, 0, 0, 0, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", "q", 0, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); @@ -349,10 +349,10 @@ public class FastJobStorageTest { @Test public void getPendingJobsWithNoDependenciesInCreatedOrder_migrationJobTakesPrecedence() { - FullSpec plainSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec plainSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 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, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec migrationSpec = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); @@ -367,10 +367,10 @@ public class FastJobStorageTest { @Test public void getPendingJobsWithNoDependenciesInCreatedOrder_runningMigrationBlocksNormalJobs() { - FullSpec plainSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 0, 0, 0, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec plainSpec = new FullSpec(new JobSpec("1", "f1", "q", 0, 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, 0, -1, -1, EMPTY_DATA, null, true, false), + FullSpec migrationSpec = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, 0, -1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList()); @@ -384,10 +384,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, 0, -1, -1, EMPTY_DATA, null, true, false), + FullSpec migrationSpec1 = new FullSpec(new JobSpec("1", "f1", Job.Parameters.MIGRATION_QUEUE_KEY, 0, 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, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec migrationSpec2 = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); @@ -401,10 +401,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, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec migrationSpec1 = new FullSpec(new JobSpec("1", "f1", Job.Parameters.MIGRATION_QUEUE_KEY, 0, 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, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec migrationSpec2 = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); @@ -419,10 +419,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, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec migrationSpec1 = new FullSpec(new JobSpec("1", "f1", Job.Parameters.MIGRATION_QUEUE_KEY, 0, 999, 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, 0, -1, -1, EMPTY_DATA, null, false, false), + FullSpec migrationSpec2 = new FullSpec(new JobSpec("2", "f2", Job.Parameters.MIGRATION_QUEUE_KEY, 5, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.emptyList()); @@ -577,9 +577,9 @@ public class FastJobStorageTest { } private static final class DataSet1 { - static final JobSpec JOB_1 = new JobSpec("id1", "f1", "q1", 1, 2, 3, 4, 5, 6, 7, EMPTY_DATA, null, false, false); - static final JobSpec JOB_2 = new JobSpec("id2", "f2", "q2", 1, 2, 3, 4, 5, 6, 7, EMPTY_DATA, null, false, false); - static final JobSpec JOB_3 = new JobSpec("id3", "f3", "q3", 1, 2, 3, 4, 5, 6, 7, EMPTY_DATA, null, false, false); + static final JobSpec JOB_1 = new JobSpec("id1", "f1", "q1", 1, 2, 3, 4, 5, 6, EMPTY_DATA, null, false, false); + static final JobSpec JOB_2 = new JobSpec("id2", "f2", "q2", 1, 2, 3, 4, 5, 6, EMPTY_DATA, null, false, false); + static final JobSpec JOB_3 = new JobSpec("id3", "f3", "q3", 1, 2, 3, 4, 5, 6, EMPTY_DATA, 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); @@ -610,7 +610,7 @@ public class FastJobStorageTest { } private static final class DataSetMemory { - static final JobSpec JOB_1 = new JobSpec("id1", "f1", "q1", 1, 2, 3, 4, 5, 6, 7, EMPTY_DATA, null, false, true); + static final JobSpec JOB_1 = new JobSpec("id1", "f1", "q1", 1, 2, 3, 4, 5, 6, EMPTY_DATA, 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 FULL_SPECS = Collections.singletonList(FULL_SPEC_1);