Skip to content
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

Upgraded google-cloud-firestore to the latest version (0.61.0-beta) … #205

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@
<artifactId>api-common</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax</artifactId>
<version>1.30.0</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
Expand All @@ -411,7 +416,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-firestore</artifactId>
<version>0.45.0-beta</version>
<version>0.61.0-beta</version>
</dependency>

<!-- Utilities -->
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/google/firebase/FirebaseOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public final class FirebaseOptions {
private final int readTimeout;
private final JsonFactory jsonFactory;
private final ThreadManager threadManager;
private final boolean firestoreTimestampsInSnapshotsEnabled;

private FirebaseOptions(@NonNull FirebaseOptions.Builder builder) {
this.credentials = checkNotNull(builder.credentials,
Expand Down Expand Up @@ -94,6 +95,8 @@ private FirebaseOptions(@NonNull FirebaseOptions.Builder builder) {
this.connectTimeout = builder.connectTimeout;
checkArgument(builder.readTimeout >= 0);
this.readTimeout = builder.readTimeout;
this.firestoreTimestampsInSnapshotsEnabled =
builder.firestoreTimestampsInSnapshotsEnabled;
}

/**
Expand Down Expand Up @@ -188,6 +191,14 @@ public int getReadTimeout() {
return readTimeout;
}

/**
* Returns whether or not {@link com.google.cloud.firestore.DocumentSnapshot DocumentSnapshots}
* return timestamp fields as {@link com.google.cloud.Timestamp Timestamps}.
*/
public boolean areFirestoreTimestampsInSnapshotsEnabled() {
return firestoreTimestampsInSnapshotsEnabled;
}

@NonNull
ThreadManager getThreadManager() {
return threadManager;
Expand Down Expand Up @@ -218,6 +229,7 @@ public static final class Builder {
private ThreadManager threadManager = FirebaseThreadManagers.DEFAULT_THREAD_MANAGER;
private int connectTimeout;
private int readTimeout;
private boolean firestoreTimestampsInSnapshotsEnabled;

/** Constructs an empty builder. */
public Builder() {}
Expand All @@ -239,6 +251,7 @@ public Builder(FirebaseOptions options) {
threadManager = options.threadManager;
connectTimeout = options.connectTimeout;
readTimeout = options.readTimeout;
firestoreTimestampsInSnapshotsEnabled = options.firestoreTimestampsInSnapshotsEnabled;
}

/**
Expand Down Expand Up @@ -411,6 +424,20 @@ public Builder setReadTimeout(int readTimeout) {
return this;
}

/**
* Sets whether timestamps are enabled in Firestore
* {@link com.google.cloud.firestore.DocumentSnapshot DocumentSnapshots}.
*
* @param firestoreTimestampsInSnapshotsEnabled If true, timestamps are enabled in Firestore
* DocumentSnapshots.
* @return This <code>Builder</code> instance is returned so subsequent calls can be chained.
*/
public Builder setFirestoreTimestampsInSnapshotsEnabled(
boolean firestoreTimestampsInSnapshotsEnabled) {
this.firestoreTimestampsInSnapshotsEnabled = firestoreTimestampsInSnapshotsEnabled;
return this;
}

/**
* Builds the {@link FirebaseOptions} instance from the previously set options.
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/google/firebase/cloud/FirestoreClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ private FirestoreClient(FirebaseApp app) {
+ "set the project ID explicitly via FirebaseOptions. Alternatively you can also "
+ "set the project ID via the GOOGLE_CLOUD_PROJECT environment variable.");
this.firestore = FirestoreOptions.newBuilder()
.setTimestampsInSnapshotsEnabled(
app.getOptions().areFirestoreTimestampsInSnapshotsEnabled())
.setCredentials(ImplFirebaseTrampolines.getCredentials(app))
.setProjectId(projectId)
.build()
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/com/google/firebase/cloud/FirestoreClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,33 @@ public void testServiceAccountProjectId() throws IOException {
assertEquals("mock-project-id", firestore.getOptions().getProjectId());
}

@Test
public void testFirestoreTimestampsInSnapshotsEnabled_defaultsToFalse() throws IOException {
FirebaseApp app = FirebaseApp.initializeApp(new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
.setProjectId("explicit-project-id")
.build());
Firestore firestore = FirestoreClient.getFirestore(app);
assertEquals(false, firestore.getOptions().areTimestampsInSnapshotsEnabled());

firestore = FirestoreClient.getFirestore();
assertEquals(false, firestore.getOptions().areTimestampsInSnapshotsEnabled());
}

@Test
public void testFirestoreTimestampsInSnapshotsEnabled_setToTrue() throws IOException {
FirebaseApp app = FirebaseApp.initializeApp(new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
.setProjectId("explicit-project-id")
.setFirestoreTimestampsInSnapshotsEnabled(true)
.build());
Firestore firestore = FirestoreClient.getFirestore(app);
assertEquals(true, firestore.getOptions().areTimestampsInSnapshotsEnabled());

firestore = FirestoreClient.getFirestore();
assertEquals(true, firestore.getOptions().areTimestampsInSnapshotsEnabled());
}

@Test
public void testAppDelete() throws IOException {
FirebaseApp app = FirebaseApp.initializeApp(new FirebaseOptions.Builder()
Expand Down