sqlive/
database_test_hooks.rs1use super::*;
5use tokio::sync::mpsc::UnboundedReceiver;
6
7impl<P: Policy> Database<P> {
8 fn checkpointer(&self) -> &WalCheckpointer<P> {
9 self.checkpoints.as_ref().expect("the database has a checkpointer")
10 }
11
12 fn statistics(&self) -> &UpkeepThread<PlannerStatistics<P>> {
13 self.statistics.as_ref().expect("the database keeps its planner's statistics")
14 }
15
16 pub fn checkpoints(&self) -> bool {
18 self.checkpoints.is_some()
19 }
20
21 pub fn fault_checkpoints(
23 &self,
24 fault: impl FnMut() -> Result<(), PolicyError<P>> + Send + 'static,
25 ) {
26 self.checkpointer().fault(fault);
27 }
28
29 pub fn after_checkpoint_copies(&self, step: impl FnMut() + Send + 'static) {
32 self.checkpointer().after_copy(step);
33 }
34
35 pub fn report_checkpoints(&self) -> UnboundedReceiver<crate::WalCheckpoint> {
39 self.checkpointer().report_restarts()
40 }
41
42 pub fn checkpoint_now(&self) -> Result<(), PolicyError<P>> {
44 self.checkpointer().run_now()
45 }
46
47 pub fn report_statistics_runs(&self) -> UnboundedReceiver<()> {
50 self.statistics().report_runs()
51 }
52
53 pub fn observe_next_reader_wait(&self) -> tokio::sync::oneshot::Receiver<()> {
56 self.readers.observe_next_wait()
57 }
58
59 pub fn each_reader(&self, visit: impl FnMut(&mut HostSql<P>)) {
61 self.readers.each(visit);
62 }
63
64 pub fn each_connection(&self, mut visit: impl FnMut(&HostSql<P>)) {
68 self.readers.each(|reader| visit(reader));
69 if let Some(checkpoints) = &self.checkpoints {
70 checkpoints.with_connection(&mut visit);
71 }
72 if let Some(statistics) = &self.statistics {
73 statistics.with_connection(&mut visit);
74 }
75 self.host(|writer| visit(writer));
76 }
77}