1616
1717package com .google .cloud .spanner .it ;
1818
19- import static org .hamcrest .CoreMatchers .equalTo ;
20- import static org .hamcrest .CoreMatchers .is ;
21- import static org .hamcrest .MatcherAssert .assertThat ;
19+ import static com .google .common .truth .Truth .assertThat ;
2220
2321import com .google .cloud .spanner .Database ;
2422import com .google .cloud .spanner .DatabaseAdminClient ;
3836import org .junit .After ;
3937import org .junit .Before ;
4038import org .junit .ClassRule ;
41- import org .junit .Rule ;
4239import org .junit .Test ;
4340import org .junit .experimental .categories .Category ;
44- import org .junit .rules .ExpectedException ;
4541import org .junit .runner .RunWith ;
4642import org .junit .runners .JUnit4 ;
4743
4844@ Category (ParallelIntegrationTest .class )
4945@ RunWith (JUnit4 .class )
5046public class ITSpannerOptionsTest {
5147 @ ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv ();
52- @ Rule public ExpectedException expectedException = ExpectedException .none ();
5348 private static Database db ;
5449
5550 @ Before
@@ -73,7 +68,7 @@ public void testCloseAllThreadsWhenClosingSpanner() throws InterruptedException
7368 // The IT environment has already started some worker threads.
7469 int baseThreadCount = getNumberOfThreadsWithName (SPANNER_THREAD_NAME );
7570 for (int i = 0 ; i < NUMBER_OF_TEST_RUNS ; i ++) {
76- assertThat (getNumberOfThreadsWithName (SPANNER_THREAD_NAME ), is ( equalTo ( baseThreadCount )) );
71+ assertThat (getNumberOfThreadsWithName (SPANNER_THREAD_NAME )). isAtMost ( baseThreadCount );
7772 // Create Spanner instance.
7873 // We make a copy of the options instance, as SpannerOptions caches any service object
7974 // that has been handed out.
@@ -106,29 +101,26 @@ public void testCloseAllThreadsWhenClosingSpanner() throws InterruptedException
106101 }
107102 // Check the number of threads after the query. Doing a request should initialize a thread
108103 // pool for the underlying SpannerClient.
109- assertThat (
110- getNumberOfThreadsWithName (SPANNER_THREAD_NAME ),
111- is (equalTo (DEFAULT_NUM_CHANNELS * NUM_THREADS_PER_CHANNEL + baseThreadCount )));
104+ assertThat (getNumberOfThreadsWithName (SPANNER_THREAD_NAME ))
105+ .isEqualTo (DEFAULT_NUM_CHANNELS * NUM_THREADS_PER_CHANNEL + baseThreadCount );
112106
113107 // Then do a request to the InstanceAdmin service and check the number of threads.
114108 // Doing a request should initialize a thread pool for the underlying InstanceAdminClient.
115109 for (int i2 = 0 ; i2 < DEFAULT_NUM_CHANNELS * 2 ; i2 ++) {
116110 InstanceAdminClient instanceAdminClient = spanner .getInstanceAdminClient ();
117111 instanceAdminClient .listInstances ();
118112 }
119- assertThat (
120- getNumberOfThreadsWithName (SPANNER_THREAD_NAME ),
121- is (equalTo (2 * DEFAULT_NUM_CHANNELS * NUM_THREADS_PER_CHANNEL + baseThreadCount )));
113+ assertThat (getNumberOfThreadsWithName (SPANNER_THREAD_NAME ))
114+ .isEqualTo (2 * DEFAULT_NUM_CHANNELS * NUM_THREADS_PER_CHANNEL + baseThreadCount );
122115
123116 // Then do a request to the DatabaseAdmin service and check the number of threads.
124117 // Doing a request should initialize a thread pool for the underlying DatabaseAdminClient.
125118 for (int i2 = 0 ; i2 < DEFAULT_NUM_CHANNELS * 2 ; i2 ++) {
126119 DatabaseAdminClient databaseAdminClient = spanner .getDatabaseAdminClient ();
127120 databaseAdminClient .listDatabases (db .getId ().getInstanceId ().getInstance ());
128121 }
129- assertThat (
130- getNumberOfThreadsWithName (SPANNER_THREAD_NAME ),
131- is (equalTo (3 * DEFAULT_NUM_CHANNELS * NUM_THREADS_PER_CHANNEL + baseThreadCount )));
122+ assertThat (getNumberOfThreadsWithName (SPANNER_THREAD_NAME ))
123+ .isEqualTo (3 * DEFAULT_NUM_CHANNELS * NUM_THREADS_PER_CHANNEL + baseThreadCount );
132124
133125 // Now close the Spanner instance and check whether the threads are shutdown or not.
134126 spanner .close ();
@@ -138,7 +130,7 @@ public void testCloseAllThreadsWhenClosingSpanner() throws InterruptedException
138130 && watch .elapsed (TimeUnit .SECONDS ) < 2 ) {
139131 Thread .sleep (50L );
140132 }
141- assertThat (getNumberOfThreadsWithName (SPANNER_THREAD_NAME ), is ( equalTo ( baseThreadCount )) );
133+ assertThat (getNumberOfThreadsWithName (SPANNER_THREAD_NAME )). isAtMost ( baseThreadCount );
142134 }
143135 }
144136
@@ -150,10 +142,10 @@ public void testMultipleSpannersFromSameSpannerOptions() throws InterruptedExcep
150142 // Having both in the try-with-resources block is not possible, as it is the same instance.
151143 // One will be closed before the other, and the closing of the second instance would fail.
152144 Spanner spanner2 = options .getService ();
153- assertThat (spanner1 == spanner2 , is ( true ) );
145+ assertThat (spanner1 ). isSameInstanceAs ( spanner2 );
154146 DatabaseClient client1 = spanner1 .getDatabaseClient (db .getId ());
155147 DatabaseClient client2 = spanner2 .getDatabaseClient (db .getId ());
156- assertThat (client1 == client2 , is ( true ) );
148+ assertThat (client1 ). isSameInstanceAs ( client2 );
157149 try (ResultSet rs1 =
158150 client1
159151 .singleUse ()
@@ -172,7 +164,7 @@ public void testMultipleSpannersFromSameSpannerOptions() throws InterruptedExcep
172164 && watch .elapsed (TimeUnit .SECONDS ) < 2 ) {
173165 Thread .sleep (50L );
174166 }
175- assertThat (getNumberOfThreadsWithName (SPANNER_THREAD_NAME ), is ( equalTo ( baseThreadCount )) );
167+ assertThat (getNumberOfThreadsWithName (SPANNER_THREAD_NAME )). isAtMost ( baseThreadCount );
176168 }
177169
178170 private int getNumberOfThreadsWithName (String serviceName ) {
0 commit comments