use crate::core::{Error, ErrorKind, Lifecycle, Result};
use crate::storage::batch::RawRecordBatch;
use crate::storage::config::{FileConfig, IoUringConfig};
use crate::storage::source::StorageSource;
pub struct IoUringSource {
#[allow(dead_code)]
file_config: FileConfig,
#[allow(dead_code)]
io_config: IoUringConfig,
}
impl IoUringSource {
pub fn new(file_config: FileConfig, io_config: IoUringConfig) -> Self {
Self {
file_config,
io_config,
}
}
}
impl Lifecycle for IoUringSource {
fn init(&mut self) -> Result<()> {
Err(Error::new(
ErrorKind::NotImplemented,
"io_uring backend: feature 'io_uring' is enabled but the backend is not yet \
implemented; use FileSource for now",
))
}
fn shutdown(&mut self) -> Result<()> {
Ok(())
}
}
impl StorageSource for IoUringSource {
fn poll_batch(&mut self, _batch: &mut RawRecordBatch) -> Result<usize> {
Err(Error::new(
ErrorKind::NotImplemented,
"io_uring backend: not yet implemented",
))
}
fn backend_name() -> &'static str {
"io_uring"
}
fn is_exhausted(&self) -> bool {
false
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::storage::batch::RawRecordBatch;
#[test]
fn init_returns_not_implemented() {
let mut src = IoUringSource::new(FileConfig::default(), IoUringConfig::default());
let err = src.init().unwrap_err();
assert_eq!(err.kind(), ErrorKind::NotImplemented);
}
#[test]
fn poll_returns_not_implemented() {
let mut src = IoUringSource::new(FileConfig::default(), IoUringConfig::default());
let mut batch = RawRecordBatch::new(4, 64);
let err = src.poll_batch(&mut batch).unwrap_err();
assert_eq!(err.kind(), ErrorKind::NotImplemented);
}
#[test]
fn backend_name_is_io_uring() {
assert_eq!(IoUringSource::backend_name(), "io_uring");
}
}