@Test public void should_call_smallFile_method_then_swift_offer_doesNotThrowAnyException() throws Exception { swiftInstanceRule.stubFor(post(urlMatching("/swift/v1(.*)")).willReturn( aResponse().withStatus(202))); swiftInstanceRule.stubFor( get(urlMatching("/swift/v1(.*)")).willReturn( aResponse().withStatus(200) .withHeader(CONTENT_TYPE, "application/octet-stream") .withBody(IOUtils.toByteArray(PropertiesUtils.getResourceAsStream(OBJECT_NAME))))); this.swift = new Swift(new SwiftKeystoneFactoryV3(configuration), configuration, 3_500L); InputStream stream = PropertiesUtils.getResourceAsStream(OBJECT_NAME); swift.putObject(CONTAINER_NAME, OBJECT_NAME, stream, VitamConfiguration.getDefaultDigestType(), 3_500L); }
@Override public String putObject(String containerName, String objectName, InputStream stream, DigestType digestType, Long size) throws ContentAddressableStorageException { ParametersChecker.checkParameter(ErrorMessage.CONTAINER_OBJECT_NAMES_ARE_A_MANDATORY_PARAMETER.getMessage(), containerName, objectName); SizedInputStream sis = new SizedInputStream(stream); Digest digest = new Digest(digestType); InputStream digestInputStream = digest.getDigestInputStream(sis); InputStream autoclose = new VitamAutoCloseInputStream(digestInputStream); if (size != null && size > swiftLimit) { bigFile(containerName, objectName, autoclose, size); } else { smallFile(containerName, objectName, autoclose); } String streamDigest = digest.digestHex(); if (size != sis.getSize()) { throw new ContentAddressableStorageException( "Illegal state. Stream size " + sis.getSize() + " did not match expected size " + size); } String computedDigest = computeObjectDigest(containerName, objectName, digestType); if (!streamDigest.equals(computedDigest)) { throw new ContentAddressableStorageException( "Illegal state for container " + containerName + " and object " + objectName + ". Stream digest " + streamDigest + " is not equal to computed digest " + computedDigest); } storeDigest(containerName, objectName, digestType, streamDigest); return streamDigest; }
Swift extends ContentAddressableStorageAbstract { @Override public String putObject(String containerName, String objectName, InputStream stream, DigestType digestType, Long size) throws ContentAddressableStorageException { ParametersChecker.checkParameter(ErrorMessage.CONTAINER_OBJECT_NAMES_ARE_A_MANDATORY_PARAMETER.getMessage(), containerName, objectName); SizedInputStream sis = new SizedInputStream(stream); Digest digest = new Digest(digestType); InputStream digestInputStream = digest.getDigestInputStream(sis); InputStream autoclose = new VitamAutoCloseInputStream(digestInputStream); if (size != null && size > swiftLimit) { bigFile(containerName, objectName, autoclose, size); } else { smallFile(containerName, objectName, autoclose); } String streamDigest = digest.digestHex(); if (size != sis.getSize()) { throw new ContentAddressableStorageException( "Illegal state. Stream size " + sis.getSize() + " did not match expected size " + size); } String computedDigest = computeObjectDigest(containerName, objectName, digestType); if (!streamDigest.equals(computedDigest)) { throw new ContentAddressableStorageException( "Illegal state for container " + containerName + " and object " + objectName + ". Stream digest " + streamDigest + " is not equal to computed digest " + computedDigest); } storeDigest(containerName, objectName, digestType, streamDigest); return streamDigest; } }
Swift extends ContentAddressableStorageAbstract { @Override public String putObject(String containerName, String objectName, InputStream stream, DigestType digestType, Long size) throws ContentAddressableStorageException { ParametersChecker.checkParameter(ErrorMessage.CONTAINER_OBJECT_NAMES_ARE_A_MANDATORY_PARAMETER.getMessage(), containerName, objectName); SizedInputStream sis = new SizedInputStream(stream); Digest digest = new Digest(digestType); InputStream digestInputStream = digest.getDigestInputStream(sis); InputStream autoclose = new VitamAutoCloseInputStream(digestInputStream); if (size != null && size > swiftLimit) { bigFile(containerName, objectName, autoclose, size); } else { smallFile(containerName, objectName, autoclose); } String streamDigest = digest.digestHex(); if (size != sis.getSize()) { throw new ContentAddressableStorageException( "Illegal state. Stream size " + sis.getSize() + " did not match expected size " + size); } String computedDigest = computeObjectDigest(containerName, objectName, digestType); if (!streamDigest.equals(computedDigest)) { throw new ContentAddressableStorageException( "Illegal state for container " + containerName + " and object " + objectName + ". Stream digest " + streamDigest + " is not equal to computed digest " + computedDigest); } storeDigest(containerName, objectName, digestType, streamDigest); return streamDigest; } Swift(Supplier<OSClient> osClient, StorageConfiguration configuration); @VisibleForTesting  Swift(Supplier<OSClient> osClient, StorageConfiguration configuration, Long swiftLimit); }
Swift extends ContentAddressableStorageAbstract { @Override public String putObject(String containerName, String objectName, InputStream stream, DigestType digestType, Long size) throws ContentAddressableStorageException { ParametersChecker.checkParameter(ErrorMessage.CONTAINER_OBJECT_NAMES_ARE_A_MANDATORY_PARAMETER.getMessage(), containerName, objectName); SizedInputStream sis = new SizedInputStream(stream); Digest digest = new Digest(digestType); InputStream digestInputStream = digest.getDigestInputStream(sis); InputStream autoclose = new VitamAutoCloseInputStream(digestInputStream); if (size != null && size > swiftLimit) { bigFile(containerName, objectName, autoclose, size); } else { smallFile(containerName, objectName, autoclose); } String streamDigest = digest.digestHex(); if (size != sis.getSize()) { throw new ContentAddressableStorageException( "Illegal state. Stream size " + sis.getSize() + " did not match expected size " + size); } String computedDigest = computeObjectDigest(containerName, objectName, digestType); if (!streamDigest.equals(computedDigest)) { throw new ContentAddressableStorageException( "Illegal state for container " + containerName + " and object " + objectName + ". Stream digest " + streamDigest + " is not equal to computed digest " + computedDigest); } storeDigest(containerName, objectName, digestType, streamDigest); return streamDigest; } Swift(Supplier<OSClient> osClient, StorageConfiguration configuration); @VisibleForTesting  Swift(Supplier<OSClient> osClient, StorageConfiguration configuration, Long swiftLimit); @Override void createContainer(String containerName); @Override boolean isExistingContainer(String containerName); @Override String putObject(String containerName, String objectName, InputStream stream, DigestType digestType,
        Long size); @Override String getObjectDigest(String containerName, String objectName, DigestType digestType, boolean noCache); @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 ContainerInformation getContainerInformation(String containerName); @Override MetadatasObject getObjectMetadata(String containerName, String objectId, boolean noCache); @Override void listContainer(String containerName, ObjectListingListener objectListingListener); @Override void close(); }
Swift extends ContentAddressableStorageAbstract { @Override public String putObject(String containerName, String objectName, InputStream stream, DigestType digestType, Long size) throws ContentAddressableStorageException { ParametersChecker.checkParameter(ErrorMessage.CONTAINER_OBJECT_NAMES_ARE_A_MANDATORY_PARAMETER.getMessage(), containerName, objectName); SizedInputStream sis = new SizedInputStream(stream); Digest digest = new Digest(digestType); InputStream digestInputStream = digest.getDigestInputStream(sis); InputStream autoclose = new VitamAutoCloseInputStream(digestInputStream); if (size != null && size > swiftLimit) { bigFile(containerName, objectName, autoclose, size); } else { smallFile(containerName, objectName, autoclose); } String streamDigest = digest.digestHex(); if (size != sis.getSize()) { throw new ContentAddressableStorageException( "Illegal state. Stream size " + sis.getSize() + " did not match expected size " + size); } String computedDigest = computeObjectDigest(containerName, objectName, digestType); if (!streamDigest.equals(computedDigest)) { throw new ContentAddressableStorageException( "Illegal state for container " + containerName + " and object " + objectName + ". Stream digest " + streamDigest + " is not equal to computed digest " + computedDigest); } storeDigest(containerName, objectName, digestType, streamDigest); return streamDigest; } Swift(Supplier<OSClient> osClient, StorageConfiguration configuration); @VisibleForTesting  Swift(Supplier<OSClient> osClient, StorageConfiguration configuration, Long swiftLimit); @Override void createContainer(String containerName); @Override boolean isExistingContainer(String containerName); @Override String putObject(String containerName, String objectName, InputStream stream, DigestType digestType,
        Long size); @Override String getObjectDigest(String containerName, String objectName, DigestType digestType, boolean noCache); @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 ContainerInformation getContainerInformation(String containerName); @Override MetadatasObject getObjectMetadata(String containerName, String objectId, boolean noCache); @Override void listContainer(String containerName, ObjectListingListener objectListingListener); @Override void close();  }