From f47c7a9d78b2823b87511a816852e4095166f982 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Tue, 11 Jul 2023 13:39:35 +0800 Subject: [PATCH] refactor generic --- sqllogictest-bin/src/main.rs | 6 +++--- sqllogictest/src/connection.rs | 16 +++++--------- sqllogictest/src/runner.rs | 39 +++++++++++++--------------------- 3 files changed, 23 insertions(+), 38 deletions(-) diff --git a/sqllogictest-bin/src/main.rs b/sqllogictest-bin/src/main.rs index aacbd64..df5d0ea 100644 --- a/sqllogictest-bin/src/main.rs +++ b/sqllogictest-bin/src/main.rs @@ -454,7 +454,7 @@ async fn connect_and_run_test_file( /// information. async fn run_test_file( out: &mut T, - mut runner: Runner, + mut runner: Runner, filename: impl AsRef, ) -> Result { let filename = filename.as_ref(); @@ -557,7 +557,7 @@ fn finish_test_file( /// progress information. async fn update_test_file( out: &mut T, - mut runner: Runner, + mut runner: Runner, filename: impl AsRef, format: bool, ) -> Result<()> { @@ -712,7 +712,7 @@ async fn update_test_file( async fn update_record( outfile: &mut File, - runner: &mut Runner, + runner: &mut Runner, record: Record<::ColumnType>, format: bool, ) -> Result<()> { diff --git a/sqllogictest/src/connection.rs b/sqllogictest/src/connection.rs index 9d794df..22bc6eb 100644 --- a/sqllogictest/src/connection.rs +++ b/sqllogictest/src/connection.rs @@ -34,12 +34,12 @@ where } /// Connections established in a [`Runner`](crate::Runner). -pub(crate) struct Connections { +pub(crate) struct Connections { make_conn: M, - conns: HashMap, + conns: HashMap, } -impl Connections { +impl> Connections { pub fn new(make_conn: M) -> Self { Connections { make_conn, @@ -48,10 +48,7 @@ impl Connections { } /// Get a connection by name. Make a new connection if it doesn't exist. - pub async fn get( - &mut self, - name: ConnectionName, - ) -> Result<&mut M::Conn, ::Error> { + pub async fn get(&mut self, name: ConnectionName) -> Result<&mut D, D::Error> { use std::collections::hash_map::Entry; let conn = match self.conns.entry(name) { @@ -68,10 +65,7 @@ impl Connections { /// Run a SQL statement on the default connection. /// /// This is a shortcut for calling `get(Default)` then `run`. - pub async fn run_default( - &mut self, - sql: &str, - ) -> Result::ColumnType>, ::Error> { + pub async fn run_default(&mut self, sql: &str) -> Result, D::Error> { self.get(ConnectionName::Default).await?.run(sql).await } } diff --git a/sqllogictest/src/runner.rs b/sqllogictest/src/runner.rs index afc88ae..ca2e88c 100644 --- a/sqllogictest/src/runner.rs +++ b/sqllogictest/src/runner.rs @@ -451,11 +451,11 @@ pub fn strict_column_validator(actual: &Vec, expected: &Vec } /// Sqllogictest runner. -pub struct Runner { - conn: Connections, +pub struct Runner { + conn: Connections, // validator is used for validate if the result of query equals to expected. validator: Validator, - column_type_validator: ColumnTypeValidator<::ColumnType>, + column_type_validator: ColumnTypeValidator, testdir: Option, sort_mode: Option, /// 0 means never hashing @@ -464,7 +464,7 @@ pub struct Runner { labels: HashSet, } -impl Runner { +impl> Runner { /// Create a new test runner on the database, with the given connection maker. /// /// See [`MakeConnection`] for more details. @@ -497,10 +497,7 @@ impl Runner { self.validator = validator; } - pub fn with_column_validator( - &mut self, - validator: ColumnTypeValidator<::ColumnType>, - ) { + pub fn with_column_validator(&mut self, validator: ColumnTypeValidator) { self.column_type_validator = validator; } @@ -510,8 +507,8 @@ impl Runner { pub async fn apply_record( &mut self, - record: Record<::ColumnType>, - ) -> RecordOutput<::ColumnType> { + record: Record, + ) -> RecordOutput { /// Returns whether we should skip this record, according to given `conditions`. fn should_skip( labels: &HashSet, @@ -651,7 +648,7 @@ impl Runner { } } Record::Sleep { duration, .. } => { - ::sleep(duration).await; + D::sleep(duration).await; RecordOutput::Nothing } Record::Control(control) => match control { @@ -676,10 +673,7 @@ impl Runner { } /// Run a single record. - pub async fn run_async( - &mut self, - record: Record<::ColumnType>, - ) -> Result<(), TestError> { + pub async fn run_async(&mut self, record: Record) -> Result<(), TestError> { tracing::debug!(?record, "testing"); match (record.clone(), self.apply_record(record).await) { @@ -828,10 +822,7 @@ impl Runner { } /// Run a single record. - pub fn run( - &mut self, - record: Record<::ColumnType>, - ) -> Result<(), TestError> { + pub fn run(&mut self, record: Record) -> Result<(), TestError> { futures::executor::block_on(self.run_async(record)) } @@ -840,7 +831,7 @@ impl Runner { /// The runner will stop early once a halt record is seen. pub async fn run_multi_async( &mut self, - records: impl IntoIterator::ColumnType>>, + records: impl IntoIterator>, ) -> Result<(), TestError> { for record in records.into_iter() { if let Record::Halt { .. } = record { @@ -856,7 +847,7 @@ impl Runner { /// The runner will stop early once a halt record is seen. pub fn run_multi( &mut self, - records: impl IntoIterator::ColumnType>>, + records: impl IntoIterator>, ) -> Result<(), TestError> { block_on(self.run_multi_async(records)) } @@ -912,7 +903,7 @@ impl Runner { jobs: usize, ) -> Result<(), ParallelTestError> where - Fut: Future, + Fut: Future, { let files = glob::glob(glob).expect("failed to read glob pattern"); let mut tasks = vec![]; @@ -962,7 +953,7 @@ impl Runner { jobs: usize, ) -> Result<(), ParallelTestError> where - Fut: Future, + Fut: Future, { block_on(self.run_parallel_async(glob, hosts, conn_builder, jobs)) } @@ -990,7 +981,7 @@ impl Runner { filename: impl AsRef, col_separator: &str, validator: Validator, - column_type_validator: ColumnTypeValidator<::ColumnType>, + column_type_validator: ColumnTypeValidator, ) -> Result<(), Box> { use std::io::{Read, Seek, SeekFrom, Write}; use std::path::PathBuf;