use of io.pravega.common.util.RetriesExhaustedException in project pravega by pravega.
the class BookKeeperLogTests method testAppendPermanentFailures.
/**
* Tests the ability to retry writes when Bookies fail.
*/
@Test
public void testAppendPermanentFailures() throws Exception {
try (DurableDataLog log = createDurableDataLog()) {
log.initialize(TIMEOUT);
List<CompletableFuture<LogAddress>> appendFutures = new ArrayList<>();
try {
// Suspend a bookie (this will trigger write errors).
stopFirstBookie();
// Issue appends in parallel.
int writeCount = getWriteCount();
for (int i = 0; i < writeCount; i++) {
appendFutures.add(log.append(new ByteArraySegment(getWriteData()), TIMEOUT));
}
// Verify that all writes failed or got cancelled.
AtomicBoolean cancellationEncountered = new AtomicBoolean(false);
for (val f : appendFutures) {
AssertExtensions.assertThrows("Write did not fail correctly.", () -> f.get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS), ex -> {
cancellationEncountered.set(cancellationEncountered.get() || ex instanceof CancellationException);
if (cancellationEncountered.get()) {
return ex instanceof CancellationException;
} else {
return ex instanceof RetriesExhaustedException || ex instanceof DurableDataLogException;
}
});
}
} finally {
// Don't forget to resume the bookie, but only AFTER we are done testing.
restartFirstBookie();
}
}
}
use of io.pravega.common.util.RetriesExhaustedException in project pravega by pravega.
the class RetryHelperTest method testWithRetriesAsync.
@Test(timeout = 10000)
public void testWithRetriesAsync() {
try {
RetryHelper.withRetriesAsync(() -> CompletableFuture.runAsync(() -> {
throw new TestException();
}), RetryHelper.RETRYABLE_PREDICATE, 2, executor);
} catch (Exception e) {
assertTrue(e instanceof RetriesExhaustedException);
Throwable ex = Exceptions.unwrap(e.getCause());
assertTrue(ex instanceof TestException);
}
AtomicInteger count = new AtomicInteger(0);
assertTrue(Futures.getAndHandleExceptions(RetryHelper.withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> {
if (count.incrementAndGet() < 2) {
throw new TestException();
}
return count.get();
}), RetryHelper.RETRYABLE_PREDICATE, 2, executor), RuntimeException::new) == 2);
assertTrue(Futures.getAndHandleExceptions(RetryHelper.withRetriesAsync(() -> CompletableFuture.supplyAsync(() -> {
if (count.incrementAndGet() < 4) {
throw new RuntimeException();
}
return count.get();
}), RetryHelper.UNCONDITIONAL_PREDICATE, 2, executor), RuntimeException::new) == 4);
}
use of io.pravega.common.util.RetriesExhaustedException in project pravega by pravega.
the class RetryHelperTest method testWithRetries.
@Test(timeout = 10000)
public void testWithRetries() {
try {
RetryHelper.withRetries(() -> {
throw new TestException();
}, RetryHelper.RETRYABLE_PREDICATE, 2);
} catch (Exception e) {
assertTrue(e instanceof RetriesExhaustedException);
Throwable ex = Exceptions.unwrap(e.getCause());
assertTrue(ex instanceof TestException);
}
AtomicInteger count = new AtomicInteger(0);
assertTrue(RetryHelper.withRetries(() -> {
if (count.incrementAndGet() < 2) {
throw new TestException();
}
return count.get();
}, RetryHelper.RETRYABLE_PREDICATE, 2) == 2);
assertTrue(RetryHelper.withRetries(() -> {
if (count.incrementAndGet() < 4) {
throw new RuntimeException();
}
return count.get();
}, RetryHelper.UNCONDITIONAL_PREDICATE, 2) == 4);
}
use of io.pravega.common.util.RetriesExhaustedException in project pravega by pravega.
the class BookKeeperDisableCommand method execute.
@Override
public void execute() throws Exception {
ensureArgCount(1);
int logId = getIntArg(0);
@Cleanup val context = createContext();
@Cleanup val log = context.logFactory.createDebugLogWrapper(logId);
// Display a summary of the BookKeeperLog.
val m = log.fetchMetadata();
outputLogSummary(logId, m);
if (m == null) {
// Nothing else to do.
return;
} else if (!m.isEnabled()) {
output("BookKeeperLog '%s' is already disabled.", logId);
return;
}
output("BookKeeperLog '%s' is about to be DISABLED.", logId);
output("\tIts SegmentContainer will shut down and it will not be able to restart until re-enabled.");
output("\tNo request on this SegmentContainer can be processed until that time (OUTAGE ALERT).");
if (!confirmContinue()) {
output("Not disabling anything at this time.");
return;
}
try {
AtomicInteger count = new AtomicInteger(0);
// We may be competing with a rather active Log which updates its metadata quite frequently, so try a few
// times to acquire the ownership.
DISABLE_RETRY.run(() -> {
output("Acquiring ownership (attempt %d/%d) ...", count.incrementAndGet(), MAX_RETRIES);
log.disable();
output("BookKeeperLog '%s' has been disabled.", logId);
return null;
});
} catch (Exception ex) {
Throwable cause = ex;
if (cause instanceof RetriesExhaustedException && cause.getCause() != null) {
cause = cause.getCause();
}
output("Disable failed: %s.", cause.getMessage());
}
output("Current metadata:");
val m2 = log.fetchMetadata();
outputLogSummary(logId, m2);
}
Aggregations