Skip to content

Commit

Permalink
[RORDEV-1152] Compile modules test-utils and integration-tests with S…
Browse files Browse the repository at this point in the history
…cala 3.3.3 (#992)
  • Loading branch information
mgoworko authored Apr 8, 2024
1 parent 519e600 commit eaf8088
Show file tree
Hide file tree
Showing 19 changed files with 135 additions and 117 deletions.
16 changes: 9 additions & 7 deletions integration-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ tasks.withType(ScalaCompile).configureEach {

// Add whatever flags you typically add
parameters += [
"-unchecked",
"-Ywarn-macros:after",
"-feature",
"-Ymacro-annotations",
"-Xfatal-warnings",
"-Ywarn-unused",
"-Wunused:nowarn"
"-Wunused:implicits",
"-Wunused:explicits",
"-Wunused:imports",
"-Wunused:locals",
"-Wunused:params",
"-Wunused:privates",
"-Wunused:nowarn",
]

// Finally set the additionalParameters
Expand Down Expand Up @@ -68,8 +70,8 @@ dependencies {
testImplementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.2'
testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
testRuntimeOnly group: 'org.pegdown', name: 'pegdown', version: '1.4.2'
testImplementation group: 'org.scala-lang', name: 'scala-library', version: '2.13.13'
testImplementation group: 'org.scalatest', name: 'scalatest_2.13', version: '3.2.15'
testImplementation group: 'org.scala-lang', name: 'scala3-library_3', version: '3.3.3'
testImplementation group: 'org.scalatest', name: 'scalatest_3', version: '3.2.18'
}

tasks.register('ldapserver', JavaExec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
package tech.beshu.ror.integration.suites

import cats.data.NonEmptyList
import eu.timepit.refined.auto._
import eu.timepit.refined.auto.*
import org.scalatest.concurrent.Eventually
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.{BeforeAndAfterEach, OptionValues}
import tech.beshu.ror.integration.suites.base.support.BaseManyEsClustersIntegrationTest
import tech.beshu.ror.integration.utils.{ESVersionSupportForAnyWordSpecLike, PluginTestSupport, SingletonLdapContainers}
import tech.beshu.ror.utils.containers.SecurityType.RorWithXpackSecurity
import tech.beshu.ror.utils.containers._
import tech.beshu.ror.utils.containers.*
import tech.beshu.ror.utils.containers.EsClusterSettings.positiveInt
import tech.beshu.ror.utils.containers.dependencies.{ldap, wiremock}
import tech.beshu.ror.utils.containers.images.domain.Enabled
import tech.beshu.ror.utils.containers.images.ReadonlyRestWithEnabledXpackSecurityPlugin
Expand All @@ -35,7 +36,7 @@ import ujson.Value.Value

import java.time.{Instant, ZoneOffset}
import java.time.temporal.ChronoUnit
import scala.concurrent.duration._
import scala.concurrent.duration.*
import scala.language.postfixOps

class AdminApiAuthMockSuite
Expand All @@ -59,7 +60,7 @@ class AdminApiAuthMockSuite
def esClusterSettingsCreator(securityType: SecurityType) =
EsClusterSettings.create(
clusterName = "ROR1",
numberOfInstances = 2,
numberOfInstances = positiveInt(2),
securityType = securityType,
nodeDataInitializer = NoOpElasticsearchNodeDataInitializer,
dependentServicesContainers = clusterDependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package tech.beshu.ror.integration.suites

import eu.timepit.refined.auto._
import tech.beshu.ror.integration.suites.base.BaseAdminApiSuite
import tech.beshu.ror.integration.utils.PluginTestSupport
import tech.beshu.ror.utils.containers.EsClusterSettings.positiveInt
import tech.beshu.ror.utils.containers.SecurityType.RorWithXpackSecurity
import tech.beshu.ror.utils.containers.images.ReadonlyRestWithEnabledXpackSecurityPlugin
import tech.beshu.ror.utils.containers.images.domain.Enabled
Expand All @@ -35,7 +35,7 @@ class AdminApiWithDefaultRorIndexSuite
def esClusterSettingsCreator(securityType: SecurityType) =
EsClusterSettings.create(
clusterName = "ROR1",
numberOfInstances = 2,
numberOfInstances = positiveInt(2),
securityType = securityType,
nodeDataInitializer = nodeDataInitializer()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
*/
package tech.beshu.ror.integration.suites

import eu.timepit.refined.auto._
import eu.timepit.refined.auto.*
import org.scalatest.wordspec.AnyWordSpec
import tech.beshu.ror.integration.suites.base.support.{BaseEsClusterIntegrationTest, SingleClientSupport}
import tech.beshu.ror.integration.utils.{ESVersionSupportForAnyWordSpecLike, PluginTestSupport}
import tech.beshu.ror.utils.containers.EsClusterSettings.positiveInt
import tech.beshu.ror.utils.containers.SecurityType.RorWithXpackSecurity
import tech.beshu.ror.utils.containers.images.ReadonlyRestWithEnabledXpackSecurityPlugin
import tech.beshu.ror.utils.containers.{ElasticsearchNodeDataInitializer, EsClusterContainer, EsClusterSettings, SecurityType}
Expand All @@ -42,7 +43,7 @@ class ClusterApiSuite
override lazy val clusterContainer: EsClusterContainer = {
def esClusterSettingsCreator(securityType: SecurityType) = EsClusterSettings.create(
clusterName = "ROR1",
numberOfInstances = 2,
numberOfInstances = positiveInt(2),
securityType = securityType,
nodeDataInitializer = ClusterApiSuite.nodeDataInitializer()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
*/
package tech.beshu.ror.integration.suites

import eu.timepit.refined.auto._
import org.scalatest.BeforeAndAfterAll
import org.scalatest.wordspec.AnyWordSpec
import tech.beshu.ror.integration.suites.base.support.{BaseEsClusterIntegrationTest, SingleClientSupport}
import tech.beshu.ror.integration.utils.{ESVersionSupportForAnyWordSpecLike, PluginTestSupport}
import tech.beshu.ror.utils.containers.*
import tech.beshu.ror.utils.containers.EsClusterSettings.positiveInt
import tech.beshu.ror.utils.containers.SecurityType.RorSecurity
import tech.beshu.ror.utils.containers._
import tech.beshu.ror.utils.containers.images.ReadonlyRestPlugin.Config.{Attributes, InternodeSsl, RestSsl}
import tech.beshu.ror.utils.containers.images.domain.{Enabled, SourceFile}
import tech.beshu.ror.utils.elasticsearch.CatManager
Expand All @@ -46,7 +46,7 @@ class FipsSslSuite
lazy val generalClusterContainer: EsClusterContainer = createLocalClusterContainer(
EsClusterSettings.create(
clusterName = "fips_cluster",
numberOfInstances = 2,
numberOfInstances = positiveInt(2),
securityType = RorSecurity(Attributes.default.copy(
rorConfigFileName = rorConfigFileName,
restSsl = Enabled.Yes(RestSsl.RorFips(SourceFile.RorFile)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package tech.beshu.ror.integration.suites

import eu.timepit.refined.auto._
import monix.execution.atomic.Atomic
import org.scalatest.BeforeAndAfterEach
import org.scalatest.concurrent.Eventually
Expand All @@ -25,8 +24,9 @@ import org.scalatest.wordspec.AnyWordSpec
import tech.beshu.ror.integration.suites.IndexLifecycleManagementApiSuite.{ExamplePolicies, PolicyGenerator}
import tech.beshu.ror.integration.suites.base.support.{BaseEsClusterIntegrationTest, SingleClientSupport}
import tech.beshu.ror.integration.utils.{ESVersionSupportForAnyWordSpecLike, PluginTestSupport}
import tech.beshu.ror.utils.containers.*
import tech.beshu.ror.utils.containers.EsClusterSettings.positiveInt
import tech.beshu.ror.utils.containers.SecurityType.RorWithXpackSecurity
import tech.beshu.ror.utils.containers._
import tech.beshu.ror.utils.containers.images.ReadonlyRestWithEnabledXpackSecurityPlugin
import tech.beshu.ror.utils.elasticsearch.BaseManager.JSON
import tech.beshu.ror.utils.elasticsearch.{ClusterManager, DocumentManager, IndexLifecycleManager, IndexManager}
Expand Down Expand Up @@ -54,9 +54,10 @@ class IndexLifecycleManagementApiSuite
def esClusterSettingsCreator(securityType: SecurityType) = EsClusterSettings.create(
clusterName = "ROR1",
securityType = securityType,
numberOfInstances = 2,
numberOfInstances = positiveInt(2),
nodeDataInitializer = IndexLifecycleManagementApiSuite.nodeDataInitializer()
)

createLocalClusterContainer(
esClusterSettingsCreator(
RorWithXpackSecurity(ReadonlyRestWithEnabledXpackSecurityPlugin.Config.Attributes.default.copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import tech.beshu.ror.integration.suites.base.support.BaseSingleNodeEsClusterTes
import tech.beshu.ror.integration.utils.{ESVersionSupportForAnyWordSpecLike, SingletonPluginTestSupport}
import tech.beshu.ror.utils.elasticsearch.CatManager
import tech.beshu.ror.utils.misc.CustomScalaTestMatchers
import tech.beshu.ror.utils.misc.JwtUtils._
import scala.jdk.CollectionConverters._
import tech.beshu.ror.utils.misc.JwtUtils.*

import scala.jdk.CollectionConverters.*
import scala.language.implicitConversions

//TODO change test names. Current names are copies from old java integration tests
class JwtAuthSuite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class RorStartingSuite extends AnyWordSpec with ESVersionSupportForAnyWordSpecLi
"ROR does not started yet" should {
"return not started response with http code 403" when {
"403 configured" in withTestEsContainerManager(Map(notStartedResponseCodeKey -> "403")) { esContainer =>
testRorStartup(using = esContainer, expectedResponseCode = 403)
testRorStartup(usingManager = esContainer, expectedResponseCode = 403)
}
"no option configured" in withTestEsContainerManager(Map.empty) { esContainer =>
testRorStartup(using = esContainer, expectedResponseCode = 403)
testRorStartup(usingManager = esContainer, expectedResponseCode = 403)
}
}
"return not started response with http code 503" when {
"503 configured" in withTestEsContainerManager(Map(notStartedResponseCodeKey -> "503")) { esContainer =>
testRorStartup(using = esContainer, expectedResponseCode = 503)
testRorStartup(usingManager = esContainer, expectedResponseCode = 503)
}
}
}
Expand All @@ -80,9 +80,9 @@ class RorStartingSuite extends AnyWordSpec with ESVersionSupportForAnyWordSpecLi
}
}

private def testRorStartup(using: TestEsContainerManager, expectedResponseCode: Int): Task[Unit] = {
private def testRorStartup(usingManager: TestEsContainerManager, expectedResponseCode: Int): Task[Unit] = {
for {
restClient <- using.createRestClient
restClient <- usingManager.createRestClient
searchTestResults <- searchTest(client = restClient, searchAttemptsCount = 200)
result <- handleResults(searchTestResults, expectedResponseCode)
} yield result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
package tech.beshu.ror.integration.suites.base

import cats.data.NonEmptyList
import eu.timepit.refined.auto._
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.Eventually
import org.scalatest.wordspec.AnyWordSpec
import tech.beshu.ror.integration.suites.base.support.{BaseEsClusterIntegrationTest, SingleClientSupport}
import tech.beshu.ror.integration.utils.{ESVersionSupportForAnyWordSpecLike, PluginTestSupport}
import tech.beshu.ror.utils.containers.EsClusterSettings.NodeType
import tech.beshu.ror.utils.containers.*
import tech.beshu.ror.utils.containers.EsClusterSettings.{NodeType, positiveInt}
import tech.beshu.ror.utils.containers.SecurityType.{RorSecurity, XPackSecurity}
import tech.beshu.ror.utils.containers._
import tech.beshu.ror.utils.containers.images.{ReadonlyRestPlugin, XpackSecurityPlugin}
import tech.beshu.ror.utils.containers.images.ReadonlyRestPlugin.Config.{InternodeSsl, RestSsl}
import tech.beshu.ror.utils.containers.images.domain.{Enabled, SourceFile}
import tech.beshu.ror.utils.elasticsearch._
import tech.beshu.ror.utils.containers.images.{ReadonlyRestPlugin, XpackSecurityPlugin}
import tech.beshu.ror.utils.elasticsearch.*
import tech.beshu.ror.utils.misc.CustomScalaTestMatchers
import tech.beshu.ror.utils.misc.Resources.getResourceContent

Expand Down Expand Up @@ -57,14 +56,14 @@ trait XpackClusterWithRorNodesAndInternodeSslSuite
restSsl = Enabled.Yes(RestSsl.Ror(SourceFile.RorFile)),
internodeSsl = Enabled.Yes(InternodeSsl.Ror(SourceFile.RorFile))
)),
numberOfInstances = 1
numberOfInstances = positiveInt(1)
),
NodeType(
securityType = XPackSecurity(XpackSecurityPlugin.Config.Attributes.default.copy(
restSslEnabled = true,
internodeSslEnabled = true
)),
numberOfInstances = 2
numberOfInstances = positiveInt(2)
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ trait ESVersionSupportForAnyWordSpecLike extends ESVersionSupport {
string.taggedAs(firstTestTag, otherTestTags: _*)
}

trait ESVersionSupportForAnyFreeSpecLike extends ESVersionSupport {
this: AnyFreeSpecLike =>
trait ESVersionSupportForAnyFreeSpecLike extends ESVersionSupport with AnyFreeSpecLike {

override type T = ResultOfTaggedAsInvocationOnString

Expand Down
31 changes: 16 additions & 15 deletions tests-utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ tasks.withType(ScalaCompile).configureEach {

// Add whatever flags you typically add
parameters += [
"-unchecked",
"-Ywarn-macros:after",
"-feature",
"-Ymacro-annotations",
"-Xfatal-warnings",
"-Ywarn-unused",
"-Wunused:implicits",
"-Wunused:explicits",
"-Wunused:imports",
"-Wunused:locals",
"-Wunused:params",
"-Wunused:privates",
"-Wunused:nowarn"
]

Expand All @@ -45,8 +47,7 @@ tasks.withType(ScalaCompile).configureEach {
}

dependencies {
api group: 'com.github.pathikrit', name: 'better-files_2.13', version: '3.9.2'
api group: 'com.github.cb372', name: 'cats-retry-core_2.13', version: '0.3.2'
api group: 'com.github.pathikrit', name: 'better-files_3', version: '3.9.2'
api group: 'commons-io', name: 'commons-io', version: '2.6'
api group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
api group: 'commons-lang', name: 'commons-lang', version: '2.6'
Expand All @@ -62,17 +63,17 @@ dependencies {
api group: 'io.jsonwebtoken', name: 'jjwt-orgjson', version: '0.11.2'
api group: 'org.jooq', name: 'joor-java-8', version: '0.9.13'
api group: 'com.jayway.jsonpath', name: 'json-path', version: '2.9.0'
api group: 'io.monix', name: 'monix_2.13', version: '3.4.1'
api group: 'com.lihaoyi', name: 'os-lib_2.13', version: '0.9.0'
api group: 'eu.timepit', name: 'refined_2.13', version: '0.10.1'
api group: 'org.scala-lang', name: 'scala-library', version: '2.13.13'
api group: 'org.scala-lang.modules' , name: 'scala-parallel-collections_2.13', version: '1.0.4'
api group: 'com.typesafe.scala-logging', name: 'scala-logging_2.13', version: '3.9.2'
api group: 'org.scalatest', name: 'scalatest_2.13', version: '3.2.9'
api group: 'com.dimafeng', name: 'testcontainers-scala_2.13', version: '0.40.17'
api group: 'io.monix', name: 'monix_3', version: '3.4.1'
api group: 'com.lihaoyi', name: 'os-lib_3', version: '0.9.3'
api group: 'eu.timepit', name: 'refined_3', version: '0.11.1'
api group: 'org.scala-lang', name: 'scala3-library_3', version: '3.3.3'
api group: 'org.scala-lang.modules' , name: 'scala-parallel-collections_3', version: '1.0.4'
api group: 'com.typesafe.scala-logging', name: 'scala-logging_3', version: '3.9.5'
api group: 'org.scalatest', name: 'scalatest_3', version: '3.2.18'
api group: 'com.dimafeng', name: 'testcontainers-scala_3', version: '0.40.17'
api group: 'org.testcontainers', name: 'testcontainers', version: "1.18.3"
api group: 'eu.rekawek.toxiproxy', name: 'toxiproxy-java', version: "2.1.4"
api group: 'com.unboundid', name: 'unboundid-ldapsdk', version: '6.0.11'
api group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'
api group: 'com.lihaoyi', name: 'upickle_2.13', version: '3.1.0'
api group: 'com.lihaoyi', name: 'upickle_3', version: '3.2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy
import tech.beshu.ror.utils.httpclient.RestClient
import tech.beshu.ror.utils.misc.{EsStartupChecker, Version}

import java.util.concurrent.TimeUnit
import scala.concurrent.duration._
import scala.util.Try

class ElasticsearchNodeWaitingStrategy(esVersion: String,
Expand All @@ -35,7 +33,6 @@ class ElasticsearchNodeWaitingStrategy(esVersion: String,
with StrictLogging {

override def waitUntilReady(): Unit = {
implicit val startupThreshold: FiniteDuration = FiniteDuration(startupTimeout.toMillis, TimeUnit.MILLISECONDS)
val client = restClient.runAttempt().fold(throw _, identity)
val checker =
if (Version.greaterOrEqualThan(esVersion, 8, 3, 0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package tech.beshu.ror.utils.containers
import cats.data.NonEmptyList
import com.dimafeng.testcontainers.{Container, SingleContainer}
import eu.timepit.refined.api.Refined
import eu.timepit.refined.auto._
import eu.timepit.refined.numeric.Positive
import monix.eval.{Coeval, Task}
import monix.execution.Scheduler.Implicits.global
Expand All @@ -28,6 +27,8 @@ import tech.beshu.ror.utils.containers.EsClusterSettings.NodeType
import tech.beshu.ror.utils.containers.images.{ReadonlyRestPlugin, ReadonlyRestWithEnabledXpackSecurityPlugin, XpackSecurityPlugin}
import tech.beshu.ror.utils.elasticsearch.ClusterManager

import scala.compiletime.error

class EsClusterContainer private[containers](val esClusterSettings: EsClusterSettings,
val nodeCreators: NonEmptyList[StartedClusterDependencies => EsContainer],
dependencies: List[DependencyDef])
Expand Down Expand Up @@ -130,7 +131,7 @@ object EsClusterSettings {

def create(clusterName: String,
securityType: SecurityType,
numberOfInstances: Int Refined Positive = 1,
numberOfInstances: Int Refined Positive = positiveInt(1),
nodeDataInitializer: ElasticsearchNodeDataInitializer = NoOpElasticsearchNodeDataInitializer,
containerSpecification: ContainerSpecification = ContainerSpecification.empty,
dependentServicesContainers: List[DependencyDef] = Nil,
Expand Down Expand Up @@ -162,7 +163,11 @@ object EsClusterSettings {
}

final case class NodeType(securityType: SecurityType,
numberOfInstances: Int Refined Positive = 1)
numberOfInstances: Int Refined Positive = positiveInt(1))

inline def positiveInt(inline i: Int): Refined[Int, Positive] = {
inline if (i > 0) Refined.unsafeApply(i) else error(s"$i is not positive")
}

}

Expand Down
Loading

0 comments on commit eaf8088

Please sign in to comment.