Skip to content

Commit

Permalink
build: Get rid of some final IntegrationTest deprecation warnings (#1292
Browse files Browse the repository at this point in the history
)

* build: Get rid of some final IntegrationTest deprecation warnings
  • Loading branch information
johanandren authored Aug 6, 2024
1 parent 2540201 commit 5b29692
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 39 deletions.
4 changes: 3 additions & 1 deletion integration-test/aws-api-ec2/aws-api-ec2-tag-based.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

# Note: this seems completely outdated and is not used by CI

echo Running integration tests for aws-api-ec2-tag-based
echo You need to run this from the root folder of the akka-management project

Expand All @@ -17,6 +19,6 @@ sbt bootstrap-demo-aws-api-ec2-tag-based/universal:packageBin
aws s3api create-bucket --bucket $BUCKET --region us-east-1
aws s3 cp bootstrap-demo/aws-api-ec2/target/universal/app.zip s3://$BUCKET/$BUILD_ID/ --acl public-read
# run the actual integration test
sbt bootstrap-demo-aws-api-ec2-tag-based/it:test
sbt bootstrap-demo-aws-api-ec2-tag-based/test
# delete file (save a few cents)
aws s3 rm s3://$BUCKET/$BUILD_ID/app.zip
6 changes: 3 additions & 3 deletions integration-test/aws-api-ec2/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ resolvers += "Akka library repository".at("https://repo.akka.io/maven")

Universal / packageName := "app" // should produce app.zip

libraryDependencies += "com.amazonaws" % "aws-java-sdk-cloudformation" % "1.12.635" % IntegrationTest
libraryDependencies += "com.amazonaws" % "aws-java-sdk-cloudformation" % "1.12.635" % Test

libraryDependencies += "com.amazonaws" % "aws-java-sdk-autoscaling" % "1.12.635" % IntegrationTest
libraryDependencies += "com.amazonaws" % "aws-java-sdk-autoscaling" % "1.12.635" % Test

libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % "2.15.3" // aws SDK depends on insecure jackson

libraryDependencies += "org.scalatest" %% "scalatest" % Dependencies.ScalaTestVersion % IntegrationTest
libraryDependencies += "org.scalatest" %% "scalatest" % Dependencies.ScalaTestVersion % Test
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
/*
* Copyright (C) 2017 Lightbend Inc. <https://www.lightbend.com>
* Copyright (C) 2017-2023 Lightbend Inc. <https://www.lightbend.com>
*/

package akka.cluster.bootstrap

import akka.actor.ActorSystem
import akka.event.Logging
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpRequest
import akka.management.cluster.{ClusterHttpManagementJsonProtocol, ClusterMembers}
import akka.management.cluster.{ ClusterHttpManagementJsonProtocol, ClusterMembers }
import akka.util.ByteString
import com.amazonaws.services.cloudformation.AmazonCloudFormationClientBuilder
import com.amazonaws.services.cloudformation.model._
import com.amazonaws.services.ec2.AmazonEC2ClientBuilder
import com.amazonaws.services.ec2.model.{DescribeInstancesRequest, Filter, Reservation}
import org.scalatest.concurrent.PatienceConfiguration.{Interval, Timeout}
import org.scalatest.concurrent.{Eventually, ScalaFutures}
import org.scalatest.time.{Seconds, Span, SpanSugar}
import com.amazonaws.services.ec2.model.{ DescribeInstancesRequest, Filter, Reservation }
import org.scalatest.concurrent.PatienceConfiguration.{ Interval, Timeout }
import org.scalatest.concurrent.{ Eventually, ScalaFutures }
import org.scalatest.time.{ Seconds, Span, SpanSugar }
import org.scalatest.BeforeAndAfterAll
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import spray.json._

import scala.concurrent.{Await, Future}
import scala.concurrent.{ Await, Future }
import scala.language.postfixOps

trait HttpClient {
Expand All @@ -35,16 +36,21 @@ trait HttpClient {
val http = Http()

def httpGetRequest(url: String): Future[(Int, String)] = {
http.singleRequest(HttpRequest(uri = url))
http
.singleRequest(HttpRequest(uri = url))
.flatMap(r => r.entity.toStrict(3 seconds).map(s => r.status -> s))
.flatMap(t => t._2.dataBytes.runFold(ByteString.empty)(_ ++ _).map(_.utf8String).map(_.filter(_ >= ' '))
.map(r => t._1.intValue() -> r))
.flatMap(t =>
t._2.dataBytes
.runFold(ByteString.empty)(_ ++ _)
.map(_.utf8String)
.map(_.filter(_ >= ' '))
.map(r => t._1.intValue() -> r))
}

}

class IntegrationTest
extends AnyFunSuite
extends AnyFunSuite
with Eventually
with BeforeAndAfterAll
with ScalaFutures
Expand Down Expand Up @@ -83,10 +89,10 @@ class IntegrationTest
// Once the CloudFormation stack has CREATE_COMPLETE status, the EC2 instances are
// still "initializing" (seems to take a very long time) so we add some additional patience for that.
private val clusterBootstrapPatience: PatienceConfig =
PatienceConfig(
timeout = 12 minutes,
interval = 5 seconds
)
PatienceConfig(
timeout = 12 minutes,
interval = 5 seconds
)

private var clusterPublicIps: List[String] = List()

Expand Down Expand Up @@ -124,8 +130,8 @@ class IntegrationTest
def conditions: Boolean = (dsr.getStacks.size() == 1) && {
val stack = dsr.getStacks.get(0)
stack.getStackStatus == StackStatus.CREATE_COMPLETE.toString &&
stack.getOutputs.size() >= 1 &&
stack.getOutputs.asScala.exists(_.getOutputKey == "AutoScalingGroupName")
stack.getOutputs.size() >= 1 &&
stack.getOutputs.asScala.exists(_.getOutputKey == "AutoScalingGroupName")
}

implicit val patienceConfig: PatienceConfig = createStackPatience
Expand All @@ -148,15 +154,14 @@ class IntegrationTest
dsr.getStacks.get(0).getOutputs.asScala.find(_.getOutputKey == "AutoScalingGroupName").get.getOutputValue

val ips: List[(String, String)] = awsEc2Client
.describeInstances(new DescribeInstancesRequest()
.withFilters(new Filter("tag:aws:autoscaling:groupName", List(asgName).asJava)))
.describeInstances(
new DescribeInstancesRequest().withFilters(new Filter("tag:aws:autoscaling:groupName", List(asgName).asJava)))
.getReservations
.asScala
.flatMap((r: Reservation) =>
r.getInstances.asScala.map(instance => (instance.getPublicIpAddress, instance.getPrivateIpAddress)))
.toList
.filter(ips =>
ips._1 != null && ips._2 != null) // TODO: investigate whether there are edge cases that may makes this necessary
.filter(ips => ips._1 != null && ips._2 != null) // TODO: investigate whether there are edge cases that may makes this necessary

clusterPublicIps = ips.map(_._1)
clusterPrivateIps = ips.map(_._2)
Expand Down Expand Up @@ -190,25 +195,27 @@ class IntegrationTest

eventually {

log.info("querying the Cluster Http Management interface of each node, eventually we should see a well formed cluster")
log.info(
"querying the Cluster Http Management interface of each node, eventually we should see a well formed cluster")

clusterPublicIps.foreach { nodeIp => {
clusterPublicIps.foreach { nodeIp =>
{

val result = httpGetRequest(s"http://$nodeIp:8558/cluster/members").futureValue(httpCallTimeout)
result._1 should ===(200)
result._2.nonEmpty should be (true)
val result = httpGetRequest(s"http://$nodeIp:8558/cluster/members").futureValue(httpCallTimeout)
result._1 should ===(200)
result._2.nonEmpty should be(true)

val clusterMembers = result._2.parseJson.convertTo[ClusterMembers]
val clusterMembers = result._2.parseJson.convertTo[ClusterMembers]

clusterMembers.members should have size instanceCount
clusterMembers.members.count(_.status == "Up") should ===(instanceCount)
clusterMembers.members.map(_.node) should ===(expectedNodes)
clusterMembers.members should have size instanceCount
clusterMembers.members.count(_.status == "Up") should ===(instanceCount)
clusterMembers.members.map(_.node) should ===(expectedNodes)

clusterMembers.unreachable.isEmpty should be(true)
clusterMembers.leader shouldBe defined
clusterMembers.oldest shouldBe defined
clusterMembers.unreachable.isEmpty should be(true)
clusterMembers.leader shouldBe defined
clusterMembers.oldest shouldBe defined

}
}
}
}
}
Expand All @@ -225,5 +232,4 @@ class IntegrationTest
system.terminate()
}


}

0 comments on commit 5b29692

Please sign in to comment.