mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 01:40:07 +01:00
Add foundation for automated performance tests.
This commit is contained in:
@@ -6,6 +6,7 @@ import android.content.Context;
|
||||
import androidx.annotation.AnyThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.annotation.WorkerThread;
|
||||
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
@@ -126,6 +127,15 @@ public final class KeyValueStore implements KeyValueReader {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the store to re-fetch all of it's data from the database.
|
||||
* Should only be used for testing!
|
||||
*/
|
||||
@VisibleForTesting
|
||||
synchronized void resetCache() {
|
||||
dataSet = null;
|
||||
initializeIfNecessary();
|
||||
}
|
||||
|
||||
private synchronized void write(@NonNull KeyValueDataSet newDataSet, @NonNull Collection<String> removes) {
|
||||
initializeIfNecessary();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.thoughtcrime.securesms.keyvalue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceDataStore;
|
||||
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.Wallpaper;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.util.SignalUncaughtExceptionHandler;
|
||||
|
||||
@@ -70,6 +70,15 @@ public final class SignalStore {
|
||||
proxy().onFirstEverAppLaunch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces the store to re-fetch all of it's data from the database.
|
||||
* Should only be used for testing!
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public static void resetCache() {
|
||||
INSTANCE.store.resetCache();
|
||||
}
|
||||
|
||||
public static @NonNull KbsValues kbsValues() {
|
||||
return INSTANCE.kbsValues;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import android.database.Cursor;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import net.sqlcipher.database.SQLiteDatabase;
|
||||
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
@@ -13,13 +15,14 @@ import org.whispersystems.libsignal.util.guava.Preconditions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public final class SqlUtil {
|
||||
private SqlUtil() {}
|
||||
|
||||
private SqlUtil() {}
|
||||
|
||||
public static boolean tableExists(@NonNull SQLiteDatabase db, @NonNull String table) {
|
||||
try (Cursor cursor = db.rawQuery("SELECT name FROM sqlite_master WHERE type=? AND name=?", new String[] { "table", table })) {
|
||||
@@ -27,6 +30,28 @@ public final class SqlUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static @NonNull List<String> getAllTables(@NonNull SQLiteDatabase db) {
|
||||
List<String> tables = new LinkedList<>();
|
||||
|
||||
try (Cursor cursor = db.rawQuery("SELECT name FROM sqlite_master WHERE type=?", new String[] { "table" })) {
|
||||
while (cursor.moveToNext()) {
|
||||
tables.add(cursor.getString(0));
|
||||
}
|
||||
}
|
||||
|
||||
return tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a multi-statement SQL block into independent statements. It is assumed that there is
|
||||
* only one statement per line, and that each statement is terminated by a semi-colon.
|
||||
*/
|
||||
public static @NonNull List<String> splitStatements(@NonNull String sql) {
|
||||
return Stream.of(Arrays.asList(sql.split(";\n")))
|
||||
.map(String::trim)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static boolean isEmpty(@NonNull SQLiteDatabase db, @NonNull String table) {
|
||||
try (Cursor cursor = db.rawQuery("SELECT COUNT(*) FROM " + table, null)) {
|
||||
if (cursor.moveToFirst()) {
|
||||
|
||||
Reference in New Issue
Block a user