use of io.pravega.test.common.IntentionalException in project pravega by pravega.
the class RollingStorageTests method testDeleteFailure.
/**
* Tests the case when Delete worked partially (only some SegmentChunks were deleted, or all SegmentChunks were deleted
* but the Header still exists).
*/
@Test
public void testDeleteFailure() throws Exception {
final int failAtIndex = 1;
@Cleanup val baseStorage = new TestStorage();
@Cleanup val s = new RollingStorage(baseStorage, DEFAULT_ROLLING_POLICY);
s.initialize(1);
s.create(SEGMENT_NAME);
val writeHandle = (RollingSegmentHandle) s.openWrite(SEGMENT_NAME);
populate(s, writeHandle, null);
// Simulate a deletion failure that is not a StreamSegmentNotExistsException.
String failOnDelete = writeHandle.chunks().get(failAtIndex).getName();
baseStorage.deleteFailure = sn -> sn.equals(failOnDelete) ? new IntentionalException() : null;
AssertExtensions.assertThrows("delete() did not propagate proper exception on failure.", () -> s.delete(writeHandle), ex -> ex instanceof IntentionalException);
Assert.assertTrue("Not expecting segment to be deleted yet.", s.exists(SEGMENT_NAME));
Assert.assertFalse("Expected first SegmentChunk to be marked as deleted.", writeHandle.chunks().get(failAtIndex - 1).exists());
Assert.assertTrue("Expected failed-to-delete SegmentChunk to not be marked as deleted.", writeHandle.chunks().get(failAtIndex).exists());
Assert.assertTrue("Expected subsequent SegmentChunk to not be marked as deleted.", writeHandle.chunks().get(failAtIndex + 1).exists());
// Clear the intentional failure, but do delete the SegmentChunk, to verify it properly handles missing SegmentChunks.
baseStorage.deleteFailure = null;
baseStorage.delete(baseStorage.openRead(failOnDelete));
s.delete(writeHandle);
Assert.assertFalse("Expecting the segment to be deleted.", s.exists(SEGMENT_NAME));
Assert.assertTrue("Expected the handle to be marked as deleted.", writeHandle.isDeleted());
Assert.assertFalse("Expected all SegmentChunks to be marked as deleted.", writeHandle.chunks().stream().anyMatch(SegmentChunk::exists));
}
use of io.pravega.test.common.IntentionalException in project pravega by pravega.
the class OrderedItemProcessorTests method testFailures.
@Test
public void testFailures() {
final int itemCount = 2 * CAPACITY;
val processedItems = Collections.synchronizedCollection(new HashSet<Integer>());
val processFutures = Collections.synchronizedList(new ArrayList<CompletableFuture<Integer>>());
Function<Integer, CompletableFuture<Integer>> itemProcessor = i -> {
if (!processedItems.add(i)) {
Assert.fail("Duplicate item detected: " + i);
}
CompletableFuture<Integer> result = new CompletableFuture<>();
processFutures.add(result);
return result;
};
val resultFutures = new ArrayList<CompletableFuture<Integer>>();
@Cleanup val p = new TestProcessor(CAPACITY, itemProcessor, executorService());
// Fill up to capacity, and beyond.
for (int i = 0; i < itemCount; i++) {
resultFutures.add(p.process(i));
}
// Fail an item.
val failedIndex = CAPACITY / 2;
processFutures.get(failedIndex).completeExceptionally(new IntentionalException());
AssertExtensions.assertThrows("Failed item did not have its result failed as well.", resultFutures.get(failedIndex)::join, ex -> ex instanceof IntentionalException);
// Verify all queued-up items have been failed, but none of the initial ones (that have already begun processing)
for (int i = CAPACITY; i < itemCount; i++) {
AssertExtensions.assertThrows("Queued-up item did not fail when a previous item failed.", resultFutures.get(i)::join, ex -> ex instanceof OrderedItemProcessor.ProcessingException && ex.getCause() instanceof IntentionalException);
}
for (int i = 0; i < CAPACITY; i++) {
if (i != failedIndex) {
Assert.assertFalse("Already-processing future was completed as well.", resultFutures.get(i).isDone());
}
}
// Verify we can't add anything else ...
AssertExtensions.assertThrows("failure did not cause OrderedItemProcessor to close.", () -> p.process(Integer.MAX_VALUE), ex -> ex instanceof ObjectClosedException);
}
use of io.pravega.test.common.IntentionalException in project pravega by pravega.
the class AbstractThreadPoolServiceTests method testCancellationException.
/**
* Tests the case when the Service stops due to a CancellationException.
*/
@Test
public void testCancellationException() {
val s = newService();
// Stop it and verify it hasn't shut down - it should still be waiting on the runFuture.
val stopException = new IntentionalException("stop");
s.errorHandler(stopException);
s.runFuture.completeExceptionally(new CancellationException());
// Complete the future and await normal termination.
s.awaitTerminated();
Assert.assertEquals("Unexpected state.", Service.State.TERMINATED, s.state());
}
use of io.pravega.test.common.IntentionalException in project pravega by pravega.
the class AbstractThreadPoolServiceTests method testAutoShutdown.
/**
* Tests the behavior of AbstractThreadPoolService when the runFuture completes (normally or not).
*/
@Test
public void testAutoShutdown() {
// When completed normally.
@Cleanup val s1 = newService();
s1.runFuture.complete(null);
s1.awaitTerminated();
Assert.assertEquals("Unexpected state upon auto-shutdown (normal completion).", Service.State.TERMINATED, s1.state());
// When completed with failure.
@Cleanup val s2 = newService();
s2.runFuture.completeExceptionally(new IntentionalException());
AssertExtensions.assertThrows("Service did not fail when runFuture failed.", () -> s2.awaitTerminated(), ex -> ex instanceof IllegalStateException);
Assert.assertEquals("Unexpected state upon auto-shutdown (failure).", Service.State.FAILED, s2.state());
Assert.assertTrue("Unexpected failure cause.", s2.failureCause() instanceof IntentionalException);
}
use of io.pravega.test.common.IntentionalException in project pravega by pravega.
the class AbstractThreadPoolServiceTests method testShutdownStopException.
/**
* Tests the behavior of AbstractThreadPoolService during shutdown when only a StopException is present.
*/
@Test
public void testShutdownStopException() {
@Cleanup val s = newService();
// Stop it and verify it hasn't shut down - it should still be waiting on the runFuture.
val correctEx = new IntentionalException();
val wrongEx = new IntentionalException();
s.errorHandler(correctEx);
s.errorHandler(wrongEx);
s.stopAsync();
s.runFuture.complete(null);
AssertExtensions.assertThrows("Service did not fail when a StopException has been recorded.", () -> s.awaitTerminated(), ex -> ex instanceof IllegalStateException);
Assert.assertEquals("Unexpected state upon failed shutdown.", Service.State.FAILED, s.state());
Assert.assertEquals("Unexpected failure cause.", correctEx, s.failureCause());
}
Aggregations