Skip to content

Commit 526eb61

Browse files
committed
Migrate SqlQueuePersistenceTests to new test structure and update SQS client to AWS SDK v2
1 parent 5c827e6 commit 526eb61

File tree

3 files changed

+241
-259
lines changed

3 files changed

+241
-259
lines changed

rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/SqlQueuePersistenceServer.scala

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ package org.elasticmq.rest.sqs
22

33
import org.apache.pekko.actor.{ActorRef, ActorSystem, Props}
44
import org.apache.pekko.util.Timeout
5-
import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials}
6-
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
7-
import com.amazonaws.services.sqs.{AmazonSQS, AmazonSQSClientBuilder}
85
import org.elasticmq.actor.QueueManagerActor
96
import org.elasticmq.actor.queue.QueueEvent
107
import org.elasticmq.actor.reply._
@@ -13,18 +10,23 @@ import org.elasticmq.util.NowProvider
1310
import org.elasticmq.{NodeAddress, StrictSQSLimits}
1411
import org.scalatest.concurrent.ScalaFutures
1512
import org.scalatest.time.{Seconds, Span}
16-
13+
import software.amazon.awssdk.auth.credentials.{AwsBasicCredentials, StaticCredentialsProvider}
14+
import software.amazon.awssdk.regions.Region
15+
import software.amazon.awssdk.services.sqs.{SqsClient => AwsSqsClient}
16+
import org.elasticmq.rest.sqs.client.AwsSdkV2SqsClient
17+
import java.net.URI
1718
import scala.util.Try
1819

1920
trait SqlQueuePersistenceServer extends ScalaFutures {
2021

2122
private val awsAccountId = "123456789012"
2223
private val awsRegion = "elasticmq"
2324

24-
private val actorSystem: ActorSystem = ActorSystem("elasticmq-test")
25+
private val actorSystem: ActorSystem = ActorSystem("elasticmq-test-v2")
2526
private var strictServer: SQSRestServer = _
2627

27-
var client: AmazonSQS = _
28+
var clientV2: AwsSqsClient = _
29+
var testClient: AwsSdkV2SqsClient = _
2830
var store: ActorRef = _
2931

3032
implicit val timeout: Timeout = {
@@ -36,15 +38,18 @@ trait SqlQueuePersistenceServer extends ScalaFutures {
3638

3739
def startServerAndRun(pruneDataOnInit: Boolean)(body: => Unit): Unit = {
3840
startServerAndSetupClient(pruneDataOnInit)
39-
body
40-
stopServerAndClient()
41+
try {
42+
body
43+
} finally {
44+
stopServerAndClient()
45+
}
4146
}
4247

4348
private def startServerAndSetupClient(pruneDataOnInit: Boolean): Unit = {
4449
val persistenceConfig = SqlQueuePersistenceConfig(
4550
enabled = true,
4651
driverClass = "org.h2.Driver",
47-
uri = "jdbc:h2:./elasticmq-h2",
52+
uri = "jdbc:h2:./elasticmq-h2-v2",
4853
pruneDataOnInit = pruneDataOnInit
4954
)
5055

@@ -54,23 +59,26 @@ trait SqlQueuePersistenceServer extends ScalaFutures {
5459
strictServer = SQSRestServerBuilder
5560
.withActorSystem(actorSystem)
5661
.withQueueManagerActor(manager)
57-
.withPort(9321)
58-
.withServerAddress(NodeAddress(port = 9321))
62+
.withPort(9323) // different port to avoid conflicts
63+
.withServerAddress(NodeAddress(port = 9323))
5964
.withAWSAccountId(awsAccountId)
6065
.withAWSRegion(awsRegion)
6166
.start()
6267

6368
(store ? QueueEvent.Restore(manager)).futureValue
6469

65-
client = AmazonSQSClientBuilder
66-
.standard()
67-
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("x", "x")))
68-
.withEndpointConfiguration(new EndpointConfiguration("http://localhost:9321", "us-east-1"))
70+
clientV2 = AwsSqsClient
71+
.builder()
72+
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x")))
73+
.region(Region.EU_CENTRAL_1)
74+
.endpointOverride(new URI("http://localhost:9323"))
6975
.build()
76+
77+
testClient = new AwsSdkV2SqsClient(clientV2)
7078
}
7179

7280
private def stopServerAndClient(): Unit = {
73-
client.shutdown()
74-
Try(strictServer.stopAndWait())
81+
if (clientV2 != null) clientV2.close()
82+
if (strictServer != null) Try(strictServer.stopAndWait())
7583
}
7684
}

rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/SqlQueuePersistenceTest.scala

Lines changed: 0 additions & 242 deletions
This file was deleted.

0 commit comments

Comments
 (0)