Skip to content

Commit

Permalink
Merge branch 'main' into generate-libraries-main
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul2393 authored Dec 18, 2024
2 parents 8be2ce5 + 5687750 commit cfa380b
Show file tree
Hide file tree
Showing 23 changed files with 253 additions and 80 deletions.
8 changes: 7 additions & 1 deletion .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,17 @@ slowtests)
verify
RETURN_CODE=$?
;;
samples)
samples|samples-slow-tests)
SAMPLES_DIR=samples
PROFILES=''
# only run ITs in snapshot/ on presubmit PRs. run ITs in all 3 samples/ subdirectories otherwise.
if [[ ! -z ${KOKORO_GITHUB_PULL_REQUEST_NUMBER} ]]
then
SAMPLES_DIR=samples/snapshot
elif [[ ${JOB_TYPE} = 'samples-slow-tests' ]]
then
SAMPLES_DIR=samples/snippets
PROFILES='-Pslow-tests,!integration-tests'
fi

if [[ -f ${SAMPLES_DIR}/pom.xml ]]
Expand All @@ -227,6 +232,7 @@ samples)
-DtrimStackTrace=false \
-Dclirr.skip=true \
-Denforcer.skip=true \
${PROFILES} \
-fae \
verify
RETURN_CODE=$?
Expand Down
39 changes: 39 additions & 0 deletions .kokoro/nightly/java11-samples-slow-tests.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Format: //devtools/kokoro/config/proto/build.proto

# Configure the docker image for kokoro-trampoline.
env_vars: {
key: "TRAMPOLINE_IMAGE"
value: "gcr.io/cloud-devrel-kokoro-resources/java11"
}

env_vars: {
key: "JOB_TYPE"
value: "samples-slow-tests"
}

# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_APPLICATION_CREDENTIALS"
value: "secret_manager/java-it-service-account"
}

env_vars: {
key: "SECRET_MANAGER_KEYS"
value: "java-it-service-account"
}

env_vars: {
key: "ENABLE_BUILD_COP"
value: "true"
}

4 changes: 2 additions & 2 deletions benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.83.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>

<properties>
Expand All @@ -34,7 +34,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<junixsocket.version>2.10.1</junixsocket.version>
<opentelemetry.version>1.44.1</opentelemetry.version>
<opentelemetry.version>1.45.0</opentelemetry.version>
</properties>

<dependencies>
Expand Down
18 changes: 9 additions & 9 deletions google-cloud-spanner-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-bom</artifactId>
<version>6.83.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<packaging>pom</packaging>
<parent>
<groupId>com.google.cloud</groupId>
Expand Down Expand Up @@ -53,43 +53,43 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.83.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<type>test-jar</type>
<version>6.83.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-v1</artifactId>
<version>6.83.0</version><!-- {x-version-update:grpc-google-cloud-spanner-v1:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-admin-instance-v1</artifactId>
<version>6.83.0</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-instance-v1:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-instance-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-admin-database-v1</artifactId>
<version>6.83.0</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-database-v1:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-database-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-admin-instance-v1</artifactId>
<version>6.83.0</version><!-- {x-version-update:proto-google-cloud-spanner-admin-instance-v1:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-admin-instance-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-v1</artifactId>
<version>6.83.0</version><!-- {x-version-update:proto-google-cloud-spanner-v1:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-admin-database-v1</artifactId>
<version>6.83.0</version><!-- {x-version-update:proto-google-cloud-spanner-admin-database-v1:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-admin-database-v1:current} -->
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
4 changes: 2 additions & 2 deletions google-cloud-spanner-executor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-executor</artifactId>
<version>6.83.0</version><!-- {x-version-update:google-cloud-spanner-executor:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner-executor:current} -->
<packaging>jar</packaging>
<name>Google Cloud Spanner Executor</name>

<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.83.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions google-cloud-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.83.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<packaging>jar</packaging>
<name>Google Cloud Spanner</name>
<url>https://github.com/googleapis/java-spanner</url>
<description>Java idiomatic client for Google Cloud Spanner.</description>
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.83.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>
<properties>
<site.installationModule>google-cloud-spanner</site.installationModule>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,16 @@ private Builder() {}
public static final String SPANNER_URI_FORMAT =
"(?:cloudspanner:)(?<HOSTGROUP>//[\\w.-]+(?:\\.[\\w\\.-]+)*[\\w\\-\\._~:/?#\\[\\]@!\\$&'\\(\\)\\*\\+,;=.]+)?/projects/(?<PROJECTGROUP>(([a-z]|[-.:]|[0-9])+|(DEFAULT_PROJECT_ID)))(/instances/(?<INSTANCEGROUP>([a-z]|[-]|[0-9])+)(/databases/(?<DATABASEGROUP>([a-z]|[-]|[_]|[0-9])+))?)?(?:[?|;].*)?";

public static final String EXTERNAL_HOST_FORMAT =
"(?:cloudspanner:)(?<HOSTGROUP>//[\\w.-]+(?::\\d+)?)(/instances/(?<INSTANCEGROUP>[a-z0-9-]+))?(/databases/(?<DATABASEGROUP>[a-z0-9_-]+))(?:[?;].*)?";
private static final String SPANNER_URI_REGEX = "(?is)^" + SPANNER_URI_FORMAT + "$";

@VisibleForTesting
static final Pattern SPANNER_URI_PATTERN = Pattern.compile(SPANNER_URI_REGEX);

@VisibleForTesting
static final Pattern EXTERNAL_HOST_PATTERN = Pattern.compile(EXTERNAL_HOST_FORMAT);

private static final String HOST_GROUP = "HOSTGROUP";
private static final String PROJECT_GROUP = "PROJECTGROUP";
private static final String INSTANCE_GROUP = "INSTANCEGROUP";
Expand All @@ -643,6 +648,10 @@ private boolean isValidUri(String uri) {
return SPANNER_URI_PATTERN.matcher(uri).matches();
}

private boolean isValidExternalHostUri(String uri) {
return EXTERNAL_HOST_PATTERN.matcher(uri).matches();
}

/**
* Sets the URI of the Cloud Spanner database to connect to. A connection URI must be specified
* in this format:
Expand Down Expand Up @@ -700,9 +709,11 @@ private boolean isValidUri(String uri) {
* @return this builder
*/
public Builder setUri(String uri) {
Preconditions.checkArgument(
isValidUri(uri),
"The specified URI is not a valid Cloud Spanner connection URI. Please specify a URI in the format \"cloudspanner:[//host[:port]]/projects/project-id[/instances/instance-id[/databases/database-name]][\\?property-name=property-value[;property-name=property-value]*]?\"");
if (!isValidExternalHostUri(uri)) {
Preconditions.checkArgument(
isValidUri(uri),
"The specified URI is not a valid Cloud Spanner connection URI. Please specify a URI in the format \"cloudspanner:[//host[:port]]/projects/project-id[/instances/instance-id[/databases/database-name]][\\?property-name=property-value[;property-name=property-value]*]?\"");
}
ConnectionPropertyValue<Boolean> value =
cast(ConnectionProperties.parseValues(uri).get(LENIENT.getKey()));
checkValidProperties(value != null && value.getValue(), uri);
Expand Down Expand Up @@ -829,7 +840,14 @@ public static Builder newBuilder() {
private final SpannerOptionsConfigurator configurator;

private ConnectionOptions(Builder builder) {
Matcher matcher = Builder.SPANNER_URI_PATTERN.matcher(builder.uri);
Matcher matcher;
boolean isExternalHost = false;
if (builder.isValidExternalHostUri(builder.uri)) {
matcher = Builder.EXTERNAL_HOST_PATTERN.matcher(builder.uri);
isExternalHost = true;
} else {
matcher = Builder.SPANNER_URI_PATTERN.matcher(builder.uri);
}
Preconditions.checkArgument(
matcher.find(), String.format("Invalid connection URI specified: %s", builder.uri));

Expand Down Expand Up @@ -947,12 +965,18 @@ && getInitialConnectionPropertyValue(OAUTH_TOKEN) == null
this.sessionPoolOptions = SessionPoolOptions.newBuilder().setAutoDetectDialect(true).build();
}

String projectId = matcher.group(Builder.PROJECT_GROUP);
String projectId = "default";
String instanceId = matcher.group(Builder.INSTANCE_GROUP);
if (!isExternalHost) {
projectId = matcher.group(Builder.PROJECT_GROUP);
} else if (instanceId == null) {
instanceId = "default";
}
if (Builder.DEFAULT_PROJECT_ID_PLACEHOLDER.equalsIgnoreCase(projectId)) {
projectId = getDefaultProjectId(this.credentials);
}
this.projectId = projectId;
this.instanceId = matcher.group(Builder.INSTANCE_GROUP);
this.instanceId = instanceId;
this.databaseName = matcher.group(Builder.DATABASE_GROUP);
}

Expand Down Expand Up @@ -981,6 +1005,10 @@ static String determineHost(
// The leading '//' is already included in the regex for the connection URL, so we don't need
// to add the leading '//' to the host name here.
host = matcher.group(Builder.HOST_GROUP);
if (Builder.EXTERNAL_HOST_FORMAT.equals(matcher.pattern().pattern())
&& !host.matches(".*:\\d+$")) {
host = String.format("%s:15000", host);
}
}
if (usePlainText) {
return PLAIN_TEXT_PROTOCOL + host;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static void stopServer() throws InterruptedException {
public void setUp() throws InterruptedException {
mockSpanner.reset();
if (spanner == null
|| spanner.getOptions().getSessionPoolOptions().isFailIfPoolExhausted()
|| spanner.getOptions().getSessionPoolOptions().isFailIfSessionNotFound()
!= failOnInvalidatedSession) {
if (spanner != null) {
spanner.close();
Expand All @@ -228,8 +228,8 @@ public void setUp() throws InterruptedException {
.build()
.getService();
client = spanner.getDatabaseClient(DatabaseId.of("[PROJECT]", "[INSTANCE]", "[DATABASE]"));
invalidateSessionPool(client, spanner.getOptions().getSessionPoolOptions().getMinSessions());
}
invalidateSessionPool(client, spanner.getOptions().getSessionPoolOptions().getMinSessions());
}

private static void invalidateSessionPool(DatabaseClient client, int minSessions)
Expand Down Expand Up @@ -1002,6 +1002,7 @@ public void transactionManagerBatchUpdate() throws InterruptedException {
} catch (AbortedException e) {
transaction = assertThrowsSessionNotFoundIfShouldFail(() -> manager.resetForRetry());
if (transaction == null) {
manager.close();
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.spanner.connection;

import static com.google.cloud.spanner.connection.ConnectionOptions.Builder.EXTERNAL_HOST_PATTERN;
import static com.google.cloud.spanner.connection.ConnectionOptions.Builder.SPANNER_URI_PATTERN;
import static com.google.cloud.spanner.connection.ConnectionOptions.DEFAULT_ENDPOINT;
import static com.google.cloud.spanner.connection.ConnectionOptions.determineHost;
Expand Down Expand Up @@ -1211,4 +1212,40 @@ public void testEnableApiTracing() {
.build()
.isEnableApiTracing());
}

@Test
public void testExternalHostPatterns() {
Matcher matcherWithoutInstance =
EXTERNAL_HOST_PATTERN.matcher("cloudspanner://localhost:15000/databases/test-db");
assertTrue(matcherWithoutInstance.matches());
assertNull(matcherWithoutInstance.group("INSTANCEGROUP"));
assertEquals("test-db", matcherWithoutInstance.group("DATABASEGROUP"));
Matcher matcherWithProperty =
EXTERNAL_HOST_PATTERN.matcher(
"cloudspanner://localhost:15000/instances/default/databases/singers-db?usePlainText=true");
assertTrue(matcherWithProperty.matches());
assertEquals("default", matcherWithProperty.group("INSTANCEGROUP"));
assertEquals("singers-db", matcherWithProperty.group("DATABASEGROUP"));
Matcher matcherWithoutPort =
EXTERNAL_HOST_PATTERN.matcher(
"cloudspanner://localhost/instances/default/databases/test-db");
assertTrue(matcherWithoutPort.matches());
assertEquals("default", matcherWithoutPort.group("INSTANCEGROUP"));
assertEquals("test-db", matcherWithoutPort.group("DATABASEGROUP"));
assertEquals(
"http://localhost:15000",
determineHost(
matcherWithoutPort,
DEFAULT_ENDPOINT,
/* autoConfigEmulator= */ true,
/* usePlainText= */ true,
ImmutableMap.of()));
Matcher matcherWithProject =
EXTERNAL_HOST_PATTERN.matcher(
"cloudspanner://localhost:15000/projects/default/instances/default/databases/singers-db");
assertFalse(matcherWithProject.matches());
Matcher matcherWithoutHost =
EXTERNAL_HOST_PATTERN.matcher("cloudspanner:/instances/default/databases/singers-db");
assertFalse(matcherWithoutHost.matches());
}
}
4 changes: 2 additions & 2 deletions grpc-google-cloud-spanner-admin-database-v1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-admin-database-v1</artifactId>
<version>6.83.0</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-database-v1:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-database-v1:current} -->
<name>grpc-google-cloud-spanner-admin-database-v1</name>
<description>GRPC library for grpc-google-cloud-spanner-admin-database-v1</description>
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.83.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>
<dependencies>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions grpc-google-cloud-spanner-admin-instance-v1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-admin-instance-v1</artifactId>
<version>6.83.0</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-instance-v1:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-instance-v1:current} -->
<name>grpc-google-cloud-spanner-admin-instance-v1</name>
<description>GRPC library for grpc-google-cloud-spanner-admin-instance-v1</description>
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.83.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>
<dependencies>
<dependency>
Expand Down
4 changes: 2 additions & 2 deletions grpc-google-cloud-spanner-executor-v1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-executor-v1</artifactId>
<version>6.83.0</version><!-- {x-version-update:grpc-google-cloud-spanner-executor-v1:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-executor-v1:current} -->
<name>grpc-google-cloud-spanner-executor-v1</name>
<description>GRPC library for google-cloud-spanner</description>
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.83.0</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.83.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>
<dependencies>
<dependency>
Expand Down
Loading

0 comments on commit cfa380b

Please sign in to comment.