Skip to content
Merged
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
20 changes: 20 additions & 0 deletions google-cloud-clients/google-cloud-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,29 @@
</parent>
<properties>
<site.installationModule>google-cloud-spanner</site.installationModule>
<jacoco.skip>true</jacoco.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package com.google.cloud.spanner;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;

import com.google.cloud.grpc.GrpcTransportOptions;
import com.google.cloud.spanner.spi.v1.SpannerRpc;

import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
Expand Down Expand Up @@ -70,4 +71,49 @@ public void createAndCloseSession() {
// The same channelHint is passed for deleteSession (contained in "options").
Mockito.verify(rpc).deleteSession(sessionName, options.getValue());
}

@Test
public void getDbclientAgainGivesSame() {
Map<String, String> labels = new HashMap<>();
labels.put("env", "dev");
Mockito.when(spannerOptions.getSessionLabels()).thenReturn(labels);
String dbName = "projects/p1/instances/i1/databases/d1";
DatabaseId db = DatabaseId.of(dbName);

Mockito.when(spannerOptions.getTransportOptions())
.thenReturn(GrpcTransportOptions.newBuilder().build());
Mockito.when(spannerOptions.getSessionPoolOptions())
.thenReturn(SessionPoolOptions.newBuilder().build());

DatabaseClient databaseClient = impl.getDatabaseClient(db);

// Get db client again
DatabaseClient databaseClient1 = impl.getDatabaseClient(db);

assertThat(databaseClient1).isSameAs(databaseClient);
}

@Test
public void getDbclientAfterCloseThrows() {
SpannerImpl imp = new SpannerImpl(rpc, 1, spannerOptions);
Map<String, String> labels = new HashMap<>();
labels.put("env", "dev");
Mockito.when(spannerOptions.getSessionLabels()).thenReturn(labels);
String dbName = "projects/p1/instances/i1/databases/d1";
DatabaseId db = DatabaseId.of(dbName);

Mockito.when(spannerOptions.getTransportOptions())
.thenReturn(GrpcTransportOptions.newBuilder().build());
Mockito.when(spannerOptions.getSessionPoolOptions())
.thenReturn(SessionPoolOptions.newBuilder().build());

imp.close();

try {
imp.getDatabaseClient(db);
fail("Expected exception");
} catch (IllegalStateException e) {
assertThat(e.getMessage()).contains("Cloud Spanner client has been closed");
}
}
}