|
15 | 15 |
|
16 | 16 | package com.spectralogic.ds3client.integration; |
17 | 17 |
|
| 18 | +import com.google.common.collect.ImmutableList; |
18 | 19 | import com.google.common.collect.ImmutableMap; |
19 | 20 | import com.google.common.collect.Lists; |
20 | 21 | import com.spectralogic.ds3client.Ds3Client; |
|
24 | 25 | import com.spectralogic.ds3client.commands.spectrads3.*; |
25 | 26 | import com.spectralogic.ds3client.commands.spectrads3.notifications.*; |
26 | 27 | import com.spectralogic.ds3client.exceptions.Ds3NoMoreRetriesException; |
27 | | -import com.spectralogic.ds3client.helpers.ChecksumFunction; |
28 | | -import com.spectralogic.ds3client.helpers.Ds3ClientHelpers; |
29 | | -import com.spectralogic.ds3client.helpers.FailureEventListener; |
30 | | -import com.spectralogic.ds3client.helpers.FileObjectGetter; |
31 | | -import com.spectralogic.ds3client.helpers.FileObjectPutter; |
32 | | -import com.spectralogic.ds3client.helpers.JobPart; |
33 | | -import com.spectralogic.ds3client.helpers.ObjectCompletedListener; |
| 28 | +import com.spectralogic.ds3client.helpers.*; |
34 | 29 | import com.spectralogic.ds3client.helpers.events.FailureEvent; |
35 | 30 | import com.spectralogic.ds3client.helpers.events.SameThreadEventRunner; |
36 | 31 | import com.spectralogic.ds3client.helpers.options.WriteJobOptions; |
37 | | -import com.spectralogic.ds3client.helpers.strategy.blobstrategy.BlobStrategy; |
38 | | -import com.spectralogic.ds3client.helpers.strategy.blobstrategy.ChunkAttemptRetryBehavior; |
39 | | -import com.spectralogic.ds3client.helpers.strategy.blobstrategy.ChunkAttemptRetryDelayBehavior; |
40 | | -import com.spectralogic.ds3client.helpers.strategy.blobstrategy.ClientDefinedChunkAttemptRetryDelayBehavior; |
41 | | -import com.spectralogic.ds3client.helpers.strategy.blobstrategy.MaxChunkAttemptsRetryBehavior; |
42 | | -import com.spectralogic.ds3client.helpers.strategy.blobstrategy.PutSequentialBlobStrategy; |
| 32 | +import com.spectralogic.ds3client.helpers.strategy.blobstrategy.*; |
43 | 33 | import com.spectralogic.ds3client.helpers.strategy.channelstrategy.ChannelStrategy; |
44 | 34 | import com.spectralogic.ds3client.helpers.strategy.channelstrategy.SequentialFileReaderChannelStrategy; |
45 | | -import com.spectralogic.ds3client.helpers.strategy.transferstrategy.EventDispatcher; |
46 | | -import com.spectralogic.ds3client.helpers.strategy.transferstrategy.EventDispatcherImpl; |
47 | | -import com.spectralogic.ds3client.helpers.strategy.transferstrategy.MaxNumObjectTransferAttemptsDecorator; |
48 | | -import com.spectralogic.ds3client.helpers.strategy.transferstrategy.TransferMethod; |
49 | | -import com.spectralogic.ds3client.helpers.strategy.transferstrategy.TransferRetryDecorator; |
50 | | -import com.spectralogic.ds3client.helpers.strategy.transferstrategy.TransferStrategy; |
51 | | -import com.spectralogic.ds3client.helpers.strategy.transferstrategy.TransferStrategyBuilder; |
52 | | -import com.spectralogic.ds3client.integration.test.helpers.ABMTestHelper; |
53 | | -import com.spectralogic.ds3client.integration.test.helpers.Ds3ClientShimFactory; |
54 | | -import com.spectralogic.ds3client.integration.test.helpers.TempStorageIds; |
55 | | -import com.spectralogic.ds3client.integration.test.helpers.TempStorageUtil; |
| 35 | +import com.spectralogic.ds3client.helpers.strategy.transferstrategy.*; |
| 36 | +import com.spectralogic.ds3client.integration.test.helpers.*; |
| 37 | +import com.spectralogic.ds3client.integration.test.helpers.Ds3ClientShimFactory.ClientFailureType; |
56 | 38 | import com.spectralogic.ds3client.metadata.MetadataAccessImpl; |
57 | 39 | import com.spectralogic.ds3client.models.*; |
| 40 | +import com.spectralogic.ds3client.models.Objects; |
58 | 41 | import com.spectralogic.ds3client.models.bulk.Ds3Object; |
59 | 42 | import com.spectralogic.ds3client.networking.FailedRequestException; |
60 | 43 | import com.spectralogic.ds3client.utils.ByteArraySeekableByteChannel; |
61 | 44 | import com.spectralogic.ds3client.utils.Platform; |
62 | 45 | import com.spectralogic.ds3client.utils.ResourceUtils; |
63 | | - |
64 | | -import com.spectralogic.ds3client.integration.test.helpers.Ds3ClientShimFactory.ClientFailureType; |
65 | | - |
66 | 46 | import com.spectralogic.ds3client.utils.hashing.ChecksumUtils; |
67 | 47 | import com.spectralogic.ds3client.utils.hashing.Hasher; |
68 | 48 | import org.apache.commons.io.FileUtils; |
69 | 49 | import org.apache.commons.io.IOUtils; |
70 | 50 | import org.junit.*; |
| 51 | +import org.slf4j.Logger; |
| 52 | +import org.slf4j.LoggerFactory; |
71 | 53 |
|
72 | 54 | import java.io.BufferedInputStream; |
73 | 55 | import java.io.File; |
|
83 | 65 | import java.nio.file.NoSuchFileException; |
84 | 66 | import java.nio.file.Path; |
85 | 67 | import java.nio.file.Paths; |
86 | | -import java.util.ArrayList; |
87 | | -import java.util.Arrays; |
88 | | -import java.util.Date; |
89 | | -import java.util.List; |
90 | | -import java.util.UUID; |
| 68 | +import java.util.*; |
91 | 69 | import java.util.concurrent.atomic.AtomicBoolean; |
92 | 70 | import java.util.concurrent.atomic.AtomicInteger; |
93 | 71 |
|
94 | | -import com.spectralogic.ds3client.integration.test.helpers.Ds3ClientShim; |
95 | | - |
96 | 72 | import static com.spectralogic.ds3client.integration.Util.RESOURCE_BASE_NAME; |
97 | 73 | import static com.spectralogic.ds3client.integration.Util.deleteAllContents; |
98 | 74 | import static org.hamcrest.Matchers.*; |
99 | 75 | import static org.junit.Assert.*; |
100 | 76 |
|
101 | | -import com.spectralogic.ds3client.helpers.*; |
102 | | - |
103 | | -import org.slf4j.Logger; |
104 | | -import org.slf4j.LoggerFactory; |
105 | | - |
106 | 77 | public class PutJobManagement_Test { |
107 | 78 | private static final Logger LOG = LoggerFactory.getLogger(PutJobManagement_Test.class); |
108 | 79 |
|
@@ -157,6 +128,52 @@ public void nakedS3Put() throws IOException, URISyntaxException { |
157 | 128 | } |
158 | 129 | } |
159 | 130 |
|
| 131 | + @SuppressWarnings("deprecation") |
| 132 | + @Test |
| 133 | + public void nakedS3PutEmptyFile() throws IOException, URISyntaxException { |
| 134 | + try { |
| 135 | + final String fileName = "emptyFile.txt"; |
| 136 | + |
| 137 | + final ByteArraySeekableByteChannel channel = new ByteArraySeekableByteChannel(0); |
| 138 | + final PutObjectResponse putObjectResponse = client.putObject( |
| 139 | + new PutObjectRequest(BUCKET_NAME, fileName, channel, 0)); |
| 140 | + assertThat(putObjectResponse, is(notNullValue())); |
| 141 | + |
| 142 | + final GetBucketResponse request = client.getBucket(new GetBucketRequest(BUCKET_NAME)); |
| 143 | + final ListBucketResult result = request.getListBucketResult(); |
| 144 | + |
| 145 | + assertThat(result.getObjects().size(), is(1)); |
| 146 | + final Contents contents = result.getObjects().get(0); |
| 147 | + assertThat(contents.getKey(), is(fileName)); |
| 148 | + assertThat(contents.getSize(), is((long) 0)); |
| 149 | + } finally { |
| 150 | + deleteAllContents(client, BUCKET_NAME); |
| 151 | + } |
| 152 | + } |
| 153 | + |
| 154 | + @SuppressWarnings("deprecation") |
| 155 | + @Test |
| 156 | + public void nakedS3PutFolder() throws IOException, URISyntaxException { |
| 157 | + try { |
| 158 | + final String fileName = "NakedS3Folder/"; |
| 159 | + |
| 160 | + final ByteArraySeekableByteChannel channel = new ByteArraySeekableByteChannel(0); |
| 161 | + final PutObjectResponse putObjectResponse = client.putObject( |
| 162 | + new PutObjectRequest(BUCKET_NAME, fileName, channel, 0)); |
| 163 | + |
| 164 | + assertThat(putObjectResponse, is(notNullValue())); |
| 165 | + final GetBucketResponse request = client.getBucket(new GetBucketRequest(BUCKET_NAME)); |
| 166 | + final ListBucketResult result = request.getListBucketResult(); |
| 167 | + assertThat(result.getObjects().size(), is(1)); |
| 168 | + |
| 169 | + final Contents contents = result.getObjects().get(0); |
| 170 | + assertThat(contents.getKey(), is(fileName)); |
| 171 | + assertThat(contents.getSize(), is((long) 0)); |
| 172 | + } finally { |
| 173 | + deleteAllContents(client, BUCKET_NAME); |
| 174 | + } |
| 175 | + } |
| 176 | + |
160 | 177 | @Test |
161 | 178 | public void getActiveJobs() throws IOException, URISyntaxException { |
162 | 179 | try { |
@@ -1102,6 +1119,34 @@ private interface ObjectTransferExceptionHandler { |
1102 | 1119 | boolean handleException(final Throwable t); |
1103 | 1120 | } |
1104 | 1121 |
|
| 1122 | + @Test |
| 1123 | + public void testWriteJobWithZeroLengthObject() throws Exception { |
| 1124 | + final Path tempDirectory = Files.createTempDirectory(Paths.get("."), null); |
| 1125 | + final Path tempFile = Files.createTempFile(tempDirectory, "EmptyFile", null); |
| 1126 | + final String fileName = tempFile.getFileName().toString(); |
| 1127 | + |
| 1128 | + try { |
| 1129 | + final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(client); |
| 1130 | + |
| 1131 | + final ImmutableList<Ds3Object> objects = ImmutableList.of(new Ds3Object(fileName, 0)); |
| 1132 | + |
| 1133 | + final Ds3ClientHelpers.Job writeJob = ds3ClientHelpers.startWriteJob(BUCKET_NAME, objects); |
| 1134 | + writeJob.transfer(new FileObjectPutter(tempDirectory)); |
| 1135 | + |
| 1136 | + final GetBucketResponse request = client.getBucket(new GetBucketRequest(BUCKET_NAME)); |
| 1137 | + final ListBucketResult result = request.getListBucketResult(); |
| 1138 | + assertThat(result.getObjects().size(), is(1)); |
| 1139 | + |
| 1140 | + final Contents contents = result.getObjects().get(0); |
| 1141 | + assertThat(contents.getKey(), is(fileName)); |
| 1142 | + assertThat(contents.getSize(), is((long) 0)); |
| 1143 | + |
| 1144 | + } finally { |
| 1145 | + FileUtils.deleteDirectory(tempDirectory.toFile()); |
| 1146 | + deleteAllContents(client, BUCKET_NAME); |
| 1147 | + } |
| 1148 | + } |
| 1149 | + |
1105 | 1150 | @Test |
1106 | 1151 | public void testWriteJobWithRetriesAndUserDefinedChecksum() throws Exception { |
1107 | 1152 | final int maxNumObjectTransferAttempts = 3; |
|
0 commit comments