|
16 | 16 |
|
17 | 17 | package com.google.cloud.spanner;
|
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 | import static org.junit.Assert.fail;
|
23 | 21 |
|
24 | 22 | import com.google.common.base.Stopwatch;
|
@@ -125,7 +123,7 @@ public Integer call() throws Exception {
|
125 | 123 | return 1 + 1;
|
126 | 124 | }
|
127 | 125 | };
|
128 |
| -assertThat(SpannerRetryHelper.runTxWithRetriesOnAborted(callable), is(equalTo(2))); |
| 126 | +assertThat(SpannerRetryHelper.runTxWithRetriesOnAborted(callable)).isEqualTo(2); |
129 | 127 | }
|
130 | 128 |
|
131 | 129 | @Test(expected = IllegalStateException.class)
|
@@ -153,7 +151,7 @@ public Integer call() throws Exception {
|
153 | 151 | return 1 + 1;
|
154 | 152 | }
|
155 | 153 | };
|
156 |
| -assertThat(SpannerRetryHelper.runTxWithRetriesOnAborted(callable), is(equalTo(2))); |
| 154 | +assertThat(SpannerRetryHelper.runTxWithRetriesOnAborted(callable)).isEqualTo(2); |
157 | 155 | }
|
158 | 156 |
|
159 | 157 | @Test
|
@@ -169,7 +167,7 @@ public Integer call() throws Exception {
|
169 | 167 | return 1 + 1;
|
170 | 168 | }
|
171 | 169 | };
|
172 |
| -assertThat(SpannerRetryHelper.runTxWithRetriesOnAborted(callable), is(equalTo(2))); |
| 170 | +assertThat(SpannerRetryHelper.runTxWithRetriesOnAborted(callable)).isEqualTo(2); |
173 | 171 | }
|
174 | 172 |
|
175 | 173 | @Test(expected = IllegalStateException.class)
|
@@ -190,12 +188,13 @@ public Integer call() throws Exception {
|
190 | 188 |
|
191 | 189 | @Test
|
192 | 190 | public void testExceptionWithRetryInfo() {
|
| 191 | +final int RETRY_DELAY_NANOS = 100_000_000; |
193 | 192 | Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance());
|
194 | 193 | Status status = Status.fromCodeValue(Status.Code.ABORTED.value());
|
195 | 194 | Metadata trailers = new Metadata();
|
196 | 195 | RetryInfo retryInfo =
|
197 | 196 | RetryInfo.newBuilder()
|
198 |
| -.setRetryDelay(Duration.newBuilder().setNanos(100000000).build()) |
| 197 | +.setRetryDelay(Duration.newBuilder().setNanos(RETRY_DELAY_NANOS).build()) |
199 | 198 | .build();
|
200 | 199 | trailers.put(key, retryInfo);
|
201 | 200 | final SpannerException e =
|
@@ -214,9 +213,9 @@ public Integer call() throws Exception {
|
214 | 213 | // The following call should take at least 100ms, as that is the retry delay specified in the
|
215 | 214 | // retry info of the exception.
|
216 | 215 | Stopwatch watch = Stopwatch.createStarted();
|
217 |
| -assertThat(SpannerRetryHelper.runTxWithRetriesOnAborted(callable), is(equalTo(2))); |
218 |
| -long elapsed = watch.elapsed(TimeUnit.MILLISECONDS); |
219 |
| -assertThat(elapsed >= 100L, is(true)); |
| 216 | +assertThat(SpannerRetryHelper.runTxWithRetriesOnAborted(callable)).isEqualTo(2); |
| 217 | +long elapsed = watch.elapsed(TimeUnit.NANOSECONDS); |
| 218 | +assertThat(elapsed >= RETRY_DELAY_NANOS).isTrue(); |
220 | 219 | }
|
221 | 220 |
|
222 | 221 | private SpannerException abortedWithRetryInfo(int nanos) {
|
|
0 commit comments