I’ve open-sourced Timestone, a small Java library that lets you abstract time sources for testable, deterministic time-based logic.
It provides an interfaces `Time` with two implementations `SystemTime` for real system clock, and `MutableTime` that can be advanced programmatically. It lets you control time precisely, without relying on mocking frameworks.
What prompted me to build this is that many large projects (like Apache Kafka and Apache Flink) implement their own internal solutions for time control:
I saw a pattern of duplicated fake clock logic across open source and internal codebases, and decided to make a reusable, standalone alternative.
And, it has been published to Maven Central:
- `io.github.predatorray:timestone-api:1.0.0` for API (optional)
- `io.github.predatorray:timestone-test:1.0.0` for test
I would love feedback on the design, and to hear how others test time-sensitive code.
1 comment
[ 0.12 ms ] story [ 10.4 ms ] threadIt provides an interfaces `Time` with two implementations `SystemTime` for real system clock, and `MutableTime` that can be advanced programmatically. It lets you control time precisely, without relying on mocking frameworks.
What prompted me to build this is that many large projects (like Apache Kafka and Apache Flink) implement their own internal solutions for time control:
- in Kafka: [org.apache.kafka.common.utils.Time](https://github.com/apache/kafka/blob/trunk/clients/src/main/...) - in Flink: [org.apache.flink.util.clock.Clock](https://github.com/apache/flink/blob/master/flink-core/src/m...)
I saw a pattern of duplicated fake clock logic across open source and internal codebases, and decided to make a reusable, standalone alternative.
And, it has been published to Maven Central: - `io.github.predatorray:timestone-api:1.0.0` for API (optional) - `io.github.predatorray:timestone-test:1.0.0` for test
I would love feedback on the design, and to hear how others test time-sensitive code.