• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 8835565085

25 Apr 2024 03:44PM UTC coverage: 31.613% (-0.06%) from 31.67%
8835565085

Pull #986

CryptoKnightIOG
ATL-6775: integration test + documentation

Signed-off-by: Bassam Riman <bassam.riman@iohk.io>
Pull Request #986: ATL-6775: integration test + documentation

4 of 7 new or added lines in 3 files covered. (57.14%)

357 existing lines in 84 files now uncovered.

4656 of 14728 relevant lines covered (31.61%)

0.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/shared/core/src/main/scala/io/iohk/atala/shared/db/TransactorLayer.scala
1
package io.iohk.atala.shared.db
2

3
import cats.effect.Async
4
import cats.effect.kernel.Resource
5
import cats.effect.std.Dispatcher
6
import com.zaxxer.hikari.HikariConfig
7
import doobie.hikari.HikariTransactor
8
import doobie.util.ExecutionContexts
9
import doobie.util.transactor.Transactor
10
import zio.*
11
import zio.interop.catz.*
12

13
object TransactorLayer {
14

1✔
15
  def task: RLayer[DbConfig, Transactor[Task]] = {
1✔
16
    ZLayer.fromZIO {
×
17
      ZIO.service[DbConfig].flatMap { config =>
18
        // Here we use `Dispatcher.apply`
19
        // but at the agent level it is `Dispatcher.parallel` due to evicted version
×
20
        Dispatcher[Task].allocated.map { case (dispatcher, _) =>
21
          given Dispatcher[Task] = dispatcher
×
22
          TransactorLayer.hikari[Task](config)
23
        }
24
      }
25
    }.flatten
26
  }
27

1✔
UNCOV
28
  def contextAwareTask: RLayer[DbConfig, Transactor[ContextAwareTask]] = {
×
29
    ZLayer.fromZIO {
×
30
      ZIO.service[DbConfig].flatMap { config =>
31
        given Async[ContextAwareTask] = summon[Async[Task]].asInstanceOf
32

33
        // Here we use `Dispatcher.apply`
34
        // but at the agent level it is `Dispatcher.parallel` due to evicted version
×
35
        Dispatcher[ContextAwareTask].allocated.map { case (dispatcher, _) =>
36
          given Dispatcher[ContextAwareTask] = dispatcher
×
37
          TransactorLayer.hikari[ContextAwareTask](config)
38
        }
39
      }
40
    }.flatten
41
  }
42

1✔
43
  def hikari[A[_]: Async: Dispatcher](config: DbConfig)(using tag: Tag[Transactor[A]]): TaskLayer[Transactor[A]] = {
×
44
    val transactorLayerZio = ZIO
45
      .attempt {
46
        // https://github.com/brettwooldridge/HikariCP/wiki/About-Pool-Sizing
47
        val poolSize = (config.awaitConnectionThreads * 2) + 1
×
48
        val hikariConfig = makeHikariConfig(config)
×
49
        hikariConfig.setPoolName("DBPool")
×
50
        hikariConfig.setLeakDetectionThreshold(300000) // 5 mins
×
51
        hikariConfig.setMinimumIdle(poolSize)
×
52
        hikariConfig.setMaximumPoolSize(poolSize) // Both Pool size amd Minimum Idle should same and is recommended
53
        hikariConfig
54
      }
55
      .map { hikariConfig =>
1✔
56
        val pool: Resource[A, Transactor[A]] = for {
57
          // Resource yielding a transactor configured with a bounded connect EC and an unbounded
58
          // transaction EC. Everything will be closed and shut down cleanly after use.
×
59
          ec <- ExecutionContexts.fixedThreadPool[A](config.awaitConnectionThreads) // our connect EC
×
60
          xa <- HikariTransactor.fromHikariConfig[A](hikariConfig, ec)
61
        } yield xa
62

×
63
        pool.toManaged.toLayer[Transactor[A]]
64
      }
65

1✔
66
    ZLayer.fromZIO(transactorLayerZio).flatten
67
  }
68

1✔
69
  private def makeHikariConfig(config: DbConfig): HikariConfig = {
1✔
70
    val hikariConfig = HikariConfig()
71

1✔
72
    hikariConfig.setJdbcUrl(config.jdbcUrl)
1✔
73
    hikariConfig.setUsername(config.username)
1✔
74
    hikariConfig.setPassword(config.password)
1✔
75
    hikariConfig.setAutoCommit(false)
76

1✔
77
    hikariConfig.setDriverClassName("org.postgresql.Driver")
1✔
78
    hikariConfig.addDataSourceProperty("cachePrepStmts", "true")
1✔
79
    hikariConfig.addDataSourceProperty("prepStmtCacheSize", "250")
1✔
80
    hikariConfig.addDataSourceProperty("prepStmtCacheSqlLimit", "2048")
81

82
    hikariConfig
83
  }
84

85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc