pjfanning commented on code in PR #522:
URL:
https://github.com/apache/pekko-persistence-r2dbc/pull/522#discussion_r4375806574
##########
core/src/main/scala/org/apache/pekko/persistence/r2dbc/internal/R2dbcExecutor.scala:
##########
@@ -134,7 +134,9 @@ class R2dbcExecutor(
private def nanoTime(): Long =
if (logDbCallsExceedingEnabled) System.nanoTime() else 0L
- private def durationInMicros(startTime: Long): Long = (nanoTime() -
startTime) / 1000
+ // Long.MinValue when disabled, so that `durationMicros >=
logDbCallsExceedingMicros` is never true
+ private def durationInMicros(startTime: Long): Long =
+ if (logDbCallsExceedingEnabled) (nanoTime() - startTime) / 1000 else
Long.MinValue
Review Comment:
Done in a3cb6dc: the enabled branch now uses `System.nanoTime() - startTime`
directly.
##########
core/src/test/scala/org/apache/pekko/persistence/r2dbc/internal/R2dbcExecutorSpec.scala:
##########
@@ -82,6 +84,43 @@ class R2dbcExecutorSpec
"R2dbcExecutor" should {
+ "not log db calls when log-db-calls-exceeding is disabled" in {
+ val executor = new R2dbcExecutor(
+ connectionFactoryProvider,
+ LoggerFactory.getLogger(getClass),
+ logDbCallsExceeding = -1.millis,
+ closeCallsExceeding)(typedSystem.executionContext, typedSystem)
+
+ LoggingTestKit.info("getConnection took").withOccurrences(0).expect {
+ LoggingTestKit.info("Selected").withOccurrences(0).expect {
+ LoggingTestKit.info("DB call completed").withOccurrences(0).expect {
+ executor
+ .select("test")(
+ _.createStatement(s"select col from $table"),
+ row => Row(row.get("col", classOf[String])))
+ .futureValue
+ executor.updateOne("test")(_.createStatement(s"delete from $table
where col = 'x'")).futureValue
+ }
+ }
+ }
+ }
+
+ "log db calls when log-db-calls-exceeding is zero" in {
+ val executor = new R2dbcExecutor(
+ connectionFactoryProvider,
+ LoggerFactory.getLogger(getClass),
+ logDbCallsExceeding = Duration.Zero,
+ closeCallsExceeding)(typedSystem.executionContext, typedSystem)
+
+ LoggingTestKit.info("Selected").expect {
Review Comment:
Done in a3cb6dc: the zero-threshold test now also expects `getConnection
took` (twice, once for the select and once for an `updateOne`) and `DB call
completed`, matching the disabled test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]