Skip to content

Commit

Permalink
Change tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylEnkidu committed Aug 1, 2023
1 parent dd5b4b8 commit 0eb1b45
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,11 @@ public void testThrowsAnErrorWhenGettingTheResultOfAnUnrequestedAggregation() {
CollectionReference collection = testCollectionWithDocs(testDocs1);

AggregateQuerySnapshot snapshot =
waitFor(collection.aggregate(sum("pages")).get(AggregateSource.SERVER));
waitFor(
collection
.whereGreaterThan("pages", 200)
.aggregate(sum("pages"))
.get(AggregateSource.SERVER));

Exception exception = null;
try {
Expand Down Expand Up @@ -860,25 +864,21 @@ public void testPerformsSumThatIsValidButCouldOverflowDuringAggregation() {
"Skip this test if running against production because sum/avg is only support "
+ "in emulator currently.",
isRunningAgainstEmulator());

// Sum of rating would be 0, but if the accumulation overflow, we expect infinity
Map<String, Map<String, Object>> testDocs =
map(
"a", map("author", "authorA", "title", "titleA", "rating", Double.MAX_VALUE),
"b", map("author", "authorB", "title", "titleB", "rating", Double.MAX_VALUE),
"c", map("author", "authorC", "title", "titleC", "rating", -Double.MAX_VALUE),
"d", map("author", "authorD", "title", "titleD", "rating", -Double.MAX_VALUE),
"e", map("author", "authorE", "title", "titleE", "rating", Double.MAX_VALUE),
"f", map("author", "authorF", "title", "titleF", "rating", -Double.MAX_VALUE),
"g", map("author", "authorG", "title", "titleG", "rating", -Double.MAX_VALUE),
"h", map("author", "authorH", "title", "titleH", "rating", Double.MAX_VALUE));
"d", map("author", "authorD", "title", "titleD", "rating", -Double.MAX_VALUE));
CollectionReference collection = testCollectionWithDocs(testDocs);

AggregateQuerySnapshot snapshot =
waitFor(collection.aggregate(sum("rating")).get(AggregateSource.SERVER));

Object sum = snapshot.get(sum("rating"));
assertTrue(sum instanceof Long);
assertEquals(sum, 0L);
assertTrue(sum.equals(0L) || sum.equals(Long.MAX_VALUE) || sum.equals(Long.MIN_VALUE));
}

@Test
Expand Down Expand Up @@ -1240,7 +1240,6 @@ public void allowsAliasesLongerThan1500Bytes() {
// 1500 bytes, the alias will be longer than 1500, which is the limit for aliases. This is to
// make sure the client
// can handle this corner case correctly.

StringBuilder builder = new StringBuilder(1500);
for (int i = 0; i < 1500; i++) {
builder.append("a");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,8 @@ private boolean matchesFilters(Document doc) {

/** A document must have a value for every ordering clause in order to show up in the results. */
private boolean matchesOrderBy(Document doc) {
// We must use `getNormalizedOrderBy()` to get the list of all orderBys (both implicit and explicit).
// We must use `getNormalizedOrderBy()` to get the list of all orderBys (both implicit and
// explicit).
// Note that for OR queries, orderBy applies to all disjunction terms and implicit orderBys must
// be taken into account. For example, the query "a > 1 || b==1" has an implicit "orderBy a" due
// to the inequality, and is evaluated as "a > 1 orderBy a || b==1 orderBy a".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void onClose(Status status) {
public Task<Map<String, Value>> runAggregateQuery(
Query query, List<AggregateField> aggregateFields) {
com.google.firestore.v1.Target.QueryTarget encodedQueryTarget =
serializer.encodeQueryTarget(query.toTarget());
serializer.encodeQueryTarget(query.toAggregateTarget());
HashMap<String, String> aliasMap = new HashMap<>();
StructuredAggregationQuery structuredAggregationQuery =
serializer.encodeStructuredAggregationQuery(encodedQueryTarget, aggregateFields, aliasMap);
Expand Down

0 comments on commit 0eb1b45

Please sign in to comment.