mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-27 21:24:42 +00:00
Improve RecipientDatabase tests.
This commit is contained in:
committed by
Alex Hart
parent
ebc1bc3f7f
commit
3fd5e55363
@@ -440,7 +440,8 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
|
||||
return getAndPossiblyMerge(serviceId = serviceId, pni = pni, e164 = e164, pniVerified = true, changeSelf = false)
|
||||
}
|
||||
|
||||
private fun getAndPossiblyMerge(serviceId: ServiceId?, pni: PNI?, e164: String?, pniVerified: Boolean = false, changeSelf: Boolean = false): RecipientId {
|
||||
@VisibleForTesting
|
||||
fun getAndPossiblyMerge(serviceId: ServiceId?, pni: PNI?, e164: String?, pniVerified: Boolean = false, changeSelf: Boolean = false): RecipientId {
|
||||
require(!(serviceId == null && e164 == null)) { "Must provide an ACI or E164!" }
|
||||
|
||||
if ((serviceId is PNI) && pni != null && serviceId != pni) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.database.Cursor;
|
||||
import androidx.annotation.AnyThread;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import org.signal.core.util.ThreadUtil;
|
||||
import org.signal.core.util.concurrent.SignalExecutors;
|
||||
@@ -48,15 +49,19 @@ public final class LiveRecipientCache {
|
||||
private final AtomicReference<RecipientId> localRecipientId;
|
||||
private final AtomicBoolean warmedUp;
|
||||
|
||||
@SuppressLint("UseSparseArrays")
|
||||
public LiveRecipientCache(@NonNull Context context) {
|
||||
this(context, ThreadUtil.trace(new FilteredExecutor(SignalExecutors.newCachedBoundedExecutor("signal-recipients", 1, 4, 15), () -> !SignalDatabase.inTransaction())));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public LiveRecipientCache(@NonNull Context context, @NonNull Executor executor) {
|
||||
this.context = context.getApplicationContext();
|
||||
this.recipientDatabase = SignalDatabase.recipients();
|
||||
this.recipients = new LRUCache<>(CACHE_MAX);
|
||||
this.warmedUp = new AtomicBoolean(false);
|
||||
this.localRecipientId = new AtomicReference<>(null);
|
||||
this.unknown = new LiveRecipient(context, Recipient.UNKNOWN);
|
||||
this.resolveExecutor = ThreadUtil.trace(new FilteredExecutor(SignalExecutors.newCachedBoundedExecutor("signal-recipients", 1, 4, 15), () -> !SignalDatabase.inTransaction()));
|
||||
this.resolveExecutor = executor;
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
|
||||
Reference in New Issue
Block a user