Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
102 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
core/src/test/scala/acsgh/metrics/scala/model/RateTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package acsgh.metrics.scala.model | ||
|
||
import java.time.Instant | ||
|
||
import org.scalatest._ | ||
|
||
import scala.collection.immutable.ListMap | ||
import scala.language.reflectiveCalls | ||
|
||
class RateTest extends FlatSpec with Matchers { | ||
|
||
"Rate" should "start at 0" in { | ||
val metric = Rate() | ||
metric.values should be( | ||
ListMap( | ||
"rate" -> 0 | ||
) | ||
) | ||
} | ||
|
||
it should "update" in { | ||
var now = Instant.now().minusSeconds(65) | ||
|
||
val metric = Rate(timeProvider = () => now) | ||
metric.hit(50) | ||
metric.values should be( | ||
ListMap( | ||
"rate" -> 50 | ||
) | ||
) | ||
|
||
now = now.plusSeconds(65) | ||
metric.tick() | ||
metric.hit(10) | ||
metric.values should be( | ||
ListMap( | ||
"rate" -> 10 | ||
) | ||
) | ||
} | ||
|
||
it should "reset" in { | ||
val metric = Rate() | ||
metric.hit(1) | ||
metric.reset() | ||
metric.values should be( | ||
ListMap( | ||
"rate" -> 0 | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters