|
16 | 16 |
|
17 | 17 | import static com.google.firebase.firestore.AccessHelper.getAsyncQueue;
|
18 | 18 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.checkOnlineAndOfflineResultsMatch;
|
| 19 | +import static com.google.firebase.firestore.testutil.IntegrationTestUtil.getLargestDocContent; |
19 | 20 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.isRunningAgainstEmulator;
|
20 | 21 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.newTestSettings;
|
21 | 22 | import static com.google.firebase.firestore.testutil.IntegrationTestUtil.provider;
|
@@ -1988,4 +1989,121 @@ public void snapshotListenerSortsInvalidUnicodeStringsAsServer() {
|
1988 | 1989 |
|
1989 | 1990 | checkOnlineAndOfflineResultsMatch(colRef, orderedQuery, expectedDocIds.toArray(new String[0]));
|
1990 | 1991 | }
|
| 1992 | + |
| 1993 | + @Test |
| 1994 | + public void testCanCRUDAndQueryLargeDocuments() { |
| 1995 | + CollectionReference collRef = testCollection(); |
| 1996 | + DocumentReference docRef = collRef.document(); |
| 1997 | + Map<String, Object> data = getLargestDocContent(); |
| 1998 | + |
| 1999 | + // Set |
| 2000 | + waitFor(docRef.set(data)); |
| 2001 | + |
| 2002 | + // Get |
| 2003 | + DocumentSnapshot snapshot = waitFor(docRef.get()); |
| 2004 | + assertEquals(data, snapshot.getData()); |
| 2005 | + |
| 2006 | + // Update |
| 2007 | + Map<String, Object> newData = getLargestDocContent(); |
| 2008 | + waitFor(docRef.update(newData)); |
| 2009 | + snapshot = waitFor(docRef.get()); |
| 2010 | + assertEquals(newData, snapshot.getData()); |
| 2011 | + |
| 2012 | + // Query |
| 2013 | + QuerySnapshot querySnapshot = waitFor(collRef.get()); |
| 2014 | + assertEquals(querySnapshot.size(), 1); |
| 2015 | + assertEquals(newData, querySnapshot.getDocuments().get(0).getData()); |
| 2016 | + |
| 2017 | + // Delete |
| 2018 | + waitFor(docRef.delete()); |
| 2019 | + snapshot = waitFor(docRef.get()); |
| 2020 | + assertFalse(snapshot.exists()); |
| 2021 | + } |
| 2022 | + |
| 2023 | + @Test |
| 2024 | + public void testCanCRUDLargeDocumentsInsideTransaction() { |
| 2025 | + CollectionReference collRef = testCollection(); |
| 2026 | + |
| 2027 | + DocumentReference docRef1 = collRef.document(); |
| 2028 | + DocumentReference docRef2 = collRef.document(); |
| 2029 | + DocumentReference docRef3 = collRef.document(); |
| 2030 | + Map<String, Object> data = getLargestDocContent(); |
| 2031 | + Map<String, Object> newData = getLargestDocContent(); |
| 2032 | + waitFor(docRef1.set(data)); |
| 2033 | + waitFor(docRef3.set(data)); |
| 2034 | + |
| 2035 | + waitFor( |
| 2036 | + collRef |
| 2037 | + .getFirestore() |
| 2038 | + .runTransaction( |
| 2039 | + transaction -> { |
| 2040 | + // Get and update |
| 2041 | + DocumentSnapshot snapshot = transaction.get(docRef1); |
| 2042 | + assertEquals(data, snapshot.getData()); |
| 2043 | + transaction.update(docRef1, newData); |
| 2044 | + |
| 2045 | + // Set |
| 2046 | + transaction.set(docRef2, data); |
| 2047 | + |
| 2048 | + // Delete |
| 2049 | + transaction.delete(docRef3); |
| 2050 | + return null; |
| 2051 | + })); |
| 2052 | + |
| 2053 | + DocumentSnapshot snapshot = waitFor(docRef1.get()); |
| 2054 | + assertEquals(newData, snapshot.getData()); |
| 2055 | + |
| 2056 | + snapshot = waitFor(docRef2.get()); |
| 2057 | + assertEquals(data, snapshot.getData()); |
| 2058 | + |
| 2059 | + snapshot = waitFor(docRef3.get()); |
| 2060 | + assertFalse(snapshot.exists()); |
| 2061 | + } |
| 2062 | + |
| 2063 | + @Test |
| 2064 | + public void listenToLargeQuerySnapshot() throws Exception { |
| 2065 | + CollectionReference collRef = testCollection(); |
| 2066 | + DocumentReference docRef = collRef.document(); |
| 2067 | + Map<String, Object> data = getLargestDocContent(); |
| 2068 | + waitFor(docRef.set(data)); |
| 2069 | + |
| 2070 | + CountDownLatch latch = new CountDownLatch(1); |
| 2071 | + List<QuerySnapshot> querySnapshots = new ArrayList<>(); |
| 2072 | + ListenerRegistration registration = |
| 2073 | + collRef.addSnapshotListener( |
| 2074 | + (value, error) -> { |
| 2075 | + querySnapshots.add(value); |
| 2076 | + latch.countDown(); |
| 2077 | + }); |
| 2078 | + |
| 2079 | + latch.await(); |
| 2080 | + registration.remove(); |
| 2081 | + |
| 2082 | + assertEquals(querySnapshots.size(), 1); |
| 2083 | + assertEquals(querySnapshots.get(0).getDocuments().size(), 1); |
| 2084 | + assertEquals(data, querySnapshots.get(0).getDocuments().get(0).getData()); |
| 2085 | + } |
| 2086 | + |
| 2087 | + @Test |
| 2088 | + public void listenToLargeDocumentSnapshot() throws Exception { |
| 2089 | + DocumentReference docRef = testDocument(); |
| 2090 | + Map<String, Object> data = getLargestDocContent(); |
| 2091 | + waitFor(docRef.set(data)); |
| 2092 | + |
| 2093 | + CountDownLatch latch = new CountDownLatch(1); |
| 2094 | + List<DocumentSnapshot> documentSnapshots = new ArrayList<>(); |
| 2095 | + |
| 2096 | + ListenerRegistration registration = |
| 2097 | + docRef.addSnapshotListener( |
| 2098 | + (value, error) -> { |
| 2099 | + documentSnapshots.add(value); |
| 2100 | + latch.countDown(); |
| 2101 | + }); |
| 2102 | + |
| 2103 | + latch.await(); |
| 2104 | + registration.remove(); |
| 2105 | + |
| 2106 | + assertEquals(documentSnapshots.size(), 1); |
| 2107 | + assertEquals(data, documentSnapshots.get(0).getData()); |
| 2108 | + } |
1991 | 2109 | }
|
0 commit comments