From affad9fa3b66e45c4b7c0bb2483e959dc0f5341a Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Fri, 23 Jan 2015 19:24:21 -0800 Subject: [PATCH] JCLOUDS-96: JCLOUDS-351: Fix S3 copy if tests Use correct options in testCopyIfUnmodifiedSince, use looser time bounds, and ensure that tests throw HttpResponseException when expected. --- .../java/org/jclouds/s3/S3ClientLiveTest.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java b/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java index 04fd5a3bc7..378eb11cdd 100644 --- a/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java +++ b/apis/s3/src/test/java/org/jclouds/s3/S3ClientLiveTest.java @@ -27,6 +27,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; import java.io.IOException; import java.net.URI; @@ -359,14 +360,13 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest { return etag; } - // TODO: fails on linux and windows public void testCopyIfModifiedSince() throws InterruptedException, ExecutionException, TimeoutException, IOException { String containerName = getContainerName(); String destinationContainer = getContainerName(); try { - Date before = new Date(); + Date before = new Date(System.currentTimeMillis() - 10 * 1000); addToContainerAndValidate(containerName, sourceKey + "mod"); - Date after = new Date(System.currentTimeMillis() + 1000); + Date after = new Date(System.currentTimeMillis() + 10 * 1000); getApi().copyObject(containerName, sourceKey + "mod", destinationContainer, destinationKey, ifSourceModifiedSince(before)); @@ -375,6 +375,7 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest { try { getApi().copyObject(containerName, sourceKey + "mod", destinationContainer, destinationKey, ifSourceModifiedSince(after)); + fail("should have thrown HttpResponseException"); } catch (HttpResponseException ex) { assertEquals(ex.getResponse().getStatusCode(), 412); } @@ -385,15 +386,14 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest { } } - // TODO: fails on linux and windows public void testCopyIfUnmodifiedSince() throws InterruptedException, ExecutionException, TimeoutException, IOException { String containerName = getContainerName(); String destinationContainer = getContainerName(); try { - Date before = new Date(); + Date before = new Date(System.currentTimeMillis() - 10 * 1000); addToContainerAndValidate(containerName, sourceKey + "un"); - Date after = new Date(System.currentTimeMillis() + 1000); + Date after = new Date(System.currentTimeMillis() + 10 * 1000); getApi().copyObject(containerName, sourceKey + "un", destinationContainer, destinationKey, ifSourceUnmodifiedSince(after)); @@ -401,7 +401,8 @@ public class S3ClientLiveTest extends BaseBlobStoreIntegrationTest { try { getApi().copyObject(containerName, sourceKey + "un", destinationContainer, destinationKey, - ifSourceModifiedSince(before)); + ifSourceUnmodifiedSince(before)); + fail("should have thrown HttpResponseException"); } catch (HttpResponseException ex) { assertEquals(ex.getResponse().getStatusCode(), 412); }