Skip to content

Commit

Permalink
Don't start an Elasticsearch container when running MainSuite
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Dumas committed Mar 13, 2024
1 parent 7e1d836 commit 2717cda
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ch.epfl.bluebrain.nexus.delta.sdk.plugin.PluginDef
import ch.epfl.bluebrain.nexus.delta.sourcing.postgres.Doobie._
import ch.epfl.bluebrain.nexus.delta.wiring.DeltaModule
import ch.epfl.bluebrain.nexus.testkit.config.SystemPropertyOverride
import ch.epfl.bluebrain.nexus.testkit.elasticsearch.ElasticSearchContainer
import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite
import ch.epfl.bluebrain.nexus.testkit.postgres.PostgresContainer
import com.typesafe.config.impl.ConfigImpl
Expand Down Expand Up @@ -73,7 +72,7 @@ object MainSuite {
trait Fixture { self: CatsEffectSuite =>

// Overload config via system properties
private def initConfig(postgres: PostgresContainer, elastic: ElasticSearchContainer): IO[Map[String, String]] =
private def initConfig(postgres: PostgresContainer): IO[Map[String, String]] =
IO.blocking {
val resourceTypesFile = Files.createTempFile("resource-types", ".json")
Files.writeString(resourceTypesFile, """["https://neuroshapes.org/Entity"]""")
Expand All @@ -92,12 +91,11 @@ object MainSuite {
"app.defaults.database.access.username" -> PostgresUser,
"app.default.database.access.password" -> PostgresPassword,
"akka.actor.testkit.typed.throw-on-shutdown-timeout" -> "false",
"plugins.elasticsearch.base" -> s"http://${elastic.getHost}:${elastic.getMappedPort(9200)}",
"plugins.elasticsearch.credentials.username" -> "elastic",
"plugins.elasticsearch.credentials.password" -> "password",
"plugins.elasticsearch.indexing-enabled" -> "false",
//TODO Investigate how to remove this property from the config
"plugins.elasticsearch.disable-metrics-projection" -> "true",
"plugins.graph-analytics.enabled" -> "true",
"plugins.graph-analytics.indexing-enabled" -> "false",
"plugins.search.enabled" -> "true",
"plugins.search.indexing.resource-types" -> resourceTypesFile.toString,
"plugins.search.indexing.mapping" -> mappingFile.toString,
Expand All @@ -109,8 +107,7 @@ object MainSuite {
private def resource() =
for {
postgres <- PostgresContainer.resource(PostgresUser, PostgresPassword)
elastic <- ElasticSearchContainer.resource()
_ <- SystemPropertyOverride(initConfig(postgres, elastic))
_ <- SystemPropertyOverride(initConfig(postgres))
} yield ()

val main: IOFixture[Unit] = ResourceSuiteLocalFixture("main", resource())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ class ElasticSearchPluginModule(priority: Int) extends ModuleDef {
config.metricsQuery,
config.prefix,
files.metricsMapping,
files.metricsSettings
files.metricsSettings,
config.indexingEnabled
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ object EventMetricsProjection {
val projectionMetadata: ProjectionMetadata = ProjectionMetadata("system", "event-metrics", None, None)
val eventMetricsIndex: String => IndexLabel = prefix => IndexLabel.unsafe(s"${prefix}_project_metrics")

// We need a value to return to Distage
private val dummy = new EventMetricsProjection {}

/**
* @param metricEncoders
* a set of encoders for all entity
Expand Down Expand Up @@ -52,8 +55,9 @@ object EventMetricsProjection {
queryConfig: QueryConfig,
indexPrefix: String,
metricMappings: MetricsMapping,
metricsSettings: MetricsSettings
): IO[EventMetricsProjection] = {
metricsSettings: MetricsSettings,
indexingEnabled: Boolean
): IO[EventMetricsProjection] = if (indexingEnabled) {
val allEntityTypes = metricEncoders.map(_.entityType).toList

implicit val multiDecoder: MultiDecoder[ProjectScopedMetric] =
Expand All @@ -70,7 +74,7 @@ object EventMetricsProjection {
val createIndex = client.createIndex(index, Some(metricMappings.value), Some(metricsSettings.value)).void

apply(sink, supervisor, metrics, createIndex)
}
} else IO.pure(dummy)

/**
* Test friendly apply method
Expand Down Expand Up @@ -98,7 +102,7 @@ object EventMetricsProjection {
for {
projection <- IO.fromEither(compiledProjection)
_ <- supervisor.run(projection, init)
} yield new EventMetricsProjection {}
} yield dummy
}

}

0 comments on commit 2717cda

Please sign in to comment.