Skip to content

Commit 7f16f81

Browse files
wprzytulaLorak-mmk
andcommitted
integration: introduce SerializeValueWithFakeType
This helper struct allows serializing a value with a different CQL type than its actual Rust type. This is useful for testing scenarios where we want to force serializing a value to a CQL column of a non-matching type (or, more specifically, a type that is not accepted by the type-checking logic in the driver). In the next commit, this will be used to insert tuples with fewer elements than the CQL type expects, to later verify that reading such tuples does not cause deserialization errors. Co-authored-by: Karol Baryła <karol.baryla@scylladb.com>
1 parent b17ab6f commit 7f16f81

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

scylla/tests/integration/utils.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use scylla::client::session::Session;
77
use scylla::client::session_builder::{GenericSessionBuilder, SessionBuilderKind};
88
use scylla::cluster::ClusterState;
99
use scylla::cluster::NodeRef;
10+
use scylla::cluster::metadata::ColumnType;
1011
use scylla::deserialize::value::DeserializeValue;
1112
use scylla::errors::{DbError, ExecutionError, RequestAttemptError};
1213
use scylla::policies::load_balancing::{
@@ -16,6 +17,7 @@ use scylla::policies::retry::{RequestInfo, RetryDecision, RetryPolicy, RetrySess
1617
use scylla::response::query_result::QueryResult;
1718
use scylla::routing::Shard;
1819
use scylla::serialize::row::SerializeRow;
20+
use scylla::serialize::value::SerializeValue;
1921
use scylla::statement::prepared::PreparedStatement;
2022
use scylla::statement::unprepared::Statement;
2123
use std::collections::HashMap;
@@ -455,3 +457,25 @@ pub(crate) async fn execute_unprepared_statement_everywhere(
455457
})
456458
.await
457459
}
460+
461+
pub(crate) struct SerializeValueWithFakeType<'typ, T> {
462+
fake_type: ColumnType<'typ>,
463+
value: T,
464+
}
465+
466+
impl<T: SerializeValue> SerializeValue for SerializeValueWithFakeType<'_, T> {
467+
fn serialize<'b>(
468+
&self,
469+
_typ: &ColumnType,
470+
writer: scylla_cql::serialize::CellWriter<'b>,
471+
) -> Result<scylla::serialize::writers::WrittenCellProof<'b>, scylla::errors::SerializationError>
472+
{
473+
<T as SerializeValue>::serialize(&self.value, &self.fake_type, writer)
474+
}
475+
}
476+
477+
impl<'typ, T> SerializeValueWithFakeType<'typ, T> {
478+
pub(crate) fn new(value: T, fake_type: ColumnType<'typ>) -> Self {
479+
Self { fake_type, value }
480+
}
481+
}

0 commit comments

Comments
 (0)