S3DownloadService implements DownloadService { @Override public ObjectSpecification download(String objectId, long offset, long length, boolean forExternalUse, boolean excludeUrls) { try { if (!excludeUrls){ checkPublishedAnalysisState(metadataService.getEntity(objectId)); } checkArgument(offset > -1L); val objectSpec = getSpecification(objectId); if (!forExternalUse && (offset == 0L && length < 0L)) { return excludeUrls ? removeUrls(objectSpec) : objectSpec; } if (!forExternalUse && (length < 0L)) { length = objectSpec.getObjectSize() - offset; } if ((offset + length) > objectSpec.getObjectSize()) { throw new InternalUnrecoverableError("Specified parameters exceed object size (object id: " + objectId + ", offset: " + offset + ", length: " + length + ")"); } val objectKey = ObjectKeys.getObjectKey(dataDir, objectId); List<Part> parts; if (forExternalUse) { parts = partCalculator.specify(0L, -1L); } else { parts = partCalculator.divide(offset, length); } fillPartUrls(objectKey, parts, objectSpec.isRelocated(), forExternalUse); val spec = new ObjectSpecification(objectKey.getKey(), objectId, objectId, parts, length, objectSpec.getObjectMd5(), objectSpec.isRelocated()); return excludeUrls ? removeUrls(spec) : spec; } catch (Exception e) { log.error("Failed to download objectId: {}, offset: {}, length: {}, forExternalUse: {}, excludeUrls: {} : {} ", objectId, offset, length, forExternalUse, excludeUrls, e); throw e; } }  @Override ObjectSpecification download(String objectId, long offset, long length, boolean forExternalUse, boolean excludeUrls); ObjectSpecification getSpecification(String objectId); @Override String getSentinelObject();  }
@Test public void verify_if_download_is_blocked_with_unpublished_objectId() { when(mockService.getAnalysisStateForMetadata(metadataEntity)).thenReturn("UNPUBLISHED"); when(mockService.getEntity(objectId)).thenReturn(metadataEntity); val throwable = catchThrowable(() -> s3DownloadService.download(objectId, 0, -1, false, false)); assertThat(throwable).isExactlyInstanceOf(NotRetryableException.class); }