use crate::ack::WriteAck;
use crate::batch::WriteBatch;
use crate::error::SinkError;
pub trait Sink: Send + Sync {
fn write(
&self,
batch: WriteBatch,
) -> impl std::future::Future<Output = Result<WriteAck, SinkError>> + Send;
}
#[cfg(test)]
mod tests {
use super::*;
use crate::batch::{DocOp, WriteOp};
use crate::MemorySink;
use osproxy_core::{ClusterId, Epoch, IndexName, Target};
#[tokio::test]
async fn memory_sink_records_and_acks() {
let sink = MemorySink::new();
let op = WriteOp::new(
Target::new(ClusterId::from("c"), IndexName::from("i")),
DocOp::Index {
id: Some("p:1".to_owned()),
routing: Some("p".to_owned()),
body: bytes::Bytes::from_static(b"{}"),
},
Epoch::new(3),
);
let ack = sink.write(WriteBatch::single(op)).await.unwrap();
assert!(ack.all_succeeded());
assert_eq!(ack.results()[0].id, "p:1");
assert_eq!(sink.recorded().len(), 1);
assert_eq!(sink.recorded()[0].ops()[0].epoch, Epoch::new(3));
}
}