Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support injected clock #343

Closed
oharaandrew314 opened this issue Jul 21, 2023 · 5 comments · Fixed by #495
Closed

Support injected clock #343

oharaandrew314 opened this issue Jul 21, 2023 · 5 comments · Fixed by #495

Comments

@oharaandrew314
Copy link

It would be nice to be able to inject a clock into the fake server so we can test expiry operations.

@inponomarev
Copy link
Collaborator

Thanks for the suggestion, you are right, that would be a great addition to the mock. Will include this feature into the plan for the autumn term

@inponomarev
Copy link
Collaborator

Clock injection is implemented in version 1.1.3

See README for details

@oharaandrew314
Copy link
Author

oharaandrew314 commented Jul 23, 2024

Does the server need to have the clock updated each time I wish to change the time? Or will the server be reactive to the clock being mutated? For example:

var time = Instant.EPOCH

server.setClock(object: Clock {
  override fun instant() = time
  ...
})

jedis.setex("key1", 20, "v1");
time += Duration.ofSeconds(30)
jedis.exists("key1") shouldBe false

@inponomarev
Copy link
Collaborator

Both approaches are possible, but please mark shared mutable time variable as @Volatile, as it will be read in a separate thread.

@oharaandrew314
Copy link
Author

Oh, I see. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants