Add stack traces to RetentionLeasesIT failures (#42425)

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 #41430.
This commit is contained in:
David Turner 2019-05-24 08:37:22 +01:00
parent c0974a9813
commit 528f8cc073
1 changed files with 19 additions and 11 deletions

View File

@ -108,7 +108,7 @@ public class RetentionLeaseIT extends ESIntegTestCase {
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));
@ -155,7 +155,7 @@ public class RetentionLeaseIT extends ESIntegTestCase {
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));
@ -166,7 +166,7 @@ public class RetentionLeaseIT extends ESIntegTestCase {
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);
@ -228,7 +228,7 @@ public class RetentionLeaseIT extends ESIntegTestCase {
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();
@ -390,7 +390,7 @@ public class RetentionLeaseIT extends ESIntegTestCase {
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));
@ -479,7 +479,7 @@ public class RetentionLeaseIT extends ESIntegTestCase {
*/
assertBusy(() -> assertThat(primary.loadRetentionLeases().leases(), contains(retentionLease.get())));
} catch (final Exception e) {
fail(e.toString());
failWithException(e);
}
});
@ -516,7 +516,7 @@ public class RetentionLeaseIT extends ESIntegTestCase {
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();
@ -545,7 +545,7 @@ public class RetentionLeaseIT extends ESIntegTestCase {
@Override
public void onFailure(final Exception e) {
fail(e.toString());
failWithException(e);
}
});
@ -598,7 +598,7 @@ public class RetentionLeaseIT extends ESIntegTestCase {
*/
assertBusy(() -> assertThat(primary.loadRetentionLeases().leases(), contains(retentionLease.get())));
} catch (final Exception e) {
fail(e.toString());
failWithException(e);
}
});
@ -637,7 +637,7 @@ public class RetentionLeaseIT extends ESIntegTestCase {
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();
@ -665,7 +665,7 @@ public class RetentionLeaseIT extends ESIntegTestCase {
@Override
public void onFailure(final Exception e) {
fail(e.toString());
failWithException(e);
}
});
@ -674,4 +674,12 @@ public class RetentionLeaseIT extends ESIntegTestCase {
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);
}
}