@@ -226,34 +226,30 @@ 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 (
232+ "Closing the spanner instance %s %s" ,
233+ spanner .getOptions ().getSessionPoolOptions ().isFailIfSessionNotFound (),
234+ failOnInvalidatedSession );
235+ spanner .close ();
236+ }
237+ SessionPoolOptions .Builder builder = SessionPoolOptions .newBuilder ().setFailOnSessionLeak ();
238+ if (failOnInvalidatedSession ) {
239+ builder .setFailIfSessionNotFound ();
256240 }
241+ // This prevents repeated retries for a large number of sessions in the pool.
242+ builder .setMinSessions (1 );
243+ SessionPoolOptions sessionPoolOptions = builder .build ();
244+ spanner =
245+ SpannerOptions .newBuilder ()
246+ .setProjectId ("[PROJECT]" )
247+ .setChannelProvider (channelProvider )
248+ .setSessionPoolOption (sessionPoolOptions )
249+ .setCredentials (NoCredentials .getInstance ())
250+ .build ()
251+ .getService ();
252+ client = spanner .getDatabaseClient (DatabaseId .of ("[PROJECT]" , "[INSTANCE]" , "[DATABASE]" ));
257253 invalidateSessionPool (client , spanner .getOptions ().getSessionPoolOptions ().getMinSessions ());
258254 }
259255
0 commit comments