Skip to content

Commit 9e889fe

Browse files
committed
Merge branch 'master' into mila/BloomFilter
2 parents 3d406f2 + 7a0f906 commit 9e889fe

File tree

11 files changed

+303
-107
lines changed

11 files changed

+303
-107
lines changed

encoders/firebase-encoders-json/firebase-encoders-json.gradle

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
plugins {
1616
id 'firebase-library'
17+
id 'kotlin-android'
1718
}
1819

1920
firebaseLibrary {
@@ -24,16 +25,19 @@ firebaseLibrary {
2425
android {
2526
compileSdkVersion project.targetSdkVersion
2627
defaultConfig {
27-
minSdkVersion project.minSdkVersion
28-
targetSdkVersion project.targetSdkVersion
29-
versionName version
30-
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
28+
minSdkVersion project.minSdkVersion
29+
targetSdkVersion project.targetSdkVersion
30+
versionName version
31+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3132
}
3233

3334
compileOptions {
3435
sourceCompatibility JavaVersion.VERSION_1_8
3536
targetCompatibility JavaVersion.VERSION_1_8
3637
}
38+
kotlinOptions {
39+
jvmTarget = '1.8'
40+
}
3741
testOptions {
3842
unitTests {
3943
includeAndroidResources = true

encoders/firebase-encoders-json/src/main/java/com/google/firebase/encoders/json/JsonValueObjectEncoderContext.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ JsonValueObjectEncoderContext add(@Nullable Object o, boolean inline) throws IOE
317317

318318
// Process enum last if it does not have a custom encoder registered.
319319
if (o instanceof Enum) {
320-
add(((Enum) o).name());
320+
if (o instanceof NumberedEnum) {
321+
add(((NumberedEnum) o).getNumber());
322+
} else {
323+
add(((Enum<?>) o).name());
324+
}
321325
return this;
322326
}
323327

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.encoders.json
18+
19+
/** Represents an explicitly numbered enum for json serialization. */
20+
interface NumberedEnum {
21+
val number: Int
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2023 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.encoders.json
18+
19+
internal enum class DummyEnum(override val number: Int) : NumberedEnum {
20+
VALUE_1(1),
21+
VALUE_2(2),
22+
}

encoders/firebase-encoders-json/src/test/java/com/google/firebase/encoders/json/JsonValueObjectEncoderContextTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ public void testEncodingEnum_withCustomEncoder() {
219219
assertThat(result).isEqualTo("[\"value_1\",\"value_2\"]");
220220
}
221221

222+
@Test
223+
public void testEncodingNumberedEnum() {
224+
String result =
225+
new JsonDataEncoderBuilder()
226+
.build()
227+
.encode(
228+
new DummyEnum[] {
229+
DummyEnum.VALUE_1, DummyEnum.VALUE_2, DummyEnum.VALUE_1, DummyEnum.VALUE_1
230+
});
231+
assertThat(result).isEqualTo("[1,2,1,1]");
232+
}
233+
222234
@Test
223235
public void testEncodingCollection() throws IOException {
224236
ObjectEncoder<InnerDummyClass> anotherObjectEncoder =

firebase-firestore/src/test/java/com/google/firebase/firestore/spec/SpecTestCase.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,12 +1025,14 @@ private void validateExpectedState(@Nullable JSONObject expectedState) throws JS
10251025
expectedActiveTargets.put(targetId, new ArrayList<>());
10261026
for (int i = 0; i < queryArrayJson.length(); i++) {
10271027
Query query = parseQuery(queryArrayJson.getJSONObject(i));
1028-
// TODO: populate the purpose of the target once it's possible to encode that in the
1029-
// spec tests. For now, hard-code that it's a listen despite the fact that it's not
1030-
// always the right value.
1028+
1029+
QueryPurpose purpose = QueryPurpose.LISTEN;
1030+
if (queryDataJson.has("targetPurpose")) {
1031+
purpose = QueryPurpose.values()[queryDataJson.getInt("targetPurpose")];
1032+
}
1033+
10311034
TargetData targetData =
1032-
new TargetData(
1033-
query.toTarget(), targetId, ARBITRARY_SEQUENCE_NUMBER, QueryPurpose.LISTEN);
1035+
new TargetData(query.toTarget(), targetId, ARBITRARY_SEQUENCE_NUMBER, purpose);
10341036
if (queryDataJson.has("resumeToken")) {
10351037
targetData =
10361038
targetData.withResumeToken(
@@ -1172,9 +1174,12 @@ private void validateActiveTargets() {
11721174
TargetData expectedTarget = expectedQueries.get(0);
11731175
TargetData actualTarget = actualTargets.get(expected.getKey());
11741176

1175-
// TODO: validate the purpose of the target once it's possible to encode that in the
1176-
// spec tests. For now, only validate properties that can be validated.
1177+
// TODO: Replace the assertEquals() checks on the individual properties of TargetData below
1178+
// with the single assertEquals on the TargetData objects themselves if the sequenceNumber is
1179+
// ever made to be consistent.
11771180
// assertEquals(expectedTarget, actualTarget);
1181+
1182+
assertEquals(expectedTarget.getPurpose(), actualTarget.getPurpose());
11781183
assertEquals(expectedTarget.getTarget(), actualTarget.getTarget());
11791184
assertEquals(expectedTarget.getTargetId(), actualTarget.getTargetId());
11801185
assertEquals(expectedTarget.getSnapshotVersion(), actualTarget.getSnapshotVersion());

firebase-firestore/src/test/resources/json/bundle_spec_test.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,8 @@
11651165
"path": "collection/a"
11661166
}
11671167
],
1168-
"resumeToken": ""
1168+
"resumeToken": "",
1169+
"targetPurpose": 2
11691170
},
11701171
"2": {
11711172
"queries": [

firebase-firestore/src/test/resources/json/existence_filter_spec_test.json

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4059,7 +4059,24 @@
40594059
"path": "collection"
40604060
}
40614061
}
4062-
]
4062+
],
4063+
"expectedState": {
4064+
"activeTargets": {
4065+
"2": {
4066+
"queries": [
4067+
{
4068+
"filters": [
4069+
],
4070+
"orderBys": [
4071+
],
4072+
"path": "collection"
4073+
}
4074+
],
4075+
"resumeToken": "",
4076+
"targetPurpose": 1
4077+
}
4078+
}
4079+
}
40634080
},
40644081
{
40654082
"restart": true,
@@ -4321,7 +4338,8 @@
43214338
"path": "collection"
43224339
}
43234340
],
4324-
"resumeToken": ""
4341+
"resumeToken": "",
4342+
"targetPurpose": 1
43254343
}
43264344
}
43274345
}
@@ -4821,7 +4839,8 @@
48214839
"path": "collection"
48224840
}
48234841
],
4824-
"resumeToken": ""
4842+
"resumeToken": "",
4843+
"targetPurpose": 1
48254844
}
48264845
}
48274846
}
@@ -4887,7 +4906,8 @@
48874906
"path": "collection/2"
48884907
}
48894908
],
4890-
"resumeToken": ""
4909+
"resumeToken": "",
4910+
"targetPurpose": 2
48914911
},
48924912
"2": {
48934913
"queries": [
@@ -4899,7 +4919,8 @@
48994919
"path": "collection"
49004920
}
49014921
],
4902-
"resumeToken": ""
4922+
"resumeToken": "",
4923+
"targetPurpose": 1
49034924
}
49044925
}
49054926
}
@@ -4954,7 +4975,8 @@
49544975
"path": "collection"
49554976
}
49564977
],
4957-
"resumeToken": ""
4978+
"resumeToken": "",
4979+
"targetPurpose": 1
49584980
}
49594981
}
49604982
}
@@ -5392,7 +5414,8 @@
53925414
"path": "collection"
53935415
}
53945416
],
5395-
"resumeToken": ""
5417+
"resumeToken": "",
5418+
"targetPurpose": 1
53965419
}
53975420
}
53985421
}
@@ -5458,7 +5481,8 @@
54585481
"path": "collection/2"
54595482
}
54605483
],
5461-
"resumeToken": ""
5484+
"resumeToken": "",
5485+
"targetPurpose": 2
54625486
},
54635487
"2": {
54645488
"queries": [
@@ -5470,7 +5494,8 @@
54705494
"path": "collection"
54715495
}
54725496
],
5473-
"resumeToken": ""
5497+
"resumeToken": "",
5498+
"targetPurpose": 1
54745499
}
54755500
}
54765501
}
@@ -5535,7 +5560,8 @@
55355560
"path": "collection"
55365561
}
55375562
],
5538-
"resumeToken": ""
5563+
"resumeToken": "",
5564+
"targetPurpose": 1
55395565
}
55405566
}
55415567
}
@@ -5741,7 +5767,8 @@
57415767
"path": "collection"
57425768
}
57435769
],
5744-
"resumeToken": ""
5770+
"resumeToken": "",
5771+
"targetPurpose": 1
57455772
}
57465773
}
57475774
}
@@ -5807,7 +5834,8 @@
58075834
"path": "collection/2"
58085835
}
58095836
],
5810-
"resumeToken": ""
5837+
"resumeToken": "",
5838+
"targetPurpose": 2
58115839
},
58125840
"2": {
58135841
"queries": [
@@ -5819,7 +5847,8 @@
58195847
"path": "collection"
58205848
}
58215849
],
5822-
"resumeToken": ""
5850+
"resumeToken": "",
5851+
"targetPurpose": 1
58235852
}
58245853
}
58255854
}
@@ -5884,7 +5913,8 @@
58845913
"path": "collection"
58855914
}
58865915
],
5887-
"resumeToken": ""
5916+
"resumeToken": "",
5917+
"targetPurpose": 1
58885918
}
58895919
}
58905920
}
@@ -6142,7 +6172,24 @@
61426172
"path": "collection"
61436173
}
61446174
}
6145-
]
6175+
],
6176+
"expectedState": {
6177+
"activeTargets": {
6178+
"2": {
6179+
"queries": [
6180+
{
6181+
"filters": [
6182+
],
6183+
"orderBys": [
6184+
],
6185+
"path": "collection"
6186+
}
6187+
],
6188+
"resumeToken": "",
6189+
"targetPurpose": 1
6190+
}
6191+
}
6192+
}
61466193
}
61476194
]
61486195
},

0 commit comments

Comments
 (0)