-
Notifications
You must be signed in to change notification settings - Fork 626
Test large documents #7040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Test large documents #7040
Changes from 1 commit
82c2224
9b25cba
a08a955
b33a7e1
b1194d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.FirebaseOptions; | ||
import com.google.firebase.firestore.AccessHelper; | ||
import com.google.firebase.firestore.Blob; | ||
import com.google.firebase.firestore.BuildConfig; | ||
import com.google.firebase.firestore.CollectionReference; | ||
import com.google.firebase.firestore.DocumentReference; | ||
|
@@ -52,9 +53,11 @@ | |
import com.google.firebase.firestore.util.Logger; | ||
import com.google.firebase.firestore.util.Logger.Level; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Random; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Semaphore; | ||
|
@@ -125,6 +128,10 @@ public enum TargetBackend { | |
|
||
private static boolean backendPrimed = false; | ||
|
||
private static final Random RANDOM = new Random(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think it'd be better to move this into the final Random random = new Random();
random.nextBytes(bytes); |
||
|
||
private static final int MAX_BYTES_PER_FIELD_VALUE = 1048487; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also on the fence about moving this into |
||
|
||
// FirebaseOptions needed to create a test FirebaseApp. | ||
private static final FirebaseOptions OPTIONS = | ||
new FirebaseOptions.Builder() | ||
|
@@ -561,4 +568,17 @@ public static void checkOnlineAndOfflineResultsMatch( | |
assertEquals(expectedDocIds, querySnapshotToIds(docsFromServer)); | ||
} | ||
} | ||
|
||
/**Add commentMore actions | ||
* Returns a Blob with the size equal to the largest number of bytes allowed to | ||
* be stored in a Firestore document. | ||
*/ | ||
public static Map<String, Object> getLargestDocContent() { | ||
// Subtract 8 for '__name__', 20 for its value, and 4 for 'blob'. | ||
int numBytesToUse = MAX_BYTES_PER_FIELD_VALUE - 8 - 20 - 4; | ||
byte[] bytes = new byte[numBytesToUse]; | ||
// Fill the byte array with random values | ||
RANDOM.nextBytes(bytes); | ||
return Collections.singletonMap("blob", Blob.fromBytes(bytes)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting the common parts of these tests into helper methods to reduce code duplication and improve readability.