Skip to content

Commit 70ef5ad

Browse files
committed
session_test: add a check on pulling view information
This test cases confirms that when pulling schema information, we also gather knowledge of materialized views. Disabled on Cassandra, where materialized views are off by default.
1 parent 2bc2efb commit 70ef5ad

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

.github/workflows/cassandra.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
run: cargo build --verbose --tests
2828
- name: Run tests on cassandra
2929
# test threads must be one because else database tests will run in parallel and will result in flaky tests
30-
run: cargo test --verbose -- --test-threads=1
30+
run: cargo test --verbose -- --test-threads=1 --skip test_views_in_schema_info

scylla/src/transport/session_test.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,3 +1978,49 @@ async fn test_unprepared_reprepare_in_caching_session_execute() {
19781978
all_rows.sort();
19791979
assert_eq!(all_rows, vec![(1, 2, 3), (1, 3, 2)]);
19801980
}
1981+
1982+
#[tokio::test]
1983+
async fn test_views_in_schema_info() {
1984+
let _ = tracing_subscriber::fmt::try_init();
1985+
1986+
let uri = std::env::var("SCYLLA_URI").unwrap_or_else(|_| "127.0.0.1:9042".to_string());
1987+
let session = SessionBuilder::new().known_node(uri).build().await.unwrap();
1988+
let ks = unique_name();
1989+
1990+
session.query(format!("CREATE KEYSPACE IF NOT EXISTS {} WITH REPLICATION = {{'class' : 'SimpleStrategy', 'replication_factor' : 1}}", ks), &[]).await.unwrap();
1991+
session.use_keyspace(ks.clone(), false).await.unwrap();
1992+
1993+
session
1994+
.query("CREATE TABLE t(id int PRIMARY KEY, v int)", &[])
1995+
.await
1996+
.unwrap();
1997+
1998+
session.query("CREATE MATERIALIZED VIEW mv1 AS SELECT * FROM t WHERE v IS NOT NULL PRIMARY KEY (v, id)", &[]).await.unwrap();
1999+
session.query("CREATE MATERIALIZED VIEW mv2 AS SELECT id, v FROM t WHERE v IS NOT NULL PRIMARY KEY (v, id)", &[]).await.unwrap();
2000+
2001+
session.await_schema_agreement().await.unwrap();
2002+
session.refresh_metadata().await.unwrap();
2003+
2004+
let keyspace_meta = session
2005+
.get_cluster_data()
2006+
.get_keyspace_info()
2007+
.get(&ks)
2008+
.unwrap()
2009+
.clone();
2010+
2011+
let tables = keyspace_meta
2012+
.tables
2013+
.keys()
2014+
.collect::<std::collections::HashSet<&String>>();
2015+
2016+
let views = keyspace_meta
2017+
.views
2018+
.keys()
2019+
.collect::<std::collections::HashSet<&String>>();
2020+
2021+
assert_eq!(tables, std::collections::HashSet::from([&"t".to_string()]));
2022+
assert_eq!(
2023+
views,
2024+
std::collections::HashSet::from([&"mv1".to_string(), &"mv2".to_string()])
2025+
);
2026+
}

0 commit comments

Comments
 (0)