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

fix: add BulkWriter system tests + pass BE error messages #252

Merged
merged 5 commits into from
Jun 12, 2020

Conversation

thebrianchen
Copy link

Porting integration tests from node.

After running into a few BE contention errors during testing, I also added the error message to BatchWriteResult, since backend errors were not being returned in a useful manner.

@thebrianchen thebrianchen self-assigned this Jun 11, 2020
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 11, 2020
@codecov
Copy link

codecov bot commented Jun 11, 2020

Codecov Report

Merging #252 into bc/bulk-master will increase coverage by 0.00%.
The diff coverage is 75.10%.

Impacted file tree graph

@@                Coverage Diff                @@
##             bc/bulk-master     #252   +/-   ##
=================================================
  Coverage             73.72%   73.73%           
- Complexity             1087     1088    +1     
=================================================
  Files                    67       67           
  Lines                  5866     5868    +2     
  Branches                642      642           
=================================================
+ Hits                   4325     4327    +2     
  Misses                 1341     1341           
  Partials                200      200           
Impacted Files Coverage Δ Complexity Δ
.../com/google/cloud/firestore/BulkWriterOptions.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...java/com/google/cloud/firestore/FirestoreImpl.java 78.19% <50.00%> (ø) 25.00 <1.00> (ø)
...in/java/com/google/cloud/firestore/BulkWriter.java 70.12% <70.12%> (ø) 26.00 <26.00> (ø)
...java/com/google/cloud/firestore/UpdateBuilder.java 95.00% <93.22%> (ø) 75.00 <17.00> (ø)
...a/com/google/cloud/firestore/BatchWriteResult.java 100.00% <100.00%> (ø) 4.00 <2.00> (+1.00)
...n/java/com/google/cloud/firestore/RateLimiter.java 100.00% <100.00%> (ø) 13.00 <1.00> (ø)
...n/java/com/google/cloud/firestore/Transaction.java 97.56% <100.00%> (ø) 11.00 <1.00> (ø)
...in/java/com/google/cloud/firestore/WriteBatch.java 100.00% <100.00%> (ø) 3.00 <1.00> (ø)
...n/java/com/google/cloud/firestore/WriteResult.java 50.00% <100.00%> (ø) 4.00 <1.00> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b76565...f57e7ac. Read the comment docs.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that these test don't verify that the BulkWriter makes the requested changes. Can you read the documents back and add asserts that they match the written data.

We also had a bug in our implementation that dropped Preconditions (caught during review). Can we add a test that verifies the we set the "Create" and "Update" preconditions. These should fail if triggered correctly.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that these test don't verify that the BulkWriter makes the requested changes. Can you read the documents back and add asserts that they match the written data.

We also had a bug in our implementation that dropped Preconditions (caught during review). Can we add a test that verifies the we set the "Create" and "Update" preconditions. These should fail if triggered correctly.

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding those tests!

public void bulkWriterCreateAddsPrecondition() throws Exception {
DocumentReference docRef = randomColl.document();
docRef.set(Collections.singletonMap("foo", (Object) "bar")).get();
BulkWriter writer = firestore.bulkWriter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These test could profit from some line breaks. You will want to separate the setup, the action and the verfication:

@Test
  public void bulkWriterCreateAddsPrecondition() throws Exception {
    DocumentReference docRef = randomColl.document();
    docRef.set(Collections.singletonMap("foo", (Object) "bar")).get();
    
    BulkWriter writer = firestore.bulkWriter();
    ApiFuture<WriteResult> result = writer.create(docRef, Collections.singletonMap("foo", (Object) "bar"));
    writer.close().get();
    
    try {
      result.get();
      fail("Create operation should have thrown exception");
    } catch (Exception e) {
      assertTrue(e.getMessage().contains("Document already exists"));
    }
  }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@Test
public void bulkWriterUpdate() throws Exception {
DocumentReference docRef = randomColl.document();
docRef.set(Collections.singletonMap("foo", "bar0")).get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/bar0/oldValue
s/bar/newValue

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

docRef.set(Collections.singletonMap("foo", "bar0")).get();
BulkWriter writer = firestore.bulkWriter();
ApiFuture<WriteResult> result =
writer.update(docRef, Collections.singletonMap("foo", (Object) "bar"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use varargs here? Removes the ugly cast.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@thebrianchen thebrianchen merged commit ce2a528 into bc/bulk-master Jun 12, 2020
@thebrianchen thebrianchen deleted the bc/bulk-system branch June 12, 2020 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants