|
19 | 19 | package org.apache.accumulo.test.fate.zookeeper;
|
20 | 20 |
|
21 | 21 | import static java.nio.charset.StandardCharsets.UTF_8;
|
| 22 | +import static java.util.concurrent.TimeUnit.SECONDS; |
22 | 23 | import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.FAILED;
|
23 | 24 | import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.FAILED_IN_PROGRESS;
|
24 | 25 | import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.IN_PROGRESS;
|
25 | 26 | import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.NEW;
|
26 | 27 | import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.SUBMITTED;
|
27 |
| -import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.SUCCESSFUL; |
28 | 28 | import static org.apache.accumulo.harness.AccumuloITBase.ZOOKEEPER_TESTING_SERVER;
|
29 | 29 | import static org.easymock.EasyMock.createMock;
|
30 | 30 | import static org.easymock.EasyMock.expect;
|
|
40 | 40 | import java.util.List;
|
41 | 41 | import java.util.UUID;
|
42 | 42 | import java.util.concurrent.CountDownLatch;
|
| 43 | +import java.util.concurrent.atomic.AtomicBoolean; |
43 | 44 |
|
44 | 45 | import org.apache.accumulo.core.Constants;
|
45 | 46 | import org.apache.accumulo.core.clientImpl.thrift.TableOperation;
|
@@ -242,27 +243,39 @@ public void testTransactionStatus() throws Exception {
|
242 | 243 | assertEquals(IN_PROGRESS, getTxStatus(zk, txid));
|
243 | 244 | // tell the op to exit the method
|
244 | 245 | finishCall.countDown();
|
245 |
| - // Check that it transitions to SUCCESSFUL |
246 |
| - TStatus s = getTxStatus(zk, txid); |
247 |
| - while (s != SUCCESSFUL) { |
248 |
| - s = getTxStatus(zk, txid); |
249 |
| - Thread.sleep(10); |
250 |
| - } |
251 |
| - // Check that it gets removed |
252 |
| - boolean errorSeen = false; |
253 |
| - while (!errorSeen) { |
| 246 | + // Check that it transitions to SUCCESSFUL and gets removed |
| 247 | + final var sawSuccess = new AtomicBoolean(false); |
| 248 | + Wait.waitFor(() -> { |
| 249 | + TStatus s; |
254 | 250 | try {
|
255 |
| - s = getTxStatus(zk, txid); |
256 |
| - Thread.sleep(10); |
| 251 | + switch (s = getTxStatus(zk, txid)) { |
| 252 | + case IN_PROGRESS: |
| 253 | + if (sawSuccess.get()) { |
| 254 | + fail("Should never see IN_PROGRESS after seeing SUCCESSFUL"); |
| 255 | + } |
| 256 | + break; |
| 257 | + case SUCCESSFUL: |
| 258 | + // expected, but might be too quick to be detected |
| 259 | + if (sawSuccess.compareAndSet(false, true)) { |
| 260 | + LOG.debug("Saw expected transaction status change to SUCCESSFUL"); |
| 261 | + } |
| 262 | + break; |
| 263 | + default: |
| 264 | + fail("Saw unexpected status: " + s); |
| 265 | + } |
257 | 266 | } catch (KeeperException e) {
|
258 | 267 | if (e.code() == KeeperException.Code.NONODE) {
|
259 |
| - errorSeen = true; |
| 268 | + if (!sawSuccess.get()) { |
| 269 | + LOG.debug("Never saw transaction status change to SUCCESSFUL, but that's okay"); |
| 270 | + } |
| 271 | + return true; |
260 | 272 | } else {
|
261 | 273 | fail("Unexpected error thrown: " + e.getMessage());
|
262 | 274 | }
|
263 | 275 | }
|
264 |
| - } |
265 |
| - |
| 276 | + // keep waiting for NoNode |
| 277 | + return false; |
| 278 | + }, SECONDS.toMillis(30), 10); |
266 | 279 | } finally {
|
267 | 280 | fate.shutdown();
|
268 | 281 | }
|
|
0 commit comments