mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-11-30 00:56:50 +00:00
Retire delayed push notifications
This commit is contained in:
1 parent
0e4ac57482
commit
8e37334d2a
12 files changed
+36
-219
No files matched your search
@@ -833,7 +833,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
||||
APNSender apnSender = new APNSender(apnSenderExecutor, Clock.systemUTC(), config.getApnConfiguration());
|
||||
FcmSender fcmSender = new FcmSender(fcmSenderExecutor, config.getFcmConfiguration().credentials().value());
|
||||
PushNotificationScheduler pushNotificationScheduler = new PushNotificationScheduler(pushSchedulerCluster,
|
||||
apnSender, fcmSender, accountsManager, 0, 0, retryExecutor);
|
||||
apnSender, fcmSender, accountsManager, 0, 0);
|
||||
PushNotificationManager pushNotificationManager =
|
||||
new PushNotificationManager(accountsManager, apnSender, fcmSender, pushNotificationScheduler);
|
||||
RateLimiters rateLimiters = RateLimiters.create(dynamicConfigurationManager, rateLimitersCluster, retryExecutor);
|
||||
@@ -1112,7 +1112,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
||||
final GroupSendTokenUtil groupSendTokenUtil = new GroupSendTokenUtil(groupZkSecretParams, Clock.systemUTC());
|
||||
final MessageMetrics messageMetrics = new MessageMetrics();
|
||||
final MessageDispatcher messageDispatcher = new MessageDispatcher(receiptSender, messagesManager, messageMetrics,
|
||||
pushNotificationManager, pushNotificationScheduler, disconnectionRequestManager, clientReleaseManager);
|
||||
pushNotificationManager, disconnectionRequestManager, clientReleaseManager);
|
||||
|
||||
final CertificateGenerator certificateGenerator =
|
||||
new CertificateGenerator(config.getDeliveryCertificate().certificate(),
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.whispersystems.textsecuregcm.auth.DisconnectionRequestManager;
|
||||
import org.whispersystems.textsecuregcm.entities.MessageProtos;
|
||||
import org.whispersystems.textsecuregcm.metrics.MessageMetrics;
|
||||
import org.whispersystems.textsecuregcm.metrics.MetricsUtil;
|
||||
import org.whispersystems.textsecuregcm.push.NotPushRegisteredException;
|
||||
import org.whispersystems.textsecuregcm.push.PushNotificationManager;
|
||||
import org.whispersystems.textsecuregcm.push.PushNotificationScheduler;
|
||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.ClientReleaseManager;
|
||||
@@ -64,7 +64,6 @@ public class MessageDispatcher {
|
||||
private final MessagesManager messagesManager;
|
||||
private final MessageMetrics messageMetrics;
|
||||
private final PushNotificationManager pushNotificationManager;
|
||||
private final PushNotificationScheduler pushNotificationScheduler;
|
||||
private final ClientReleaseManager clientReleaseManager;
|
||||
private final DisconnectionRequestManager disconnectionRequestManager;
|
||||
|
||||
@@ -72,14 +71,12 @@ public class MessageDispatcher {
|
||||
final MessagesManager messagesManager,
|
||||
final MessageMetrics messageMetrics,
|
||||
final PushNotificationManager pushNotificationManager,
|
||||
final PushNotificationScheduler pushNotificationScheduler,
|
||||
final DisconnectionRequestManager disconnectionRequestManager,
|
||||
final ClientReleaseManager clientReleaseManager) {
|
||||
this.receiptSender = receiptSender;
|
||||
this.messagesManager = messagesManager;
|
||||
this.messageMetrics = messageMetrics;
|
||||
this.pushNotificationManager = pushNotificationManager;
|
||||
this.pushNotificationScheduler = pushNotificationScheduler;
|
||||
this.disconnectionRequestManager = disconnectionRequestManager;
|
||||
this.clientReleaseManager = clientReleaseManager;
|
||||
}
|
||||
@@ -196,16 +193,18 @@ public class MessageDispatcher {
|
||||
pendingAcknowledgementTracker.queueDrained(),
|
||||
// Emit an invalid credentials error if we receive a disconnection request
|
||||
disconnectionSignal(account, device, userAgent))
|
||||
.doFinally(_ -> maybeSchedulePush(account, device));
|
||||
.doFinally(_ -> maybeSendNewMessagePushNotification(account, device));
|
||||
}
|
||||
|
||||
/// If the device potentially has more messages available, schedule a push notification.
|
||||
private void maybeSchedulePush(final Account account, final Device device) {
|
||||
/// If the device potentially has more messages available, send a push notification.
|
||||
private void maybeSendNewMessagePushNotification(final Account account, final Device device) {
|
||||
messagesManager.mayHaveMessages(account.getAccountIdentifier(), device)
|
||||
.thenAccept(mayHaveMessages -> {
|
||||
if (mayHaveMessages) {
|
||||
pushNotificationScheduler.scheduleDelayedNotification(account, device,
|
||||
CLOSE_WITH_PENDING_MESSAGES_NOTIFICATION_DELAY);
|
||||
try {
|
||||
pushNotificationManager.sendNewMessageNotification(account, device.getId(), true);
|
||||
} catch (NotPushRegisteredException _) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+5
-114
@@ -23,7 +23,6 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.BiFunction;
|
||||
@@ -38,7 +37,6 @@ import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.util.ExceptionUtils;
|
||||
import org.whispersystems.textsecuregcm.util.Pair;
|
||||
import org.whispersystems.textsecuregcm.util.RedisClusterUtil;
|
||||
import org.whispersystems.textsecuregcm.util.ResilienceUtil;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -49,7 +47,6 @@ public class PushNotificationScheduler implements Managed {
|
||||
private static final String PENDING_BACKGROUND_APN_NOTIFICATIONS_KEY_PREFIX = "PENDING_BACKGROUND_APN";
|
||||
private static final String PENDING_BACKGROUND_FCM_NOTIFICATIONS_KEY_PREFIX = "PENDING_BACKGROUND_FCM";
|
||||
private static final String LAST_BACKGROUND_NOTIFICATION_TIMESTAMP_KEY_PREFIX = "LAST_BACKGROUND_NOTIFICATION";
|
||||
private static final String PENDING_DELAYED_NOTIFICATIONS_KEY_PREFIX = "DELAYED";
|
||||
|
||||
@VisibleForTesting
|
||||
static final String NEXT_SLOT_TO_PROCESS_KEY = "pending_notification_next_slot";
|
||||
@@ -59,16 +56,12 @@ public class PushNotificationScheduler implements Managed {
|
||||
private static final String BACKGROUND_NOTIFICATION_SCHEDULED_COUNTER_NAME = name(PushNotificationScheduler.class, "backgroundNotification", "scheduled");
|
||||
private static final String BACKGROUND_NOTIFICATION_SENT_COUNTER_NAME = name(PushNotificationScheduler.class, "backgroundNotification", "sent");
|
||||
|
||||
private static final String DELAYED_NOTIFICATION_SCHEDULED_COUNTER_NAME = name(PushNotificationScheduler.class, "delayedNotificationScheduled");
|
||||
private static final String DELAYED_NOTIFICATION_SENT_COUNTER_NAME = name(PushNotificationScheduler.class, "delayedNotificationSent");
|
||||
private static final String TOKEN_TYPE_TAG = "tokenType";
|
||||
private static final String ACCEPTED_TAG = "accepted";
|
||||
|
||||
private final APNSender apnSender;
|
||||
private final FcmSender fcmSender;
|
||||
private final AccountsManager accountsManager;
|
||||
private final FaultTolerantRedisClusterClient pushSchedulingCluster;
|
||||
private final ScheduledExecutorService retryExecutor;
|
||||
private final Clock clock;
|
||||
|
||||
private final ClusterLuaScript scheduleBackgroundNotificationScript;
|
||||
@@ -80,8 +73,6 @@ public class PushNotificationScheduler implements Managed {
|
||||
|
||||
private final AtomicBoolean running = new AtomicBoolean(false);
|
||||
|
||||
private static final String RETRY_NAME = ResilienceUtil.name(PushNotificationScheduler.class);
|
||||
|
||||
class NotificationWorker implements Runnable {
|
||||
|
||||
private final int maxConcurrency;
|
||||
@@ -118,8 +109,7 @@ public class PushNotificationScheduler implements Managed {
|
||||
connection.sync().incr(NEXT_SLOT_TO_PROCESS_KEY)) % SlotHash.SLOT_COUNT);
|
||||
|
||||
return processScheduledBackgroundNotifications(PushNotification.TokenType.APN, slot)
|
||||
+ processScheduledBackgroundNotifications(PushNotification.TokenType.FCM, slot)
|
||||
+ processScheduledDelayedNotifications(slot);
|
||||
+ processScheduledBackgroundNotifications(PushNotification.TokenType.FCM, slot);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -129,12 +119,6 @@ public class PushNotificationScheduler implements Managed {
|
||||
}
|
||||
|
||||
|
||||
@VisibleForTesting
|
||||
long processScheduledDelayedNotifications(final int slot) {
|
||||
return processScheduledNotifications(getDelayedNotificationQueueKey(slot),
|
||||
PushNotificationScheduler.this::sendDelayedNotification);
|
||||
}
|
||||
|
||||
private long processScheduledNotifications(final String queueKey,
|
||||
final BiFunction<Account, Device, CompletableFuture<Void>> sendNotificationFunction) {
|
||||
|
||||
@@ -163,8 +147,7 @@ public class PushNotificationScheduler implements Managed {
|
||||
final FcmSender fcmSender,
|
||||
final AccountsManager accountsManager,
|
||||
final int dedicatedProcessWorkerThreadCount,
|
||||
final int workerMaxConcurrency,
|
||||
final ScheduledExecutorService retryExecutor) throws IOException {
|
||||
final int workerMaxConcurrency) throws IOException {
|
||||
|
||||
this(pushSchedulingCluster,
|
||||
apnSender,
|
||||
@@ -172,8 +155,7 @@ public class PushNotificationScheduler implements Managed {
|
||||
accountsManager,
|
||||
Clock.systemUTC(),
|
||||
dedicatedProcessWorkerThreadCount,
|
||||
workerMaxConcurrency,
|
||||
retryExecutor);
|
||||
workerMaxConcurrency);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -183,8 +165,7 @@ public class PushNotificationScheduler implements Managed {
|
||||
final AccountsManager accountsManager,
|
||||
final Clock clock,
|
||||
final int dedicatedProcessThreadCount,
|
||||
final int workerMaxConcurrency,
|
||||
final ScheduledExecutorService retryExecutor) throws IOException {
|
||||
final int workerMaxConcurrency) throws IOException {
|
||||
|
||||
this.apnSender = apnSender;
|
||||
this.fcmSender = fcmSender;
|
||||
@@ -196,7 +177,6 @@ public class PushNotificationScheduler implements Managed {
|
||||
"lua/apn/schedule_background_notification.lua", ScriptOutputType.VALUE);
|
||||
|
||||
this.workerThreads = new Thread[dedicatedProcessThreadCount];
|
||||
this.retryExecutor = retryExecutor;
|
||||
|
||||
for (int i = 0; i < this.workerThreads.length; i++) {
|
||||
this.workerThreads[i] = new Thread(new NotificationWorker(workerMaxConcurrency), "PushNotificationScheduler-" + i);
|
||||
@@ -226,31 +206,6 @@ public class PushNotificationScheduler implements Managed {
|
||||
.thenRun(Util.NOOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a "new message" push notification to be delivered to the given device after at least the given duration.
|
||||
* If another notification had previously been scheduled, calling this method will replace the previously-scheduled
|
||||
* delivery time with the given time.
|
||||
*
|
||||
* @param account the account to which the target device belongs
|
||||
* @param device the device to which to deliver a "new message" push notification
|
||||
* @param minDelay the minimum delay after which to deliver the notification
|
||||
*
|
||||
* @return a future that completes once the notification has been scheduled
|
||||
*/
|
||||
public CompletableFuture<Void> scheduleDelayedNotification(final Account account, final Device device, final Duration minDelay) {
|
||||
final long deliveryTime = clock.instant().plus(minDelay).toEpochMilli();
|
||||
|
||||
return ResilienceUtil.getGeneralRedisRetry(RETRY_NAME)
|
||||
.executeCompletionStage(retryExecutor, () -> pushSchedulingCluster.withCluster(connection ->
|
||||
connection.async().zadd(getDelayedNotificationQueueKey(account, device),
|
||||
deliveryTime,
|
||||
encodeAciAndDeviceId(account, device)))
|
||||
.thenRun(() -> Metrics.counter(DELAYED_NOTIFICATION_SCHEDULED_COUNTER_NAME,
|
||||
TOKEN_TYPE_TAG, getTokenType(device))
|
||||
.increment()))
|
||||
.toCompletableFuture();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel scheduled notifications for the given account and device.
|
||||
*
|
||||
@@ -259,8 +214,7 @@ public class PushNotificationScheduler implements Managed {
|
||||
public CompletionStage<Void> cancelScheduledNotifications(Account account, Device device) {
|
||||
return CompletableFuture.allOf(
|
||||
cancelBackgroundNotifications(PushNotification.TokenType.FCM, account, device),
|
||||
cancelBackgroundNotifications(PushNotification.TokenType.APN, account, device),
|
||||
cancelDelayedNotifications(account, device));
|
||||
cancelBackgroundNotifications(PushNotification.TokenType.APN, account, device));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -271,15 +225,6 @@ public class PushNotificationScheduler implements Managed {
|
||||
.toCompletableFuture();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
CompletableFuture<Void> cancelDelayedNotifications(final Account account, final Device device) {
|
||||
return pushSchedulingCluster.withCluster(connection ->
|
||||
connection.async().zrem(getDelayedNotificationQueueKey(account, device),
|
||||
encodeAciAndDeviceId(account, device)))
|
||||
.thenRun(Util.NOOP)
|
||||
.toCompletableFuture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void start() {
|
||||
running.set(true);
|
||||
@@ -322,32 +267,6 @@ public class PushNotificationScheduler implements Managed {
|
||||
.toCompletableFuture();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
CompletableFuture<Void> sendDelayedNotification(final Account account, final Device device) {
|
||||
if (StringUtils.isAllBlank(device.getApnId(), device.getGcmId())) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
final boolean isApnsDevice = StringUtils.isNotBlank(device.getApnId());
|
||||
|
||||
final PushNotification pushNotification = new PushNotification(
|
||||
isApnsDevice ? device.getApnId() : device.getGcmId(),
|
||||
isApnsDevice ? PushNotification.TokenType.APN : PushNotification.TokenType.FCM,
|
||||
PushNotification.NotificationType.NOTIFICATION,
|
||||
null,
|
||||
account,
|
||||
device,
|
||||
true, null);
|
||||
|
||||
final PushNotificationSender pushNotificationSender = isApnsDevice ? apnSender : fcmSender;
|
||||
|
||||
return pushNotificationSender.sendNotification(pushNotification)
|
||||
.thenAccept(response -> Metrics.counter(DELAYED_NOTIFICATION_SENT_COUNTER_NAME,
|
||||
TOKEN_TYPE_TAG, getTokenType(device),
|
||||
ACCEPTED_TAG, String.valueOf(response.accepted()))
|
||||
.increment());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static String encodeAciAndDeviceId(final Account account, final Device device) {
|
||||
// Note: This does not include a device registration id. If a device is unlinked and a new device is linked with
|
||||
@@ -400,15 +319,6 @@ public class PushNotificationScheduler implements Managed {
|
||||
return LAST_BACKGROUND_NOTIFICATION_TIMESTAMP_KEY_PREFIX + "::{" + encodeAciAndDeviceId(account, device) + "}";
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static String getDelayedNotificationQueueKey(final Account account, final Device device) {
|
||||
return getDelayedNotificationQueueKey(SlotHash.getSlot(encodeAciAndDeviceId(account, device)));
|
||||
}
|
||||
|
||||
private static String getDelayedNotificationQueueKey(final int slot) {
|
||||
return PENDING_DELAYED_NOTIFICATIONS_KEY_PREFIX + "::{" + RedisClusterUtil.getMinimalHashTag(slot) + "}";
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Optional<Instant> getLastBackgroundApnsNotificationTimestamp(final Account account, final Device device) {
|
||||
return Optional.ofNullable(
|
||||
@@ -426,25 +336,6 @@ public class PushNotificationScheduler implements Managed {
|
||||
.map(timestamp -> Instant.ofEpochMilli(timestamp.longValue()));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
Optional<Instant> getNextScheduledDelayedNotificationTimestamp(final Account account, final Device device) {
|
||||
return Optional.ofNullable(
|
||||
pushSchedulingCluster.withCluster(connection ->
|
||||
connection.sync().zscore(getDelayedNotificationQueueKey(account, device),
|
||||
encodeAciAndDeviceId(account, device))))
|
||||
.map(timestamp -> Instant.ofEpochMilli(timestamp.longValue()));
|
||||
}
|
||||
|
||||
private static String getTokenType(final Device device) {
|
||||
if (StringUtils.isNotBlank(device.getApnId())) {
|
||||
return "apns";
|
||||
} else if (StringUtils.isNotBlank(device.getGcmId())) {
|
||||
return "fcm";
|
||||
} else {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
private static String getPushToken(final PushNotification.TokenType tokenType, final Device device) {
|
||||
return switch (tokenType) {
|
||||
case FCM -> device.getGcmId();
|
||||
|
||||
+1
-3
@@ -70,13 +70,11 @@ public class AuthenticatedConnectListener implements WebSocketConnectListener {
|
||||
messagesManager,
|
||||
messageMetrics,
|
||||
pushNotificationManager,
|
||||
pushNotificationScheduler,
|
||||
account,
|
||||
device,
|
||||
client,
|
||||
messageDeliveryScheduler,
|
||||
clientReleaseManager,
|
||||
experimentEnrollmentManager)
|
||||
clientReleaseManager)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+6
-15
@@ -13,7 +13,6 @@ import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
import io.micrometer.core.instrument.Timer;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -27,14 +26,13 @@ import org.eclipse.jetty.util.ConstantThrowable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.whispersystems.textsecuregcm.entities.MessageProtos.Envelope;
|
||||
import org.whispersystems.textsecuregcm.experiment.ExperimentEnrollmentManager;
|
||||
import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.identity.ServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.metrics.MessageMetrics;
|
||||
import org.whispersystems.textsecuregcm.metrics.MetricsUtil;
|
||||
import org.whispersystems.textsecuregcm.metrics.UserAgentTagUtil;
|
||||
import org.whispersystems.textsecuregcm.push.NotPushRegisteredException;
|
||||
import org.whispersystems.textsecuregcm.push.PushNotificationManager;
|
||||
import org.whispersystems.textsecuregcm.push.PushNotificationScheduler;
|
||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.ClientReleaseManager;
|
||||
@@ -79,8 +77,6 @@ public class WebSocketConnection {
|
||||
@VisibleForTesting
|
||||
static final int MESSAGE_SENDER_MAX_CONCURRENCY = 256;
|
||||
|
||||
private static final Duration CLOSE_WITH_PENDING_MESSAGES_NOTIFICATION_DELAY = Duration.ofMinutes(1);
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(WebSocketConnection.class);
|
||||
private static final Logger droppedErrorLogger = LoggerFactory.getLogger("droppedError");
|
||||
|
||||
@@ -88,8 +84,6 @@ public class WebSocketConnection {
|
||||
private final MessagesManager messagesManager;
|
||||
private final MessageMetrics messageMetrics;
|
||||
private final PushNotificationManager pushNotificationManager;
|
||||
private final PushNotificationScheduler pushNotificationScheduler;
|
||||
private final ExperimentEnrollmentManager experimentEnrollmentManager;
|
||||
|
||||
private final Account authenticatedAccount;
|
||||
private final Device authenticatedDevice;
|
||||
@@ -109,25 +103,21 @@ public class WebSocketConnection {
|
||||
final MessagesManager messagesManager,
|
||||
final MessageMetrics messageMetrics,
|
||||
final PushNotificationManager pushNotificationManager,
|
||||
final PushNotificationScheduler pushNotificationScheduler,
|
||||
final Account authenticatedAccount,
|
||||
final Device authenticatedDevice,
|
||||
final WebSocketClient client,
|
||||
final Scheduler messageDeliveryScheduler,
|
||||
final ClientReleaseManager clientReleaseManager,
|
||||
final ExperimentEnrollmentManager experimentEnrollmentManager) {
|
||||
final ClientReleaseManager clientReleaseManager) {
|
||||
|
||||
this.receiptSender = receiptSender;
|
||||
this.messagesManager = messagesManager;
|
||||
this.messageMetrics = messageMetrics;
|
||||
this.pushNotificationManager = pushNotificationManager;
|
||||
this.pushNotificationScheduler = pushNotificationScheduler;
|
||||
this.authenticatedAccount = authenticatedAccount;
|
||||
this.authenticatedDevice = authenticatedDevice;
|
||||
this.client = client;
|
||||
this.messageDeliveryScheduler = messageDeliveryScheduler;
|
||||
this.clientReleaseManager = clientReleaseManager;
|
||||
this.experimentEnrollmentManager = experimentEnrollmentManager;
|
||||
|
||||
this.messageStream =
|
||||
messagesManager.getMessages(authenticatedAccount.getAccountIdentifier(), authenticatedDevice);
|
||||
@@ -194,9 +184,10 @@ public class WebSocketConnection {
|
||||
messagesManager.mayHaveMessages(authenticatedAccount.getAccountIdentifier(), authenticatedDevice)
|
||||
.thenAccept(mayHaveMessages -> {
|
||||
if (mayHaveMessages) {
|
||||
pushNotificationScheduler.scheduleDelayedNotification(authenticatedAccount,
|
||||
authenticatedDevice,
|
||||
CLOSE_WITH_PENDING_MESSAGES_NOTIFICATION_DELAY);
|
||||
try {
|
||||
pushNotificationManager.sendNewMessageNotification(authenticatedAccount, authenticatedDevice.getId(), true);
|
||||
} catch (NotPushRegisteredException _) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -446,7 +446,7 @@ public record CommandDependencies(
|
||||
APNSender apnSender = new APNSender(apnSenderExecutor, Clock.systemUTC(), configuration.getApnConfiguration());
|
||||
FcmSender fcmSender = new FcmSender(fcmSenderExecutor, configuration.getFcmConfiguration().credentials().value());
|
||||
PushNotificationScheduler pushNotificationScheduler = new PushNotificationScheduler(pushSchedulerCluster,
|
||||
apnSender, fcmSender, accountsManager, 0, 0, retryExecutor);
|
||||
apnSender, fcmSender, accountsManager, 0, 0);
|
||||
PushNotificationManager pushNotificationManager = new PushNotificationManager(accountsManager,
|
||||
apnSender, fcmSender, pushNotificationScheduler);
|
||||
|
||||
|
||||
+1
-2
@@ -90,8 +90,7 @@ public class ScheduledApnPushNotificationSenderServiceCommand extends ServerComm
|
||||
deps.fcmSender(),
|
||||
deps.accountsManager(),
|
||||
namespace.getInt(WORKER_COUNT),
|
||||
namespace.getInt(MAX_CONCURRENCY),
|
||||
retryExecutor
|
||||
namespace.getInt(MAX_CONCURRENCY)
|
||||
);
|
||||
|
||||
environment.lifecycle().manage(pushNotificationScheduler);
|
||||
|
||||
-2
@@ -54,7 +54,6 @@ import org.whispersystems.textsecuregcm.entities.MessageProtos.Envelope;
|
||||
import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.metrics.MessageMetrics;
|
||||
import org.whispersystems.textsecuregcm.push.PushNotificationManager;
|
||||
import org.whispersystems.textsecuregcm.push.PushNotificationScheduler;
|
||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||
import org.whispersystems.textsecuregcm.redis.RedisServerExtension;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
@@ -160,7 +159,6 @@ class MessageDispatcherIntegrationTest {
|
||||
sharedExecutorService, Clock.systemUTC()),
|
||||
new MessageMetrics(),
|
||||
mock(PushNotificationManager.class),
|
||||
mock(PushNotificationScheduler.class),
|
||||
disconnectionRequestManager,
|
||||
mock(ClientReleaseManager.class));
|
||||
}
|
||||
|
||||
+5
-6
@@ -41,6 +41,7 @@ import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.identity.IdentityType;
|
||||
import org.whispersystems.textsecuregcm.identity.ServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.metrics.MessageMetrics;
|
||||
import org.whispersystems.textsecuregcm.push.NotPushRegisteredException;
|
||||
import org.whispersystems.textsecuregcm.push.PushNotificationManager;
|
||||
import org.whispersystems.textsecuregcm.push.PushNotificationScheduler;
|
||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||
@@ -74,7 +75,6 @@ class MessageDispatcherTest {
|
||||
private PushNotificationManager pushNotificationManager;
|
||||
private MessageDispatcher dispatcher;
|
||||
private DisconnectionRequestManager disconnectionRequestManager;
|
||||
private PushNotificationScheduler pushNotificationScheduler;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@@ -87,7 +87,6 @@ class MessageDispatcherTest {
|
||||
receiptSender = mock(ReceiptSender.class);
|
||||
pushNotificationManager = mock(PushNotificationManager.class);
|
||||
disconnectionRequestManager = mock(DisconnectionRequestManager.class);
|
||||
pushNotificationScheduler = mock(PushNotificationScheduler.class);
|
||||
|
||||
when(device.getId()).thenReturn(DEVICE_ID);
|
||||
when(device.isPrimary()).thenReturn(true);
|
||||
@@ -97,14 +96,13 @@ class MessageDispatcherTest {
|
||||
messagesManager,
|
||||
new MessageMetrics(),
|
||||
pushNotificationManager,
|
||||
pushNotificationScheduler,
|
||||
disconnectionRequestManager,
|
||||
mock(ClientReleaseManager.class));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void drainSingleMessage(final boolean mayHaveMoreMessages) {
|
||||
void drainSingleMessage(final boolean mayHaveMoreMessages) throws NotPushRegisteredException {
|
||||
final ServiceIdentifier sourceServiceId = new AciServiceIdentifier(UUID.randomUUID());
|
||||
final long timestamp = 17;
|
||||
|
||||
@@ -127,8 +125,9 @@ class MessageDispatcherTest {
|
||||
verify(disconnectionRequestManager).removeListener(eq(ACI), eq(DEVICE_ID), any());
|
||||
verify(pushNotificationManager).handleMessagesRetrieved(account, device, TEST_UA);
|
||||
verify(messagesManager).mayHaveMessages(ACI, device);
|
||||
verify(pushNotificationScheduler, times(mayHaveMoreMessages ? 1 : 0))
|
||||
.scheduleDelayedNotification(account, device, MessageDispatcher.CLOSE_WITH_PENDING_MESSAGES_NOTIFICATION_DELAY);
|
||||
verify(pushNotificationManager, times(mayHaveMoreMessages ? 1 : 0))
|
||||
.sendNewMessageNotification(account, device.getId(), true);
|
||||
|
||||
verifyNoInteractions(receiptSender);
|
||||
}
|
||||
|
||||
|
||||
+2
-50
@@ -16,17 +16,14 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import io.lettuce.core.cluster.SlotHash;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
@@ -89,7 +86,7 @@ class PushNotificationSchedulerTest {
|
||||
.thenReturn(CompletableFuture.completedFuture(new SendPushNotificationResult(true, Optional.empty(), false, Optional.empty())));
|
||||
|
||||
pushNotificationScheduler = new PushNotificationScheduler(REDIS_CLUSTER_EXTENSION.getRedisCluster(),
|
||||
apnSender, fcmSender, accountsManager, clock, 1, 1, mock(ScheduledExecutorService.class));
|
||||
apnSender, fcmSender, accountsManager, clock, 1, 1);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -207,51 +204,6 @@ class PushNotificationSchedulerTest {
|
||||
verify(apnSender, never()).sendNotification(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testScheduleDelayedNotification() {
|
||||
clock.pin(Instant.now());
|
||||
|
||||
assertEquals(Optional.empty(),
|
||||
pushNotificationScheduler.getNextScheduledDelayedNotificationTimestamp(account, device));
|
||||
|
||||
pushNotificationScheduler.scheduleDelayedNotification(account, device, Duration.ofMinutes(1)).join();
|
||||
|
||||
assertEquals(Optional.of(clock.instant().truncatedTo(ChronoUnit.MILLIS).plus(Duration.ofMinutes(1))),
|
||||
pushNotificationScheduler.getNextScheduledDelayedNotificationTimestamp(account, device));
|
||||
|
||||
pushNotificationScheduler.scheduleDelayedNotification(account, device, Duration.ofMinutes(2)).join();
|
||||
|
||||
assertEquals(Optional.of(clock.instant().truncatedTo(ChronoUnit.MILLIS).plus(Duration.ofMinutes(2))),
|
||||
pushNotificationScheduler.getNextScheduledDelayedNotificationTimestamp(account, device));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCancelDelayedNotification() {
|
||||
pushNotificationScheduler.scheduleDelayedNotification(account, device, Duration.ofMinutes(1)).join();
|
||||
pushNotificationScheduler.cancelDelayedNotifications(account, device).join();
|
||||
|
||||
assertEquals(Optional.empty(),
|
||||
pushNotificationScheduler.getNextScheduledDelayedNotificationTimestamp(account, device));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testProcessScheduledDelayedNotifications() {
|
||||
final PushNotificationScheduler.NotificationWorker worker = pushNotificationScheduler.new NotificationWorker(1);
|
||||
final int slot = SlotHash.getSlot(PushNotificationScheduler.getDelayedNotificationQueueKey(account, device));
|
||||
|
||||
clock.pin(Instant.now());
|
||||
|
||||
pushNotificationScheduler.scheduleDelayedNotification(account, device, Duration.ofMinutes(1)).join();
|
||||
|
||||
assertEquals(0, worker.processScheduledDelayedNotifications(slot));
|
||||
|
||||
clock.pin(clock.instant().plus(Duration.ofMinutes(1)));
|
||||
|
||||
assertEquals(1, worker.processScheduledDelayedNotifications(slot));
|
||||
assertEquals(Optional.empty(),
|
||||
pushNotificationScheduler.getNextScheduledDelayedNotificationTimestamp(account, device));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"1, true",
|
||||
@@ -266,7 +218,7 @@ class PushNotificationSchedulerTest {
|
||||
final AccountsManager accountsManager = mock(AccountsManager.class);
|
||||
|
||||
pushNotificationScheduler = new PushNotificationScheduler(redisCluster, apnSender, fcmSender,
|
||||
accountsManager, dedicatedThreadCount, 1, mock(ScheduledExecutorService.class));
|
||||
accountsManager, dedicatedThreadCount, 1);
|
||||
|
||||
pushNotificationScheduler.start();
|
||||
pushNotificationScheduler.stop();
|
||||
|
||||
+4
-12
@@ -200,13 +200,11 @@ class WebSocketConnectionIntegrationTest {
|
||||
new MessagesManager(messagesDynamoDb, foundationDbMessageStore, reportMessageManager, sharedExecutorService, Clock.systemUTC()),
|
||||
new MessageMetrics(),
|
||||
mock(PushNotificationManager.class),
|
||||
mock(PushNotificationScheduler.class),
|
||||
account,
|
||||
device,
|
||||
webSocketClient,
|
||||
messageDeliveryScheduler,
|
||||
clientReleaseManager,
|
||||
mock(ExperimentEnrollmentManager.class)
|
||||
clientReleaseManager
|
||||
);
|
||||
|
||||
final List<MessageProtos.Envelope> expectedMessages = new ArrayList<>(dynamoDbMessageCount + foundationDbMessageCount);
|
||||
@@ -285,13 +283,11 @@ class WebSocketConnectionIntegrationTest {
|
||||
new MessagesManager(messagesDynamoDb, foundationDbMessageStore, reportMessageManager, sharedExecutorService, Clock.systemUTC()),
|
||||
new MessageMetrics(),
|
||||
mock(PushNotificationManager.class),
|
||||
mock(PushNotificationScheduler.class),
|
||||
account,
|
||||
device,
|
||||
webSocketClient,
|
||||
messageDeliveryScheduler,
|
||||
clientReleaseManager,
|
||||
mock(ExperimentEnrollmentManager.class)
|
||||
clientReleaseManager
|
||||
);
|
||||
|
||||
final int dynamoDbMessageCount = 77;
|
||||
@@ -406,13 +402,11 @@ class WebSocketConnectionIntegrationTest {
|
||||
new MessagesManager(messagesDynamoDb, foundationDbMessageStore, reportMessageManager, sharedExecutorService, Clock.systemUTC()),
|
||||
new MessageMetrics(),
|
||||
mock(PushNotificationManager.class),
|
||||
mock(PushNotificationScheduler.class),
|
||||
account,
|
||||
device,
|
||||
webSocketClient,
|
||||
messageDeliveryScheduler,
|
||||
clientReleaseManager,
|
||||
mock(ExperimentEnrollmentManager.class)
|
||||
clientReleaseManager
|
||||
);
|
||||
|
||||
final int dynamoDBMessageCount = 207;
|
||||
@@ -493,13 +487,11 @@ class WebSocketConnectionIntegrationTest {
|
||||
messagesManager,
|
||||
new MessageMetrics(),
|
||||
mock(PushNotificationManager.class),
|
||||
mock(PushNotificationScheduler.class),
|
||||
account,
|
||||
device,
|
||||
webSocketClient,
|
||||
messageDeliveryScheduler,
|
||||
clientReleaseManager,
|
||||
mock(ExperimentEnrollmentManager.class));
|
||||
clientReleaseManager);
|
||||
|
||||
final WebSocketResponseMessage successResponse = mock(WebSocketResponseMessage.class);
|
||||
when(successResponse.getStatus()).thenReturn(200);
|
||||
|
||||
+1
-3
@@ -119,13 +119,11 @@ class WebSocketConnectionTest {
|
||||
messagesManager,
|
||||
new MessageMetrics(),
|
||||
mock(PushNotificationManager.class),
|
||||
mock(PushNotificationScheduler.class),
|
||||
account,
|
||||
device,
|
||||
client,
|
||||
Schedulers.immediate(),
|
||||
clientReleaseManager,
|
||||
mock(ExperimentEnrollmentManager.class));
|
||||
clientReleaseManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user