Skip to content

Commit 8755154

Browse files
author
sshevchenko
committed
Apply Codacy Production fixes
1 parent 312db34 commit 8755154

File tree

2 files changed

+28
-36
lines changed

2 files changed

+28
-36
lines changed

sequentially-ce-metrics/src/test/scala/com/evolutiongaming/concurrent/MeteredSequentiallyFSpec.scala

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ class MeteredSequentiallyFSpec extends AnyWordSpec with Matchers with ScalaFutur
7070

7171
val results = (task1, task2).tupled.unsafeRunSync()
7272

73-
results._1 shouldEqual "key1-result"
74-
results._2 shouldEqual "key2-result"
73+
val (key1, key2) = results
74+
key1 shouldEqual "key1-result"
75+
key2 shouldEqual "key2-result"
76+
7577
key1Counter.get() shouldEqual 1
7678
key2Counter.get() shouldEqual 1
7779

@@ -100,8 +102,6 @@ class MeteredSequentiallyFSpec extends AnyWordSpec with Matchers with ScalaFutur
100102
Array("test-metrics", "run")
101103
)
102104

103-
queueCount should not be null
104-
runCount should not be null
105105
queueCount.doubleValue() should be >= 0.0
106106
runCount.doubleValue() should be >= 0.0
107107

@@ -161,8 +161,6 @@ class MeteredSequentiallyFSpec extends AnyWordSpec with Matchers with ScalaFutur
161161
Array("test-apply-metrics", "run")
162162
)
163163

164-
queueCount should not be null
165-
runCount should not be null
166164
queueCount.doubleValue() should be >= 0.0
167165
runCount.doubleValue() should be >= 0.0
168166

@@ -265,8 +263,6 @@ class MeteredSequentiallyFSpec extends AnyWordSpec with Matchers with ScalaFutur
265263
Array("name2", "run")
266264
)
267265

268-
count1 should not be null
269-
count2 should not be null
270266
count1.doubleValue() should be >= 0.0
271267
count2.doubleValue() should be >= 0.0
272268

@@ -323,7 +319,6 @@ class MeteredSequentiallyFSpec extends AnyWordSpec with Matchers with ScalaFutur
323319

324320
try {
325321
val metered = factory("test-factory")
326-
metered should not be null
327322

328323
val result = metered.applyF(1)(IO.pure("result")).unsafeRunSync()
329324
result shouldEqual "result"
@@ -379,7 +374,6 @@ class MeteredSequentiallyFSpec extends AnyWordSpec with Matchers with ScalaFutur
379374
Array("factory-test", "run")
380375
)
381376

382-
count should not be null
383377
count.doubleValue() should be >= 0.0
384378

385379
} finally {

sequentially-ce-metrics/src/test/scala/com/evolutiongaming/concurrent/SequentiallyMetricsFSpec.scala

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import io.prometheus.client.CollectorRegistry
66
import org.scalatest.matchers.should.Matchers
77
import org.scalatest.wordspec.AnyWordSpec
88

9+
import java.util.concurrent.atomic.AtomicBoolean
910
import scala.jdk.CollectionConverters.*
11+
import scala.util.Try
1012

1113
class SequentiallyMetricsFSpec extends AnyWordSpec with Matchers {
1214

@@ -18,7 +20,6 @@ class SequentiallyMetricsFSpec extends AnyWordSpec with Matchers {
1820

1921
val metrics = factory("test-name")
2022

21-
metrics should not be null
2223
// Verify it has the expected methods by calling queue
2324
val queueResult = metrics.queue(System.nanoTime())
2425
queueResult shouldBe a[IO[_]]
@@ -80,7 +81,7 @@ class SequentiallyMetricsFSpec extends AnyWordSpec with Matchers {
8081
Array("test-queue", "queue")
8182
)
8283

83-
summary should not be null
84+
Option(summary).isDefined shouldBe true
8485
summary.doubleValue() should be >= 0.0
8586
}
8687

@@ -106,8 +107,8 @@ class SequentiallyMetricsFSpec extends AnyWordSpec with Matchers {
106107
Array("name2", "queue")
107108
)
108109

109-
count1 should not be null
110-
count2 should not be null
110+
Option(count1).isDefined shouldBe true
111+
Option(count2).isDefined shouldBe true
111112
count1.doubleValue() should be >= 0.0
112113
count2.doubleValue() should be >= 0.0
113114
}
@@ -141,7 +142,7 @@ class SequentiallyMetricsFSpec extends AnyWordSpec with Matchers {
141142
Array("test-run", "run")
142143
)
143144

144-
count should not be null
145+
Option(count).isDefined shouldBe true
145146
count.doubleValue() should be >= 0.0
146147
}
147148

@@ -166,8 +167,8 @@ class SequentiallyMetricsFSpec extends AnyWordSpec with Matchers {
166167
Array("name2", "run")
167168
)
168169

169-
count1 should not be null
170-
count2 should not be null
170+
Option(count1).isDefined shouldBe true
171+
Option(count2).isDefined shouldBe true
171172
count1.doubleValue() should be >= 0.0
172173
count2.doubleValue() should be >= 0.0
173174
}
@@ -192,45 +193,40 @@ class SequentiallyMetricsFSpec extends AnyWordSpec with Matchers {
192193

193194
val task = IO.raiseError[String](new RuntimeException("test error"))
194195

195-
// Attempt to run and catch exception
196-
try {
197-
metrics.run(task).unsafeRunSync()
198-
} catch {
199-
case _: RuntimeException => // Expected
200-
}
196+
// Attempt to run and catch exception using Try
197+
val result = Try(metrics.run(task).unsafeRunSync())
198+
result.isFailure shouldBe true
201199

202200
// Note: The current implementation records metrics only on success
203201
// This test documents the current behavior
204-
val count = registry.getSampleValue(
202+
val count = Option(registry.getSampleValue(
205203
"sequentially_time_count",
206204
Array("name", "operation"),
207205
Array("test-error", "run")
208-
)
206+
))
209207

210208
// If exception occurs before flatMap completes, metric may not be recorded
211209
// This is expected behavior based on the implementation
212-
if (count != null) {
213-
count.doubleValue() shouldEqual 0.0
214-
}
210+
count.foreach(_.doubleValue() shouldEqual 0.0)
215211
}
216212

217213
"execute task lazily" in {
218214
val registry = new CollectorRegistry()
219215
val factory = SequentiallyMetricsF.Factory[IO](registry)
220216
val metrics = factory("test-lazy")
221217

222-
var executed = false
218+
val executed = new AtomicBoolean(false)
223219
val task = IO {
224-
executed = true
220+
executed.set(true)
225221
"result"
226222
}
227223

228224
// Task should not execute until run is called
229-
executed shouldBe false
225+
executed.get() shouldBe false
230226

231227
val result = metrics.run(task).unsafeRunSync()
232228

233-
executed shouldBe true
229+
executed.get() shouldBe true
234230
result shouldEqual "result"
235231
}
236232

@@ -258,9 +254,9 @@ class SequentiallyMetricsFSpec extends AnyWordSpec with Matchers {
258254
Array("test-duration", "run")
259255
)
260256

261-
summary should not be null
257+
Option(summary).isDefined shouldBe true
262258
summary.doubleValue() should be > 0.0
263-
summary.doubleValue() should be < duration + 0.1 // Allow some margin
259+
summary.doubleValue() should be < duration + 0.5
264260
}
265261
}
266262

@@ -287,8 +283,8 @@ class SequentiallyMetricsFSpec extends AnyWordSpec with Matchers {
287283
Array("test-integration", "run")
288284
)
289285

290-
queueCount should not be null
291-
runCount should not be null
286+
Option(queueCount).isDefined shouldBe true
287+
Option(runCount).isDefined shouldBe true
292288
queueCount.doubleValue() should be >= 0.0
293289
runCount.doubleValue() should be >= 0.0
294290
}
@@ -317,6 +313,8 @@ class SequentiallyMetricsFSpec extends AnyWordSpec with Matchers {
317313
Array("test-multiple", "run")
318314
)
319315

316+
Option(queueCount).isDefined shouldBe true
317+
Option(runCount).isDefined shouldBe true
320318
queueCount.doubleValue() shouldEqual 10.0
321319
runCount.doubleValue() shouldEqual 10.0
322320
}

0 commit comments

Comments
 (0)