Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 76ffdaa

Browse files
author
Oleksandr Shmatko
committed
Exposing message list limit for external usage
1 parent af6f3d9 commit 76ffdaa

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

‎src/main/java/com/google/firebase/messaging/FirebaseMessaging.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
*/
4242
public class FirebaseMessaging {
4343

44+
public static final int MAX_MESSAGES_IN_LIST = 500;
45+
4446
private final FirebaseApp app;
4547
private final Supplier<? extends FirebaseMessagingClient> messagingClient;
4648
private final Supplier<? extends InstanceIdClient> instanceIdClient;
@@ -147,7 +149,7 @@ protected String execute() throws FirebaseMessagingException {
147149
* <p>The responses list obtained by calling {@link BatchResponse#getResponses()} on the return
148150
* value corresponds to the order of input messages.
149151
*
150-
* @param messages A non-null, non-empty list containing up to 500 messages.
152+
* @param messages A non-null, non-empty list containing up to {@value #MAX_MESSAGES_IN_LIST} messages.
151153
* @return A {@link BatchResponse} indicating the result of the operation.
152154
* @throws FirebaseMessagingException If an error occurs while handing the messages off to FCM for
153155
* delivery. An exception here indicates a total failure -- i.e. none of the messages in the
@@ -171,7 +173,7 @@ public BatchResponse sendAll(
171173
* <p>The responses list obtained by calling {@link BatchResponse#getResponses()} on the return
172174
* value corresponds to the order of input messages.
173175
*
174-
* @param messages A non-null, non-empty list containing up to 500 messages.
176+
* @param messages A non-null, non-empty list containing up to {@value #MAX_MESSAGES_IN_LIST} messages.
175177
* @param dryRun A boolean indicating whether to perform a dry run (validation only) of the send.
176178
* @return A {@link BatchResponse} indicating the result of the operation.
177179
* @throws FirebaseMessagingException If an error occurs while handing the messages off to FCM for
@@ -186,7 +188,7 @@ public BatchResponse sendAll(
186188
/**
187189
* Similar to {@link #sendAll(List)} but performs the operation asynchronously.
188190
*
189-
* @param messages A non-null, non-empty list containing up to 500 messages.
191+
* @param messages A non-null, non-empty list containing up to {@value #MAX_MESSAGES_IN_LIST} messages.
190192
* @return @return An {@code ApiFuture} that will complete with a {@link BatchResponse} when
191193
* the messages have been sent.
192194
*/
@@ -197,7 +199,7 @@ public ApiFuture<BatchResponse> sendAllAsync(@NonNull List<Message> messages) {
197199
/**
198200
* Similar to {@link #sendAll(List, boolean)} but performs the operation asynchronously.
199201
*
200-
* @param messages A non-null, non-empty list containing up to 500 messages.
202+
* @param messages A non-null, non-empty list containing up to {@value #MAX_MESSAGES_IN_LIST} messages.
201203
* @param dryRun A boolean indicating whether to perform a dry run (validation only) of the send.
202204
* @return @return An {@code ApiFuture} that will complete with a {@link BatchResponse} when
203205
* the messages have been sent, or when the emulation has finished.
@@ -286,8 +288,8 @@ private CallableOperation<BatchResponse, FirebaseMessagingException> sendAllOp(
286288

287289
final List<Message> immutableMessages = ImmutableList.copyOf(messages);
288290
checkArgument(!immutableMessages.isEmpty(), "messages list must not be empty");
289-
checkArgument(immutableMessages.size() <= 500,
290-
"messages list must not contain more than 500 elements");
291+
checkArgument(immutableMessages.size() <= MAX_MESSAGES_IN_LIST,
292+
"messages list must not contain more than " + MAX_MESSAGES_IN_LIST + " elements");
291293
final FirebaseMessagingClient messagingClient = getMessagingClient();
292294
return new CallableOperation<BatchResponse,FirebaseMessagingException>() {
293295
@Override

‎src/main/java/com/google/firebase/messaging/MulticastMessage.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.firebase.messaging;
1818

1919
import static com.google.common.base.Preconditions.checkArgument;
20+
import static com.google.firebase.messaging.FirebaseMessaging.MAX_MESSAGES_IN_LIST;
2021

2122
import com.google.api.client.util.Strings;
2223
import com.google.common.collect.ImmutableList;
@@ -31,7 +32,7 @@
3132
/**
3233
* Represents a message that can be sent to multiple devices via Firebase Cloud Messaging (FCM).
3334
* Contains payload information as well as the list of device registration tokens to which the
34-
* message should be sent. A single {@code MulticastMessage} may contain up to 500 registration
35+
* message should be sent. A single {@code MulticastMessage} may contain up to {@value com.google.firebase.messaging.FirebaseMessaging#MAX_MESSAGES_IN_LIST} registration
3536
* tokens.
3637
*
3738
* <p>Instances of this class are thread-safe and immutable. Use {@link MulticastMessage.Builder}
@@ -56,7 +57,7 @@ public class MulticastMessage {
5657
private MulticastMessage(Builder builder) {
5758
this.tokens = builder.tokens.build();
5859
checkArgument(!this.tokens.isEmpty(), "at least one token must be specified");
59-
checkArgument(this.tokens.size() <= 500, "no more than 500 tokens can be specified");
60+
checkArgument(this.tokens.size() <= MAX_MESSAGES_IN_LIST, "no more than " + MAX_MESSAGES_IN_LIST + " tokens can be specified");
6061
for (String token : this.tokens) {
6162
checkArgument(!Strings.isNullOrEmpty(token), "none of the tokens can be null or empty");
6263
}
@@ -107,7 +108,7 @@ public static class Builder {
107108
private Builder() {}
108109

109110
/**
110-
* Adds a token to which the message should be sent. Up to 500 tokens can be specified on
111+
* Adds a token to which the message should be sent. Up to {@value com.google.firebase.messaging.FirebaseMessaging#MAX_MESSAGES_IN_LIST} tokens can be specified on
111112
* a single instance of {@link MulticastMessage}.
112113
*
113114
* @param token A non-null, non-empty Firebase device registration token.
@@ -119,7 +120,7 @@ public Builder addToken(@NonNull String token) {
119120
}
120121

121122
/**
122-
* Adds a collection of tokens to which the message should be sent. Up to 500 tokens can be
123+
* Adds a collection of tokens to which the message should be sent. Up to {@value com.google.firebase.messaging.FirebaseMessaging#MAX_MESSAGES_IN_LIST} tokens can be
123124
* specified on a single instance of {@link MulticastMessage}.
124125
*
125126
* @param tokens Collection of Firebase device registration tokens.

‎src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.firebase.messaging;
1818

19+
import static com.google.firebase.messaging.FirebaseMessaging.MAX_MESSAGES_IN_LIST;
1920
import static org.junit.Assert.assertEquals;
2021
import static org.junit.Assert.assertFalse;
2122
import static org.junit.Assert.assertNotNull;
@@ -147,16 +148,16 @@ public void testSendAll() throws Exception {
147148
}
148149

149150
@Test
150-
public void testSendFiveHundred() throws Exception {
151+
public void testSendMaximumAmountOfMessages() throws Exception {
151152
List<Message> messages = new ArrayList<>();
152-
for (int i = 0; i < 500; i++) {
153+
for (int i = 0; i < MAX_MESSAGES_IN_LIST; i++) {
153154
messages.add(Message.builder().setTopic("foo-bar-" + (i % 10)).build());
154155
}
155156

156157
BatchResponse response = FirebaseMessaging.getInstance().sendAll(messages, true);
157158

158-
assertEquals(500, response.getResponses().size());
159-
assertEquals(500, response.getSuccessCount());
159+
assertEquals(MAX_MESSAGES_IN_LIST, response.getResponses().size());
160+
assertEquals(MAX_MESSAGES_IN_LIST, response.getSuccessCount());
160161
assertEquals(0, response.getFailureCount());
161162
for (SendResponse sendResponse : response.getResponses()) {
162163
if (!sendResponse.isSuccessful()) {

‎src/test/java/com/google/firebase/messaging/FirebaseMessagingTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.firebase.messaging;
1818

19+
import static com.google.firebase.messaging.FirebaseMessaging.MAX_MESSAGES_IN_LIST;
1920
import static org.junit.Assert.assertEquals;
2021
import static org.junit.Assert.assertFalse;
2122
import static org.junit.Assert.assertNull;
@@ -297,7 +298,7 @@ public void testSendAllWithTooManyMessages() throws FirebaseMessagingException {
297298
MockFirebaseMessagingClient client = MockFirebaseMessagingClient.fromMessageId(null);
298299
FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client));
299300
ImmutableList.Builder<Message> listBuilder = ImmutableList.builder();
300-
for (int i = 0; i < 501; i++) {
301+
for (int i = 0; i < MAX_MESSAGES_IN_LIST + 1; i++) {
301302
listBuilder.add(Message.builder().setTopic("topic").build());
302303
}
303304

‎src/test/java/com/google/firebase/messaging/MulticastMessageTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.firebase.messaging;
1818

19+
import static com.google.firebase.messaging.FirebaseMessaging.MAX_MESSAGES_IN_LIST;
1920
import static org.junit.Assert.assertEquals;
2021
import static org.junit.Assert.assertSame;
2122
import static org.junit.Assert.fail;
@@ -75,7 +76,7 @@ public void testNoTokens() {
7576
@Test
7677
public void testTooManyTokens() {
7778
MulticastMessage.Builder builder = MulticastMessage.builder();
78-
for (int i = 0; i < 501; i++) {
79+
for (int i = 0; i < MAX_MESSAGES_IN_LIST + 1; i++) {
7980
builder.addToken("token" + i);
8081
}
8182
try {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /