|
18 | 18 | import com.google.common.collect.Lists; |
19 | 19 | import com.spectralogic.ds3client.Ds3Client; |
20 | 20 | import com.spectralogic.ds3client.Ds3ClientImpl; |
| 21 | +import com.spectralogic.ds3client.IntValue; |
21 | 22 | import com.spectralogic.ds3client.commands.DeleteObjectRequest; |
22 | 23 | import com.spectralogic.ds3client.commands.GetObjectRequest; |
23 | 24 | import com.spectralogic.ds3client.commands.GetObjectResponse; |
24 | 25 | import com.spectralogic.ds3client.commands.PutObjectRequest; |
25 | 26 | import com.spectralogic.ds3client.commands.spectrads3.GetJobSpectraS3Request; |
26 | 27 | import com.spectralogic.ds3client.commands.spectrads3.GetJobSpectraS3Response; |
27 | 28 | import com.spectralogic.ds3client.helpers.Ds3ClientHelpers; |
| 29 | +import com.spectralogic.ds3client.helpers.FailureEventListener; |
28 | 30 | import com.spectralogic.ds3client.helpers.FileObjectGetter; |
29 | 31 | import com.spectralogic.ds3client.helpers.FileObjectPutter; |
| 32 | +import com.spectralogic.ds3client.helpers.events.FailureEvent; |
30 | 33 | import com.spectralogic.ds3client.helpers.options.ReadJobOptions; |
31 | 34 | import com.spectralogic.ds3client.integration.test.helpers.ABMTestHelper; |
32 | 35 | import com.spectralogic.ds3client.integration.test.helpers.Ds3ClientShim; |
| 36 | +import com.spectralogic.ds3client.integration.test.helpers.Ds3ClientShimFactory; |
| 37 | +import com.spectralogic.ds3client.integration.test.helpers.Ds3ClientShimWithFailedChunkAllocation; |
33 | 38 | import com.spectralogic.ds3client.integration.test.helpers.TempStorageIds; |
34 | 39 | import com.spectralogic.ds3client.integration.test.helpers.TempStorageUtil; |
35 | 40 | import com.spectralogic.ds3client.models.ChecksumType; |
|
61 | 66 | import static com.spectralogic.ds3client.integration.Util.RESOURCE_BASE_NAME; |
62 | 67 | import static com.spectralogic.ds3client.integration.Util.deleteAllContents; |
63 | 68 | import static org.hamcrest.Matchers.is; |
| 69 | +import static org.junit.Assert.assertEquals; |
64 | 70 | import static org.junit.Assert.assertThat; |
65 | 71 | import static org.junit.Assert.assertTrue; |
66 | 72 |
|
@@ -309,4 +315,97 @@ public void testPartialRetriesWithInjectedFailures() throws NoSuchMethodExceptio |
309 | 315 | deleteBigFileFromBlackPearlBucket(); |
310 | 316 | } |
311 | 317 | } |
| 318 | + |
| 319 | + @Test |
| 320 | + public void testFiringFailureHandlerWhenGettingChunks() |
| 321 | + throws URISyntaxException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException |
| 322 | + { |
| 323 | + putBigFile(); |
| 324 | + |
| 325 | + final String tempPathPrefix = null; |
| 326 | + final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); |
| 327 | + |
| 328 | + try { |
| 329 | + final IntValue numFailuresRecorded = new IntValue(); |
| 330 | + |
| 331 | + final FailureEventListener failureEventListener = new FailureEventListener() { |
| 332 | + @Override |
| 333 | + public void onFailure(final FailureEvent failureEvent) { |
| 334 | + numFailuresRecorded.increment(); |
| 335 | + assertEquals(FailureEvent.FailureActivity.GettingObject, failureEvent.doingWhat()); |
| 336 | + } |
| 337 | + }; |
| 338 | + |
| 339 | + final Ds3ClientHelpers.Job readJob = createReadJobWithObjectsReadyToTransfer(Ds3ClientShimFactory.ClientFailureType.ChunkAllocation); |
| 340 | + |
| 341 | + readJob.attachFailureEventListener(failureEventListener); |
| 342 | + |
| 343 | + try { |
| 344 | + readJob.transfer(new FileObjectGetter(tempDirectory)); |
| 345 | + } catch (final IOException e) { |
| 346 | + assertEquals(1, numFailuresRecorded.getValue()); |
| 347 | + } |
| 348 | + } finally { |
| 349 | + FileUtils.deleteDirectory(tempDirectory.toFile()); |
| 350 | + deleteBigFileFromBlackPearlBucket(); |
| 351 | + } |
| 352 | + } |
| 353 | + |
| 354 | + private Ds3ClientHelpers.Job createReadJobWithObjectsReadyToTransfer(final Ds3ClientShimFactory.ClientFailureType clientFailureType) |
| 355 | + throws IOException, URISyntaxException, NoSuchMethodException, IllegalAccessException, InvocationTargetException |
| 356 | + { |
| 357 | + final String DIR_NAME = "largeFiles/"; |
| 358 | + final String FILE_NAME = "lesmis-copies.txt"; |
| 359 | + |
| 360 | + final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME); |
| 361 | + final long bookSize = Files.size(objPath); |
| 362 | + final Ds3Object obj = new Ds3Object(FILE_NAME, bookSize); |
| 363 | + |
| 364 | + final Ds3Client ds3Client = Ds3ClientShimFactory.makeWrappedDs3Client(clientFailureType, client); |
| 365 | + |
| 366 | + final int maxNumBlockAllocationRetries = 3; |
| 367 | + final int maxNumObjectTransferAttempts = 3; |
| 368 | + final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3Client, |
| 369 | + maxNumBlockAllocationRetries, |
| 370 | + maxNumObjectTransferAttempts); |
| 371 | + |
| 372 | + final Ds3ClientHelpers.Job readJob = ds3ClientHelpers.startReadJob(BUCKET_NAME, Arrays.asList(obj)); |
| 373 | + |
| 374 | + return readJob; |
| 375 | + } |
| 376 | + |
| 377 | + @Test |
| 378 | + public void testFiringFailureHandlerWhenGettingObject() |
| 379 | + throws URISyntaxException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, IOException |
| 380 | + { |
| 381 | + putBigFile(); |
| 382 | + |
| 383 | + final String tempPathPrefix = null; |
| 384 | + final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); |
| 385 | + |
| 386 | + try { |
| 387 | + final IntValue numFailuresRecorded = new IntValue(); |
| 388 | + |
| 389 | + final FailureEventListener failureEventListener = new FailureEventListener() { |
| 390 | + @Override |
| 391 | + public void onFailure(final FailureEvent failureEvent) { |
| 392 | + numFailuresRecorded.increment(); |
| 393 | + assertEquals(FailureEvent.FailureActivity.GettingObject, failureEvent.doingWhat()); |
| 394 | + } |
| 395 | + }; |
| 396 | + |
| 397 | + final Ds3ClientHelpers.Job readJob = createReadJobWithObjectsReadyToTransfer(Ds3ClientShimFactory.ClientFailureType.GetObject); |
| 398 | + |
| 399 | + readJob.attachFailureEventListener(failureEventListener); |
| 400 | + |
| 401 | + try { |
| 402 | + readJob.transfer(new FileObjectGetter(tempDirectory)); |
| 403 | + } catch (final IOException e) { |
| 404 | + assertEquals(1, numFailuresRecorded.getValue()); |
| 405 | + } |
| 406 | + } finally { |
| 407 | + FileUtils.deleteDirectory(tempDirectory.toFile()); |
| 408 | + deleteBigFileFromBlackPearlBucket(); |
| 409 | + } |
| 410 | + } |
312 | 411 | } |
0 commit comments