Skip to content

Commit

Permalink
don't use execution context, use the akka one (#4486)
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyhappydan authored Nov 9, 2023
1 parent 5f6cc4b commit 82c5fd0
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import izumi.distage.model.definition.{Id, ModuleDef}
import monix.bio.UIO
import org.slf4j.{Logger, LoggerFactory}

import scala.concurrent.ExecutionContext
import scala.concurrent.duration.DurationInt

/**
Expand All @@ -62,8 +61,6 @@ class DeltaModule(appCfg: AppConfig, config: Config)(implicit classLoader: Class
make[StrictEntity].from { appCfg.http.strictEntityTimeout }
make[ServiceAccount].from { appCfg.serviceAccount.value }

implicit val executionContext: ExecutionContext = ExecutionContext.global

make[Transactors].fromResource { (cs: ContextShift[IO]) =>
Transactors.init(appCfg.database)(classLoader, cs)
}
Expand Down Expand Up @@ -135,8 +132,6 @@ class DeltaModule(appCfg: AppConfig, config: Config)(implicit classLoader: Class
}
Resource.make(make)(release)
}
make[ExecutionContext].from((as: ActorSystem[Nothing]) => as.executionContext)

make[Materializer].from((as: ActorSystem[Nothing]) => SystemMaterializer(as).materializer)
make[Logger].from { LoggerFactory.getLogger("delta") }
make[RejectionHandler].from { (cr: RemoteContextResolution @Id("aggregate"), ordering: JsonKeyOrdering) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors
import izumi.distage.model.definition.{Id, ModuleDef}

import scala.concurrent.ExecutionContext

/**
* Realms module wiring config.
*/
Expand Down Expand Up @@ -53,9 +51,8 @@ object RealmsModule extends ModuleDef {
new RealmsRoutes(identities, realms, aclCheck)(cfg.http.baseUri, cfg.realms.pagination, cr, ordering)
}

make[HttpClient].named("realm").from {
(as: ActorSystem[Nothing], ec: ExecutionContext, timer: Timer[IO], cs: ContextShift[IO]) =>
HttpClient.noRetry(compression = false)(as.classicSystem, ec, timer, cs)
make[HttpClient].named("realm").from { (as: ActorSystem[Nothing], timer: Timer[IO], cs: ContextShift[IO]) =>
HttpClient.noRetry(compression = false)(as.classicSystem, timer, cs)
}

many[SseEncoder[_]].add { base: BaseUri => RealmEvent.sseEncoder(base) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.projections.{ProjectionErrors, Pro
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.{ReferenceRegistry, Supervisor}
import izumi.distage.model.definition.{Id, ModuleDef}

import scala.concurrent.ExecutionContext

/**
* Blazegraph plugin wiring
*/
Expand All @@ -57,11 +55,10 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef {
(
cfg: BlazegraphViewsConfig,
as: ActorSystem[Nothing],
ec: ExecutionContext,
timer: Timer[IO],
cs: ContextShift[IO]
) =>
HttpClient()(cfg.indexingClient, as.classicSystem, ec, timer, cs)
HttpClient()(cfg.indexingClient, as.classicSystem, timer, cs)
}

make[BlazegraphSlowQueryStore].from { (xas: Transactors) =>
Expand Down Expand Up @@ -105,11 +102,10 @@ class BlazegraphPluginModule(priority: Int) extends ModuleDef {
(
cfg: BlazegraphViewsConfig,
as: ActorSystem[Nothing],
ec: ExecutionContext,
timer: Timer[IO],
cs: ContextShift[IO]
) =>
HttpClient()(cfg.queryClient, as.classicSystem, ec, timer, cs)
HttpClient()(cfg.queryClient, as.classicSystem, timer, cs)
}

make[BlazegraphClient].named("blazegraph-query-client").from {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import ch.epfl.bluebrain.nexus.testkit.ce.CatsRunContext
import ch.epfl.bluebrain.nexus.testkit.mu.ce.ResourceFixture
import ch.epfl.bluebrain.nexus.testkit.mu.ce.ResourceFixture.IOFixture

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

object BlazegraphClientSetup extends Fixtures {

def resource()(implicit
ec: ExecutionContext,
timer: Timer[IO],
cs: ContextShift[IO]
): Resource[IO, BlazegraphClient] = {
Expand All @@ -37,7 +35,7 @@ object BlazegraphClientSetup extends Fixtures {

def suiteLocalFixture(
name: String
)(implicit ec: ExecutionContext, timer: Timer[IO], cs: ContextShift[IO]): IOFixture[BlazegraphClient] =
)(implicit timer: Timer[IO], cs: ContextShift[IO]): IOFixture[BlazegraphClient] =
ResourceFixture.suiteLocal(name, resource())

trait Fixture { self: CatsRunContext with BioRunContext =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import io.circe.Json
import org.scalatest.concurrent.Eventually
import org.scalatest.{CancelAfterFailure, DoNotDiscover}

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
import scala.xml.Elem

Expand All @@ -40,7 +39,6 @@ class BlazegraphClientSpec(docker: BlazegraphDocker)
with CancelAfterFailure
with Eventually {

implicit private val sc: ExecutionContext = ExecutionContext.global
implicit private val httpCfg: HttpClientConfig = httpClientConfig
implicit private val api: JsonLdApi = JsonLdJavaApi.strict
implicit private val rcr: RemoteContextResolution = RemoteContextResolution.never
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import org.scalatest.concurrent.Eventually
import org.scalatest.{CancelAfterFailure, DoNotDiscover, Inspectors}

import java.time.Instant
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

@DoNotDiscover
Expand All @@ -65,7 +64,6 @@ class BlazegraphViewsQuerySpec(docker: BlazegraphDocker)
override def apply[A](context: BlazegraphQueryContext, query: IO[A]): IO[A] = query
}

implicit private val ec: ExecutionContext = ExecutionContext.global
implicit private val httpConfig: HttpClientConfig = HttpClientConfig(AlwaysGiveUp, HttpClientWorthRetry.never, false)
implicit private val baseUri: BaseUri = BaseUri("http://localhost", Label.unsafe("v1"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.stream.{PipeChain, ReferenceRegist
import distage.ModuleDef
import izumi.distage.model.definition.Id

import scala.concurrent.ExecutionContext

class CompositeViewsPluginModule(priority: Int) extends ModuleDef {

implicit private val classLoader: ClassLoader = getClass.getClassLoader
Expand All @@ -58,12 +56,11 @@ class CompositeViewsPluginModule(priority: Int) extends ModuleDef {
(
cfg: CompositeViewsConfig,
as: ActorSystem[Nothing],
ec: ExecutionContext,
timer: Timer[IO],
cs: ContextShift[IO],
authTokenProvider: AuthTokenProvider
) =>
val httpClient = HttpClient()(cfg.remoteSourceClient.http, as.classicSystem, ec, timer, cs)
val httpClient = HttpClient()(cfg.remoteSourceClient.http, as.classicSystem, timer, cs)
DeltaClient(httpClient, authTokenProvider, cfg.remoteSourceCredentials, cfg.remoteSourceClient.retryDelay)(
as,
cs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.projections.{ProjectionErrors, Pro
import ch.epfl.bluebrain.nexus.delta.sourcing.stream.{PipeChain, ReferenceRegistry, Supervisor}
import izumi.distage.model.definition.{Id, ModuleDef}

import scala.concurrent.ExecutionContext

/**
* ElasticSearch plugin wiring.
*/
Expand All @@ -56,8 +54,8 @@ class ElasticSearchPluginModule(priority: Int) extends ModuleDef {

make[HttpClient].named("elasticsearch-client").from {
val httpConfig = HttpClientConfig.noRetry(true)
(as: ActorSystem[Nothing], ec: ExecutionContext, timer: Timer[IO], cs: ContextShift[IO]) =>
HttpClient()(httpConfig, as.classicSystem, ec, timer, cs)
(as: ActorSystem[Nothing], timer: Timer[IO], cs: ContextShift[IO]) =>
HttpClient()(httpConfig, as.classicSystem, timer, cs)
}

make[ElasticSearchClient].from {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import ch.epfl.bluebrain.nexus.testkit.mu.ce.ResourceFixture
import ch.epfl.bluebrain.nexus.testkit.mu.ce.ResourceFixture.IOFixture
import munit.Suite

import scala.concurrent.ExecutionContext

object ElasticSearchClientSetup extends CirceLiteral with CatsRunContext with Fixtures {

private val template = jobj"""{
Expand All @@ -29,7 +27,7 @@ object ElasticSearchClientSetup extends CirceLiteral with CatsRunContext with Fi
}
}"""

def resource()(implicit ec: ExecutionContext): Resource[IO, ElasticSearchClient] = {
def resource(): Resource[IO, ElasticSearchClient] = {
for {
(httpClient, actorSystem) <- HttpClientSetup(compression = true)
container <- ElasticSearchContainer.resource()
Expand All @@ -47,7 +45,7 @@ object ElasticSearchClientSetup extends CirceLiteral with CatsRunContext with Fi
client.createIndexTemplate("test_template", template)
}

def suiteLocalFixture(name: String)(implicit ec: ExecutionContext): IOFixture[ElasticSearchClient] =
def suiteLocalFixture(name: String): IOFixture[ElasticSearchClient] =
ResourceFixture.suiteLocal(name, resource())

trait Fixture { self: Suite with BioRunContext =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import org.scalatest.CancelAfterFailure
import org.scalatest.concurrent.Eventually

import java.util.regex.Pattern.quote
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

class SearchSparqlQuerySpec
Expand All @@ -41,7 +40,6 @@ class SearchSparqlQuerySpec

private val searchDocument = contexts + "search-document.json"

implicit private val ec: ExecutionContext = ExecutionContext.global
implicit private val httpCfg: HttpClientConfig = httpClientConfig
implicit private val api: JsonLdApi = JsonLdJavaApi.strict
implicit private val rcr: RemoteContextResolution = RemoteContextResolution.fixed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ import ch.epfl.bluebrain.nexus.delta.sourcing.stream.Supervisor
import com.typesafe.config.Config
import izumi.distage.model.definition.{Id, ModuleDef}

import scala.concurrent.ExecutionContext

/**
* Storages and Files wiring
*/
Expand All @@ -61,9 +59,8 @@ class StoragePluginModule(priority: Int) extends ModuleDef {

make[StorageTypeConfig].from { cfg: StoragePluginConfig => cfg.storages.storageTypeConfig }

make[HttpClient].named("storage").from {
(as: ActorSystem[Nothing], ec: ExecutionContext, timer: Timer[IO], cs: ContextShift[IO]) =>
HttpClient.noRetry(compression = false)(as.classicSystem, ec, timer, cs)
make[HttpClient].named("storage").from { (as: ActorSystem[Nothing], timer: Timer[IO], cs: ContextShift[IO]) =>
HttpClient.noRetry(compression = false)(as.classicSystem, timer, cs)
}

make[Storages]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import ch.epfl.bluebrain.nexus.testkit.scalatest.ce.CatsEffectSpec
import org.scalatest.concurrent.Eventually
import org.scalatest.{BeforeAndAfterAll, DoNotDiscover}

import scala.concurrent.ExecutionContext

@DoNotDiscover
class RemoteDiskStorageAccessSpec(docker: RemoteStorageDocker)
extends TestKit(ActorSystem("RemoteDiskStorageAccessSpec"))
Expand All @@ -32,7 +30,6 @@ class RemoteDiskStorageAccessSpec(docker: RemoteStorageDocker)
with BeforeAndAfterAll
with ConfigFixtures {

implicit private val ec: ExecutionContext = ExecutionContext.global
implicit private val httpConfig: HttpClientConfig = httpClientConfig
private val httpClient: HttpClient = HttpClient()
private val authTokenProvider: AuthTokenProvider = AuthTokenProvider.anonymousForTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ object HttpClient {
final def apply()(implicit
httpConfig: HttpClientConfig,
as: ActorSystem,
ec: ExecutionContext,
timer: Timer[IO],
cs: ContextShift[IO]
): HttpClient = {
Expand All @@ -97,7 +96,7 @@ object HttpClient {
*/
final def noRetry(
compression: Boolean
)(implicit as: ActorSystem, ec: ExecutionContext, timer: Timer[IO], cs: ContextShift[IO]): HttpClient = {
)(implicit as: ActorSystem, timer: Timer[IO], cs: ContextShift[IO]): HttpClient = {
implicit val config: HttpClientConfig = HttpClientConfig.noRetry(compression)
apply()
}
Expand All @@ -107,11 +106,11 @@ object HttpClient {
)(implicit
httpConfig: HttpClientConfig,
as: ActorSystem,
ec: ExecutionContext,
timer: Timer[IO],
cs: ContextShift[IO]
): HttpClient =
new HttpClient {
implicit private val ec: ExecutionContext = as.dispatcher

private def decodeResponse(req: HttpRequest, response: HttpResponse): IO[HttpResponse] = {
val decoder = response.encoding match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import akka.actor.ActorSystem
import cats.effect.{ContextShift, IO, Resource, Timer}
import ch.epfl.bluebrain.nexus.delta.kernel.RetryStrategyConfig

import scala.concurrent.ExecutionContext

object HttpClientSetup {

def apply(
compression: Boolean
)(implicit ec: ExecutionContext, timer: Timer[IO], cs: ContextShift[IO]): Resource[IO, (HttpClient, ActorSystem)] = {
)(implicit timer: Timer[IO], cs: ContextShift[IO]): Resource[IO, (HttpClient, ActorSystem)] = {
implicit val httpConfig: HttpClientConfig =
HttpClientConfig(RetryStrategyConfig.AlwaysGiveUp, HttpClientWorthRetry.never, compression = compression)
Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import org.scalatest.BeforeAndAfterEach
import org.scalatest.concurrent.ScalaFutures

import java.util.concurrent.atomic.AtomicInteger
import scala.concurrent.ExecutionContext
import scala.concurrent.duration._

class HttpClientSpec
Expand All @@ -39,7 +38,6 @@ class HttpClientSpec
with EitherValues {

implicit private val config: HttpClientConfig = HttpClientConfig(OnceStrategyConfig(200.millis), onServerError, false)
implicit private val ec: ExecutionContext = ExecutionContext.global

private val value1 = Value("first", 1, deprecated = false)
private val value2 = Value("second", 2, deprecated = true)
Expand Down

0 comments on commit 82c5fd0

Please sign in to comment.