|
34 | 34 | import com.spectralogic.ds3client.models.ChecksumType; |
35 | 35 | import com.spectralogic.ds3client.models.Priority; |
36 | 36 | import com.spectralogic.ds3client.models.bulk.Ds3Object; |
| 37 | +import com.spectralogic.ds3client.models.bulk.PartialDs3Object; |
| 38 | +import com.spectralogic.ds3client.models.common.Range; |
37 | 39 | import com.spectralogic.ds3client.utils.ResourceUtils; |
38 | 40 | import org.apache.commons.io.FileUtils; |
39 | 41 | import org.junit.AfterClass; |
|
44 | 46 |
|
45 | 47 | import java.io.File; |
46 | 48 | import java.io.IOException; |
| 49 | +import java.io.InputStream; |
47 | 50 | import java.lang.reflect.InvocationTargetException; |
48 | 51 | import java.net.URISyntaxException; |
49 | 52 | import java.nio.channels.SeekableByteChannel; |
50 | 53 | import java.nio.channels.WritableByteChannel; |
51 | 54 | import java.nio.file.Files; |
52 | 55 | import java.nio.file.Path; |
53 | 56 | import java.nio.file.Paths; |
54 | | -import java.util.ArrayList; |
55 | | -import java.util.Arrays; |
56 | | -import java.util.List; |
57 | | -import java.util.UUID; |
| 57 | +import java.util.*; |
58 | 58 |
|
59 | 59 | import static com.spectralogic.ds3client.integration.Util.RESOURCE_BASE_NAME; |
60 | 60 | import static com.spectralogic.ds3client.integration.Util.deleteAllContents; |
@@ -140,33 +140,6 @@ public void createReadJob() throws IOException, InterruptedException, URISyntaxE |
140 | 140 | assertThat(jobSpectraS3Response.getStatusCode(), is(200)); |
141 | 141 | } |
142 | 142 |
|
143 | | - private void putBigFile() throws IOException, URISyntaxException { |
144 | | - final String DIR_NAME = "largeFiles/"; |
145 | | - final String[] FILE_NAMES = new String[] { "lesmis-copies.txt" }; |
146 | | - |
147 | | - final Path dirPath = ResourceUtils.loadFileResource(DIR_NAME); |
148 | | - |
149 | | - final List<String> bookTitles = new ArrayList<>(); |
150 | | - final List<Ds3Object> objects = new ArrayList<>(); |
151 | | - for (final String book : FILE_NAMES) { |
152 | | - final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + book); |
153 | | - final long bookSize = Files.size(objPath); |
154 | | - final Ds3Object obj = new Ds3Object(book, bookSize); |
155 | | - |
156 | | - bookTitles.add(book); |
157 | | - objects.add(obj); |
158 | | - } |
159 | | - |
160 | | - final int maxNumBlockAllocationRetries = 1; |
161 | | - final int maxNumObjectTransferAttempts = 3; |
162 | | - final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(client, |
163 | | - maxNumBlockAllocationRetries, |
164 | | - maxNumObjectTransferAttempts); |
165 | | - |
166 | | - final Ds3ClientHelpers.Job writeJob = ds3ClientHelpers.startWriteJob(BUCKET_NAME, objects); |
167 | | - writeJob.transfer(new FileObjectPutter(dirPath)); |
168 | | - } |
169 | | - |
170 | 143 | @Test |
171 | 144 | public void createReadJobWithBigFile() throws IOException, URISyntaxException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { |
172 | 145 | putBigFile(); |
@@ -208,6 +181,34 @@ public void createReadJobWithBigFile() throws IOException, URISyntaxException, N |
208 | 181 | } |
209 | 182 | } |
210 | 183 |
|
| 184 | + private void putBigFile() throws IOException, URISyntaxException { |
| 185 | + final String DIR_NAME = "largeFiles/"; |
| 186 | + final String[] FILE_NAMES = new String[] { "lesmis-copies.txt" }; |
| 187 | + |
| 188 | + final Path dirPath = ResourceUtils.loadFileResource(DIR_NAME); |
| 189 | + |
| 190 | + final List<String> bookTitles = new ArrayList<>(); |
| 191 | + final List<Ds3Object> objects = new ArrayList<>(); |
| 192 | + for (final String book : FILE_NAMES) { |
| 193 | + final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + book); |
| 194 | + final long bookSize = Files.size(objPath); |
| 195 | + final Ds3Object obj = new Ds3Object(book, bookSize); |
| 196 | + |
| 197 | + bookTitles.add(book); |
| 198 | + objects.add(obj); |
| 199 | + } |
| 200 | + |
| 201 | + final int maxNumBlockAllocationRetries = 1; |
| 202 | + final int maxNumObjectTransferAttempts = 3; |
| 203 | + final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(client, |
| 204 | + maxNumBlockAllocationRetries, |
| 205 | + maxNumObjectTransferAttempts); |
| 206 | + |
| 207 | + final Ds3ClientHelpers.Job writeJob = ds3ClientHelpers.startWriteJob(BUCKET_NAME, objects); |
| 208 | + writeJob.transfer(new FileObjectPutter(dirPath)); |
| 209 | + } |
| 210 | + |
| 211 | + |
211 | 212 | @Test |
212 | 213 | public void createReadJobWithPriorityOption() throws IOException, |
213 | 214 | InterruptedException, URISyntaxException { |
@@ -245,4 +246,53 @@ public void createReadJobWithNameAndPriorityOptions() throws IOException, |
245 | 246 | assertThat(jobSpectraS3Response.getMasterObjectListResult().getName(), is("test_job")); |
246 | 247 | assertThat(jobSpectraS3Response.getMasterObjectListResult().getPriority(), is(Priority.LOW)); |
247 | 248 | } |
| 249 | + |
| 250 | + @Test |
| 251 | + public void testPartialRetriesWithInjectedFailures() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException, URISyntaxException { |
| 252 | + putBigFile(); |
| 253 | + |
| 254 | + final String tempPathPrefix = null; |
| 255 | + final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); |
| 256 | + |
| 257 | + try { |
| 258 | + final List<Ds3Object> filesToGet = new ArrayList<>(); |
| 259 | + |
| 260 | + filesToGet.add(new PartialDs3Object("lesmis-copies.txt", Range.byLength(0, 100))); |
| 261 | + |
| 262 | + filesToGet.add(new PartialDs3Object("lesmis-copies.txt", Range.byLength(100, 100))); |
| 263 | + |
| 264 | + final Ds3ClientShim ds3ClientShim = new Ds3ClientShim((Ds3ClientImpl) client); |
| 265 | + |
| 266 | + final int maxNumBlockAllocationRetries = 1; |
| 267 | + final int maxNumObjectTransferAttempts = 3; |
| 268 | + final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3ClientShim, |
| 269 | + maxNumBlockAllocationRetries, |
| 270 | + maxNumObjectTransferAttempts); |
| 271 | + |
| 272 | + final Ds3ClientHelpers.Job job = ds3ClientHelpers.startReadJob(BUCKET_NAME, filesToGet); |
| 273 | + |
| 274 | + job.transfer(new FileObjectGetter(tempDirectory)); |
| 275 | + |
| 276 | + final String DIR_NAME = "largeFiles/"; |
| 277 | + final String FILE_NAME = "lesmis-copies.txt"; |
| 278 | + |
| 279 | + try (final InputStream originalFileStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(DIR_NAME + FILE_NAME)) { |
| 280 | + final byte[] first200Bytes = new byte[200]; |
| 281 | + int numBytesRead = originalFileStream.read(first200Bytes, 0, 200); |
| 282 | + |
| 283 | + assertThat(numBytesRead, is(200)); |
| 284 | + |
| 285 | + try (final InputStream fileReadFromBP = Files.newInputStream(Paths.get(tempDirectory.toString(), "lesmis-copies.txt"))) { |
| 286 | + final byte[] first200BytesFromBP = new byte[200]; |
| 287 | + |
| 288 | + numBytesRead = fileReadFromBP.read(first200BytesFromBP, 0, 200); |
| 289 | + assertThat(numBytesRead, is(200)); |
| 290 | + |
| 291 | + assertTrue(Arrays.equals(first200Bytes, first200BytesFromBP)); |
| 292 | + } |
| 293 | + } |
| 294 | + } finally { |
| 295 | + FileUtils.deleteDirectory(tempDirectory.toFile()); |
| 296 | + } |
| 297 | + } |
248 | 298 | } |
0 commit comments