Rename PushSender to MessageSender and add docs.
This commit is contained in:
parent
74b3daa70a
commit
05929871c9
|
@ -104,7 +104,7 @@ import org.whispersystems.textsecuregcm.push.ApnFallbackManager;
|
||||||
import org.whispersystems.textsecuregcm.push.ClientPresenceManager;
|
import org.whispersystems.textsecuregcm.push.ClientPresenceManager;
|
||||||
import org.whispersystems.textsecuregcm.push.GCMSender;
|
import org.whispersystems.textsecuregcm.push.GCMSender;
|
||||||
import org.whispersystems.textsecuregcm.push.ProvisioningManager;
|
import org.whispersystems.textsecuregcm.push.ProvisioningManager;
|
||||||
import org.whispersystems.textsecuregcm.push.PushSender;
|
import org.whispersystems.textsecuregcm.push.MessageSender;
|
||||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||||
import org.whispersystems.textsecuregcm.recaptcha.RecaptchaClient;
|
import org.whispersystems.textsecuregcm.recaptcha.RecaptchaClient;
|
||||||
import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster;
|
import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster;
|
||||||
|
@ -329,8 +329,8 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
||||||
ApnFallbackManager apnFallbackManager = new ApnFallbackManager(pushSchedulerClient, apnSender, accountsManager);
|
ApnFallbackManager apnFallbackManager = new ApnFallbackManager(pushSchedulerClient, apnSender, accountsManager);
|
||||||
TwilioSmsSender twilioSmsSender = new TwilioSmsSender(config.getTwilioConfiguration());
|
TwilioSmsSender twilioSmsSender = new TwilioSmsSender(config.getTwilioConfiguration());
|
||||||
SmsSender smsSender = new SmsSender(twilioSmsSender);
|
SmsSender smsSender = new SmsSender(twilioSmsSender);
|
||||||
PushSender pushSender = new PushSender(apnFallbackManager, clientPresenceManager, messagesManager, gcmSender, apnSender, config.getPushConfiguration().getQueueSize(), pushLatencyManager);
|
MessageSender messageSender = new MessageSender(apnFallbackManager, clientPresenceManager, messagesManager, gcmSender, apnSender, config.getPushConfiguration().getQueueSize(), pushLatencyManager);
|
||||||
ReceiptSender receiptSender = new ReceiptSender(accountsManager, pushSender);
|
ReceiptSender receiptSender = new ReceiptSender(accountsManager, messageSender);
|
||||||
TurnTokenGenerator turnTokenGenerator = new TurnTokenGenerator(config.getTurnConfiguration());
|
TurnTokenGenerator turnTokenGenerator = new TurnTokenGenerator(config.getTurnConfiguration());
|
||||||
RecaptchaClient recaptchaClient = new RecaptchaClient(config.getRecaptchaConfiguration().getSecret());
|
RecaptchaClient recaptchaClient = new RecaptchaClient(config.getRecaptchaConfiguration().getSecret());
|
||||||
|
|
||||||
|
@ -351,7 +351,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
||||||
apnSender.setApnFallbackManager(apnFallbackManager);
|
apnSender.setApnFallbackManager(apnFallbackManager);
|
||||||
environment.lifecycle().manage(apnFallbackManager);
|
environment.lifecycle().manage(apnFallbackManager);
|
||||||
environment.lifecycle().manage(pubSubManager);
|
environment.lifecycle().manage(pubSubManager);
|
||||||
environment.lifecycle().manage(pushSender);
|
environment.lifecycle().manage(messageSender);
|
||||||
environment.lifecycle().manage(accountDatabaseCrawler);
|
environment.lifecycle().manage(accountDatabaseCrawler);
|
||||||
environment.lifecycle().manage(remoteConfigsManager);
|
environment.lifecycle().manage(remoteConfigsManager);
|
||||||
environment.lifecycle().manage(messagesCache);
|
environment.lifecycle().manage(messagesCache);
|
||||||
|
@ -374,7 +374,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
|
||||||
AttachmentControllerV2 attachmentControllerV2 = new AttachmentControllerV2(rateLimiters, config.getAwsAttachmentsConfiguration().getAccessKey(), config.getAwsAttachmentsConfiguration().getAccessSecret(), config.getAwsAttachmentsConfiguration().getRegion(), config.getAwsAttachmentsConfiguration().getBucket());
|
AttachmentControllerV2 attachmentControllerV2 = new AttachmentControllerV2(rateLimiters, config.getAwsAttachmentsConfiguration().getAccessKey(), config.getAwsAttachmentsConfiguration().getAccessSecret(), config.getAwsAttachmentsConfiguration().getRegion(), config.getAwsAttachmentsConfiguration().getBucket());
|
||||||
AttachmentControllerV3 attachmentControllerV3 = new AttachmentControllerV3(rateLimiters, config.getGcpAttachmentsConfiguration().getDomain(), config.getGcpAttachmentsConfiguration().getEmail(), config.getGcpAttachmentsConfiguration().getMaxSizeInBytes(), config.getGcpAttachmentsConfiguration().getPathPrefix(), config.getGcpAttachmentsConfiguration().getRsaSigningKey());
|
AttachmentControllerV3 attachmentControllerV3 = new AttachmentControllerV3(rateLimiters, config.getGcpAttachmentsConfiguration().getDomain(), config.getGcpAttachmentsConfiguration().getEmail(), config.getGcpAttachmentsConfiguration().getMaxSizeInBytes(), config.getGcpAttachmentsConfiguration().getPathPrefix(), config.getGcpAttachmentsConfiguration().getRsaSigningKey());
|
||||||
KeysController keysController = new KeysController(rateLimiters, keys, accountsManager, directoryQueue);
|
KeysController keysController = new KeysController(rateLimiters, keys, accountsManager, directoryQueue);
|
||||||
MessageController messageController = new MessageController(rateLimiters, pushSender, receiptSender, accountsManager, messagesManager, apnFallbackManager);
|
MessageController messageController = new MessageController(rateLimiters, messageSender, receiptSender, accountsManager, messagesManager, apnFallbackManager);
|
||||||
ProfileController profileController = new ProfileController(rateLimiters, accountsManager, profilesManager, usernamesManager, cdnS3Client, profileCdnPolicyGenerator, profileCdnPolicySigner, config.getCdnConfiguration().getBucket(), zkProfileOperations, isZkEnabled);
|
ProfileController profileController = new ProfileController(rateLimiters, accountsManager, profilesManager, usernamesManager, cdnS3Client, profileCdnPolicyGenerator, profileCdnPolicySigner, config.getCdnConfiguration().getBucket(), zkProfileOperations, isZkEnabled);
|
||||||
StickerController stickerController = new StickerController(rateLimiters, config.getCdnConfiguration().getAccessKey(), config.getCdnConfiguration().getAccessSecret(), config.getCdnConfiguration().getRegion(), config.getCdnConfiguration().getBucket());
|
StickerController stickerController = new StickerController(rateLimiters, config.getCdnConfiguration().getAccessKey(), config.getCdnConfiguration().getAccessSecret(), config.getCdnConfiguration().getRegion(), config.getCdnConfiguration().getBucket());
|
||||||
RemoteConfigController remoteConfigController = new RemoteConfigController(remoteConfigsManager, config.getRemoteConfigConfiguration().getAuthorizedTokens(), config.getRemoteConfigConfiguration().getGlobalConfig());
|
RemoteConfigController remoteConfigController = new RemoteConfigController(remoteConfigsManager, config.getRemoteConfigConfiguration().getAuthorizedTokens(), config.getRemoteConfigConfiguration().getGlobalConfig());
|
||||||
|
|
|
@ -42,7 +42,7 @@ import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||||
import org.whispersystems.textsecuregcm.metrics.UserAgentTagUtil;
|
import org.whispersystems.textsecuregcm.metrics.UserAgentTagUtil;
|
||||||
import org.whispersystems.textsecuregcm.push.ApnFallbackManager;
|
import org.whispersystems.textsecuregcm.push.ApnFallbackManager;
|
||||||
import org.whispersystems.textsecuregcm.push.NotPushRegisteredException;
|
import org.whispersystems.textsecuregcm.push.NotPushRegisteredException;
|
||||||
import org.whispersystems.textsecuregcm.push.PushSender;
|
import org.whispersystems.textsecuregcm.push.MessageSender;
|
||||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||||
import org.whispersystems.textsecuregcm.redis.RedisOperation;
|
import org.whispersystems.textsecuregcm.redis.RedisOperation;
|
||||||
import org.whispersystems.textsecuregcm.storage.Account;
|
import org.whispersystems.textsecuregcm.storage.Account;
|
||||||
|
@ -93,7 +93,7 @@ public class MessageController {
|
||||||
private final Histogram outgoingMessageListSizeHistogram = metricRegistry.histogram(name(getClass(), "outgoingMessageListSize"));
|
private final Histogram outgoingMessageListSizeHistogram = metricRegistry.histogram(name(getClass(), "outgoingMessageListSize"));
|
||||||
|
|
||||||
private final RateLimiters rateLimiters;
|
private final RateLimiters rateLimiters;
|
||||||
private final PushSender pushSender;
|
private final MessageSender messageSender;
|
||||||
private final ReceiptSender receiptSender;
|
private final ReceiptSender receiptSender;
|
||||||
private final AccountsManager accountsManager;
|
private final AccountsManager accountsManager;
|
||||||
private final MessagesManager messagesManager;
|
private final MessagesManager messagesManager;
|
||||||
|
@ -105,14 +105,14 @@ public class MessageController {
|
||||||
private static final int MAX_MESSAGE_SIZE = 64 * 1024;
|
private static final int MAX_MESSAGE_SIZE = 64 * 1024;
|
||||||
|
|
||||||
public MessageController(RateLimiters rateLimiters,
|
public MessageController(RateLimiters rateLimiters,
|
||||||
PushSender pushSender,
|
MessageSender messageSender,
|
||||||
ReceiptSender receiptSender,
|
ReceiptSender receiptSender,
|
||||||
AccountsManager accountsManager,
|
AccountsManager accountsManager,
|
||||||
MessagesManager messagesManager,
|
MessagesManager messagesManager,
|
||||||
ApnFallbackManager apnFallbackManager)
|
ApnFallbackManager apnFallbackManager)
|
||||||
{
|
{
|
||||||
this.rateLimiters = rateLimiters;
|
this.rateLimiters = rateLimiters;
|
||||||
this.pushSender = pushSender;
|
this.messageSender = messageSender;
|
||||||
this.receiptSender = receiptSender;
|
this.receiptSender = receiptSender;
|
||||||
this.accountsManager = accountsManager;
|
this.accountsManager = accountsManager;
|
||||||
this.messagesManager = messagesManager;
|
this.messagesManager = messagesManager;
|
||||||
|
@ -325,7 +325,7 @@ public class MessageController {
|
||||||
messageBuilder.setContent(ByteString.copyFrom(messageContent.get()));
|
messageBuilder.setContent(ByteString.copyFrom(messageContent.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pushSender.sendMessage(destinationAccount, destinationDevice, messageBuilder.build(), online);
|
messageSender.sendMessage(destinationAccount, destinationDevice, messageBuilder.build(), online);
|
||||||
} catch (NotPushRegisteredException e) {
|
} catch (NotPushRegisteredException e) {
|
||||||
if (destinationDevice.isMaster()) throw new NoSuchUserException(e);
|
if (destinationDevice.isMaster()) throw new NoSuchUserException(e);
|
||||||
else logger.debug("Not registered", e);
|
else logger.debug("Not registered", e);
|
||||||
|
|
|
@ -39,7 +39,20 @@ import static com.codahale.metrics.MetricRegistry.name;
|
||||||
import io.dropwizard.lifecycle.Managed;
|
import io.dropwizard.lifecycle.Managed;
|
||||||
import static org.whispersystems.textsecuregcm.entities.MessageProtos.Envelope;
|
import static org.whispersystems.textsecuregcm.entities.MessageProtos.Envelope;
|
||||||
|
|
||||||
public class PushSender implements Managed {
|
/**
|
||||||
|
* A MessageSender sends Signal messages to destination devices. Messages may be "normal" user-to-user messages,
|
||||||
|
* ephemeral ("online") messages like typing indicators, or delivery receipts.
|
||||||
|
* <p/>
|
||||||
|
* If a client is not actively connected to a Signal server to receive a message as soon as it is sent, the
|
||||||
|
* MessageSender will send a push notification to the destination device if possible. Some messages may be designated
|
||||||
|
* for "online" delivery only and will not be delivered (and clients will not be notified) if the destination device
|
||||||
|
* isn't actively connected to a Signal server.
|
||||||
|
*
|
||||||
|
* @see ClientPresenceManager
|
||||||
|
* @see org.whispersystems.textsecuregcm.storage.MessageAvailabilityListener
|
||||||
|
* @see ReceiptSender
|
||||||
|
*/
|
||||||
|
public class MessageSender implements Managed {
|
||||||
|
|
||||||
private final ApnFallbackManager apnFallbackManager;
|
private final ApnFallbackManager apnFallbackManager;
|
||||||
private final ClientPresenceManager clientPresenceManager;
|
private final ClientPresenceManager clientPresenceManager;
|
||||||
|
@ -50,18 +63,18 @@ public class PushSender implements Managed {
|
||||||
private final int queueSize;
|
private final int queueSize;
|
||||||
private final PushLatencyManager pushLatencyManager;
|
private final PushLatencyManager pushLatencyManager;
|
||||||
|
|
||||||
private static final String SEND_COUNTER_NAME = name(PushSender.class, "sendMessage");
|
private static final String SEND_COUNTER_NAME = name(MessageSender.class, "sendMessage");
|
||||||
private static final String CHANNEL_TAG_NAME = "channel";
|
private static final String CHANNEL_TAG_NAME = "channel";
|
||||||
private static final String EPHEMERAL_TAG_NAME = "ephemeral";
|
private static final String EPHEMERAL_TAG_NAME = "ephemeral";
|
||||||
private static final String CLIENT_ONLINE_TAG_NAME = "clientOnline";
|
private static final String CLIENT_ONLINE_TAG_NAME = "clientOnline";
|
||||||
|
|
||||||
public PushSender(ApnFallbackManager apnFallbackManager,
|
public MessageSender(ApnFallbackManager apnFallbackManager,
|
||||||
ClientPresenceManager clientPresenceManager,
|
ClientPresenceManager clientPresenceManager,
|
||||||
MessagesManager messagesManager,
|
MessagesManager messagesManager,
|
||||||
GCMSender gcmSender,
|
GCMSender gcmSender,
|
||||||
APNSender apnSender,
|
APNSender apnSender,
|
||||||
int queueSize,
|
int queueSize,
|
||||||
PushLatencyManager pushLatencyManager)
|
PushLatencyManager pushLatencyManager)
|
||||||
{
|
{
|
||||||
this(apnFallbackManager,
|
this(apnFallbackManager,
|
||||||
clientPresenceManager,
|
clientPresenceManager,
|
||||||
|
@ -73,19 +86,19 @@ public class PushSender implements Managed {
|
||||||
pushLatencyManager);
|
pushLatencyManager);
|
||||||
|
|
||||||
SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME)
|
SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME)
|
||||||
.register(name(PushSender.class, "send_queue_depth"),
|
.register(name(MessageSender.class, "send_queue_depth"),
|
||||||
(Gauge<Integer>) ((BlockingThreadPoolExecutor)executor)::getSize);
|
(Gauge<Integer>) ((BlockingThreadPoolExecutor)executor)::getSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
PushSender(ApnFallbackManager apnFallbackManager,
|
MessageSender(ApnFallbackManager apnFallbackManager,
|
||||||
ClientPresenceManager clientPresenceManager,
|
ClientPresenceManager clientPresenceManager,
|
||||||
MessagesManager messagesManager,
|
MessagesManager messagesManager,
|
||||||
GCMSender gcmSender,
|
GCMSender gcmSender,
|
||||||
APNSender apnSender,
|
APNSender apnSender,
|
||||||
int queueSize,
|
int queueSize,
|
||||||
ExecutorService executor,
|
ExecutorService executor,
|
||||||
PushLatencyManager pushLatencyManager) {
|
PushLatencyManager pushLatencyManager) {
|
||||||
|
|
||||||
this.apnFallbackManager = apnFallbackManager;
|
this.apnFallbackManager = apnFallbackManager;
|
||||||
this.clientPresenceManager = clientPresenceManager;
|
this.clientPresenceManager = clientPresenceManager;
|
|
@ -12,16 +12,16 @@ import java.util.Optional;
|
||||||
|
|
||||||
public class ReceiptSender {
|
public class ReceiptSender {
|
||||||
|
|
||||||
private final PushSender pushSender;
|
private final MessageSender messageSender;
|
||||||
private final AccountsManager accountManager;
|
private final AccountsManager accountManager;
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ReceiptSender.class);
|
private static final Logger logger = LoggerFactory.getLogger(ReceiptSender.class);
|
||||||
|
|
||||||
public ReceiptSender(AccountsManager accountManager,
|
public ReceiptSender(AccountsManager accountManager,
|
||||||
PushSender pushSender)
|
MessageSender messageSender)
|
||||||
{
|
{
|
||||||
this.accountManager = accountManager;
|
this.accountManager = accountManager;
|
||||||
this.pushSender = pushSender;
|
this.messageSender = messageSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendReceipt(Account source, String destination, long messageId)
|
public void sendReceipt(Account source, String destination, long messageId)
|
||||||
|
@ -45,7 +45,7 @@ public class ReceiptSender {
|
||||||
|
|
||||||
for (final Device destinationDevice : destinationAccount.getDevices()) {
|
for (final Device destinationDevice : destinationAccount.getDevices()) {
|
||||||
try {
|
try {
|
||||||
pushSender.sendMessage(destinationAccount, destinationDevice, message.build(), false);
|
messageSender.sendMessage(destinationAccount, destinationDevice, message.build(), false);
|
||||||
} catch (NotPushRegisteredException e) {
|
} catch (NotPushRegisteredException e) {
|
||||||
logger.info("User no longer push registered for delivery receipt: " + e.getMessage());
|
logger.info("User no longer push registered for delivery receipt: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.whispersystems.textsecuregcm.redis;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.textsecuregcm.push.PushSender;
|
|
||||||
|
|
||||||
public class RedisOperation {
|
public class RedisOperation {
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,8 @@ import com.codahale.metrics.MetricRegistry;
|
||||||
import com.codahale.metrics.SharedMetricRegistries;
|
import com.codahale.metrics.SharedMetricRegistries;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import com.google.protobuf.InvalidProtocolBufferException;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.whispersystems.dispatch.DispatchChannel;
|
|
||||||
import org.whispersystems.textsecuregcm.controllers.MessageController;
|
import org.whispersystems.textsecuregcm.controllers.MessageController;
|
||||||
import org.whispersystems.textsecuregcm.controllers.NoSuchUserException;
|
import org.whispersystems.textsecuregcm.controllers.NoSuchUserException;
|
||||||
import org.whispersystems.textsecuregcm.entities.CryptoEncodingException;
|
import org.whispersystems.textsecuregcm.entities.CryptoEncodingException;
|
||||||
|
@ -17,8 +15,6 @@ import org.whispersystems.textsecuregcm.entities.EncryptedOutgoingMessage;
|
||||||
import org.whispersystems.textsecuregcm.entities.OutgoingMessageEntity;
|
import org.whispersystems.textsecuregcm.entities.OutgoingMessageEntity;
|
||||||
import org.whispersystems.textsecuregcm.entities.OutgoingMessageEntityList;
|
import org.whispersystems.textsecuregcm.entities.OutgoingMessageEntityList;
|
||||||
import org.whispersystems.textsecuregcm.push.DisplacedPresenceListener;
|
import org.whispersystems.textsecuregcm.push.DisplacedPresenceListener;
|
||||||
import org.whispersystems.textsecuregcm.push.NotPushRegisteredException;
|
|
||||||
import org.whispersystems.textsecuregcm.push.PushSender;
|
|
||||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||||
import org.whispersystems.textsecuregcm.storage.Account;
|
import org.whispersystems.textsecuregcm.storage.Account;
|
||||||
import org.whispersystems.textsecuregcm.storage.Device;
|
import org.whispersystems.textsecuregcm.storage.Device;
|
||||||
|
@ -41,7 +37,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static com.codahale.metrics.MetricRegistry.name;
|
import static com.codahale.metrics.MetricRegistry.name;
|
||||||
import static org.whispersystems.textsecuregcm.entities.MessageProtos.Envelope;
|
import static org.whispersystems.textsecuregcm.entities.MessageProtos.Envelope;
|
||||||
import static org.whispersystems.textsecuregcm.storage.PubSubProtos.PubSubMessage;
|
|
||||||
|
|
||||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||||
public class WebSocketConnection implements MessageAvailabilityListener, DisplacedPresenceListener {
|
public class WebSocketConnection implements MessageAvailabilityListener, DisplacedPresenceListener {
|
||||||
|
|
|
@ -21,7 +21,7 @@ import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class PushSenderTest {
|
public class MessageSenderTest {
|
||||||
|
|
||||||
private Account account;
|
private Account account;
|
||||||
private Device device;
|
private Device device;
|
||||||
|
@ -31,7 +31,7 @@ public class PushSenderTest {
|
||||||
private MessagesManager messagesManager;
|
private MessagesManager messagesManager;
|
||||||
private GCMSender gcmSender;
|
private GCMSender gcmSender;
|
||||||
private APNSender apnSender;
|
private APNSender apnSender;
|
||||||
private PushSender pushSender;
|
private MessageSender messageSender;
|
||||||
|
|
||||||
private static final UUID ACCOUNT_UUID = UUID.randomUUID();
|
private static final UUID ACCOUNT_UUID = UUID.randomUUID();
|
||||||
private static final long DEVICE_ID = 1L;
|
private static final long DEVICE_ID = 1L;
|
||||||
|
@ -47,14 +47,14 @@ public class PushSenderTest {
|
||||||
messagesManager = mock(MessagesManager.class);
|
messagesManager = mock(MessagesManager.class);
|
||||||
gcmSender = mock(GCMSender.class);
|
gcmSender = mock(GCMSender.class);
|
||||||
apnSender = mock(APNSender.class);
|
apnSender = mock(APNSender.class);
|
||||||
pushSender = new PushSender(mock(ApnFallbackManager.class),
|
messageSender = new MessageSender(mock(ApnFallbackManager.class),
|
||||||
clientPresenceManager,
|
clientPresenceManager,
|
||||||
messagesManager,
|
messagesManager,
|
||||||
gcmSender,
|
gcmSender,
|
||||||
apnSender,
|
apnSender,
|
||||||
0,
|
0,
|
||||||
mock(ExecutorService.class),
|
mock(ExecutorService.class),
|
||||||
mock(PushLatencyManager.class));
|
mock(PushLatencyManager.class));
|
||||||
|
|
||||||
when(account.getUuid()).thenReturn(ACCOUNT_UUID);
|
when(account.getUuid()).thenReturn(ACCOUNT_UUID);
|
||||||
when(device.getId()).thenReturn(DEVICE_ID);
|
when(device.getId()).thenReturn(DEVICE_ID);
|
||||||
|
@ -65,7 +65,7 @@ public class PushSenderTest {
|
||||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(true);
|
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(true);
|
||||||
when(device.getGcmId()).thenReturn("gcm-id");
|
when(device.getGcmId()).thenReturn("gcm-id");
|
||||||
|
|
||||||
pushSender.sendSynchronousMessage(account, device, message, true);
|
messageSender.sendSynchronousMessage(account, device, message, true);
|
||||||
|
|
||||||
verify(messagesManager).insertEphemeral(ACCOUNT_UUID, DEVICE_ID, message);
|
verify(messagesManager).insertEphemeral(ACCOUNT_UUID, DEVICE_ID, message);
|
||||||
verify(messagesManager, never()).insert(any(), anyLong(), any());
|
verify(messagesManager, never()).insert(any(), anyLong(), any());
|
||||||
|
@ -78,7 +78,7 @@ public class PushSenderTest {
|
||||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
||||||
when(device.getGcmId()).thenReturn("gcm-id");
|
when(device.getGcmId()).thenReturn("gcm-id");
|
||||||
|
|
||||||
pushSender.sendSynchronousMessage(account, device, message, true);
|
messageSender.sendSynchronousMessage(account, device, message, true);
|
||||||
|
|
||||||
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
||||||
verify(messagesManager, never()).insert(any(), anyLong(), any());
|
verify(messagesManager, never()).insert(any(), anyLong(), any());
|
||||||
|
@ -91,7 +91,7 @@ public class PushSenderTest {
|
||||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(true);
|
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(true);
|
||||||
when(device.getGcmId()).thenReturn("gcm-id");
|
when(device.getGcmId()).thenReturn("gcm-id");
|
||||||
|
|
||||||
pushSender.sendSynchronousMessage(account, device, message, false);
|
messageSender.sendSynchronousMessage(account, device, message, false);
|
||||||
|
|
||||||
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
||||||
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
||||||
|
@ -104,7 +104,7 @@ public class PushSenderTest {
|
||||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
||||||
when(device.getGcmId()).thenReturn("gcm-id");
|
when(device.getGcmId()).thenReturn("gcm-id");
|
||||||
|
|
||||||
pushSender.sendSynchronousMessage(account, device, message, false);
|
messageSender.sendSynchronousMessage(account, device, message, false);
|
||||||
|
|
||||||
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
||||||
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
||||||
|
@ -117,7 +117,7 @@ public class PushSenderTest {
|
||||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
||||||
when(device.getApnId()).thenReturn("apn-id");
|
when(device.getApnId()).thenReturn("apn-id");
|
||||||
|
|
||||||
pushSender.sendSynchronousMessage(account, device, message, false);
|
messageSender.sendSynchronousMessage(account, device, message, false);
|
||||||
|
|
||||||
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
||||||
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
||||||
|
@ -130,7 +130,7 @@ public class PushSenderTest {
|
||||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
||||||
when(device.getFetchesMessages()).thenReturn(true);
|
when(device.getFetchesMessages()).thenReturn(true);
|
||||||
|
|
||||||
pushSender.sendSynchronousMessage(account, device, message, false);
|
messageSender.sendSynchronousMessage(account, device, message, false);
|
||||||
|
|
||||||
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
verify(messagesManager, never()).insertEphemeral(any(), anyLong(), any());
|
||||||
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
verify(messagesManager).insert(ACCOUNT_UUID, DEVICE_ID, message);
|
|
@ -22,7 +22,7 @@ import org.whispersystems.textsecuregcm.entities.StaleDevices;
|
||||||
import org.whispersystems.textsecuregcm.limits.RateLimiter;
|
import org.whispersystems.textsecuregcm.limits.RateLimiter;
|
||||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||||
import org.whispersystems.textsecuregcm.push.ApnFallbackManager;
|
import org.whispersystems.textsecuregcm.push.ApnFallbackManager;
|
||||||
import org.whispersystems.textsecuregcm.push.PushSender;
|
import org.whispersystems.textsecuregcm.push.MessageSender;
|
||||||
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
import org.whispersystems.textsecuregcm.push.ReceiptSender;
|
||||||
import org.whispersystems.textsecuregcm.storage.Account;
|
import org.whispersystems.textsecuregcm.storage.Account;
|
||||||
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
import org.whispersystems.textsecuregcm.storage.AccountsManager;
|
||||||
|
@ -62,12 +62,12 @@ public class MessageControllerTest {
|
||||||
private static final String MULTI_DEVICE_RECIPIENT = "+14152222222";
|
private static final String MULTI_DEVICE_RECIPIENT = "+14152222222";
|
||||||
private static final UUID MULTI_DEVICE_UUID = UUID.randomUUID();
|
private static final UUID MULTI_DEVICE_UUID = UUID.randomUUID();
|
||||||
|
|
||||||
private final PushSender pushSender = mock(PushSender.class );
|
private final MessageSender messageSender = mock(MessageSender.class);
|
||||||
private final ReceiptSender receiptSender = mock(ReceiptSender.class);
|
private final ReceiptSender receiptSender = mock(ReceiptSender.class);
|
||||||
private final AccountsManager accountsManager = mock(AccountsManager.class );
|
private final AccountsManager accountsManager = mock(AccountsManager.class);
|
||||||
private final MessagesManager messagesManager = mock(MessagesManager.class);
|
private final MessagesManager messagesManager = mock(MessagesManager.class);
|
||||||
private final RateLimiters rateLimiters = mock(RateLimiters.class );
|
private final RateLimiters rateLimiters = mock(RateLimiters.class);
|
||||||
private final RateLimiter rateLimiter = mock(RateLimiter.class );
|
private final RateLimiter rateLimiter = mock(RateLimiter.class);
|
||||||
private final ApnFallbackManager apnFallbackManager = mock(ApnFallbackManager.class);
|
private final ApnFallbackManager apnFallbackManager = mock(ApnFallbackManager.class);
|
||||||
|
|
||||||
private final ObjectMapper mapper = new ObjectMapper();
|
private final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
@ -77,7 +77,7 @@ public class MessageControllerTest {
|
||||||
.addProvider(AuthHelper.getAuthFilter())
|
.addProvider(AuthHelper.getAuthFilter())
|
||||||
.addProvider(new PolymorphicAuthValueFactoryProvider.Binder<>(ImmutableSet.of(Account.class, DisabledPermittedAccount.class)))
|
.addProvider(new PolymorphicAuthValueFactoryProvider.Binder<>(ImmutableSet.of(Account.class, DisabledPermittedAccount.class)))
|
||||||
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
|
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
|
||||||
.addResource(new MessageController(rateLimiters, pushSender, receiptSender, accountsManager,
|
.addResource(new MessageController(rateLimiters, messageSender, receiptSender, accountsManager,
|
||||||
messagesManager, apnFallbackManager))
|
messagesManager, apnFallbackManager))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ public class MessageControllerTest {
|
||||||
assertThat("Good Response", response.getStatus(), is(equalTo(200)));
|
assertThat("Good Response", response.getStatus(), is(equalTo(200)));
|
||||||
|
|
||||||
ArgumentCaptor<Envelope> captor = ArgumentCaptor.forClass(Envelope.class);
|
ArgumentCaptor<Envelope> captor = ArgumentCaptor.forClass(Envelope.class);
|
||||||
verify(pushSender, times(1)).sendMessage(any(Account.class), any(Device.class), captor.capture(), eq(false));
|
verify(messageSender, times(1)).sendMessage(any(Account.class), any(Device.class), captor.capture(), eq(false));
|
||||||
|
|
||||||
assertTrue(captor.getValue().hasSource());
|
assertTrue(captor.getValue().hasSource());
|
||||||
assertTrue(captor.getValue().hasSourceDevice());
|
assertTrue(captor.getValue().hasSourceDevice());
|
||||||
|
@ -150,7 +150,7 @@ public class MessageControllerTest {
|
||||||
assertThat("Good Response", response.getStatus(), is(equalTo(200)));
|
assertThat("Good Response", response.getStatus(), is(equalTo(200)));
|
||||||
|
|
||||||
ArgumentCaptor<Envelope> captor = ArgumentCaptor.forClass(Envelope.class);
|
ArgumentCaptor<Envelope> captor = ArgumentCaptor.forClass(Envelope.class);
|
||||||
verify(pushSender, times(1)).sendMessage(any(Account.class), any(Device.class), captor.capture(), eq(false));
|
verify(messageSender, times(1)).sendMessage(any(Account.class), any(Device.class), captor.capture(), eq(false));
|
||||||
|
|
||||||
assertFalse(captor.getValue().hasSource());
|
assertFalse(captor.getValue().hasSource());
|
||||||
assertFalse(captor.getValue().hasSourceDevice());
|
assertFalse(captor.getValue().hasSourceDevice());
|
||||||
|
@ -185,7 +185,7 @@ public class MessageControllerTest {
|
||||||
asJson(response.readEntity(MismatchedDevices.class)),
|
asJson(response.readEntity(MismatchedDevices.class)),
|
||||||
is(equalTo(jsonFixture("fixtures/missing_device_response.json"))));
|
is(equalTo(jsonFixture("fixtures/missing_device_response.json"))));
|
||||||
|
|
||||||
verifyNoMoreInteractions(pushSender);
|
verifyNoMoreInteractions(messageSender);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -204,7 +204,7 @@ public class MessageControllerTest {
|
||||||
asJson(response.readEntity(MismatchedDevices.class)),
|
asJson(response.readEntity(MismatchedDevices.class)),
|
||||||
is(equalTo(jsonFixture("fixtures/missing_device_response2.json"))));
|
is(equalTo(jsonFixture("fixtures/missing_device_response2.json"))));
|
||||||
|
|
||||||
verifyNoMoreInteractions(pushSender);
|
verifyNoMoreInteractions(messageSender);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -219,7 +219,7 @@ public class MessageControllerTest {
|
||||||
|
|
||||||
assertThat("Good Response Code", response.getStatus(), is(equalTo(200)));
|
assertThat("Good Response Code", response.getStatus(), is(equalTo(200)));
|
||||||
|
|
||||||
verify(pushSender, times(2)).sendMessage(any(Account.class), any(Device.class), any(Envelope.class), eq(false));
|
verify(messageSender, times(2)).sendMessage(any(Account.class), any(Device.class), any(Envelope.class), eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -237,7 +237,7 @@ public class MessageControllerTest {
|
||||||
asJson(response.readEntity(StaleDevices.class)),
|
asJson(response.readEntity(StaleDevices.class)),
|
||||||
is(equalTo(jsonFixture("fixtures/mismatched_registration_id.json"))));
|
is(equalTo(jsonFixture("fixtures/mismatched_registration_id.json"))));
|
||||||
|
|
||||||
verifyNoMoreInteractions(pushSender);
|
verifyNoMoreInteractions(messageSender);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue