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

Add working Debug impl for caching session #1161

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion scylla/src/transport/caching_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use scylla_cql::frame::response::result::{PreparedMetadata, ResultMetadata};
use scylla_cql::types::serialize::batch::BatchValues;
use scylla_cql::types::serialize::row::SerializeRow;
use std::collections::hash_map::RandomState;
use std::fmt;
use std::hash::BuildHasher;
use std::sync::Arc;

Expand All @@ -39,7 +40,6 @@ struct RawPreparedStatementData {
}

/// Provides auto caching while executing queries
#[derive(Debug)]
pub struct GenericCachingSession<DeserializationApi, S = RandomState>
where
S: Clone + BuildHasher,
Expand All @@ -53,6 +53,20 @@ where
cache: DashMap<String, RawPreparedStatementData, S>,
}

impl<DeserializationApi, S> fmt::Debug for GenericCachingSession<DeserializationApi, S>
where
S: Clone + BuildHasher,
DeserializationApi: DeserializationApiKind,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("GenericCachingSession")
.field("session", &self.session)
.field("max_capacity", &self.max_capacity)
.field("cache", &self.cache)
.finish()
}
}

pub type CachingSession<S = RandomState> = GenericCachingSession<CurrentDeserializationApi, S>;

#[deprecated(
Expand Down Expand Up @@ -335,6 +349,8 @@ mod tests {
use crate::transport::partitioner::PartitionerName;
use crate::transport::session::Session;
use crate::utils::test_utils::unique_keyspace_name;
#[allow(deprecated)]
use crate::LegacyCachingSession;
use crate::{
batch::{Batch, BatchStatement},
prepared_statement::PreparedStatement,
Expand Down Expand Up @@ -766,4 +782,12 @@ mod tests {
verify_partitioner().await;
verify_partitioner().await;
}

// NOTE: intentionally no `#[test]`: this is a compile-time test
fn _caching_session_impls_debug() {
fn assert_debug<T: std::fmt::Debug>() {}
assert_debug::<CachingSession>();
#[allow(deprecated)]
assert_debug::<LegacyCachingSession>();
}
}
Loading