Skip to content

Commit fb564d5

Browse files
millemskiiadi
authored andcommitted
Switched some integration test Thread.sleep implementations to use the new waiter. No longer run checkstyle, findbugs or unit tests when using the integration test profile.
1 parent 4190271 commit fb564d5

File tree

18 files changed

+392
-521
lines changed

18 files changed

+392
-521
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,11 @@
549549
<name>doRelease</name>
550550
</property>
551551
</activation>
552+
<properties>
553+
<checkstyle.skip>true</checkstyle.skip>
554+
<findbugs.skip>true</findbugs.skip>
555+
<skip.unit.tests>true</skip.unit.tests>
556+
</properties>
552557
<build>
553558
<plugins>
554559
<plugin>

services/cloudformation/src/it/java/software/amazon/awssdk/services/cloudformation/StackIntegrationTests.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.Assert.assertTrue;
2222
import static org.junit.Assert.fail;
2323

24+
import java.time.Duration;
2425
import java.util.Iterator;
2526
import java.util.List;
2627
import org.junit.AfterClass;
@@ -66,6 +67,7 @@
6667
import software.amazon.awssdk.services.cloudformation.model.StackSummary;
6768
import software.amazon.awssdk.services.cloudformation.model.UpdateStackRequest;
6869
import software.amazon.awssdk.services.cloudformation.model.UpdateStackResponse;
70+
import software.amazon.awssdk.testutils.Waiter;
6971

7072
/**
7173
* Tests of the Stack APIs : CloudFormation
@@ -392,27 +394,9 @@ public void testAlreadyExistsException() {
392394
* the test stack has a status other than this.
393395
*/
394396
private void waitForStackToChangeStatus(StackStatus oldStatus) throws Exception {
395-
long startTime = System.currentTimeMillis();
396-
long timeoutInMinutes = 35;
397-
while (true) {
398-
List<Stack> stacks = cf.describeStacks(DescribeStacksRequest.builder().stackName(testStackName).build())
399-
.stacks();
400-
assertEquals(1, stacks.size());
401-
402-
if (!stacks.get(0).stackStatusString().equalsIgnoreCase(oldStatus.toString())) {
403-
return;
404-
}
405-
406-
System.out.println("Waiting for stack to change out of status " + oldStatus.toString()
407-
+ " (current status: " + stacks.get(0).stackStatus() + ")");
408-
409-
if ((System.currentTimeMillis() - startTime) > (timeoutInMinutes * 1000 * 60)) {
410-
throw new RuntimeException("Waited " + timeoutInMinutes
411-
+ " minutes, but stack never changed status from " + oldStatus.toString());
412-
}
413-
414-
Thread.sleep(1000 * 120);
415-
}
397+
Waiter.run(() -> cf.describeStacks(d -> d.stackName(testStackName)))
398+
.until(r -> r.stacks().size() == 1 && r.stacks().get(0).stackStatus() != oldStatus)
399+
.orFailAfter(Duration.ofMinutes(2));
416400
}
417401

418402
/**

services/cloudwatch/src/it/java/software/amazon/awssdk/services/cloudwatch/CloudWatchIntegrationTest.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import software.amazon.awssdk.core.AmazonServiceException;
3535
import software.amazon.awssdk.core.SdkGlobalTime;
3636
import software.amazon.awssdk.core.auth.StaticCredentialsProvider;
37+
import software.amazon.awssdk.core.regions.Region;
3738
import software.amazon.awssdk.services.cloudwatch.model.Datapoint;
3839
import software.amazon.awssdk.services.cloudwatch.model.DeleteAlarmsRequest;
3940
import software.amazon.awssdk.services.cloudwatch.model.DescribeAlarmHistoryRequest;
@@ -56,6 +57,7 @@
5657
import software.amazon.awssdk.services.cloudwatch.model.PutMetricAlarmRequest;
5758
import software.amazon.awssdk.services.cloudwatch.model.PutMetricDataRequest;
5859
import software.amazon.awssdk.services.cloudwatch.model.SetAlarmStateRequest;
60+
import software.amazon.awssdk.testutils.Waiter;
5961
import software.amazon.awssdk.testutils.service.AwsIntegrationTestBase;
6062
import software.amazon.awssdk.testutils.SdkAsserts;
6163

@@ -75,7 +77,10 @@ public class CloudWatchIntegrationTest extends AwsIntegrationTestBase {
7577
*/
7678
@BeforeClass
7779
public static void setUp() throws IOException {
78-
cloudwatch = CloudWatchClient.builder().credentialsProvider(StaticCredentialsProvider.create(getCredentials())).build();
80+
cloudwatch = CloudWatchClient.builder()
81+
.credentialsProvider(getCredentialsProvider())
82+
.region(Region.US_WEST_2)
83+
.build();
7984
}
8085

8186
/**
@@ -116,20 +121,17 @@ public void put_get_metricdata_list_metric_returns_success() throws
116121
cloudwatch.putMetricData(PutMetricDataRequest.builder()
117122
.namespace("AWS.EC2").metricData(datum).build());
118123

119-
// TODO: get an ETA on the arrival of this data
120-
Thread.sleep(60 * 1000);
121-
122-
GetMetricStatisticsRequest getRequest = GetMetricStatisticsRequest.builder()
123-
.startTime(Instant.now().minus(Duration.ofDays(7)))
124-
.namespace("AWS.EC2")
125-
.period(60 * 60)
126-
.dimensions(Dimension.builder().name("InstanceType").value("m1.small").build())
127-
.metricName(measureName)
128-
.statistics("Average", "Maximum", "Minimum", "Sum")
129-
.endTime(Instant.now())
130-
.build();
131-
GetMetricStatisticsResponse result = cloudwatch
132-
.getMetricStatistics(getRequest);
124+
GetMetricStatisticsResponse result =
125+
Waiter.run(() -> cloudwatch.getMetricStatistics(r -> r.startTime(Instant.now().minus(Duration.ofDays(7)))
126+
.namespace("AWS.EC2")
127+
.period(60 * 60)
128+
.dimensions(Dimension.builder().name("InstanceType")
129+
.value("m1.small").build())
130+
.metricName(measureName)
131+
.statistics("Average", "Maximum", "Minimum", "Sum")
132+
.endTime(Instant.now())))
133+
.until(r -> r.datapoints().size() == 1)
134+
.orFailAfter(Duration.ofMinutes(1));
133135

134136
assertNotNull(result.label());
135137
assertEquals(measureName, result.label());

services/dynamodb/src/it/java/software/amazon/awssdk/services/dynamodb/DynamoServiceIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public void testServiceOperations() throws Exception {
280280
assertTrue(itemResult.item().get("BS").bs().contains(ByteBuffer.wrap(generateByteArray(contentLength + 1))));
281281

282282
// Pause to try and deal with ProvisionedThroughputExceededExceptions
283-
Thread.sleep(1000 * 20);
283+
Thread.sleep(1000 * 5);
284284

285285
// Add some data into the table with binary hash key
286286
ByteBuffer byteBuffer = ByteBuffer.allocate(contentLength * 2);
@@ -314,7 +314,7 @@ public void testServiceOperations() throws Exception {
314314
assertTrue(itemResult.item().get("BS").bs().contains(ByteBuffer.wrap(generateByteArray(contentLength + 1))));
315315

316316
// Pause to try and deal with ProvisionedThroughputExceededExceptions
317-
Thread.sleep(1000 * 20);
317+
Thread.sleep(1000 * 5);
318318

319319
// Load some random data
320320
System.out.println("Loading data...");

services/dynamodb/src/test/java/utils/resources/TestResourceUtils.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
package utils.resources;
1717

18+
import java.time.Duration;
1819
import software.amazon.awssdk.core.AmazonClientException;
20+
import software.amazon.awssdk.testutils.Waiter;
1921
import software.amazon.awssdk.utils.Logger;
2022
import utils.resources.RequiredResources.ResourceCreationPolicy;
2123
import utils.resources.TestResource.ResourceStatus;
@@ -57,17 +59,8 @@ public static void deleteResource(TestResource resource) throws InterruptedExcep
5759
}
5860

5961
public static ResourceStatus waitForFinalizedStatus(TestResource resource) throws InterruptedException {
60-
long startTime = System.currentTimeMillis();
61-
long endTime = startTime + (10 * 60 * 1000);
62-
while (System.currentTimeMillis() < endTime) {
63-
ResourceStatus status = resource.getResourceStatus();
64-
if (status != ResourceStatus.TRANSIENT) {
65-
return status;
66-
}
67-
log.info(() -> "Waiting for " + resource + " to escape the transient state...");
68-
Thread.sleep(1000 * 10);
69-
}
70-
71-
throw new AmazonClientException("Resource never escaped the transient state.");
62+
return Waiter.run(resource::getResourceStatus)
63+
.until(s -> s != ResourceStatus.TRANSIENT)
64+
.orFailAfter(Duration.ofMinutes(5));
7265
}
7366
}

0 commit comments

Comments
 (0)