Skip to content

Commit

Permalink
Upgrade to JUNIT5 and refactoring (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyanli-amazon committed Mar 31, 2023
1 parent 8b7e3ff commit 210b228
Show file tree
Hide file tree
Showing 21 changed files with 289 additions and 349 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Temporary queues are also automatically deleted if the clients that created them
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>amazon-sqs-java-temporary-queues-client</artifactId>
<version>1.2.4</version>
<version>1.2.5</version>
<type>jar</type>
</dependency>
```
Expand Down
58 changes: 26 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.amazonaws</groupId>
<artifactId>amazon-sqs-java-temporary-queues-client</artifactId>
<version>1.2.4</version>
<version>1.2.5</version>
<name>Amazon SQS Java Temporary Queues Client</name>
<description>An Amazon SQS client that supports creating lightweight, automatically-deleted temporary queues, for use in common messaging patterns such as Request/Response. See http:https://aws.amazon.com/sqs.</description>
<url>https://github.com/awslabs/amazon-sqs-java-temporary-queues-client</url>
Expand All @@ -27,55 +27,39 @@
</developer>
</developers>
<properties>
<aws-java-sdk.version>1.12.128</aws-java-sdk.version>
<aws-java-sdk.version>1.12.438</aws-java-sdk.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.12.128</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
<version>${aws-java-sdk.version}</version>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0-M1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.0-M1</version>
<artifactId>junit-jupiter</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.10.0</version>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.0.2</version>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sts</artifactId>
<version>${aws-java-sdk.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -86,7 +70,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
Expand All @@ -109,6 +93,11 @@
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
Expand All @@ -125,34 +114,39 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<version>3.5.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<!--
TODO-RS: Java 8 is more strict about some javadoc tags.
We'll need to update quite a few to remove this workaround.
-->
<additionalparam>-Xdoclint:none</additionalparam>
<source>8</source>
<doclint>none</doclint>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://aws.oss.sonatype.org</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
package com.amazonaws.services.sqs;

import java.util.Collections;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import com.amazonaws.services.sqs.model.SendMessageRequest;
import com.amazonaws.services.sqs.util.Constants;
import com.amazonaws.services.sqs.util.SQSMessageConsumerBuilder;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import com.amazonaws.services.sqs.model.CreateQueueRequest;
import com.amazonaws.services.sqs.model.Message;
import com.amazonaws.services.sqs.model.QueueDoesNotExistException;
import com.amazonaws.services.sqs.model.SendMessageRequest;
import com.amazonaws.services.sqs.util.Constants;
import com.amazonaws.services.sqs.util.IntegrationTest;
import com.amazonaws.services.sqs.util.SQSMessageConsumer;
import com.amazonaws.services.sqs.util.SQSMessageConsumerBuilder;
import com.amazonaws.services.sqs.util.SQSQueueUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;


public class AmazonSQSIdleQueueDeletingIT extends IntegrationTest {
Expand All @@ -28,15 +30,15 @@ public class AmazonSQSIdleQueueDeletingIT extends IntegrationTest {
private static AmazonSQSRequester requester;
private static AmazonSQSResponder responder;

@Before
@BeforeEach
public void setup() {
client = new AmazonSQSIdleQueueDeletingClient(sqs, queueNamePrefix);
requester = new AmazonSQSRequesterClient(sqs, queueNamePrefix,
Collections.emptyMap(), exceptionHandler);
responder = new AmazonSQSResponderClient(sqs);
}

@After
@AfterEach
public void teardown() {
if (client != null && queueUrl != null) {
try {
Expand Down Expand Up @@ -65,8 +67,8 @@ public void idleQueueIsDeleted() throws InterruptedException {
queueUrl = client.createQueue(createQueueRequest).getQueueUrl();

// May have to wait for up to a minute for the new queue to show up in ListQueues
Assert.assertTrue("Expected queue to be deleted: " + queueUrl,
SQSQueueUtils.awaitQueueDeleted(sqs, queueUrl, 70, TimeUnit.SECONDS));
assertTrue(SQSQueueUtils.awaitQueueDeleted(sqs, queueUrl, 70, TimeUnit.SECONDS),
"Expected queue to be deleted: " + queueUrl);
}

@Test
Expand All @@ -91,7 +93,7 @@ public void updatedHeartBeatTag() throws InterruptedException {

String updatedHeartbeat = getLastHeartbeatTimestamp();

Assert.assertNotEquals(initialHeartBeat, updatedHeartbeat);
assertNotEquals(initialHeartBeat, updatedHeartbeat);
}

private String getLastHeartbeatTimestamp() {
Expand Down Expand Up @@ -121,7 +123,7 @@ public void notUpdatedHeartBeatTag() throws InterruptedException {

String notUpdatedHeartbeat = getLastHeartbeatTimestamp();

Assert.assertEquals(initialHeartBeat, notUpdatedHeartbeat);
assertEquals(initialHeartBeat, notUpdatedHeartbeat);
}

@Test
Expand All @@ -147,8 +149,8 @@ public void recreatingQueues() throws InterruptedException {
// Ensure the original queue is eventually recreated. This becoming true at least once
// indicates that CreateQueue was successfully called, even if it may flip back to false
// on subsequent calls.
Assert.assertTrue("Expected original queue to be recreated: " + queueUrl,
SQSQueueUtils.awaitQueueCreated(sqs, queueUrl, 70, TimeUnit.SECONDS));
assertTrue(SQSQueueUtils.awaitQueueCreated(sqs, queueUrl, 70, TimeUnit.SECONDS),
"Expected original queue to be recreated: " + queueUrl);

// Ensure the user doesn't experience any send or receive failures
user.finish();
Expand All @@ -168,10 +170,10 @@ public void recreatingQueues() throws InterruptedException {
}
});

Assert.assertTrue("Expected original queue to be deleted: " + failoverQueueUrl,
SQSQueueUtils.awaitQueueDeleted(sqs, queueUrl, 70, TimeUnit.SECONDS));
Assert.assertTrue("Expected failover queue to be deleted with the original: " + failoverQueueUrl,
SQSQueueUtils.awaitQueueDeleted(sqs, failoverQueueUrl, 70, TimeUnit.SECONDS));
assertTrue(SQSQueueUtils.awaitQueueDeleted(sqs, queueUrl, 70, TimeUnit.SECONDS),
"Expected original queue to be deleted: " + failoverQueueUrl);
assertTrue(SQSQueueUtils.awaitQueueDeleted(sqs, failoverQueueUrl, 70, TimeUnit.SECONDS),
"Expected failover queue to be deleted with the original: " + failoverQueueUrl);
}

private class QueueUser {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package com.amazonaws.services.sqs;

import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import com.amazonaws.services.sqs.model.Message;
import com.amazonaws.services.sqs.model.SendMessageRequest;
import com.amazonaws.services.sqs.util.Constants;
import com.amazonaws.services.sqs.util.ExceptionAsserter;
import com.amazonaws.services.sqs.util.MockSQS;
import com.amazonaws.services.sqs.util.SQSQueueUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import com.amazonaws.services.sqs.util.Constants;
import org.junit.After;
import org.junit.Test;

import com.amazonaws.services.sqs.model.Message;
import com.amazonaws.services.sqs.model.SendMessageRequest;
import com.amazonaws.services.sqs.util.ExceptionAsserter;
import com.amazonaws.services.sqs.util.MockSQS;
import com.amazonaws.services.sqs.util.SQSQueueUtils;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class AmazonSQSRequesterClientTest {

Expand All @@ -32,15 +30,15 @@ public class AmazonSQSRequesterClientTest {
private final AmazonSQSResponderClient responderClient;

public AmazonSQSRequesterClientTest() {
this.accountPrefix = "http:https://queue.amazon.com/123456789012/";
this.accountPrefix = "https:https://queue.amazon.com/123456789012/";
this.sqs = new MockSQS(accountPrefix);
this.requesterClient = new AmazonSQSRequesterClient(sqs, "RequesterClientQueues",
Collections.emptyMap(),
exceptionHandler);
this.responderClient = new AmazonSQSResponderClient(sqs);
}

@After
@AfterEach
public void tearDown() {
this.exceptionHandler.assertNothingThrown();
}
Expand Down Expand Up @@ -86,14 +84,9 @@ public void timeout() throws TimeoutException, InterruptedException, ExecutionEx
assertEquals(requestMessageBody, requestMessage.getBody());
String responseQueueUrl = requestMessage.getMessageAttributes().get(Constants.RESPONSE_QUEUE_URL_ATTRIBUTE_NAME).getStringValue();
assertNotNull(responseQueueUrl);

// TODO-RS: Junit 5
try {
future.get();
fail();
} catch (ExecutionException e) {
assertThat(e.getCause(), instanceOf(TimeoutException.class));
}

Exception exception = assertThrows(ExecutionException.class, future::get);
assertInstanceOf(TimeoutException.class, exception.getCause());

// Make sure the response queue was deleted
SQSQueueUtils.awaitQueueDeleted(sqs, responseQueueUrl, 70, TimeUnit.SECONDS);
Expand Down
Loading

0 comments on commit 210b228

Please sign in to comment.