use of org.apache.samza.SamzaException in project samza by apache.
the class TestBlobStoreUtil method testPutDirFailsIfAnySubDirFileUploadFails.
@Test
public void testPutDirFailsIfAnySubDirFileUploadFails() throws IOException, TimeoutException, InterruptedException {
BlobStoreManager blobStoreManager = mock(BlobStoreManager.class);
// File, dir and recursive dir added, retained and removed in local
String local = "[a/1, b/2]";
String remote = "[]";
// Set up environment
Path localSnapshotDir = BlobStoreTestUtil.createLocalDir(local);
String basePath = localSnapshotDir.toAbsolutePath().toString();
DirIndex remoteSnapshotDir = BlobStoreTestUtil.createDirIndex(remote);
SnapshotMetadata snapshotMetadata = new SnapshotMetadata(checkpointId, jobName, jobId, taskName, storeName);
DirDiff dirDiff = DirDiffUtil.getDirDiff(localSnapshotDir.toFile(), remoteSnapshotDir, (localFile, remoteFile) -> localFile.getName().equals(remoteFile.getFileName()));
// Set up mocks
SamzaException exception = new SamzaException("Error uploading file");
CompletableFuture<String> failedFuture = new CompletableFuture<>();
failedFuture.completeExceptionally(exception);
when(blobStoreManager.put(any(InputStream.class), any(Metadata.class))).thenAnswer((Answer<CompletableFuture<String>>) invocation -> {
Metadata metadata = invocation.getArgumentAt(1, Metadata.class);
String path = metadata.getPayloadPath();
if (path.endsWith("1")) {
return CompletableFuture.completedFuture("a1BlobId");
} else {
return failedFuture;
}
});
// Execute
BlobStoreUtil blobStoreUtil = new BlobStoreUtil(blobStoreManager, EXECUTOR, null, null);
CompletionStage<DirIndex> dirIndexFuture = blobStoreUtil.putDir(dirDiff, snapshotMetadata);
try {
// should be already complete. if not, future composition in putDir is broken.
dirIndexFuture.toCompletableFuture().get(0, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
// Assert that the result future fails and that the cause is propagated correctly
assertEquals(exception, cause);
return;
}
fail("DirIndex future should have been completed with an exception");
}
use of org.apache.samza.SamzaException in project samza by apache.
the class TestSSPMetadataCache method testGetMetadataExceptionAfterSuccessfulFetch.
/**
* Given that the admin throws an exception when trying to get the metadata after a successful fetch, getMetadata
* should propagate the exception.
*/
@Test(expected = SamzaException.class)
public void testGetMetadataExceptionAfterSuccessfulFetch() {
SystemStreamPartition ssp = buildSSP(0);
SSPMetadataCache cache = buildSSPMetadataCache(ImmutableSet.of(ssp));
// do a successful fetch first
when(clock.currentTimeMillis()).thenReturn(10L);
when(systemAdmin.getSSPMetadata(ImmutableSet.of(ssp))).thenReturn(ImmutableMap.of(ssp, sspMetadata(1)));
cache.getMetadata(ssp);
// throw an exception on the next fetch
when(clock.currentTimeMillis()).thenReturn(11 + CACHE_TTL.toMillis());
when(systemAdmin.getSSPMetadata(ImmutableSet.of(ssp))).thenThrow(new SamzaException());
cache.getMetadata(ssp);
}
use of org.apache.samza.SamzaException in project samza by apache.
the class TestFutureUtil method testUnwrapExceptionReturnsNullIfNoNonWrapperCause.
@Test
public void testUnwrapExceptionReturnsNullIfNoNonWrapperCause() {
Throwable t = new SamzaException(new SamzaException());
Throwable unwrappedThrowable = FutureUtil.unwrapExceptions(SamzaException.class, t);
assertNull(unwrappedThrowable);
}
use of org.apache.samza.SamzaException in project samza by apache.
the class TestFutureUtil method testUnwrapExceptionUnwrapsMultipleExceptions.
@Test
public void testUnwrapExceptionUnwrapsMultipleExceptions() {
IllegalArgumentException cause = new IllegalArgumentException();
Throwable t = new SamzaException(new SamzaException(cause));
Throwable unwrappedThrowable = FutureUtil.unwrapExceptions(SamzaException.class, t);
assertEquals(cause, unwrappedThrowable);
}
use of org.apache.samza.SamzaException in project samza by apache.
the class TestTaskFactoryUtil method testFinalizeTaskFactory.
@Test
public void testFinalizeTaskFactory() throws NoSuchFieldException, IllegalAccessException {
TaskFactory mockFactory = mock(TaskFactory.class);
try {
TaskFactoryUtil.finalizeTaskFactory(mockFactory, null);
fail("Should have failed with validation");
} catch (SamzaException se) {
// expected
}
StreamTaskFactory mockStreamFactory = mock(StreamTaskFactory.class);
ExecutorService mockThreadPool = mock(ExecutorService.class);
TaskFactory retFactory = TaskFactoryUtil.finalizeTaskFactory(mockStreamFactory, mockThreadPool);
assertTrue(retFactory instanceof AsyncStreamTaskFactory);
assertTrue(((AsyncStreamTaskFactory) retFactory).createInstance() instanceof AsyncStreamTaskAdapter);
AsyncStreamTaskAdapter taskAdapter = (AsyncStreamTaskAdapter) ((AsyncStreamTaskFactory) retFactory).createInstance();
Field executorSrvFld = AsyncStreamTaskAdapter.class.getDeclaredField("executor");
executorSrvFld.setAccessible(true);
ExecutorService executor = (ExecutorService) executorSrvFld.get(taskAdapter);
assertEquals(executor, mockThreadPool);
AsyncStreamTaskFactory mockAsyncStreamFactory = mock(AsyncStreamTaskFactory.class);
retFactory = TaskFactoryUtil.finalizeTaskFactory(mockAsyncStreamFactory, null);
assertEquals(retFactory, mockAsyncStreamFactory);
}
Aggregations