ath-08 commented on code in PR #39241:
URL: https://github.com/apache/beam/pull/39241#discussion_r3547926508
##########
sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/spanner/SpannerAccessorTest.java:
##########
@@ -251,4 +252,54 @@ public void testBuildSpannerOptionsWithCustomHost() {
SpannerOptions options = SpannerAccessor.buildSpannerOptions(config1);
assertEquals(host, options.getHost());
}
+
+ @Test
+ public void testBuildSpannerOptionsWithDirectedReadOptions() {
+ DirectedReadOptions directedReadOptions =
+ DirectedReadOptions.newBuilder()
+ .setIncludeReplicas(
+ DirectedReadOptions.IncludeReplicas.newBuilder()
+ .addReplicaSelections(
+ DirectedReadOptions.ReplicaSelection.newBuilder()
+ .setLocation("us-central1")
+
.setType(DirectedReadOptions.ReplicaSelection.Type.READ_ONLY)))
+ .build();
+ SpannerConfig config1 =
+ SpannerConfig.create()
+ .toBuilder()
+ .setServiceFactory(serviceFactory)
+
.setDirectedReadOptions(StaticValueProvider.of(directedReadOptions))
+ .setProjectId(StaticValueProvider.of("project"))
+ .setInstanceId(StaticValueProvider.of("test1"))
+ .setDatabaseId(StaticValueProvider.of("test1"))
+ .build();
+
+ SpannerOptions options = SpannerAccessor.buildSpannerOptions(config1);
+ assertEquals(directedReadOptions, options.getDirectedReadOptions());
+ }
+
+ @Test
+ public void testBuildSpannerOptionsWithDirectedReadOptionsJson() {
+ String jsonString =
+
"{\"includeReplicas\":{\"replicaSelections\":[{\"location\":\"us-east1\",\"type\":\"READ_WRITE\"}]}}";
Review Comment:
Thanks for the suggestion! I agree that Java Text Blocks ( """ ) would be
much cleaner here to avoid backslash escapes.
However, we can't use them in this module because Apache Beam's Java SDK
modules (including sdks/java/io/google-cloud-platform ) enforce Java 8 source
and target compatibility ( sourceCompatibility = 1.8 , targetCompatibility =
1.8 ) so that compiled pipeline jars remain
compatible with legacy Java 8 cluster environments (like older Flink,
Spark, or Dataflow workers).
Because Text Blocks were introduced in Java 15 (JEP 378), using """ here
causes a syntax error under Spotless / Java 8 compilation mode:
com.google.googlejavaformat.java.FormatterException: error: unclosed
string literal
Execution failed for task
':sdks:java:io:google-cloud-platform:spotlessJava'.
To maintain Java 8 compatibility, we need to keep standard escaped string
literals in these tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]