@Test public void putObject() throws Exception { AtomicReference<String> storageId = new AtomicReference<>(); doAnswer( (args) -> { String str = (String) args.callRealMethod(); storageId.set(str); return str; } ).when(basicFileStorage).writeFile(any(), any(), any(), anyLong()); byte[] data = "test data".getBytes(); String digest = tapeLibraryContentAddressableStorage.putObject("containerName", "objectName", new ByteArrayInputStream(data), DigestType.SHA512, (long) data.length); assertThat(digest).isEqualTo(new Digest(DigestType.SHA512).update(data).digestHex()); verify(basicFileStorage).writeFile(eq("containerName"), eq("objectName"), any(), eq((long) data.length)); ArgumentCaptor<TapeObjectReferentialEntity> objectReferentialEntityArgumentCaptor = ArgumentCaptor.forClass(TapeObjectReferentialEntity.class); verify(objectReferentialRepository).insertOrUpdate(objectReferentialEntityArgumentCaptor.capture()); assertThat(objectReferentialEntityArgumentCaptor.getValue().getId().getContainerName()) .isEqualTo("containerName"); assertThat(objectReferentialEntityArgumentCaptor.getValue().getId().getObjectName()).isEqualTo("objectName"); assertThat(objectReferentialEntityArgumentCaptor.getValue().getSize()).isEqualTo(data.length); assertThat(objectReferentialEntityArgumentCaptor.getValue().getDigestType()).isEqualTo("SHA-512"); assertThat(objectReferentialEntityArgumentCaptor.getValue().getDigest()).isEqualTo(digest); assertThat(objectReferentialEntityArgumentCaptor.getValue().getLastUpdateDate()).isNotNull(); assertThat(objectReferentialEntityArgumentCaptor.getValue().getLastObjectModifiedDate()).isNotNull(); ArgumentCaptor<InputFileToProcessMessage> inputFileToProcessMessageArgumentCaptor = ArgumentCaptor.forClass(InputFileToProcessMessage.class); verify(fileBucketTarCreatorManager).addToQueue(inputFileToProcessMessageArgumentCaptor.capture()); assertThat(inputFileToProcessMessageArgumentCaptor.getValue().getContainerName()).isEqualTo("containerName"); assertThat(inputFileToProcessMessageArgumentCaptor.getValue().getObjectName()).isEqualTo("objectName"); assertThat(inputFileToProcessMessageArgumentCaptor.getValue().getSize()).isEqualTo(data.length); assertThat(inputFileToProcessMessageArgumentCaptor.getValue().getDigestValue()).isEqualTo(digest); assertThat(inputFileToProcessMessageArgumentCaptor.getValue().getDigestAlgorithm()).isEqualTo("SHA-512"); Mockito.verifyNoMoreInteractions(basicFileStorage, objectReferentialRepository, archiveReferentialRepository, fileBucketTarCreatorManager, readWriteQueueRepository, tapeCatalogService); assertThat(basicFileStorage.readFile("containerName", storageId.get())).hasSameContentAs( new ByteArrayInputStream(data)); }
@Override public String putObject(String containerName, String objectName, InputStream stream, DigestType digestType, Long size) throws ContentAddressableStorageException { LOGGER.debug(String.format("Upload object %s in container %s", objectName, containerName)); Digest digest = new Digest(digestType); InputStream digestInputStream = digest.getDigestInputStream(stream); String storageId; try { storageId = this.basicFileStorage.writeFile(containerName, objectName, digestInputStream, size); } catch (IOException e) { throw new ContentAddressableStorageException( "Could not persist file to disk " + containerName + "/" + objectName, e); } String digestValue = digest.digestHex(); try { String now = LocalDateUtil.now().toString(); objectReferentialRepository.insertOrUpdate(new TapeObjectReferentialEntity( new TapeLibraryObjectReferentialId(containerName, objectName), size, digestType.getName(), digestValue, storageId, new TapeLibraryInputFileObjectStorageLocation(), now, now )); } catch (ObjectReferentialException ex) { throw new ContentAddressableStorageServerException( String.format("Could not index the object %s in container %s in database", objectName, containerName), ex); } finally { fileBucketTarCreatorManager.addToQueue( new InputFileToProcessMessage(containerName, objectName, storageId, size, digestValue, digestType.getName())); } return digestValue; }
TapeLibraryContentAddressableStorage implements ContentAddressableStorage { @Override public String putObject(String containerName, String objectName, InputStream stream, DigestType digestType, Long size) throws ContentAddressableStorageException { LOGGER.debug(String.format("Upload object %s in container %s", objectName, containerName)); Digest digest = new Digest(digestType); InputStream digestInputStream = digest.getDigestInputStream(stream); String storageId; try { storageId = this.basicFileStorage.writeFile(containerName, objectName, digestInputStream, size); } catch (IOException e) { throw new ContentAddressableStorageException( "Could not persist file to disk " + containerName + "/" + objectName, e); } String digestValue = digest.digestHex(); try { String now = LocalDateUtil.now().toString(); objectReferentialRepository.insertOrUpdate(new TapeObjectReferentialEntity( new TapeLibraryObjectReferentialId(containerName, objectName), size, digestType.getName(), digestValue, storageId, new TapeLibraryInputFileObjectStorageLocation(), now, now )); } catch (ObjectReferentialException ex) { throw new ContentAddressableStorageServerException( String.format("Could not index the object %s in container %s in database", objectName, containerName), ex); } finally { fileBucketTarCreatorManager.addToQueue( new InputFileToProcessMessage(containerName, objectName, storageId, size, digestValue, digestType.getName())); } return digestValue; } }
TapeLibraryContentAddressableStorage implements ContentAddressableStorage { @Override public String putObject(String containerName, String objectName, InputStream stream, DigestType digestType, Long size) throws ContentAddressableStorageException { LOGGER.debug(String.format("Upload object %s in container %s", objectName, containerName)); Digest digest = new Digest(digestType); InputStream digestInputStream = digest.getDigestInputStream(stream); String storageId; try { storageId = this.basicFileStorage.writeFile(containerName, objectName, digestInputStream, size); } catch (IOException e) { throw new ContentAddressableStorageException( "Could not persist file to disk " + containerName + "/" + objectName, e); } String digestValue = digest.digestHex(); try { String now = LocalDateUtil.now().toString(); objectReferentialRepository.insertOrUpdate(new TapeObjectReferentialEntity( new TapeLibraryObjectReferentialId(containerName, objectName), size, digestType.getName(), digestValue, storageId, new TapeLibraryInputFileObjectStorageLocation(), now, now )); } catch (ObjectReferentialException ex) { throw new ContentAddressableStorageServerException( String.format("Could not index the object %s in container %s in database", objectName, containerName), ex); } finally { fileBucketTarCreatorManager.addToQueue( new InputFileToProcessMessage(containerName, objectName, storageId, size, digestValue, digestType.getName())); } return digestValue; } TapeLibraryContentAddressableStorage(
        BasicFileStorage basicFileStorage,
        ObjectReferentialRepository objectReferentialRepository,
        ArchiveReferentialRepository archiveReferentialRepository,
        ReadRequestReferentialRepository readRequestReferentialRepository,
        FileBucketTarCreatorManager fileBucketTarCreatorManager,
        QueueRepository readWriteQueue, TapeCatalogService tapeCatalogService,
        String outputTarStorageFolder,
        ArchiveOutputRetentionPolicy archiveOutputRetentionPolicy); }
TapeLibraryContentAddressableStorage implements ContentAddressableStorage { @Override public String putObject(String containerName, String objectName, InputStream stream, DigestType digestType, Long size) throws ContentAddressableStorageException { LOGGER.debug(String.format("Upload object %s in container %s", objectName, containerName)); Digest digest = new Digest(digestType); InputStream digestInputStream = digest.getDigestInputStream(stream); String storageId; try { storageId = this.basicFileStorage.writeFile(containerName, objectName, digestInputStream, size); } catch (IOException e) { throw new ContentAddressableStorageException( "Could not persist file to disk " + containerName + "/" + objectName, e); } String digestValue = digest.digestHex(); try { String now = LocalDateUtil.now().toString(); objectReferentialRepository.insertOrUpdate(new TapeObjectReferentialEntity( new TapeLibraryObjectReferentialId(containerName, objectName), size, digestType.getName(), digestValue, storageId, new TapeLibraryInputFileObjectStorageLocation(), now, now )); } catch (ObjectReferentialException ex) { throw new ContentAddressableStorageServerException( String.format("Could not index the object %s in container %s in database", objectName, containerName), ex); } finally { fileBucketTarCreatorManager.addToQueue( new InputFileToProcessMessage(containerName, objectName, storageId, size, digestValue, digestType.getName())); } return digestValue; } TapeLibraryContentAddressableStorage(
        BasicFileStorage basicFileStorage,
        ObjectReferentialRepository objectReferentialRepository,
        ArchiveReferentialRepository archiveReferentialRepository,
        ReadRequestReferentialRepository readRequestReferentialRepository,
        FileBucketTarCreatorManager fileBucketTarCreatorManager,
        QueueRepository readWriteQueue, TapeCatalogService tapeCatalogService,
        String outputTarStorageFolder,
        ArchiveOutputRetentionPolicy archiveOutputRetentionPolicy); @Override void createContainer(String containerName); @Override boolean isExistingContainer(String containerName); @Override String putObject(String containerName, String objectName, InputStream stream, DigestType digestType,
        Long size); @Override ObjectContent getObject(String containerName, String objectName); @Override String createReadOrderRequest(String containerName, List<String> objectsIds); @Override void removeReadOrderRequest(String readRequestID); @Override void deleteObject(String containerName, String objectName); @Override boolean isExistingObject(String containerName, String objectName); @Override String getObjectDigest(String containerName, String objectName, DigestType algo, boolean noCache); @Override ContainerInformation getContainerInformation(String containerName); @Override MetadatasObject getObjectMetadata(String containerName, String objectName, boolean noCache); @Override void listContainer(String containerName, ObjectListingListener objectListingListener); @Override void close(); }
TapeLibraryContentAddressableStorage implements ContentAddressableStorage { @Override public String putObject(String containerName, String objectName, InputStream stream, DigestType digestType, Long size) throws ContentAddressableStorageException { LOGGER.debug(String.format("Upload object %s in container %s", objectName, containerName)); Digest digest = new Digest(digestType); InputStream digestInputStream = digest.getDigestInputStream(stream); String storageId; try { storageId = this.basicFileStorage.writeFile(containerName, objectName, digestInputStream, size); } catch (IOException e) { throw new ContentAddressableStorageException( "Could not persist file to disk " + containerName + "/" + objectName, e); } String digestValue = digest.digestHex(); try { String now = LocalDateUtil.now().toString(); objectReferentialRepository.insertOrUpdate(new TapeObjectReferentialEntity( new TapeLibraryObjectReferentialId(containerName, objectName), size, digestType.getName(), digestValue, storageId, new TapeLibraryInputFileObjectStorageLocation(), now, now )); } catch (ObjectReferentialException ex) { throw new ContentAddressableStorageServerException( String.format("Could not index the object %s in container %s in database", objectName, containerName), ex); } finally { fileBucketTarCreatorManager.addToQueue( new InputFileToProcessMessage(containerName, objectName, storageId, size, digestValue, digestType.getName())); } return digestValue; } TapeLibraryContentAddressableStorage(
        BasicFileStorage basicFileStorage,
        ObjectReferentialRepository objectReferentialRepository,
        ArchiveReferentialRepository archiveReferentialRepository,
        ReadRequestReferentialRepository readRequestReferentialRepository,
        FileBucketTarCreatorManager fileBucketTarCreatorManager,
        QueueRepository readWriteQueue, TapeCatalogService tapeCatalogService,
        String outputTarStorageFolder,
        ArchiveOutputRetentionPolicy archiveOutputRetentionPolicy); @Override void createContainer(String containerName); @Override boolean isExistingContainer(String containerName); @Override String putObject(String containerName, String objectName, InputStream stream, DigestType digestType,
        Long size); @Override ObjectContent getObject(String containerName, String objectName); @Override String createReadOrderRequest(String containerName, List<String> objectsIds); @Override void removeReadOrderRequest(String readRequestID); @Override void deleteObject(String containerName, String objectName); @Override boolean isExistingObject(String containerName, String objectName); @Override String getObjectDigest(String containerName, String objectName, DigestType algo, boolean noCache); @Override ContainerInformation getContainerInformation(String containerName); @Override MetadatasObject getObjectMetadata(String containerName, String objectName, boolean noCache); @Override void listContainer(String containerName, ObjectListingListener objectListingListener); @Override void close();  }