GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — spanner: expand test coverage for getDatabaseClient() (#3686) · feisuo/google-cloud-java@a175980

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • google-cloud-clients/google-cloud-spanner
    • pom.xml
    • src/test/java/com/google/cloud/spanner
      • SpannerImplTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎google-cloud-clients/google-cloud-spanner/pom.xml‎

Copy file name to clipboardExpand all lines: google-cloud-clients/google-cloud-spanner/pom.xml
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,29 @@
1818
</parent>
1919
<properties>
2020
<site.installationModule>google-cloud-spanner</site.installationModule>
21+
<jacoco.skip>true</jacoco.skip>
2122
</properties>
2223
<build>
2324
<plugins>
25+
<plugin>
26+
<groupId>org.jacoco</groupId>
27+
<artifactId>jacoco-maven-plugin</artifactId>
28+
<version>0.8.2</version>
29+
<executions>
30+
<execution>
31+
<goals>
32+
<goal>prepare-agent</goal>
33+
</goals>
34+
</execution>
35+
<execution>
36+
<id>report</id>
37+
<phase>prepare-package</phase>
38+
<goals>
39+
<goal>report</goal>
40+
</goals>
41+
</execution>
42+
</executions>
43+
</plugin>
2444
<plugin>
2545
<groupId>org.apache.maven.plugins</groupId>
2646
<artifactId>maven-surefire-plugin</artifactId>
Collapse file

‎google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerImplTest.java‎

Copy file name to clipboardExpand all lines: google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpannerImplTest.java
+47-1Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
package com.google.cloud.spanner;
1818

1919
import static com.google.common.truth.Truth.assertThat;
20+
import static org.junit.Assert.fail;
2021

22+
import com.google.cloud.grpc.GrpcTransportOptions;
2123
import com.google.cloud.spanner.spi.v1.SpannerRpc;
22-
2324
import java.util.HashMap;
2425
import java.util.Map;
2526
import org.junit.Before;
@@ -70,4 +71,49 @@ public void createAndCloseSession() {
7071
// The same channelHint is passed for deleteSession (contained in "options").
7172
Mockito.verify(rpc).deleteSession(sessionName, options.getValue());
7273
}
74+
75+
@Test
76+
public void getDbclientAgainGivesSame() {
77+
Map<String, String> labels = new HashMap<>();
78+
labels.put("env", "dev");
79+
Mockito.when(spannerOptions.getSessionLabels()).thenReturn(labels);
80+
String dbName = "projects/p1/instances/i1/databases/d1";
81+
DatabaseId db = DatabaseId.of(dbName);
82+
83+
Mockito.when(spannerOptions.getTransportOptions())
84+
.thenReturn(GrpcTransportOptions.newBuilder().build());
85+
Mockito.when(spannerOptions.getSessionPoolOptions())
86+
.thenReturn(SessionPoolOptions.newBuilder().build());
87+
88+
DatabaseClient databaseClient = impl.getDatabaseClient(db);
89+
90+
// Get db client again
91+
DatabaseClient databaseClient1 = impl.getDatabaseClient(db);
92+
93+
assertThat(databaseClient1).isSameAs(databaseClient);
94+
}
95+
96+
@Test
97+
public void getDbclientAfterCloseThrows() {
98+
SpannerImpl imp = new SpannerImpl(rpc, 1, spannerOptions);
99+
Map<String, String> labels = new HashMap<>();
100+
labels.put("env", "dev");
101+
Mockito.when(spannerOptions.getSessionLabels()).thenReturn(labels);
102+
String dbName = "projects/p1/instances/i1/databases/d1";
103+
DatabaseId db = DatabaseId.of(dbName);
104+
105+
Mockito.when(spannerOptions.getTransportOptions())
106+
.thenReturn(GrpcTransportOptions.newBuilder().build());
107+
Mockito.when(spannerOptions.getSessionPoolOptions())
108+
.thenReturn(SessionPoolOptions.newBuilder().build());
109+
110+
imp.close();
111+
112+
try {
113+
imp.getDatabaseClient(db);
114+
fail("Expected exception");
115+
} catch (IllegalStateException e) {
116+
assertThat(e.getMessage()).contains("Cloud Spanner client has been closed");
117+
}
118+
}
73119
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.