|
16 | 16 |
|
17 | 17 | package com.google.cloud.spanner.it;
|
18 | 18 |
|
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; |
22 | 20 |
|
23 | 21 | import com.google.cloud.spanner.Database;
|
24 | 22 | import com.google.cloud.spanner.DatabaseAdminClient;
|
|
38 | 36 | import org.junit.After;
|
39 | 37 | import org.junit.Before;
|
40 | 38 | import org.junit.ClassRule;
|
41 |
| -import org.junit.Rule; |
42 | 39 | import org.junit.Test;
|
43 | 40 | import org.junit.experimental.categories.Category;
|
44 |
| -import org.junit.rules.ExpectedException; |
45 | 41 | import org.junit.runner.RunWith;
|
46 | 42 | import org.junit.runners.JUnit4;
|
47 | 43 |
|
48 | 44 | @Category(ParallelIntegrationTest.class)
|
49 | 45 | @RunWith(JUnit4.class)
|
50 | 46 | public class ITSpannerOptionsTest {
|
51 | 47 | @ClassRule public static IntegrationTestEnv env = new IntegrationTestEnv();
|
52 |
| -@Rule public ExpectedException expectedException = ExpectedException.none(); |
53 | 48 | private static Database db;
|
54 | 49 |
|
55 | 50 | @Before
|
@@ -73,7 +68,7 @@ public void testCloseAllThreadsWhenClosingSpanner() throws InterruptedException
|
73 | 68 | // The IT environment has already started some worker threads.
|
74 | 69 | int baseThreadCount = getNumberOfThreadsWithName(SPANNER_THREAD_NAME);
|
75 | 70 | 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); |
77 | 72 | // Create Spanner instance.
|
78 | 73 | // We make a copy of the options instance, as SpannerOptions caches any service object
|
79 | 74 | // that has been handed out.
|
@@ -106,29 +101,26 @@ public void testCloseAllThreadsWhenClosingSpanner() throws InterruptedException
|
106 | 101 | }
|
107 | 102 | // Check the number of threads after the query. Doing a request should initialize a thread
|
108 | 103 | // 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); |
112 | 106 |
|
113 | 107 | // Then do a request to the InstanceAdmin service and check the number of threads.
|
114 | 108 | // Doing a request should initialize a thread pool for the underlying InstanceAdminClient.
|
115 | 109 | for (int i2 = 0; i2 < DEFAULT_NUM_CHANNELS * 2; i2++) {
|
116 | 110 | InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient();
|
117 | 111 | instanceAdminClient.listInstances();
|
118 | 112 | }
|
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); |
122 | 115 |
|
123 | 116 | // Then do a request to the DatabaseAdmin service and check the number of threads.
|
124 | 117 | // Doing a request should initialize a thread pool for the underlying DatabaseAdminClient.
|
125 | 118 | for (int i2 = 0; i2 < DEFAULT_NUM_CHANNELS * 2; i2++) {
|
126 | 119 | DatabaseAdminClient databaseAdminClient = spanner.getDatabaseAdminClient();
|
127 | 120 | databaseAdminClient.listDatabases(db.getId().getInstanceId().getInstance());
|
128 | 121 | }
|
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); |
132 | 124 |
|
133 | 125 | // Now close the Spanner instance and check whether the threads are shutdown or not.
|
134 | 126 | spanner.close();
|
@@ -138,7 +130,7 @@ public void testCloseAllThreadsWhenClosingSpanner() throws InterruptedException
|
138 | 130 | && watch.elapsed(TimeUnit.SECONDS) < 2) {
|
139 | 131 | Thread.sleep(50L);
|
140 | 132 | }
|
141 |
| -assertThat(getNumberOfThreadsWithName(SPANNER_THREAD_NAME), is(equalTo(baseThreadCount))); |
| 133 | +assertThat(getNumberOfThreadsWithName(SPANNER_THREAD_NAME)).isAtMost(baseThreadCount); |
142 | 134 | }
|
143 | 135 | }
|
144 | 136 |
|
@@ -150,10 +142,10 @@ public void testMultipleSpannersFromSameSpannerOptions() throws InterruptedExcep
|
150 | 142 | // Having both in the try-with-resources block is not possible, as it is the same instance.
|
151 | 143 | // One will be closed before the other, and the closing of the second instance would fail.
|
152 | 144 | Spanner spanner2 = options.getService();
|
153 |
| -assertThat(spanner1 == spanner2, is(true)); |
| 145 | +assertThat(spanner1).isSameInstanceAs(spanner2); |
154 | 146 | DatabaseClient client1 = spanner1.getDatabaseClient(db.getId());
|
155 | 147 | DatabaseClient client2 = spanner2.getDatabaseClient(db.getId());
|
156 |
| -assertThat(client1 == client2, is(true)); |
| 148 | +assertThat(client1).isSameInstanceAs(client2); |
157 | 149 | try (ResultSet rs1 =
|
158 | 150 | client1
|
159 | 151 | .singleUse()
|
@@ -172,7 +164,7 @@ public void testMultipleSpannersFromSameSpannerOptions() throws InterruptedExcep
|
172 | 164 | && watch.elapsed(TimeUnit.SECONDS) < 2) {
|
173 | 165 | Thread.sleep(50L);
|
174 | 166 | }
|
175 |
| -assertThat(getNumberOfThreadsWithName(SPANNER_THREAD_NAME), is(equalTo(baseThreadCount))); |
| 167 | +assertThat(getNumberOfThreadsWithName(SPANNER_THREAD_NAME)).isAtMost(baseThreadCount); |
176 | 168 | }
|
177 | 169 |
|
178 | 170 | private int getNumberOfThreadsWithName(String serviceName) {
|
|
0 commit comments