@@ -226,34 +226,28 @@ public static void stopServer() throws InterruptedException {
226226 @ Before
227227 public void setUp () throws InterruptedException {
228228 mockSpanner .reset ();
229- if (spanner == null
230- || spanner .getOptions ().getSessionPoolOptions ().isFailIfSessionNotFound ()
231- != failOnInvalidatedSession ) {
232- System .out .println ("Recreating spanner instance" );
233- if (spanner != null ) {
234- System .out .printf (
235- "Closing the spanner instance %s %s" ,
236- spanner .getOptions ().getSessionPoolOptions ().isFailIfSessionNotFound (),
237- failOnInvalidatedSession );
238- spanner .close ();
239- }
240- SessionPoolOptions .Builder builder = SessionPoolOptions .newBuilder ().setFailOnSessionLeak ();
241- if (failOnInvalidatedSession ) {
242- builder .setFailIfSessionNotFound ();
243- }
244- // This prevents repeated retries for a large number of sessions in the pool.
245- builder .setMinSessions (1 );
246- SessionPoolOptions sessionPoolOptions = builder .build ();
247- spanner =
248- SpannerOptions .newBuilder ()
249- .setProjectId ("[PROJECT]" )
250- .setChannelProvider (channelProvider )
251- .setSessionPoolOption (sessionPoolOptions )
252- .setCredentials (NoCredentials .getInstance ())
253- .build ()
254- .getService ();
255- client = spanner .getDatabaseClient (DatabaseId .of ("[PROJECT]" , "[INSTANCE]" , "[DATABASE]" ));
229+ System .out .println ("Recreating spanner instance" );
230+ if (spanner != null ) {
231+ System .out .printf ("Closing the spanner instance %s %s" ,
232+ spanner .getOptions ().getSessionPoolOptions ().isFailIfSessionNotFound (), failOnInvalidatedSession );
233+ spanner .close ();
234+ }
235+ SessionPoolOptions .Builder builder = SessionPoolOptions .newBuilder ().setFailOnSessionLeak ();
236+ if (failOnInvalidatedSession ) {
237+ builder .setFailIfSessionNotFound ();
256238 }
239+ // This prevents repeated retries for a large number of sessions in the pool.
240+ builder .setMinSessions (1 );
241+ SessionPoolOptions sessionPoolOptions = builder .build ();
242+ spanner =
243+ SpannerOptions .newBuilder ()
244+ .setProjectId ("[PROJECT]" )
245+ .setChannelProvider (channelProvider )
246+ .setSessionPoolOption (sessionPoolOptions )
247+ .setCredentials (NoCredentials .getInstance ())
248+ .build ()
249+ .getService ();
250+ client = spanner .getDatabaseClient (DatabaseId .of ("[PROJECT]" , "[INSTANCE]" , "[DATABASE]" ));
257251 invalidateSessionPool (client , spanner .getOptions ().getSessionPoolOptions ().getMinSessions ());
258252 }
259253
0 commit comments