Skip to content

Commit c8ad86d

Browse files
authored
Merge branch 'scylladb:main' into query_rows_result_displayer
2 parents 97f9eec + 64647f9 commit c8ad86d

35 files changed

+1123
-826
lines changed

.github/workflows/cassandra.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: cargo build --verbose --tests --features "full-serialization"
3232
- name: Run tests on cassandra
3333
run: |
34-
CDC='disabled' RUST_LOG=trace SCYLLA_URI=172.42.0.2:9042 SCYLLA_URI2=172.42.0.3:9042 SCYLLA_URI3=172.42.0.4:9042 cargo test --verbose --features "full-serialization" -- --skip test_views_in_schema_info --skip test_large_batch_statements
34+
CDC='disabled' RUSTFLAGS="--cfg cassandra_tests" RUST_LOG=trace SCYLLA_URI=172.42.0.2:9042 SCYLLA_URI2=172.42.0.3:9042 SCYLLA_URI3=172.42.0.4:9042 cargo test --verbose --features "full-serialization" -- --skip test_views_in_schema_info --skip test_large_batch_statements
3535
- name: Stop the cluster
3636
if: ${{ always() }}
3737
run: docker compose -f test/cluster/cassandra/docker-compose.yml stop

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ The above commands will leave a running ScyllaDB cluster in the background.
4949
To stop it, use `make down`.\
5050
Starting a cluster without running any test is possible with `make up`.
5151

52+
### Writing tests that need to connect to Scylla
53+
54+
If you test requires connecting to Scylla, there are a few things you should consider.
55+
56+
1. Such tests are considered integration tests and should be placed in `scylla/tests/integration`.
57+
2. To avoid name conflicts while creating a keyspace use `unique_keyspace_name` function from `utils` module.
58+
3. This `utils` module (`scylla/tests/integration/utils.rs`) contains other functions that may be helpful for writing tests.
59+
For example `create_new_session_builder` or `test_with_3_node_cluster`.
60+
4. To perform DDL queries (creating / altering / dropping a keyspace / table /type) use `ddl` method from the utils module.
61+
To do this, import the `PerformDDL` trait (`use crate::utils::PerformDDL;`). Then you can call `ddl` method on a
62+
`Session`.
63+
5264
### Tracing in tests
5365

5466
By default cargo captures `print!` macro's output from tests and prints them for failed tests.

docs/source/data-types/date.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ while let Some((date_value,)) = iter.try_next().await? {
4242

4343
## chrono::NaiveDate
4444

45-
If full range is not required and `chrono` feature is enabled,
45+
If full range is not required and `chrono-04` feature is enabled,
4646
[`chrono::NaiveDate`](https://docs.rs/chrono/0.4/chrono/naive/struct.NaiveDate.html) can be used.
4747
[`chrono::NaiveDate`](https://docs.rs/chrono/0.4/chrono/naive/struct.NaiveDate.html) supports dates from
4848
-262145-01-01 to 262143-12-31.
@@ -78,7 +78,7 @@ while let Some((date_value,)) = iter.try_next().await? {
7878

7979
## time::Date
8080

81-
Alternatively, `time` feature can be used to enable support of
81+
Alternatively, the `time-03` feature can be used to enable support of
8282
[`time::Date`](https://docs.rs/time/0.3/time/struct.Date.html).
8383
[`time::Date`](https://docs.rs/time/0.3/time/struct.Date.html)'s value range depends on feature flags, see its
8484
documentation to get more info.

docs/source/data-types/time.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ while let Some((value,)) = iter.try_next().await? {
4242

4343
## chrono::NaiveTime
4444

45-
If `chrono` feature is enabled, [`chrono::NaiveTime`](https://docs.rs/chrono/0.4/chrono/naive/struct.NaiveDate.html)
45+
If the `chrono-04` feature is enabled, [`chrono::NaiveTime`](https://docs.rs/chrono/0.4/chrono/naive/struct.NaiveDate.html)
4646
can be used to interact with the database. Although chrono can represent leap seconds, they are not supported.
4747
Attempts to convert [`chrono::NaiveTime`](https://docs.rs/chrono/0.4/chrono/naive/struct.NaiveDate.html) with leap
4848
second to `CqlTime` or write it to the database will return an error.
@@ -78,7 +78,7 @@ while let Some((time_value,)) = iter.try_next().await? {
7878

7979
## time::Time
8080

81-
If `time` feature is enabled, [`time::Time`](https://docs.rs/time/0.3/time/struct.Time.html) can be used to interact
81+
If the `time-03` feature is enabled, [`time::Time`](https://docs.rs/time/0.3/time/struct.Time.html) can be used to interact
8282
with the database.
8383

8484
```rust

docs/source/data-types/timestamp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ while let Some((value,)) = iter.try_next().await? {
4343

4444
## chrono::DateTime
4545

46-
If full value range is not required, `chrono` feature can be used to enable support of
46+
If the full value range is not required, the `chrono-04` feature can be used to enable support of
4747
[`chrono::DateTime`](https://docs.rs/chrono/0.4/chrono/struct.DateTime.html). All values are expected to be converted
4848
to UTC timezone explicitly, as [timestamp](https://docs.scylladb.com/stable/cql/types.html#timestamps) doesn't store
4949
timezone information. Any precision finer than 1ms will be lost.
@@ -83,7 +83,7 @@ while let Some((timestamp_value,)) = iter.try_next().await? {
8383

8484
## time::OffsetDateTime
8585

86-
Alternatively, `time` feature can be used to enable support of
86+
Alternatively, the `time-03` feature can be used to enable support of
8787
[`time::OffsetDateTime`](https://docs.rs/time/0.3/time/struct.OffsetDateTime.html). As
8888
[timestamp](https://docs.scylladb.com/stable/cql/types.html#timestamps) doesn't support timezone information, time will
8989
be corrected to UTC and timezone info will be erased on write. On read, UTC timestamp is returned. Any precision finer

scylla/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ harness = false
9999
[lints.rust]
100100
unnameable_types = "warn"
101101
unreachable_pub = "warn"
102-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(scylla_cloud_tests)'] }
102+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(scylla_cloud_tests)', 'cfg(cassandra_tests)'] }

scylla/src/history.rs

Lines changed: 2 additions & 247 deletions
Original file line numberDiff line numberDiff line change
@@ -449,28 +449,21 @@ fn write_fiber_attempts(fiber: &FiberHistory, f: &mut std::fmt::Formatter<'_>) -
449449

450450
#[cfg(test)]
451451
mod tests {
452-
use std::{
453-
net::{IpAddr, Ipv4Addr, SocketAddr},
454-
sync::Arc,
455-
};
452+
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
456453

457454
use crate::{
458-
query::Query,
459455
retry_policy::RetryDecision,
460456
test_utils::setup_tracing,
461457
transport::errors::{DbError, QueryError},
462-
utils::test_utils::unique_keyspace_name,
463458
};
464459

465460
use super::{
466461
AttemptId, AttemptResult, HistoryCollector, HistoryListener, QueryHistoryResult, QueryId,
467462
SpeculativeId, StructuredHistory, TimePoint,
468463
};
469-
use crate::test_utils::create_new_session_builder;
470464
use assert_matches::assert_matches;
471465
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
472-
use futures::StreamExt as _;
473-
use scylla_cql::{frame::response::result::Row, Consistency};
466+
use scylla_cql::Consistency;
474467

475468
// Set a single time for all timestamps within StructuredHistory.
476469
// HistoryCollector sets the timestamp to current time which changes with each test.
@@ -510,53 +503,6 @@ mod tests {
510503
history
511504
}
512505

513-
// Set a single node for all attempts within StructuredHistory.
514-
// When running against real life nodes this address may change,
515-
// setting it to one value makes it possible to run tests consistently.
516-
fn set_one_node(mut history: StructuredHistory) -> StructuredHistory {
517-
let the_node: SocketAddr = node1_addr();
518-
519-
for query in &mut history.queries {
520-
for fiber in std::iter::once(&mut query.non_speculative_fiber)
521-
.chain(query.speculative_fibers.iter_mut())
522-
{
523-
for attempt in &mut fiber.attempts {
524-
attempt.node_addr = the_node;
525-
}
526-
}
527-
}
528-
529-
history
530-
}
531-
532-
// Set a single error message for all DbErrors within StructuredHistory.
533-
// The error message changes between Scylla/Cassandra/their versions.
534-
// Setting it to one value makes it possible to run tests consistently.
535-
fn set_one_db_error_message(mut history: StructuredHistory) -> StructuredHistory {
536-
let set_msg = |err: &mut QueryError| {
537-
if let QueryError::DbError(_, msg) = err {
538-
*msg = "Error message from database".to_string();
539-
}
540-
};
541-
542-
for query in &mut history.queries {
543-
if let Some(QueryHistoryResult::Error(_, err)) = &mut query.result {
544-
set_msg(err);
545-
}
546-
for fiber in std::iter::once(&mut query.non_speculative_fiber)
547-
.chain(query.speculative_fibers.iter_mut())
548-
{
549-
for attempt in &mut fiber.attempts {
550-
if let Some(AttemptResult::Error(_, err, _)) = &mut attempt.result {
551-
set_msg(err);
552-
}
553-
}
554-
}
555-
}
556-
557-
history
558-
}
559-
560506
fn node1_addr() -> SocketAddr {
561507
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 19042)
562508
}
@@ -913,195 +859,4 @@ mod tests {
913859
";
914860
assert_eq!(displayed, format!("{}", set_one_time(history)));
915861
}
916-
917-
#[tokio::test]
918-
async fn successful_query_history() {
919-
setup_tracing();
920-
let session = create_new_session_builder().build().await.unwrap();
921-
922-
let mut query = Query::new("SELECT * FROM system.local");
923-
let history_collector = Arc::new(HistoryCollector::new());
924-
query.set_history_listener(history_collector.clone());
925-
926-
session.query_unpaged(query.clone(), ()).await.unwrap();
927-
928-
let history: StructuredHistory = history_collector.clone_structured_history();
929-
930-
let displayed = "Queries History:
931-
=== Query #0 ===
932-
| start_time: 2022-02-22 20:22:22 UTC
933-
| Non-speculative attempts:
934-
| - Attempt #0 sent to 127.0.0.1:19042
935-
| request send time: 2022-02-22 20:22:22 UTC
936-
| Success at 2022-02-22 20:22:22 UTC
937-
|
938-
| Query successful at 2022-02-22 20:22:22 UTC
939-
=================
940-
";
941-
assert_eq!(
942-
displayed,
943-
format!(
944-
"{}",
945-
set_one_db_error_message(set_one_node(set_one_time(history)))
946-
)
947-
);
948-
949-
// Prepared queries retain the history listener set in Query.
950-
let prepared = session.prepare(query).await.unwrap();
951-
session.execute_unpaged(&prepared, ()).await.unwrap();
952-
953-
let history2: StructuredHistory = history_collector.clone_structured_history();
954-
955-
let displayed2 = "Queries History:
956-
=== Query #0 ===
957-
| start_time: 2022-02-22 20:22:22 UTC
958-
| Non-speculative attempts:
959-
| - Attempt #0 sent to 127.0.0.1:19042
960-
| request send time: 2022-02-22 20:22:22 UTC
961-
| Success at 2022-02-22 20:22:22 UTC
962-
|
963-
| Query successful at 2022-02-22 20:22:22 UTC
964-
=================
965-
=== Query #1 ===
966-
| start_time: 2022-02-22 20:22:22 UTC
967-
| Non-speculative attempts:
968-
| - Attempt #0 sent to 127.0.0.1:19042
969-
| request send time: 2022-02-22 20:22:22 UTC
970-
| Success at 2022-02-22 20:22:22 UTC
971-
|
972-
| Query successful at 2022-02-22 20:22:22 UTC
973-
=================
974-
";
975-
assert_eq!(
976-
displayed2,
977-
format!(
978-
"{}",
979-
set_one_db_error_message(set_one_node(set_one_time(history2)))
980-
)
981-
);
982-
}
983-
984-
#[tokio::test]
985-
async fn failed_query_history() {
986-
setup_tracing();
987-
let session = create_new_session_builder().build().await.unwrap();
988-
989-
let mut query = Query::new("This isnt even CQL");
990-
let history_collector = Arc::new(HistoryCollector::new());
991-
query.set_history_listener(history_collector.clone());
992-
993-
assert!(session.query_unpaged(query.clone(), ()).await.is_err());
994-
995-
let history: StructuredHistory = history_collector.clone_structured_history();
996-
997-
let displayed =
998-
"Queries History:
999-
=== Query #0 ===
1000-
| start_time: 2022-02-22 20:22:22 UTC
1001-
| Non-speculative attempts:
1002-
| - Attempt #0 sent to 127.0.0.1:19042
1003-
| request send time: 2022-02-22 20:22:22 UTC
1004-
| Error at 2022-02-22 20:22:22 UTC
1005-
| Error: Database returned an error: The submitted query has a syntax error, Error message: Error message from database
1006-
| Retry decision: DontRetry
1007-
|
1008-
| Query failed at 2022-02-22 20:22:22 UTC
1009-
| Error: Database returned an error: The submitted query has a syntax error, Error message: Error message from database
1010-
=================
1011-
";
1012-
assert_eq!(
1013-
displayed,
1014-
format!(
1015-
"{}",
1016-
set_one_db_error_message(set_one_node(set_one_time(history)))
1017-
)
1018-
);
1019-
}
1020-
1021-
#[tokio::test]
1022-
async fn iterator_query_history() {
1023-
setup_tracing();
1024-
let session = create_new_session_builder().build().await.unwrap();
1025-
let ks = unique_keyspace_name();
1026-
session
1027-
.query_unpaged(format!("CREATE KEYSPACE {} WITH REPLICATION = {{'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1}}", ks), &[])
1028-
.await
1029-
.unwrap();
1030-
session.use_keyspace(ks, true).await.unwrap();
1031-
1032-
session
1033-
.query_unpaged("CREATE TABLE t (p int primary key)", ())
1034-
.await
1035-
.unwrap();
1036-
for i in 0..32 {
1037-
session
1038-
.query_unpaged("INSERT INTO t (p) VALUES (?)", (i,))
1039-
.await
1040-
.unwrap();
1041-
}
1042-
1043-
let mut iter_query: Query = Query::new("SELECT * FROM t");
1044-
iter_query.set_page_size(8);
1045-
let history_collector = Arc::new(HistoryCollector::new());
1046-
iter_query.set_history_listener(history_collector.clone());
1047-
1048-
let mut rows_iterator = session
1049-
.query_iter(iter_query, ())
1050-
.await
1051-
.unwrap()
1052-
.rows_stream::<Row>()
1053-
.unwrap();
1054-
while let Some(_row) = rows_iterator.next().await {
1055-
// Receive rows...
1056-
}
1057-
1058-
let history = history_collector.clone_structured_history();
1059-
1060-
assert!(history.queries.len() >= 4);
1061-
1062-
let displayed_prefix = "Queries History:
1063-
=== Query #0 ===
1064-
| start_time: 2022-02-22 20:22:22 UTC
1065-
| Non-speculative attempts:
1066-
| - Attempt #0 sent to 127.0.0.1:19042
1067-
| request send time: 2022-02-22 20:22:22 UTC
1068-
| Success at 2022-02-22 20:22:22 UTC
1069-
|
1070-
| Query successful at 2022-02-22 20:22:22 UTC
1071-
=================
1072-
=== Query #1 ===
1073-
| start_time: 2022-02-22 20:22:22 UTC
1074-
| Non-speculative attempts:
1075-
| - Attempt #0 sent to 127.0.0.1:19042
1076-
| request send time: 2022-02-22 20:22:22 UTC
1077-
| Success at 2022-02-22 20:22:22 UTC
1078-
|
1079-
| Query successful at 2022-02-22 20:22:22 UTC
1080-
=================
1081-
=== Query #2 ===
1082-
| start_time: 2022-02-22 20:22:22 UTC
1083-
| Non-speculative attempts:
1084-
| - Attempt #0 sent to 127.0.0.1:19042
1085-
| request send time: 2022-02-22 20:22:22 UTC
1086-
| Success at 2022-02-22 20:22:22 UTC
1087-
|
1088-
| Query successful at 2022-02-22 20:22:22 UTC
1089-
=================
1090-
=== Query #3 ===
1091-
| start_time: 2022-02-22 20:22:22 UTC
1092-
| Non-speculative attempts:
1093-
| - Attempt #0 sent to 127.0.0.1:19042
1094-
| request send time: 2022-02-22 20:22:22 UTC
1095-
| Success at 2022-02-22 20:22:22 UTC
1096-
|
1097-
| Query successful at 2022-02-22 20:22:22 UTC
1098-
=================
1099-
";
1100-
let displayed_str = format!(
1101-
"{}",
1102-
set_one_db_error_message(set_one_node(set_one_time(history)))
1103-
);
1104-
1105-
assert!(displayed_str.starts_with(displayed_prefix),);
1106-
}
1107862
}

scylla/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,8 @@ pub mod transport;
257257

258258
pub(crate) mod utils;
259259

260-
/// This module is NOT part of the public API (it is `pub` only for internal use of integration tests).
261-
/// Future minor releases are free to introduce breaking API changes inside it.
262-
#[doc(hidden)]
263-
pub use utils::test_utils;
260+
#[cfg(test)]
261+
pub(crate) use utils::test_utils;
264262

265263
pub use statement::batch;
266264
pub use statement::prepared_statement;

0 commit comments

Comments
 (0)