Skip to content

Commit adb0727

Browse files
committed
Merge branch 'master' into fix_eject_storage_domain
2 parents 8ecb53f + 7189d97 commit adb0727

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1470
-423
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ The SDK can also be included directly into a Maven or Gradle build. There is als
4141
<dependency>
4242
<groupId>com.spectralogic.ds3</groupId>
4343
<artifactId>ds3-sdk</artifactId>
44-
<version>3.2.4</version>
44+
<version>3.2.5</version>
4545
<!-- <classifier>all</classifier> -->
4646
</dependency>
4747
...
@@ -64,8 +64,8 @@ repositories {
6464
6565
dependencies {
6666
...
67-
compile 'com.spectralogic.ds3:ds3-sdk:3.2.4'
68-
// compile 'com.spectralogic.ds3:ds3-sdk:3.2.4:all'
67+
compile 'com.spectralogic.ds3:ds3-sdk:3.2.5'
68+
// compile 'com.spectralogic.ds3:ds3-sdk:3.2.5:all'
6969
...
7070
}
7171

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
allprojects {
1717
group = 'com.spectralogic.ds3'
18-
version = '3.2.4'
18+
version = '3.2.5'
1919
}
2020

2121
subprojects {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* ****************************************************************************
3+
* Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
package com.spectralogic.ds3client;
17+
18+
public final class IntValue {
19+
private int intValue = 0;
20+
21+
public int increment() {
22+
return ++intValue;
23+
}
24+
25+
public int getValue() {
26+
return intValue;
27+
}
28+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* ****************************************************************************
3+
* Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
package com.spectralogic.ds3client;
17+
18+
import com.google.common.collect.Lists;
19+
import com.spectralogic.ds3client.networking.Headers;
20+
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import java.util.Map;
24+
import java.util.Set;
25+
26+
public class MockedHeaders implements Headers {
27+
private final Map<String, String> headerValues;
28+
29+
public MockedHeaders(final Map<String, String> headerValues) {
30+
this.headerValues = normalizeHeaderValues(headerValues);
31+
}
32+
33+
private static Map<String, String> normalizeHeaderValues(final Map<String, String> headerValues) {
34+
final Map<String, String> headers = new HashMap<>();
35+
for (final Map.Entry<String, String> entry : headerValues.entrySet()) {
36+
headers.put(entry.getKey().toLowerCase(), entry.getValue());
37+
}
38+
return headers;
39+
}
40+
41+
@Override
42+
public List<String> get(final String key) {
43+
return Lists.newArrayList(this.headerValues.get(key.toLowerCase()));
44+
}
45+
46+
@Override
47+
public Set<String> keys() {
48+
return null;
49+
}
50+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* ****************************************************************************
3+
* Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved.
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the "license" file accompanying this file.
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
11+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
* specific language governing permissions and limitations under the License.
13+
* ****************************************************************************
14+
*/
15+
16+
package com.spectralogic.ds3client;
17+
18+
import com.spectralogic.ds3client.networking.Headers;
19+
import com.spectralogic.ds3client.networking.WebResponse;
20+
21+
import org.apache.commons.io.IOUtils;
22+
23+
import java.io.IOException;
24+
import java.io.InputStream;
25+
import java.util.Map;
26+
27+
public class MockedWebResponse implements WebResponse {
28+
private final InputStream responseStream;
29+
private final int statusCode;
30+
private final Headers headers;
31+
32+
public MockedWebResponse(final String responseString, final int statusCode, final Map<String, String> headers) {
33+
this.responseStream = IOUtils.toInputStream(responseString);
34+
this.statusCode = statusCode;
35+
this.headers = new MockedHeaders(headers);
36+
}
37+
38+
@Override
39+
public InputStream getResponseStream() throws IOException {
40+
return this.responseStream;
41+
}
42+
43+
@Override
44+
public int getStatusCode() {
45+
return this.statusCode;
46+
}
47+
48+
@Override
49+
public Headers getHeaders() {
50+
return headers;
51+
}
52+
53+
@Override
54+
public void close() throws IOException {
55+
}
56+
}

ds3-sdk-integration/src/test/java/com/spectralogic/ds3client/integration/GetJobManagement_Test.java

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,23 @@
1818
import com.google.common.collect.Lists;
1919
import com.spectralogic.ds3client.Ds3Client;
2020
import com.spectralogic.ds3client.Ds3ClientImpl;
21+
import com.spectralogic.ds3client.IntValue;
2122
import com.spectralogic.ds3client.commands.DeleteObjectRequest;
2223
import com.spectralogic.ds3client.commands.GetObjectRequest;
2324
import com.spectralogic.ds3client.commands.GetObjectResponse;
2425
import com.spectralogic.ds3client.commands.PutObjectRequest;
2526
import com.spectralogic.ds3client.commands.spectrads3.GetJobSpectraS3Request;
2627
import com.spectralogic.ds3client.commands.spectrads3.GetJobSpectraS3Response;
2728
import com.spectralogic.ds3client.helpers.Ds3ClientHelpers;
29+
import com.spectralogic.ds3client.helpers.FailureEventListener;
2830
import com.spectralogic.ds3client.helpers.FileObjectGetter;
2931
import com.spectralogic.ds3client.helpers.FileObjectPutter;
32+
import com.spectralogic.ds3client.helpers.events.FailureEvent;
3033
import com.spectralogic.ds3client.helpers.options.ReadJobOptions;
3134
import com.spectralogic.ds3client.integration.test.helpers.ABMTestHelper;
3235
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;
3338
import com.spectralogic.ds3client.integration.test.helpers.TempStorageIds;
3439
import com.spectralogic.ds3client.integration.test.helpers.TempStorageUtil;
3540
import com.spectralogic.ds3client.models.ChecksumType;
@@ -61,6 +66,7 @@
6166
import static com.spectralogic.ds3client.integration.Util.RESOURCE_BASE_NAME;
6267
import static com.spectralogic.ds3client.integration.Util.deleteAllContents;
6368
import static org.hamcrest.Matchers.is;
69+
import static org.junit.Assert.assertEquals;
6470
import static org.junit.Assert.assertThat;
6571
import static org.junit.Assert.assertTrue;
6672

@@ -309,4 +315,97 @@ public void testPartialRetriesWithInjectedFailures() throws NoSuchMethodExceptio
309315
deleteBigFileFromBlackPearlBucket();
310316
}
311317
}
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+
}
312411
}

0 commit comments

Comments
 (0)