2424import static org .junit .Assume .assumeTrue ;
2525
2626import com .google .api .core .ApiFunction ;
27+ import com .google .api .gax .core .GaxProperties ;
2728import com .google .api .gax .rpc .ApiCallContext ;
2829import com .google .api .gax .rpc .HeaderProvider ;
2930import com .google .auth .oauth2 .AccessToken ;
@@ -153,6 +154,7 @@ public class GapicSpannerRpcTest {
153154 private InetSocketAddress address ;
154155 private final Map <SpannerRpc .Option , Object > optionsMap = new HashMap <>();
155156 private Metadata seenHeaders ;
157+ private String defaultUserAgent ;
156158
157159 @ BeforeClass
158160 public static void checkNotEmulator () {
@@ -163,6 +165,7 @@ public static void checkNotEmulator() {
163165
164166 @ Before
165167 public void startServer () throws IOException {
168+ defaultUserAgent = "spanner-java/" + GaxProperties .getLibraryVersion (GapicSpannerRpc .class );
166169 mockSpanner = new MockSpannerServiceImpl ();
167170 mockSpanner .setAbortProbability (0.0D ); // We don't want any unpredictable aborted transactions.
168171 mockSpanner .putStatementResult (StatementResult .query (SELECT1AND2 , SELECT1_RESULTSET ));
@@ -505,6 +508,21 @@ public void testAdminRequestsLimitExceededRetryAlgorithm() {
505508 assertThat (alg .shouldRetry (new Exception ("random exception" ), null )).isFalse ();
506509 }
507510
511+ @ Test
512+ public void testDefaultUserAgent () {
513+ final SpannerOptions options = createSpannerOptions ();
514+ final Spanner spanner = options .getService ();
515+ final DatabaseClient databaseClient =
516+ spanner .getDatabaseClient (DatabaseId .of ("[PROJECT]" , "[INSTANCE]" , "[DATABASE]" ));
517+
518+ try (final ResultSet rs = databaseClient .singleUse ().executeQuery (SELECT1AND2 )) {
519+ rs .next ();
520+ }
521+
522+ assertThat (seenHeaders .get (Key .of ("user-agent" , Metadata .ASCII_STRING_MARSHALLER )))
523+ .contains (defaultUserAgent );
524+ }
525+
508526 @ Test
509527 public void testCustomUserAgent () {
510528 final HeaderProvider userAgentHeaderProvider =
@@ -521,12 +539,13 @@ public Map<String, String> getHeaders() {
521539 final Spanner spanner = options .getService ();
522540 final DatabaseClient databaseClient =
523541 spanner .getDatabaseClient (DatabaseId .of ("[PROJECT]" , "[INSTANCE]" , "[DATABASE]" ));
542+
524543 try (final ResultSet rs = databaseClient .singleUse ().executeQuery (SELECT1AND2 )) {
525544 rs .next ();
526545 }
527546
528547 assertThat (seenHeaders .get (Key .of ("user-agent" , Metadata .ASCII_STRING_MARSHALLER )))
529- .contains ("test-agent" );
548+ .contains ("test-agent " + defaultUserAgent );
530549 }
531550
532551 @ SuppressWarnings ("rawtypes" )
0 commit comments