@Test public void imageArtifactGetStoredLocallyWhenBackendException() throws IOException, StorageException { long jobId = 4231; long mediaId = 456; ArtifactExtractionRequest request = mock(ArtifactExtractionRequest.class); when(request.getJobId()) .thenReturn(jobId); when(request.getMediaType()) .thenReturn(MediaType.IMAGE); when(request.getMediaId()) .thenReturn(mediaId); when(_mockNginxBackend.canStore(request)) .thenReturn(true); doThrow(StorageException.class) .when(_mockNginxBackend).storeArtifacts(request); Table<Integer, Integer, URI> expectedResults = new ImmutableTable.Builder<Integer, Integer, URI>() .put(0, 0, TEST_LOCAL_URI).build(); when(_mockLocalBackend.storeArtifacts(request)) .thenReturn(expectedResults); Table<Integer, Integer, URI> result = _storageService.storeArtifacts(request); assertEquals(expectedResults, result); verifyWarning(jobId, request.getMediaId()); }
public Table<Integer, Integer, URI> storeArtifacts(ArtifactExtractionRequest request) throws IOException { if ((request.getMediaType() != MediaType.VIDEO) && (request.getMediaType() !=MediaType.IMAGE)) { throw new IllegalArgumentException("Expected media type of IMAGE or VIDEO, but it was " + request.getMediaType()); } Exception remoteException = null; try { for (StorageBackend remoteBackend : _remoteBackends) { if (remoteBackend.canStore(request)) { return remoteBackend.storeArtifacts(request); } } } catch (IOException | StorageException ex) { remoteException = ex; handleRemoteStorageFailure(request, remoteException); } try { return _localBackend.storeArtifacts(request); } catch (IOException localException) { if (remoteException != null) { localException.addSuppressed(remoteException); } throw localException; } }
StorageService { public Table<Integer, Integer, URI> storeArtifacts(ArtifactExtractionRequest request) throws IOException { if ((request.getMediaType() != MediaType.VIDEO) && (request.getMediaType() !=MediaType.IMAGE)) { throw new IllegalArgumentException("Expected media type of IMAGE or VIDEO, but it was " + request.getMediaType()); } Exception remoteException = null; try { for (StorageBackend remoteBackend : _remoteBackends) { if (remoteBackend.canStore(request)) { return remoteBackend.storeArtifacts(request); } } } catch (IOException | StorageException ex) { remoteException = ex; handleRemoteStorageFailure(request, remoteException); } try { return _localBackend.storeArtifacts(request); } catch (IOException localException) { if (remoteException != null) { localException.addSuppressed(remoteException); } throw localException; } } }
StorageService { public Table<Integer, Integer, URI> storeArtifacts(ArtifactExtractionRequest request) throws IOException { if ((request.getMediaType() != MediaType.VIDEO) && (request.getMediaType() !=MediaType.IMAGE)) { throw new IllegalArgumentException("Expected media type of IMAGE or VIDEO, but it was " + request.getMediaType()); } Exception remoteException = null; try { for (StorageBackend remoteBackend : _remoteBackends) { if (remoteBackend.canStore(request)) { return remoteBackend.storeArtifacts(request); } } } catch (IOException | StorageException ex) { remoteException = ex; handleRemoteStorageFailure(request, remoteException); } try { return _localBackend.storeArtifacts(request); } catch (IOException localException) { if (remoteException != null) { localException.addSuppressed(remoteException); } throw localException; } } @Inject  StorageService(
            InProgressBatchJobsService inProgressJobs,
            S3StorageBackend s3StorageBackend,
            CustomNginxStorageBackend nginxStorageBackend,
            LocalStorageBackend localStorageBackend); }
StorageService { public Table<Integer, Integer, URI> storeArtifacts(ArtifactExtractionRequest request) throws IOException { if ((request.getMediaType() != MediaType.VIDEO) && (request.getMediaType() !=MediaType.IMAGE)) { throw new IllegalArgumentException("Expected media type of IMAGE or VIDEO, but it was " + request.getMediaType()); } Exception remoteException = null; try { for (StorageBackend remoteBackend : _remoteBackends) { if (remoteBackend.canStore(request)) { return remoteBackend.storeArtifacts(request); } } } catch (IOException | StorageException ex) { remoteException = ex; handleRemoteStorageFailure(request, remoteException); } try { return _localBackend.storeArtifacts(request); } catch (IOException localException) { if (remoteException != null) { localException.addSuppressed(remoteException); } throw localException; } } @Inject  StorageService(
            InProgressBatchJobsService inProgressJobs,
            S3StorageBackend s3StorageBackend,
            CustomNginxStorageBackend nginxStorageBackend,
            LocalStorageBackend localStorageBackend); URI store(JsonOutputObject outputObject, Mutable<BatchJobStatusType> jobStatus); Table<Integer, Integer, URI> storeArtifacts(ArtifactExtractionRequest request); void store(MarkupResult markupResult); }
StorageService { public Table<Integer, Integer, URI> storeArtifacts(ArtifactExtractionRequest request) throws IOException { if ((request.getMediaType() != MediaType.VIDEO) && (request.getMediaType() !=MediaType.IMAGE)) { throw new IllegalArgumentException("Expected media type of IMAGE or VIDEO, but it was " + request.getMediaType()); } Exception remoteException = null; try { for (StorageBackend remoteBackend : _remoteBackends) { if (remoteBackend.canStore(request)) { return remoteBackend.storeArtifacts(request); } } } catch (IOException | StorageException ex) { remoteException = ex; handleRemoteStorageFailure(request, remoteException); } try { return _localBackend.storeArtifacts(request); } catch (IOException localException) { if (remoteException != null) { localException.addSuppressed(remoteException); } throw localException; } } @Inject  StorageService(
            InProgressBatchJobsService inProgressJobs,
            S3StorageBackend s3StorageBackend,
            CustomNginxStorageBackend nginxStorageBackend,
            LocalStorageBackend localStorageBackend); URI store(JsonOutputObject outputObject, Mutable<BatchJobStatusType> jobStatus); Table<Integer, Integer, URI> storeArtifacts(ArtifactExtractionRequest request); void store(MarkupResult markupResult);  }