Skip to content

Conversation

@zoercai
Copy link
Contributor

@zoercai zoercai commented Feb 14, 2022

Add sad path unit tests for the Cloud Spanner's ReadChangeStream, including testing for errors from the Spanner backend.

testImplementation library.java.powermock
testImplementation library.java.powermock_mockito
testImplementation library.java.joda_time
testImplementation "com.google.cloud:google-cloud-spanner:6.17.4:tests"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the version come from the BOM? (if you remove the version, does it work?)

Could you create a variable as the other libraries (e.g. library.java.spanner.tests)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't work if I remove the version, but I've moved this to BeamModulePlugin.groovy with the versions defined by variables

@github-actions github-actions bot added the build label Feb 15, 2022
Copy link
Contributor

@thiagotnunes thiagotnunes left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM with a few nits.

Do we need to add documentation (javadocs) for the new options?

def classgraph_version = "4.8.104"
def errorprone_version = "2.10.0"
// Try to keep gax_version consistent with gax-grpc version in google_cloud_platform_libraries_bom
def gax_version = "2.8.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that this one will work without the version as the BOM defines a version for it (https://mvnrepository.com/artifact/com.google.cloud/libraries-bom/24.2.0)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did try this without the version, but the URL becomes invalid if the version is not between the gax-grpc: and the :testlib on line 549. This is the error produced without the version:

image

Let me know if you know of another way!

Copy link
Contributor

Choose a reason for hiding this comment

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

That is ok, thanks for trying


Statement changeStreamQueryStatement =
Statement.newBuilder(
"SELECT * FROM READ_my-change-stream( start_timestamp => @startTimestamp, end_timestamp => @endTimestamp, partition_token => @partitionToken, read_options => null, heartbeat_milliseconds => @heartbeatMillis)")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we could remove the extra spacing here (probably spotless added it when merging lines into one)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually how it looks in the actual request statement, I believe the test will fail if I take out the spaces — https://github.com/googleapis/java-spanner/blob/main/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockSpannerServiceImpl.java#L113

@thiagotnunes
Copy link
Contributor

You should change the title to match the JIRA ticket [BEAM-12164]: <title>

@zoercai zoercai changed the title test: Add sad path tests for Cloud Spanner's ReadChangeStream [BEAM-12164]: Add sad path tests for Cloud Spanner's ReadChangeStream Feb 15, 2022
@codecov
Copy link

codecov bot commented Feb 15, 2022

Codecov Report

Merging #16846 (0e12e60) into master (8bf68ad) will increase coverage by 8.99%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16846      +/-   ##
==========================================
+ Coverage   74.63%   83.63%   +8.99%     
==========================================
  Files         655      453     -202     
  Lines       82237    62471   -19766     
==========================================
- Hits        61380    52245    -9135     
+ Misses      19861    10226    -9635     
+ Partials      996        0     -996     
Impacted Files Coverage Δ
sdks/python/apache_beam/io/jdbc.py 78.26% <0.00%> (-6.74%) ⬇️
...s/python/apache_beam/runners/portability/stager.py 85.54% <0.00%> (-2.82%) ⬇️
...apache_beam/runners/portability/portable_runner.py 75.87% <0.00%> (-0.27%) ⬇️
setup.py 0.00% <0.00%> (ø)
sdks/python/apache_beam/transforms/core.py 92.64% <0.00%> (ø)
sdks/python/apache_beam/portability/common_urns.py 100.00% <0.00%> (ø)
...python/apache_beam/runners/direct/direct_runner.py 93.92% <0.00%> (ø)
...hon/apache_beam/runners/worker/bundle_processor.py 93.39% <0.00%> (ø)
...on/apache_beam/examples/dataframe/flight_delays.py 27.90% <0.00%> (ø)
...apache_beam/portability/api/beam_runner_api_pb2.py 100.00% <0.00%> (ø)
... and 220 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 8bf68ad...0e12e60. Read the comment docs.

@zoercai
Copy link
Contributor Author

zoercai commented Feb 17, 2022

Hey @pabloem could you please review this PR?

@zoercai
Copy link
Contributor Author

zoercai commented Feb 17, 2022

@thiagotnunes I've made a PR (#16879) with the javadocs which I'll rebase once this PR is merged.

@pabloem
Copy link
Member

pabloem commented Feb 25, 2022

once again I'm sorry about the delay. Taking a look now!

builder.setEmulatorHost(emulatorHost.get());
if (spannerConfig.getIsLocalChannelProvider() != null
&& spannerConfig.getIsLocalChannelProvider().get()) {
builder.setChannelProvider(LocalChannelProvider.create(emulatorHost.get()));
Copy link
Member

Choose a reason for hiding this comment

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

is there any chance of passing the LocalChannelProvider from the test to avoid depending on gax_grpc_test in the main package? It's not mandatory, but it would make life easier for like 1% of users, who, may have version clashes with that at some point : )

Copy link
Member

@pabloem pabloem left a comment

Choose a reason for hiding this comment

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

LGTM! Merging this. Javadoc is missing as properly pointed out by others.

.withInclusiveEndAt(after3Seconds));
pipeline.run().waitUntilFinish();
} finally {
assertThat(
Copy link
Member

Choose a reason for hiding this comment

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

Today this value is always zero. It seems very sensitive to internal details. Can we change it so that the assertion is checking correct results?

testImplementation library.java.powermock
testImplementation library.java.powermock_mockito
testImplementation library.java.joda_time
testImplementation library.java.google_cloud_spanner_test
Copy link
Member

Choose a reason for hiding this comment

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

This is wrong. "test" dependencies indicate that they are test suites. They are not for use as "test-related libraries". On a technical level, their dependency resolution does not work that way and you just got lucky this worked.

"test" scope jars are just for when you want to actually run someone else's tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants