Search in sources :

Example 1 with SwiftLargeUploadWriteFeature

use of ch.cyberduck.core.openstack.SwiftLargeUploadWriteFeature in project cyberduck by iterate-ch.

the class SwiftLargeUploadWriteFeatureTest method testWrite.

@Test
public void testWrite() throws Exception {
    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 CryptoWriteFeature feature = new CryptoWriteFeature<>(session, new SwiftLargeUploadWriteFeature(session, regionService, new SwiftSegmentService(session, ".segments-test/")), cryptomator);
    final TransferStatus writeStatus = new TransferStatus();
    final FileHeader header = cryptomator.getFileHeaderCryptor().create();
    writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
    writeStatus.setNonces(new RandomNonceGenerator());
    writeStatus.setLength(-1L);
    final OutputStream out = feature.write(test, writeStatus, new DisabledConnectionCallback());
    final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024);
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    final TransferStatus progress = new TransferStatus();
    final BytecountStreamListener listener = new BytecountStreamListener();
    new StreamCopier(new TransferStatus(), progress).withListener(listener).transfer(in, out);
    assertEquals(content.length, listener.getSent());
    assertTrue(new CryptoFindFeature(session, new SwiftFindFeature(session), cryptomator).find(test));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new CryptoReadFeature(session, new SwiftReadFeature(session, regionService), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    cryptomator.getFeature(session, Delete.class, new SwiftDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
Also used : Delete(ch.cyberduck.core.features.Delete) CryptoWriteFeature(ch.cyberduck.core.cryptomator.features.CryptoWriteFeature) OutputStream(java.io.OutputStream) SwiftSegmentService(ch.cyberduck.core.openstack.SwiftSegmentService) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) SwiftDeleteFeature(ch.cyberduck.core.openstack.SwiftDeleteFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) FileHeader(org.cryptomator.cryptolib.api.FileHeader) SwiftFindFeature(ch.cyberduck.core.openstack.SwiftFindFeature) Path(ch.cyberduck.core.Path) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) SwiftReadFeature(ch.cyberduck.core.openstack.SwiftReadFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RandomNonceGenerator(ch.cyberduck.core.cryptomator.random.RandomNonceGenerator) BytecountStreamListener(ch.cyberduck.core.BytecountStreamListener) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) SwiftRegionService(ch.cyberduck.core.openstack.SwiftRegionService) SwiftLargeUploadWriteFeature(ch.cyberduck.core.openstack.SwiftLargeUploadWriteFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) AbstractSwiftTest(ch.cyberduck.core.openstack.AbstractSwiftTest) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)1 BytecountStreamListener (ch.cyberduck.core.BytecountStreamListener)1 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)1 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)1 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)1 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)1 Path (ch.cyberduck.core.Path)1 CryptoFindFeature (ch.cyberduck.core.cryptomator.features.CryptoFindFeature)1 CryptoReadFeature (ch.cyberduck.core.cryptomator.features.CryptoReadFeature)1 CryptoWriteFeature (ch.cyberduck.core.cryptomator.features.CryptoWriteFeature)1 RandomNonceGenerator (ch.cyberduck.core.cryptomator.random.RandomNonceGenerator)1 Delete (ch.cyberduck.core.features.Delete)1 StreamCopier (ch.cyberduck.core.io.StreamCopier)1 AbstractSwiftTest (ch.cyberduck.core.openstack.AbstractSwiftTest)1 SwiftDeleteFeature (ch.cyberduck.core.openstack.SwiftDeleteFeature)1 SwiftFindFeature (ch.cyberduck.core.openstack.SwiftFindFeature)1 SwiftLargeUploadWriteFeature (ch.cyberduck.core.openstack.SwiftLargeUploadWriteFeature)1 SwiftReadFeature (ch.cyberduck.core.openstack.SwiftReadFeature)1 SwiftRegionService (ch.cyberduck.core.openstack.SwiftRegionService)1 SwiftSegmentService (ch.cyberduck.core.openstack.SwiftSegmentService)1