Skip to content

Commit 98e2092

Browse files
authored
Merge pull request #292 from DenverM80/get_job_status_timing
Fix inverted logic in FolderNameFiler and toDs3Iterable; Add retry he…
2 parents bbd5b95 + 91cbae5 commit 98e2092

File tree

8 files changed

+110
-10
lines changed

8 files changed

+110
-10
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.spectralogic.ds3client.helpers.JobRecoveryException;
2727
import com.spectralogic.ds3client.helpers.ObjectCompletedListener;
2828
import com.spectralogic.ds3client.helpers.options.WriteJobOptions;
29+
import com.spectralogic.ds3client.integration.test.helpers.JobStatusHelper;
2930
import com.spectralogic.ds3client.integration.test.helpers.TempStorageIds;
3031
import com.spectralogic.ds3client.integration.test.helpers.TempStorageUtil;
3132
import com.spectralogic.ds3client.models.*;
@@ -56,7 +57,6 @@
5657
import java.util.List;
5758
import java.util.Map;
5859
import java.util.UUID;
59-
import java.util.concurrent.TimeUnit;
6060
import java.util.concurrent.atomic.AtomicBoolean;
6161
import java.util.concurrent.atomic.AtomicInteger;
6262

@@ -218,7 +218,7 @@ public void listContents() throws IOException, SignatureException,
218218
}
219219

220220
@Test
221-
public void getContents() throws IOException, SignatureException, URISyntaxException, XmlProcessingException {
221+
public void getContents() throws IOException, SignatureException, URISyntaxException, XmlProcessingException, InterruptedException {
222222
final String bucketName = "test_get_contents";
223223

224224
try {
@@ -239,9 +239,7 @@ public SeekableByteChannel buildChannel(final String key) throws IOException {
239239
}
240240
});
241241

242-
final GetJobSpectraS3Response jobResponse = client
243-
.getJobSpectraS3(new GetJobSpectraS3Request(jobId));
244-
assertThat(jobResponse.getMasterObjectListResult().getStatus(), is(JobStatus.COMPLETED));
242+
assertThat(JobStatusHelper.getJobStatusWithRetries(client, jobId, JobStatus.COMPLETED), is(JobStatus.COMPLETED));
245243

246244
} finally {
247245
deleteAllContents(client, bucketName);

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
116
package com.spectralogic.ds3client.integration.test.helpers;
217

318
import com.spectralogic.ds3client.Ds3Client;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.integration.test.helpers;
17+
18+
import com.spectralogic.ds3client.Ds3Client;
19+
import com.spectralogic.ds3client.commands.spectrads3.GetJobSpectraS3Request;
20+
import com.spectralogic.ds3client.models.JobStatus;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
23+
24+
import java.io.IOException;
25+
import java.util.UUID;
26+
27+
/**
28+
* This class provides utilities for checking job status
29+
*/
30+
public final class JobStatusHelper {
31+
private JobStatusHelper() {
32+
// pass
33+
}
34+
35+
final private static Logger LOG = LoggerFactory.getLogger(JobStatusHelper.class);
36+
37+
private static final int MAX_RETRIES = 10;
38+
private static final int POLLING_PERIOD_MILLIS = 10;
39+
40+
private static JobStatus actualStatus;
41+
42+
public static JobStatus getJobStatusWithRetries(final Ds3Client client,
43+
final UUID jobId,
44+
final JobStatus expectedStatus) throws IOException, InterruptedException {
45+
final GetJobSpectraS3Request getJobSpectraS3Request = new GetJobSpectraS3Request(jobId);
46+
for (int retry = 0; retry < MAX_RETRIES; retry++) {
47+
actualStatus = client.getJobSpectraS3(getJobSpectraS3Request).getMasterObjectListResult().getStatus();
48+
if (actualStatus == expectedStatus) {
49+
LOG.info("Found expected JobStatus " + expectedStatus + " after " + retry*POLLING_PERIOD_MILLIS + " millis.");
50+
break;
51+
}
52+
LOG.info("Expected JobStatus " + expectedStatus + " but is actually " + actualStatus + " after " + retry*POLLING_PERIOD_MILLIS + " millis.");
53+
Thread.sleep(POLLING_PERIOD_MILLIS);
54+
}
55+
return actualStatus;
56+
}
57+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
116
package com.spectralogic.ds3client.integration.test.helpers;
217

318
import java.util.UUID;

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
116
package com.spectralogic.ds3client.integration.test.helpers;
217

318
import com.spectralogic.ds3client.Ds3Client;

ds3-sdk/src/main/java/com/spectralogic/ds3client/helpers/Ds3ClientHelpersImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ public Iterable<Ds3Object> toDs3Iterable(final Iterable<Contents> objects, final
280280
return FluentIterable.from(objects).filter(new com.google.common.base.Predicate<Contents>() {
281281
@Override
282282
public boolean apply(@Nullable final Contents input) {
283-
return input == null;
283+
return input != null;
284284
}
285285
}).filter(new com.google.common.base.Predicate<Contents>() {
286286
@Override
287287
public boolean apply(@Nullable final Contents input) {
288288
if (filter != null) {
289289
return filter.test(input);
290290
} else {
291-
return false; // do not filter anything if filter is null
291+
return true; // do not filter anything if filter is null
292292
}
293293
}
294294
}).transform(new Function<Contents, Ds3Object>() {

ds3-sdk/src/main/java/com/spectralogic/ds3client/helpers/FolderNameFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class FolderNameFilter implements Predicate<Contents> {
2222

2323
@Override
2424
public boolean test(final Contents contents) {
25-
return contents.getKey().endsWith("/");
25+
return !contents.getKey().endsWith("/");
2626
}
2727

2828
public static Predicate<Contents> filter() {

ds3-sdk/src/test/java/com/spectralogic/ds3client/helpers/FolderNameFilter_Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void filterTest() {
2929
final Contents contents = new Contents();
3030
contents.setKey("name/");
3131

32-
assertTrue(filter.test(contents));
32+
assertFalse(filter.test(contents));
3333
}
3434

3535
@Test
@@ -39,6 +39,6 @@ public void noFilterTest() {
3939
final Contents contents = new Contents();
4040
contents.setKey("name");
4141

42-
assertFalse(filter.test(contents));
42+
assertTrue(filter.test(contents));
4343
}
4444
}

0 commit comments

Comments
 (0)