|
25 | 25 | import static com.google.cloud.firestore.LocalFirestoreHelper.UPDATE_SINGLE_FIELD_OBJECT;
|
26 | 26 | import static com.google.cloud.firestore.LocalFirestoreHelper.fullPath;
|
27 | 27 | import static com.google.cloud.firestore.LocalFirestoreHelper.map;
|
| 28 | +import static com.google.cloud.firestore.it.TestHelper.getLargestDocContent; |
28 | 29 | import static com.google.cloud.firestore.it.TestHelper.isRunningAgainstFirestoreEmulator;
|
29 | 30 | import static com.google.common.truth.Truth.assertThat;
|
30 | 31 | import static java.util.Arrays.asList;
|
@@ -2311,4 +2312,133 @@ public void testEnforcesTimeouts() {
|
2311 | 2312 | FirestoreException.class,
|
2312 | 2313 | () -> collection.document().listCollections().iterator().hasNext());
|
2313 | 2314 | }
|
| 2315 | + |
| 2316 | + @Test |
| 2317 | + public void testCanCRUDAndQueryLargeDocuments() throws Exception { |
| 2318 | + // Note, do not use the 'randomColl' because its format contanis the |
| 2319 | + // test name, and that makes it difficult to correctly calculate the |
| 2320 | + // largest number of bytes we can put in the document. |
| 2321 | + CollectionReference collRef = firestore.collection(LocalFirestoreHelper.autoId()); |
| 2322 | + DocumentReference docRef = collRef.document(); |
| 2323 | + Map<String, Object> data = getLargestDocContent(); |
| 2324 | + |
| 2325 | + // Set |
| 2326 | + docRef.set(data).get(); |
| 2327 | + |
| 2328 | + // Get |
| 2329 | + DocumentSnapshot snapshot = docRef.get().get(); |
| 2330 | + assertEquals(data, snapshot.getData()); |
| 2331 | + |
| 2332 | + // Update |
| 2333 | + Map<String, Object> newData = getLargestDocContent(); |
| 2334 | + docRef.update(newData).get(); |
| 2335 | + snapshot = docRef.get().get(); |
| 2336 | + assertEquals(newData, snapshot.getData()); |
| 2337 | + |
| 2338 | + // Query |
| 2339 | + QuerySnapshot querySnapshot = collRef.get().get(); |
| 2340 | + assertEquals(querySnapshot.size(), 1); |
| 2341 | + assertEquals(newData, querySnapshot.getDocuments().get(0).getData()); |
| 2342 | + |
| 2343 | + // Delete |
| 2344 | + docRef.delete().get(); |
| 2345 | + snapshot = docRef.get().get(); |
| 2346 | + assertFalse(snapshot.exists()); |
| 2347 | + } |
| 2348 | + |
| 2349 | + @Test |
| 2350 | + public void testCanCRUDLargeDocumentsInsideTransaction() throws Exception { |
| 2351 | + // Note, do not use the 'randomColl' because its format contanis the |
| 2352 | + // test name, and that makes it difficult to correctly calculate the |
| 2353 | + // largest number of bytes we can put in the document. |
| 2354 | + CollectionReference collRef = firestore.collection(LocalFirestoreHelper.autoId()); |
| 2355 | + DocumentReference docRef1 = collRef.document(); |
| 2356 | + DocumentReference docRef2 = collRef.document(); |
| 2357 | + DocumentReference docRef3 = collRef.document(); |
| 2358 | + Map<String, Object> data = getLargestDocContent(); |
| 2359 | + Map<String, Object> newData = getLargestDocContent(); |
| 2360 | + docRef1.set(data).get(); |
| 2361 | + docRef3.set(data).get(); |
| 2362 | + |
| 2363 | + collRef |
| 2364 | + .getFirestore() |
| 2365 | + .runTransaction( |
| 2366 | + transaction -> { |
| 2367 | + // Get and update |
| 2368 | + DocumentSnapshot snapshot = transaction.get(docRef1).get(); |
| 2369 | + assertEquals(data, snapshot.getData()); |
| 2370 | + transaction.update(docRef1, newData); |
| 2371 | + |
| 2372 | + // Set |
| 2373 | + transaction.set(docRef2, data); |
| 2374 | + |
| 2375 | + // Delete |
| 2376 | + transaction.delete(docRef3); |
| 2377 | + return null; |
| 2378 | + }) |
| 2379 | + .get(); |
| 2380 | + |
| 2381 | + DocumentSnapshot snapshot = docRef1.get().get(); |
| 2382 | + assertEquals(newData, snapshot.getData()); |
| 2383 | + |
| 2384 | + snapshot = docRef2.get().get(); |
| 2385 | + assertEquals(data, snapshot.getData()); |
| 2386 | + |
| 2387 | + snapshot = docRef3.get().get(); |
| 2388 | + assertFalse(snapshot.exists()); |
| 2389 | + } |
| 2390 | + |
| 2391 | + @Test |
| 2392 | + public void listenToLargeQuerySnapshot() throws Exception { |
| 2393 | + // Note, do not use the 'randomColl' because its format contanis the |
| 2394 | + // test name, and that makes it difficult to correctly calculate the |
| 2395 | + // largest number of bytes we can put in the document. |
| 2396 | + CollectionReference collRef = firestore.collection(LocalFirestoreHelper.autoId()); |
| 2397 | + DocumentReference docRef = collRef.document(); |
| 2398 | + Map<String, Object> data = getLargestDocContent(); |
| 2399 | + docRef.set(data).get(); |
| 2400 | + |
| 2401 | + CountDownLatch latch = new CountDownLatch(1); |
| 2402 | + List<QuerySnapshot> querySnapshots = new ArrayList<>(); |
| 2403 | + ListenerRegistration registration = |
| 2404 | + collRef.addSnapshotListener( |
| 2405 | + (value, error) -> { |
| 2406 | + querySnapshots.add(value); |
| 2407 | + latch.countDown(); |
| 2408 | + }); |
| 2409 | + |
| 2410 | + latch.await(); |
| 2411 | + registration.remove(); |
| 2412 | + |
| 2413 | + assertEquals(querySnapshots.size(), 1); |
| 2414 | + assertEquals(querySnapshots.get(0).getDocuments().size(), 1); |
| 2415 | + assertEquals(data, querySnapshots.get(0).getDocuments().get(0).getData()); |
| 2416 | + } |
| 2417 | + |
| 2418 | + @Test |
| 2419 | + public void listenToLargeDocumentSnapshot() throws Exception { |
| 2420 | + // Note, do not use the 'randomColl' because its format contanis the |
| 2421 | + // test name, and that makes it difficult to correctly calculate the |
| 2422 | + // largest number of bytes we can put in the document. |
| 2423 | + CollectionReference collRef = firestore.collection(LocalFirestoreHelper.autoId()); |
| 2424 | + DocumentReference docRef = collRef.document(); |
| 2425 | + Map<String, Object> data = getLargestDocContent(); |
| 2426 | + docRef.set(data).get(); |
| 2427 | + |
| 2428 | + CountDownLatch latch = new CountDownLatch(1); |
| 2429 | + List<DocumentSnapshot> documentSnapshots = new ArrayList<>(); |
| 2430 | + |
| 2431 | + ListenerRegistration registration = |
| 2432 | + docRef.addSnapshotListener( |
| 2433 | + (value, error) -> { |
| 2434 | + documentSnapshots.add(value); |
| 2435 | + latch.countDown(); |
| 2436 | + }); |
| 2437 | + |
| 2438 | + latch.await(); |
| 2439 | + registration.remove(); |
| 2440 | + |
| 2441 | + assertEquals(documentSnapshots.size(), 1); |
| 2442 | + assertEquals(data, documentSnapshots.get(0).getData()); |
| 2443 | + } |
2314 | 2444 | }
|
0 commit comments