Skip to content

Commit 5cb0fbf

Browse files
committed
IT: fix MonotonicTimestampGenerator test and remove C++ timestamp generator
The MonotonicTimestampGenerator integration test was disabled because it relied on C++ internal classes from src/timestamp_generator.{cpp,hpp} to capture generated timestamps. Since timestamp generation is now handled entirely on the Rust side, the test needs a Rust-side testing utility. This commit: - Adds RecordingTimestampGenerator in Rust that wraps MonotonicTimestampGenerator and records all generated timestamps (behind cfg(cpp_integration_testing)) - Exposes testing_timestamp_gen_monotonic_new() and testing_timestamp_gen_contains_timestamp() FFI functions for the test - Rewrites the C++ test to use the new testing API - Removes src/timestamp_generator.{cpp,hpp} (no longer needed) - Enables the previously disabled test in both Scylla and Cassandra filters Fixes: #296
1 parent 5e39c8c commit 5cb0fbf

10 files changed

Lines changed: 97 additions & 208 deletions

File tree

Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ SCYLLA_TEST_FILTER := $(subst ${SPACE},${EMPTY},ClusterTests.*\
5858
:-SchemaMetadataTest.Integration_Cassandra_RegularMetadataNotMarkedVirtual\
5959
:SchemaMetadataTest.Integration_Cassandra_VirtualMetadata\
6060
:HeartbeatTests.Integration_Cassandra_HeartbeatFailed\
61-
:TimestampTests.Integration_Cassandra_MonotonicTimestampGenerator\
6261
:ExecutionProfileTest.Integration_Cassandra_RoundRobin\
6362
:ExecutionProfileTest.Integration_Cassandra_TokenAwareRouting\
6463
:ExecutionProfileTest.Integration_Cassandra_SpeculativeExecutionPolicy\
@@ -117,7 +116,6 @@ CASSANDRA_TEST_FILTER := $(subst ${SPACE},${EMPTY},ClusterTests.*\
117116
:SchemaMetadataTest.Integration_Cassandra_RegularMetadataNotMarkedVirtual\
118117
:SchemaMetadataTest.Integration_Cassandra_VirtualMetadata\
119118
:HeartbeatTests.Integration_Cassandra_HeartbeatFailed\
120-
:TimestampTests.Integration_Cassandra_MonotonicTimestampGenerator\
121119
:ExecutionProfileTest.Integration_Cassandra_RoundRobin\
122120
:ExecutionProfileTest.Integration_Cassandra_TokenAwareRouting\
123121
:ExecutionProfileTest.Integration_Cassandra_SpeculativeExecutionPolicy\

scylla-rust-wrapper/src/api.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,8 @@ pub mod integration_testing {
966966
testing_retry_policy_ignoring_new,
967967
testing_statement_set_recording_history_listener,
968968
testing_statement_set_sleeping_history_listener,
969+
testing_timestamp_gen_contains_timestamp,
970+
testing_timestamp_gen_monotonic_new,
969971
};
970972

971973
/// Stubs of functions that must be implemented for the integration tests to compile,

scylla-rust-wrapper/src/cluster.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,10 @@ pub unsafe extern "C" fn cass_cluster_set_timestamp_gen(
622622
CassTimestampGen::Monotonic(monotonic_timestamp_generator) => {
623623
Some(Arc::clone(monotonic_timestamp_generator) as _)
624624
}
625+
#[cfg(cpp_integration_testing)]
626+
CassTimestampGen::RecordingMonotonic(recording_timestamp_generator) => {
627+
Some(Arc::clone(recording_timestamp_generator) as _)
628+
}
625629
};
626630

627631
cluster.session_builder.config.timestamp_generator = rust_timestamp_gen;

scylla-rust-wrapper/src/testing/integration.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use scylla::policies::retry::RetryDecision;
1010

1111
use crate::argconv::{
1212
ArcFFI, BoxFFI, CConst, CMut, CassBorrowedExclusivePtr, CassBorrowedSharedPtr,
13-
CassOwnedSharedPtr,
13+
CassOwnedExclusivePtr, CassOwnedSharedPtr,
1414
};
1515
use crate::cluster::CassCluster;
1616
use crate::future::{CassFuture, CassResultValue};
@@ -19,7 +19,8 @@ use crate::retry_policy::CassRetryPolicy;
1919
use crate::runtime::Runtime;
2020
use crate::statements::batch::CassBatch;
2121
use crate::statements::statement::{BoundStatement, CassStatement};
22-
use crate::types::{cass_bool_t, cass_int32_t, cass_uint16_t, cass_uint64_t, size_t};
22+
use crate::timestamp_generator::{CassTimestampGen, RecordingTimestampGenerator};
23+
use crate::types::{cass_bool_t, cass_int32_t, cass_int64_t, cass_uint16_t, cass_uint64_t, size_t};
2324

2425
#[unsafe(no_mangle)]
2526
pub unsafe extern "C" fn testing_cluster_get_connect_timeout(
@@ -378,6 +379,43 @@ pub unsafe extern "C" fn testing_retry_policy_ignoring_new()
378379
))))
379380
}
380381

382+
/// Creates a new monotonic timestamp generator that records all generated timestamps.
383+
/// This is useful for testing purposes, allowing us to verify which timestamps were
384+
/// generated during query execution.
385+
/// The recorded timestamps can later be queried using `testing_timestamp_gen_contains_timestamp`.
386+
#[unsafe(no_mangle)]
387+
pub unsafe extern "C" fn testing_timestamp_gen_monotonic_new()
388+
-> CassOwnedExclusivePtr<CassTimestampGen, CMut> {
389+
BoxFFI::into_ptr(Box::new(CassTimestampGen::RecordingMonotonic(Arc::new(
390+
RecordingTimestampGenerator::new(),
391+
))))
392+
}
393+
394+
/// Checks whether the given timestamp was generated by the recording monotonic
395+
/// timestamp generator. Returns `cass_true` if found, `cass_false` otherwise.
396+
///
397+
/// If the provided generator is not a recording monotonic generator, returns `cass_false`.
398+
#[unsafe(no_mangle)]
399+
pub unsafe extern "C" fn testing_timestamp_gen_contains_timestamp(
400+
timestamp_gen_raw: CassBorrowedExclusivePtr<CassTimestampGen, CMut>,
401+
timestamp: cass_int64_t,
402+
) -> cass_bool_t {
403+
let Some(timestamp_gen) = BoxFFI::as_ref(timestamp_gen_raw) else {
404+
return 0;
405+
};
406+
407+
match timestamp_gen {
408+
CassTimestampGen::RecordingMonotonic(recording) => {
409+
if recording.contains(timestamp) {
410+
1
411+
} else {
412+
0
413+
}
414+
}
415+
_ => 0,
416+
}
417+
}
418+
381419
/// Stubs of functions that must be implemented for the integration tests
382420
/// or examples to compile, but the proper implementation is not needed for
383421
/// the tests/examples to run, and at the same time the functions are not

scylla-rust-wrapper/src/timestamp_generator.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,47 @@ use std::sync::Arc;
22
use std::time::Duration;
33

44
use scylla::policies::timestamp_generator::MonotonicTimestampGenerator;
5+
#[cfg(cpp_integration_testing)]
6+
use scylla::policies::timestamp_generator::TimestampGenerator;
57

68
use crate::argconv::{BoxFFI, CMut, CassOwnedExclusivePtr, FFI, FromBox};
79

810
pub enum CassTimestampGen {
911
ServerSide,
1012
Monotonic(Arc<MonotonicTimestampGenerator>),
13+
#[cfg(cpp_integration_testing)]
14+
RecordingMonotonic(Arc<RecordingTimestampGenerator>),
15+
}
16+
17+
/// A wrapper around `MonotonicTimestampGenerator` that records all generated timestamps.
18+
/// This is used for integration testing purposes only.
19+
#[cfg(cpp_integration_testing)]
20+
pub struct RecordingTimestampGenerator {
21+
inner: MonotonicTimestampGenerator,
22+
timestamps: std::sync::Mutex<Vec<i64>>,
23+
}
24+
25+
#[cfg(cpp_integration_testing)]
26+
impl RecordingTimestampGenerator {
27+
pub fn new() -> Self {
28+
Self {
29+
inner: MonotonicTimestampGenerator::new(),
30+
timestamps: std::sync::Mutex::new(Vec::new()),
31+
}
32+
}
33+
34+
pub fn contains(&self, timestamp: i64) -> bool {
35+
self.timestamps.lock().unwrap().contains(&timestamp)
36+
}
37+
}
38+
39+
#[cfg(cpp_integration_testing)]
40+
impl TimestampGenerator for RecordingTimestampGenerator {
41+
fn next_timestamp(&self) -> i64 {
42+
let ts = self.inner.next_timestamp();
43+
self.timestamps.lock().unwrap().push(ts);
44+
ts
45+
}
1146
}
1247

1348
impl FFI for CassTimestampGen {

src/testing_rust_impls.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ CASS_EXPORT void testing_statement_set_recording_history_listener(CassStatement*
5454
// The returned pointer is allocated and must be freed with `testing_free_cstring`.
5555
CASS_EXPORT char* testing_future_get_attempted_hosts(CassFuture* future);
5656

57+
// Creates a new monotonic timestamp generator that records all generated timestamps.
58+
// Recorded timestamps can be queried using `testing_timestamp_gen_contains_timestamp`.
59+
// The returned generator must be freed with `cass_timestamp_gen_free`.
60+
CASS_EXPORT CassTimestampGen* testing_timestamp_gen_monotonic_new();
61+
62+
// Checks whether the given timestamp was generated by the recording monotonic generator.
63+
// Returns cass_true if the timestamp was generated, cass_false otherwise.
64+
CASS_EXPORT cass_bool_t testing_timestamp_gen_contains_timestamp(CassTimestampGen* timestamp_gen,
65+
cass_int64_t timestamp);
66+
5767
/**
5868
* Creates a new ignoring retry policy.
5969
*

src/timestamp_generator.cpp

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/timestamp_generator.hpp

Lines changed: 0 additions & 87 deletions
This file was deleted.

tests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ set(CPP_DRIVER_SOURCE_FILES
120120
${CASS_SRC_DIR}/get_time-win.cpp
121121
${CASS_SRC_DIR}/address.cpp
122122
${CASS_SRC_DIR}/memory.cpp
123-
${CASS_SRC_DIR}/timestamp_generator.cpp
124123
${CASS_SRC_DIR}/testing.cpp
125124
${CASS_SRC_DIR}/logger.cpp
126125
${CASS_SRC_DIR}/testing_unimplemented.cpp

0 commit comments

Comments
 (0)