Skip to content

Commit cd764e6

Browse files
committed
Add stack traces to RetentionLeasesIT failures
Today `RetentionLeaseIT` calls `fail(e.toString())` on some exceptions, losing the stack trace that came with the exception. This commit adjusts this to re-throw the exception wrapped in an `AssertionError` so we can see more details about failures such as elastic#41430.
1 parent c9d04cc commit cd764e6

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

server/src/test/java/org/elasticsearch/index/seqno/RetentionLeaseIT.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void testRetentionLeasesSyncedOnAdd() throws Exception {
108108
final long retainingSequenceNumber = randomLongBetween(0, Long.MAX_VALUE);
109109
final String source = randomAlphaOfLength(8);
110110
final CountDownLatch latch = new CountDownLatch(1);
111-
final ActionListener<ReplicationResponse> listener = ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString()));
111+
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
112112
// simulate a peer recovery which locks the soft deletes policy on the primary
113113
final Closeable retentionLock = randomBoolean() ? primary.acquireRetentionLock() : () -> {};
114114
currentRetentionLeases.put(id, primary.addRetentionLease(id, retainingSequenceNumber, source, listener));
@@ -155,7 +155,7 @@ public void testRetentionLeaseSyncedOnRemove() throws Exception {
155155
final long retainingSequenceNumber = randomLongBetween(0, Long.MAX_VALUE);
156156
final String source = randomAlphaOfLength(8);
157157
final CountDownLatch latch = new CountDownLatch(1);
158-
final ActionListener<ReplicationResponse> listener = ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString()));
158+
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
159159
// simulate a peer recovery which locks the soft deletes policy on the primary
160160
final Closeable retentionLock = randomBoolean() ? primary.acquireRetentionLock() : () -> {};
161161
currentRetentionLeases.put(id, primary.addRetentionLease(id, retainingSequenceNumber, source, listener));
@@ -166,7 +166,7 @@ public void testRetentionLeaseSyncedOnRemove() throws Exception {
166166
for (int i = 0; i < length; i++) {
167167
final String id = randomFrom(currentRetentionLeases.keySet());
168168
final CountDownLatch latch = new CountDownLatch(1);
169-
primary.removeRetentionLease(id, ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString())));
169+
primary.removeRetentionLease(id, countDownLatchListener(latch));
170170
// simulate a peer recovery which locks the soft deletes policy on the primary
171171
final Closeable retentionLock = randomBoolean() ? primary.acquireRetentionLock() : () -> {};
172172
currentRetentionLeases.remove(id);
@@ -228,7 +228,7 @@ public void testRetentionLeasesSyncOnExpiration() throws Exception {
228228
final long retainingSequenceNumber = randomLongBetween(0, Long.MAX_VALUE);
229229
final String source = randomAlphaOfLength(8);
230230
final CountDownLatch latch = new CountDownLatch(1);
231-
final ActionListener<ReplicationResponse> listener = ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString()));
231+
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
232232
final RetentionLease currentRetentionLease = primary.addRetentionLease(id, retainingSequenceNumber, source, listener);
233233
final long now = System.nanoTime();
234234
latch.await();
@@ -390,7 +390,7 @@ public void testRetentionLeasesSyncOnRecovery() throws Exception {
390390
final long retainingSequenceNumber = randomLongBetween(0, Long.MAX_VALUE);
391391
final String source = randomAlphaOfLength(8);
392392
final CountDownLatch latch = new CountDownLatch(1);
393-
final ActionListener<ReplicationResponse> listener = ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString()));
393+
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
394394
currentRetentionLeases.put(id, primary.addRetentionLease(id, retainingSequenceNumber, source, listener));
395395
latch.await();
396396
currentRetentionLeases.put(id, primary.renewRetentionLease(id, retainingSequenceNumber, source));
@@ -479,7 +479,7 @@ public void testCanRenewRetentionLeaseUnderBlock() throws InterruptedException {
479479
*/
480480
assertBusy(() -> assertThat(primary.loadRetentionLeases().leases(), contains(retentionLease.get())));
481481
} catch (final Exception e) {
482-
fail(e.toString());
482+
failWithException(e);
483483
}
484484
});
485485

@@ -516,7 +516,7 @@ private void runUnderBlockTest(
516516

517517
final String source = randomAlphaOfLength(8);
518518
final CountDownLatch latch = new CountDownLatch(1);
519-
final ActionListener<ReplicationResponse> listener = ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString()));
519+
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
520520
primary.addRetentionLease(idForInitialRetentionLease, initialRetainingSequenceNumber, source, listener);
521521
latch.await();
522522

@@ -545,7 +545,7 @@ public void onResponse(final ReplicationResponse replicationResponse) {
545545

546546
@Override
547547
public void onFailure(final Exception e) {
548-
fail(e.toString());
548+
failWithException(e);
549549
}
550550

551551
});
@@ -598,7 +598,7 @@ public void testCanRenewRetentionLeaseWithoutWaitingForShards() throws Interrupt
598598
*/
599599
assertBusy(() -> assertThat(primary.loadRetentionLeases().leases(), contains(retentionLease.get())));
600600
} catch (final Exception e) {
601-
fail(e.toString());
601+
failWithException(e);
602602
}
603603
});
604604

@@ -637,7 +637,7 @@ private void runWaitForShardsTest(
637637

638638
final String source = randomAlphaOfLength(8);
639639
final CountDownLatch latch = new CountDownLatch(1);
640-
final ActionListener<ReplicationResponse> listener = ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString()));
640+
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
641641
primary.addRetentionLease(idForInitialRetentionLease, initialRetainingSequenceNumber, source, listener);
642642
latch.await();
643643

@@ -665,7 +665,7 @@ public void onResponse(final ReplicationResponse replicationResponse) {
665665

666666
@Override
667667
public void onFailure(final Exception e) {
668-
fail(e.toString());
668+
failWithException(e);
669669
}
670670

671671
});
@@ -674,4 +674,12 @@ public void onFailure(final Exception e) {
674674
afterSync.accept(primary);
675675
}
676676

677+
private static void failWithException(Exception e) {
678+
throw new AssertionError("unexpected", e);
679+
}
680+
681+
private static ActionListener<ReplicationResponse> countDownLatchListener(CountDownLatch latch) {
682+
return ActionListener.wrap(r -> latch.countDown(), RetentionLeaseIT::failWithException);
683+
}
684+
677685
}

0 commit comments

Comments
 (0)