Skip to content

Commit

Permalink
Merge pull request #292 from DenverM80/get_job_status_timing
Browse files Browse the repository at this point in the history
Fix inverted logic in FolderNameFiler and toDs3Iterable; Add retry he…
  • Loading branch information
rpmoore authored Jul 20, 2016
2 parents bbd5b95 + 91cbae5 commit 98e2092
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.spectralogic.ds3client.helpers.JobRecoveryException;
import com.spectralogic.ds3client.helpers.ObjectCompletedListener;
import com.spectralogic.ds3client.helpers.options.WriteJobOptions;
import com.spectralogic.ds3client.integration.test.helpers.JobStatusHelper;
import com.spectralogic.ds3client.integration.test.helpers.TempStorageIds;
import com.spectralogic.ds3client.integration.test.helpers.TempStorageUtil;
import com.spectralogic.ds3client.models.*;
Expand Down Expand Up @@ -56,7 +57,6 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -218,7 +218,7 @@ public void listContents() throws IOException, SignatureException,
}

@Test
public void getContents() throws IOException, SignatureException, URISyntaxException, XmlProcessingException {
public void getContents() throws IOException, SignatureException, URISyntaxException, XmlProcessingException, InterruptedException {
final String bucketName = "test_get_contents";

try {
Expand All @@ -239,9 +239,7 @@ public SeekableByteChannel buildChannel(final String key) throws IOException {
}
});

final GetJobSpectraS3Response jobResponse = client
.getJobSpectraS3(new GetJobSpectraS3Request(jobId));
assertThat(jobResponse.getMasterObjectListResult().getStatus(), is(JobStatus.COMPLETED));
assertThat(JobStatusHelper.getJobStatusWithRetries(client, jobId, JobStatus.COMPLETED), is(JobStatus.COMPLETED));

} finally {
deleteAllContents(client, bucketName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* ******************************************************************************
* Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* ****************************************************************************
*/

package com.spectralogic.ds3client.integration.test.helpers;

import com.spectralogic.ds3client.Ds3Client;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* ******************************************************************************
* Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* ****************************************************************************
*/

package com.spectralogic.ds3client.integration.test.helpers;

import com.spectralogic.ds3client.Ds3Client;
import com.spectralogic.ds3client.commands.spectrads3.GetJobSpectraS3Request;
import com.spectralogic.ds3client.models.JobStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.UUID;

/**
* This class provides utilities for checking job status
*/
public final class JobStatusHelper {
private JobStatusHelper() {
// pass
}

final private static Logger LOG = LoggerFactory.getLogger(JobStatusHelper.class);

private static final int MAX_RETRIES = 10;
private static final int POLLING_PERIOD_MILLIS = 10;

private static JobStatus actualStatus;

public static JobStatus getJobStatusWithRetries(final Ds3Client client,
final UUID jobId,
final JobStatus expectedStatus) throws IOException, InterruptedException {
final GetJobSpectraS3Request getJobSpectraS3Request = new GetJobSpectraS3Request(jobId);
for (int retry = 0; retry < MAX_RETRIES; retry++) {
actualStatus = client.getJobSpectraS3(getJobSpectraS3Request).getMasterObjectListResult().getStatus();
if (actualStatus == expectedStatus) {
LOG.info("Found expected JobStatus " + expectedStatus + " after " + retry*POLLING_PERIOD_MILLIS + " millis.");
break;
}
LOG.info("Expected JobStatus " + expectedStatus + " but is actually " + actualStatus + " after " + retry*POLLING_PERIOD_MILLIS + " millis.");
Thread.sleep(POLLING_PERIOD_MILLIS);
}
return actualStatus;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* ******************************************************************************
* Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* ****************************************************************************
*/

package com.spectralogic.ds3client.integration.test.helpers;

import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* ******************************************************************************
* Copyright 2014-2016 Spectra Logic Corporation. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* ****************************************************************************
*/

package com.spectralogic.ds3client.integration.test.helpers;

import com.spectralogic.ds3client.Ds3Client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,15 @@ public Iterable<Ds3Object> toDs3Iterable(final Iterable<Contents> objects, final
return FluentIterable.from(objects).filter(new com.google.common.base.Predicate<Contents>() {
@Override
public boolean apply(@Nullable final Contents input) {
return input == null;
return input != null;
}
}).filter(new com.google.common.base.Predicate<Contents>() {
@Override
public boolean apply(@Nullable final Contents input) {
if (filter != null) {
return filter.test(input);
} else {
return false; // do not filter anything if filter is null
return true; // do not filter anything if filter is null
}
}
}).transform(new Function<Contents, Ds3Object>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class FolderNameFilter implements Predicate<Contents> {

@Override
public boolean test(final Contents contents) {
return contents.getKey().endsWith("/");
return !contents.getKey().endsWith("/");
}

public static Predicate<Contents> filter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void filterTest() {
final Contents contents = new Contents();
contents.setKey("name/");

assertTrue(filter.test(contents));
assertFalse(filter.test(contents));
}

@Test
Expand All @@ -39,6 +39,6 @@ public void noFilterTest() {
final Contents contents = new Contents();
contents.setKey("name");

assertFalse(filter.test(contents));
assertTrue(filter.test(contents));
}
}

0 comments on commit 98e2092

Please sign in to comment.