Cyberduck Mountain Duck CLI

Changeset 20552


Ignore:
Timestamp:
May 19, 2016 8:32:49 PM (2 years ago)
Author:
dkocher
Message:

Add test.

Location:
trunk/backblaze/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/backblaze/src/main/java/ch/cyberduck/core/b2/B2LargeUploadService.java

    r20260 r20552  
    7575    public B2LargeUploadService(final B2Session session, final Long partSize) {
    7676        this(session, new B2PartWriteFeature(session), partSize, PreferencesFactory.get().getInteger("b2.upload.largeobject.concurrency"));
     77    }
     78
     79    public B2LargeUploadService(final B2Session session, final Long partSize, final Integer concurrency) {
     80        this(session, new B2PartWriteFeature(session), partSize, concurrency);
    7781    }
    7882
  • trunk/backblaze/src/test/java/ch/cyberduck/core/b2/B2LargeUploadServiceTest.java

    r20551 r20552  
    2020import ch.cyberduck.core.DisabledConnectionCallback;
    2121import ch.cyberduck.core.DisabledHostKeyCallback;
     22import ch.cyberduck.core.DisabledListProgressListener;
    2223import ch.cyberduck.core.DisabledLoginCallback;
    2324import ch.cyberduck.core.DisabledPasswordStore;
     
    2627import ch.cyberduck.core.Local;
    2728import ch.cyberduck.core.Path;
     29import ch.cyberduck.core.exception.BackgroundException;
    2830import ch.cyberduck.core.features.Delete;
    2931import ch.cyberduck.core.io.BandwidthThrottle;
     
    4547import java.util.Random;
    4648import java.util.UUID;
     49import java.util.concurrent.atomic.AtomicBoolean;
    4750
    4851import static org.junit.Assert.*;
     
    101104        session.close();
    102105    }
     106
     107    @Test
     108    public void testAppendNoPartCompleted() throws Exception {
     109        final B2Session session = new B2Session(
     110                new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
     111                        new Credentials(
     112                                System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")
     113                        )));
     114        session.open(new DisabledHostKeyCallback(), new DisabledTranscriptListener());
     115        session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
     116        final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
     117        final Path test = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
     118        final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
     119        final int length = 100 * 1024 * 1024 + 20 * 1024 * 1024;
     120        final byte[] random = new byte[length];
     121        new Random().nextBytes(random);
     122        IOUtils.write(random, local.getOutputStream(false));
     123        final TransferStatus status = new TransferStatus();
     124        status.setLength(random.length);
     125        final AtomicBoolean interrupt = new AtomicBoolean();
     126        try {
     127            new B2LargeUploadService(session, 100 * 1024L * 1024L, 1).upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener() {
     128                long count;
     129
     130                @Override
     131                public void sent(final long bytes) {
     132                    count += bytes;
     133                    if(count >= 5242880L) {
     134                        throw new RuntimeException();
     135                    }
     136                }
     137            }, status, new DisabledLoginCallback());
     138        }
     139        catch(BackgroundException e) {
     140            // Expected
     141            interrupt.set(true);
     142        }
     143        assertTrue(interrupt.get());
     144        assertEquals(5242880L, status.getOffset(), 0L);
     145        assertFalse(status.isComplete());
     146
     147        final TransferStatus append = new TransferStatus().append(true).length(random.length);
     148        new B2LargeUploadService(session, 100 * 1024L * 1024L, 1).upload(test, local,
     149                new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), append,
     150                new DisabledLoginCallback());
     151        assertEquals(random.length, append.getOffset(), 0L);
     152        assertTrue(append.isComplete());
     153        assertTrue(new B2FindFeature(session).find(test));
     154        assertEquals(random.length, session.list(bucket,
     155                new DisabledListProgressListener()).get(test).attributes().getSize());
     156        final byte[] buffer = new byte[random.length];
     157        final InputStream in = new B2ReadFeature(session).read(test, new TransferStatus());
     158        IOUtils.readFully(in, buffer);
     159        in.close();
     160        assertArrayEquals(random, buffer);
     161        new B2DeleteFeature(session).delete(Collections.<Path>singletonList(test), new DisabledLoginCallback(), new Delete.Callback() {
     162            @Override
     163            public void delete(final Path file) {
     164                //
     165            }
     166        });
     167        local.delete();
     168        session.close();
     169    }
    103170}
Note: See TracChangeset for help on using the changeset viewer.
swiss made software