use of ch.cyberduck.core.openstack.SwiftLargeObjectUploadFeature in project cyberduck by iterate-ch.
the class SwiftSingleTransferWorkerTest method testTransferredSizeRepeat.
@Test
public void testTransferredSizeRepeat() throws Exception {
final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
final byte[] content = new byte[2 * 1024 * 1024];
new Random().nextBytes(content);
final OutputStream out = local.getOutputStream(false);
IOUtils.write(content, out);
out.close();
final Host host = new Host(new SwiftProtocol(), "identity.api.rackspacecloud.com", new Credentials(System.getProperties().getProperty("rackspace.key"), System.getProperties().getProperty("rackspace.secret")));
final AtomicBoolean failed = new AtomicBoolean();
final SwiftSession session = new SwiftSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()) {
@Override
@SuppressWarnings("unchecked")
public <T> T _getFeature(final Class<T> type) {
if (type == Upload.class) {
final SwiftRegionService regionService = new SwiftRegionService(this);
return (T) new SwiftLargeObjectUploadFeature(this, regionService, new SwiftWriteFeature(this, regionService), 1024L * 1024L, 5) {
@Override
protected InputStream decorate(final InputStream in, final MessageDigest digest) {
if (failed.get()) {
// Second attempt successful
return in;
}
return new CountingInputStream(in) {
@Override
protected void beforeRead(final int n) throws IOException {
super.beforeRead(n);
if (this.getByteCount() > 1024L * 1024L) {
failed.set(true);
throw new SocketTimeoutException();
}
}
};
}
};
}
return super._getFeature(type);
}
};
session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback());
final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
container.attributes().setRegion("IAD");
final Path test = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final Transfer t = new UploadTransfer(session.getHost(), test, local);
final BytecountStreamListener counter = new BytecountStreamListener();
assertTrue(new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {
@Override
public TransferAction prompt(final TransferItem file) {
return TransferAction.overwrite;
}
}, new DisabledTransferErrorCallback(), new DisabledProgressListener(), counter, new DisabledLoginCallback(), new DisabledNotificationService()) {
}.run(session));
local.delete();
assertTrue(t.isComplete());
assertEquals(content.length, new SwiftAttributesFinderFeature(session).find(test).getSize());
assertEquals(content.length, counter.getRecv(), 0L);
assertEquals(content.length, counter.getSent(), 0L);
assertTrue(failed.get());
new SwiftDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.openstack.SwiftLargeObjectUploadFeature in project cyberduck by iterate-ch.
the class SwiftLargeObjectUploadFeatureTest method testLargeObjectUpload.
@Test
public void testLargeObjectUpload() throws Exception {
// 5L * 1024L * 1024L
final Path home = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.volume, Path.Type.directory));
home.attributes().setRegion("IAD");
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final SwiftRegionService regionService = new SwiftRegionService(session);
final CryptoUploadFeature m = new CryptoUploadFeature<>(session, new SwiftLargeObjectUploadFeature(session, regionService, new SwiftWriteFeature(session, regionService), 5242880L, 5), new SwiftWriteFeature(session, regionService), cryptomator);
final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
final int length = 5242885;
final byte[] content = RandomUtils.nextBytes(length);
IOUtils.write(content, local.getOutputStream(false));
final TransferStatus writeStatus = new TransferStatus();
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
writeStatus.setLength(content.length);
final BytecountStreamListener count = new BytecountStreamListener();
m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), count, writeStatus, null);
assertEquals(content.length, count.getSent());
assertTrue(writeStatus.isComplete());
assertTrue(new CryptoFindFeature(session, new SwiftFindFeature(session), cryptomator).find(test));
assertEquals(content.length, new CryptoListService(session, new SwiftListService(session, regionService), cryptomator).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize());
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final TransferStatus readStatus = new TransferStatus().withLength(content.length);
final InputStream in = new CryptoReadFeature(session, new SwiftReadFeature(session, regionService), cryptomator).read(test, readStatus, new DisabledConnectionCallback());
new StreamCopier(readStatus, readStatus).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
cryptomator.getFeature(session, Delete.class, new SwiftDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
local.delete();
session.close();
}
Aggregations