Skip to content

Commit e0168bb

Browse files
committed
Merge branch '2.1' into 3.1
2 parents 3d19788 + 70e73bc commit e0168bb

File tree

1 file changed

+28
-15
lines changed
  • test/src/main/java/org/apache/accumulo/test/fate/zookeeper

1 file changed

+28
-15
lines changed

test/src/main/java/org/apache/accumulo/test/fate/zookeeper/FateIT.java

+28-15
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
package org.apache.accumulo.test.fate.zookeeper;
2020

2121
import static java.nio.charset.StandardCharsets.UTF_8;
22+
import static java.util.concurrent.TimeUnit.SECONDS;
2223
import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.FAILED;
2324
import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.FAILED_IN_PROGRESS;
2425
import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.IN_PROGRESS;
2526
import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.NEW;
2627
import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.SUBMITTED;
27-
import static org.apache.accumulo.core.fate.ReadOnlyTStore.TStatus.SUCCESSFUL;
2828
import static org.apache.accumulo.harness.AccumuloITBase.ZOOKEEPER_TESTING_SERVER;
2929
import static org.easymock.EasyMock.createMock;
3030
import static org.easymock.EasyMock.expect;
@@ -40,6 +40,7 @@
4040
import java.util.List;
4141
import java.util.UUID;
4242
import java.util.concurrent.CountDownLatch;
43+
import java.util.concurrent.atomic.AtomicBoolean;
4344

4445
import org.apache.accumulo.core.Constants;
4546
import org.apache.accumulo.core.clientImpl.thrift.TableOperation;
@@ -242,27 +243,39 @@ public void testTransactionStatus() throws Exception {
242243
assertEquals(IN_PROGRESS, getTxStatus(zk, txid));
243244
// tell the op to exit the method
244245
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;
254250
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+
}
257266
} catch (KeeperException e) {
258267
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;
260272
} else {
261273
fail("Unexpected error thrown: " + e.getMessage());
262274
}
263275
}
264-
}
265-
276+
// keep waiting for NoNode
277+
return false;
278+
}, SECONDS.toMillis(30), 10);
266279
} finally {
267280
fate.shutdown();
268281
}

0 commit comments

Comments
 (0)