Skip to content

Commit fd368f5

Browse files
committed
okay let cursor refactor tests
1 parent e21b643 commit fd368f5

File tree

2 files changed

+101
-52
lines changed

2 files changed

+101
-52
lines changed

kernel/src/transaction/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ impl Transaction {
314314
/// the same domain in a single transaction. If a duplicate domain is included, the `commit` will
315315
/// fail (that is, we don't eagerly check domain validity here).
316316
pub fn with_domain_metadata_removed(mut self, domain: String) -> Self {
317-
self.domain_metadatas.push(DomainMetadata::new(domain.clone(), String::new(), true));
317+
self.domain_metadatas
318+
.push(DomainMetadata::new(domain.clone(), String::new(), true));
318319
self
319320
}
320321
}

kernel/tests/write.rs

Lines changed: 99 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ async fn test_set_domain_metadata_basic() -> Result<(), Box<dyn std::error::Erro
11901190
setup_test_tables(schema.clone(), &[], None, "test_table").await?
11911191
{
11921192
let snapshot = Arc::new(Snapshot::builder(table_url.clone()).build(&engine)?);
1193-
let mut txn = snapshot.transaction()?;
1193+
let txn = snapshot.transaction()?;
11941194

11951195
// write context does not conflict with domain metadata in any way
11961196
let _write_context = txn.get_write_context();
@@ -1201,9 +1201,9 @@ async fn test_set_domain_metadata_basic() -> Result<(), Box<dyn std::error::Erro
12011201
let domain2 = "spark.settings";
12021202
let config2 = r#"{"cores": 4}"#;
12031203

1204-
txn.set_domain_metadata(domain1.to_string(), config1.to_string())?;
1205-
txn.set_domain_metadata(domain2.to_string(), config2.to_string())?;
1206-
txn.commit(&engine)?;
1204+
txn.with_domain_metadata(domain1.to_string(), config1.to_string())
1205+
.with_domain_metadata(domain2.to_string(), config2.to_string())
1206+
.commit(&engine)?;
12071207

12081208
let commit_data = store
12091209
.get(&Path::from(format!(
@@ -1258,20 +1258,23 @@ async fn test_set_domain_metadata_errors() -> Result<(), Box<dyn std::error::Err
12581258
setup_test_tables(schema.clone(), &[], None, "test_table").await?
12591259
{
12601260
let snapshot = Arc::new(Snapshot::builder(table_url.clone()).build(&engine)?);
1261-
let mut txn = snapshot.transaction()?;
12621261

1263-
// System domain rejection
1262+
// Scenario 1: System domain rejection
1263+
let txn = snapshot.clone().transaction()?;
12641264
let err = txn
1265-
.set_domain_metadata("delta.system".to_string(), "config".to_string())
1265+
.with_domain_metadata("delta.system".to_string(), "config".to_string())
1266+
.commit(&engine)
12661267
.unwrap_err();
12671268
assert!(err
12681269
.to_string()
1269-
.contains("system-controlled 'delta.*' domain"));
1270-
1271-
// Duplicate domain rejection
1272-
txn.set_domain_metadata("app.config".to_string(), "v1".to_string())?;
1273-
let err = txn
1274-
.set_domain_metadata("app.config".to_string(), "v2".to_string())
1270+
.contains("Users cannot modify system controlled metadata domains"));
1271+
1272+
// Scenario 2: Duplicate domain rejection
1273+
let txn2 = snapshot.clone().transaction()?;
1274+
let err = txn2
1275+
.with_domain_metadata("app.config".to_string(), "v1".to_string())
1276+
.with_domain_metadata("app.config".to_string(), "v2".to_string())
1277+
.commit(&engine)
12751278
.unwrap_err();
12761279
assert!(err
12771280
.to_string()
@@ -1284,15 +1287,20 @@ async fn test_set_domain_metadata_errors() -> Result<(), Box<dyn std::error::Err
12841287
async fn test_remove_domain_metadata_basic() -> Result<(), Box<dyn std::error::Error>> {
12851288
let _ = tracing_subscriber::fmt::try_init();
12861289

1287-
let schema = Arc::new(StructType::new(vec![StructField::nullable("number", DataType::INTEGER)]));
1290+
let schema = Arc::new(StructType::new(vec![StructField::nullable(
1291+
"number",
1292+
DataType::INTEGER,
1293+
)]));
12881294

1289-
for (table_url, engine, store, table_name) in setup_test_tables(schema.clone(), &[], None, "test_table").await? {
1295+
for (table_url, engine, store, table_name) in
1296+
setup_test_tables(schema.clone(), &[], None, "test_table").await?
1297+
{
12901298
let snapshot = Arc::new(Snapshot::builder(table_url.clone()).build(&engine)?);
1291-
let mut txn = snapshot.transaction()?;
1299+
let txn = snapshot.transaction()?;
12921300

12931301
// Remove domain metadata (creates tombstone even if it doesn't exist)
1294-
txn.remove_domain_metadata("app.deprecated".to_string())?;
1295-
txn.commit(&engine)?;
1302+
txn.with_domain_metadata_removed("app.deprecated".to_string())
1303+
.commit(&engine)?;
12961304

12971305
let commit_data = store
12981306
.get(&Path::from(format!(
@@ -1305,7 +1313,10 @@ async fn test_remove_domain_metadata_basic() -> Result<(), Box<dyn std::error::E
13051313
.into_iter()
13061314
.try_collect()?;
13071315

1308-
let domain_action = actions.iter().find(|v| v.get("domainMetadata").is_some()).unwrap();
1316+
let domain_action = actions
1317+
.iter()
1318+
.find(|v| v.get("domainMetadata").is_some())
1319+
.unwrap();
13091320
assert_eq!(domain_action["domainMetadata"]["domain"], "app.deprecated");
13101321
assert_eq!(domain_action["domainMetadata"]["configuration"], "");
13111322
assert_eq!(domain_action["domainMetadata"]["removed"], true);
@@ -1317,52 +1328,86 @@ async fn test_remove_domain_metadata_basic() -> Result<(), Box<dyn std::error::E
13171328
async fn test_domain_metadata_set_remove_conflicts() -> Result<(), Box<dyn std::error::Error>> {
13181329
let _ = tracing_subscriber::fmt::try_init();
13191330

1320-
let schema = Arc::new(StructType::new(vec![StructField::nullable("number", DataType::INTEGER)]));
1331+
let schema = Arc::new(StructType::new(vec![StructField::nullable(
1332+
"number",
1333+
DataType::INTEGER,
1334+
)]));
13211335

1322-
for (table_url, engine, _, _) in setup_test_tables(schema.clone(), &[], None, "test_table").await? {
1336+
for (table_url, engine, _, _) in
1337+
setup_test_tables(schema.clone(), &[], None, "test_table").await?
1338+
{
13231339
let snapshot = Arc::new(Snapshot::builder(table_url.clone()).build(&engine)?);
1324-
let mut txn = snapshot.transaction()?;
1325-
1326-
// Test 1: Set then remove in same transaction
1327-
txn.set_domain_metadata("app.config".to_string(), "v1".to_string())?;
1328-
let err = txn.remove_domain_metadata("app.config".to_string()).unwrap_err();
1329-
assert!(err.to_string().contains("already specified in this transaction"));
1330-
1331-
// Test 2: Remove then set in same transaction
1332-
txn.remove_domain_metadata("test.domain".to_string())?;
1333-
let err = txn.set_domain_metadata("test.domain".to_string(), "v1".to_string()).unwrap_err();
1334-
assert!(err.to_string().contains("already specified in this transaction"));
1335-
1336-
// Test 3: Remove then remove same domain
1337-
txn.remove_domain_metadata("another.domain".to_string())?;
1338-
let err = txn.remove_domain_metadata("another.domain".to_string()).unwrap_err();
1339-
assert!(err.to_string().contains("already specified in this transaction"));
1340-
1341-
// Test 4: System domain removal
1342-
let err = txn.remove_domain_metadata("delta.system".to_string()).unwrap_err();
1343-
assert!(err.to_string().contains("system-controlled 'delta.*' domain"));
1340+
1341+
// Scenario 1: Set then remove same domain
1342+
let txn = snapshot.clone().transaction()?;
1343+
let err = txn
1344+
.with_domain_metadata("app.config".to_string(), "v1".to_string())
1345+
.with_domain_metadata_removed("app.config".to_string())
1346+
.commit(&engine)
1347+
.unwrap_err();
1348+
assert!(err
1349+
.to_string()
1350+
.contains("already specified in this transaction"));
1351+
1352+
// Scenario 2: Remove then set same domain
1353+
let txn2 = snapshot.clone().transaction()?;
1354+
let err = txn2
1355+
.with_domain_metadata_removed("test.domain".to_string())
1356+
.with_domain_metadata("test.domain".to_string(), "v1".to_string())
1357+
.commit(&engine)
1358+
.unwrap_err();
1359+
assert!(err
1360+
.to_string()
1361+
.contains("already specified in this transaction"));
1362+
1363+
// Scenario 3: Remove then remove same domain
1364+
let txn3 = snapshot.clone().transaction()?;
1365+
let err = txn3
1366+
.with_domain_metadata_removed("another.domain".to_string())
1367+
.with_domain_metadata_removed("another.domain".to_string())
1368+
.commit(&engine)
1369+
.unwrap_err();
1370+
assert!(err
1371+
.to_string()
1372+
.contains("already specified in this transaction"));
1373+
1374+
// Scenario 4: System domain removal
1375+
let txn4 = snapshot.clone().transaction()?;
1376+
let err = txn4
1377+
.with_domain_metadata_removed("delta.system".to_string())
1378+
.commit(&engine)
1379+
.unwrap_err();
1380+
assert!(err
1381+
.to_string()
1382+
.contains("Users cannot modify system controlled metadata domains"));
13441383
}
13451384
Ok(())
13461385
}
13471386

13481387
#[tokio::test]
1349-
async fn test_domain_metadata_set_then_remove_across_transactions() -> Result<(), Box<dyn std::error::Error>> {
1388+
async fn test_domain_metadata_set_then_remove_across_transactions(
1389+
) -> Result<(), Box<dyn std::error::Error>> {
13501390
let _ = tracing_subscriber::fmt::try_init();
13511391

1352-
let schema = Arc::new(StructType::new(vec![StructField::nullable("number", DataType::INTEGER)]));
1392+
let schema = Arc::new(StructType::new(vec![StructField::nullable(
1393+
"number",
1394+
DataType::INTEGER,
1395+
)]));
13531396

1354-
for (table_url, engine, store, table_name) in setup_test_tables(schema.clone(), &[], None, "test_table").await? {
1397+
for (table_url, engine, store, table_name) in
1398+
setup_test_tables(schema.clone(), &[], None, "test_table").await?
1399+
{
13551400
// Transaction 1: Set domain metadata
13561401
let snapshot = Arc::new(Snapshot::builder(table_url.clone()).build(&engine)?);
1357-
let mut txn = snapshot.transaction()?;
1358-
txn.set_domain_metadata("app.config".to_string(), r#"{"version": 1}"#.to_string())?;
1359-
txn.commit(&engine)?;
1402+
let txn = snapshot.transaction()?;
1403+
txn.with_domain_metadata("app.config".to_string(), r#"{"version": 1}"#.to_string())
1404+
.commit(&engine)?;
13601405

13611406
// Transaction 2: Remove the same domain metadata
13621407
let snapshot = Arc::new(Snapshot::builder(table_url.clone()).build(&engine)?);
1363-
let mut txn = snapshot.transaction()?;
1364-
txn.remove_domain_metadata("app.config".to_string())?;
1365-
txn.commit(&engine)?;
1408+
let txn = snapshot.transaction()?;
1409+
txn.with_domain_metadata_removed("app.config".to_string())
1410+
.commit(&engine)?;
13661411

13671412
// Verify removal commit
13681413
let commit_data = store
@@ -1376,7 +1421,10 @@ async fn test_domain_metadata_set_then_remove_across_transactions() -> Result<()
13761421
.into_iter()
13771422
.try_collect()?;
13781423

1379-
let domain_action = actions.iter().find(|v| v.get("domainMetadata").is_some()).unwrap();
1424+
let domain_action = actions
1425+
.iter()
1426+
.find(|v| v.get("domainMetadata").is_some())
1427+
.unwrap();
13801428
assert_eq!(domain_action["domainMetadata"]["domain"], "app.config");
13811429
assert_eq!(domain_action["domainMetadata"]["configuration"], "");
13821430
assert_eq!(domain_action["domainMetadata"]["removed"], true);

0 commit comments

Comments
 (0)