Skip to content

Commit

Permalink
Add stack traces to RetentionLeasesIT failures
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DaveCTurner committed May 23, 2019
1 parent c9d04cc commit cd764e6
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void testRetentionLeasesSyncedOnAdd() throws Exception {
final long retainingSequenceNumber = randomLongBetween(0, Long.MAX_VALUE);
final String source = randomAlphaOfLength(8);
final CountDownLatch latch = new CountDownLatch(1);
final ActionListener<ReplicationResponse> listener = ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString()));
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
// simulate a peer recovery which locks the soft deletes policy on the primary
final Closeable retentionLock = randomBoolean() ? primary.acquireRetentionLock() : () -> {};
currentRetentionLeases.put(id, primary.addRetentionLease(id, retainingSequenceNumber, source, listener));
Expand Down Expand Up @@ -155,7 +155,7 @@ public void testRetentionLeaseSyncedOnRemove() throws Exception {
final long retainingSequenceNumber = randomLongBetween(0, Long.MAX_VALUE);
final String source = randomAlphaOfLength(8);
final CountDownLatch latch = new CountDownLatch(1);
final ActionListener<ReplicationResponse> listener = ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString()));
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
// simulate a peer recovery which locks the soft deletes policy on the primary
final Closeable retentionLock = randomBoolean() ? primary.acquireRetentionLock() : () -> {};
currentRetentionLeases.put(id, primary.addRetentionLease(id, retainingSequenceNumber, source, listener));
Expand All @@ -166,7 +166,7 @@ public void testRetentionLeaseSyncedOnRemove() throws Exception {
for (int i = 0; i < length; i++) {
final String id = randomFrom(currentRetentionLeases.keySet());
final CountDownLatch latch = new CountDownLatch(1);
primary.removeRetentionLease(id, ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString())));
primary.removeRetentionLease(id, countDownLatchListener(latch));
// simulate a peer recovery which locks the soft deletes policy on the primary
final Closeable retentionLock = randomBoolean() ? primary.acquireRetentionLock() : () -> {};
currentRetentionLeases.remove(id);
Expand Down Expand Up @@ -228,7 +228,7 @@ public void testRetentionLeasesSyncOnExpiration() throws Exception {
final long retainingSequenceNumber = randomLongBetween(0, Long.MAX_VALUE);
final String source = randomAlphaOfLength(8);
final CountDownLatch latch = new CountDownLatch(1);
final ActionListener<ReplicationResponse> listener = ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString()));
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
final RetentionLease currentRetentionLease = primary.addRetentionLease(id, retainingSequenceNumber, source, listener);
final long now = System.nanoTime();
latch.await();
Expand Down Expand Up @@ -390,7 +390,7 @@ public void testRetentionLeasesSyncOnRecovery() throws Exception {
final long retainingSequenceNumber = randomLongBetween(0, Long.MAX_VALUE);
final String source = randomAlphaOfLength(8);
final CountDownLatch latch = new CountDownLatch(1);
final ActionListener<ReplicationResponse> listener = ActionListener.wrap(r -> latch.countDown(), e -> fail(e.toString()));
final ActionListener<ReplicationResponse> listener = countDownLatchListener(latch);
currentRetentionLeases.put(id, primary.addRetentionLease(id, retainingSequenceNumber, source, listener));
latch.await();
currentRetentionLeases.put(id, primary.renewRetentionLease(id, retainingSequenceNumber, source));
Expand Down Expand Up @@ -479,7 +479,7 @@ public void testCanRenewRetentionLeaseUnderBlock() throws InterruptedException {
*/
assertBusy(() -> assertThat(primary.loadRetentionLeases().leases(), contains(retentionLease.get())));
} catch (final Exception e) {
fail(e.toString());
failWithException(e);
}
});

Expand Down Expand Up @@ -516,7 +516,7 @@ private void runUnderBlockTest(

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

Expand Down Expand Up @@ -545,7 +545,7 @@ public void onResponse(final ReplicationResponse replicationResponse) {

@Override
public void onFailure(final Exception e) {
fail(e.toString());
failWithException(e);
}

});
Expand Down Expand Up @@ -598,7 +598,7 @@ public void testCanRenewRetentionLeaseWithoutWaitingForShards() throws Interrupt
*/
assertBusy(() -> assertThat(primary.loadRetentionLeases().leases(), contains(retentionLease.get())));
} catch (final Exception e) {
fail(e.toString());
failWithException(e);
}
});

Expand Down Expand Up @@ -637,7 +637,7 @@ private void runWaitForShardsTest(

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

Expand Down Expand Up @@ -665,7 +665,7 @@ public void onResponse(final ReplicationResponse replicationResponse) {

@Override
public void onFailure(final Exception e) {
fail(e.toString());
failWithException(e);
}

});
Expand All @@ -674,4 +674,12 @@ public void onFailure(final Exception e) {
afterSync.accept(primary);
}

private static void failWithException(Exception e) {
throw new AssertionError("unexpected", e);
}

private static ActionListener<ReplicationResponse> countDownLatchListener(CountDownLatch latch) {
return ActionListener.wrap(r -> latch.countDown(), RetentionLeaseIT::failWithException);
}

}

0 comments on commit cd764e6

Please sign in to comment.