0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2024-12-04 18:58:00 +00:00
ad hoc 9db13fe48c
libsql wal restore (#1569)
* make copy_to_file take ref to file

* turn compacted segment frame_count to u32

* add size after to compacted segment header

* make durable frame_no async

* pass namespace by ref

* add backend to async storage

* add restore to Storage

* add restore to shell

* fix shell bug

* error handling

* fix tests
2024-07-22 09:28:35 +00:00

103 lines
2.6 KiB
Rust

use libsql_wal::test::TestEnv;
#[tokio::test]
async fn transaction_rollback() {
let env = TestEnv::new();
let mut conn1 = env.open_conn("test");
let conn2 = env.open_conn("test");
let tx = conn1.transaction().unwrap();
tx.execute("create table test (x)", ()).unwrap();
assert!(conn2
.query_row("select count(0) from test", (), |_| { Ok(()) })
.is_err());
tx.execute("insert into test values (42)", ()).unwrap();
tx.query_row("select count(0) from test", (), |r| {
assert_eq!(r.get::<_, usize>(0).unwrap(), 1);
Ok(())
})
.unwrap();
assert!(conn2
.query_row("select count(0) from test", (), |_| { Ok(()) })
.is_err());
tx.rollback().unwrap();
assert!(conn1
.query_row("select count(0) from test", (), |_| { Ok(()) })
.is_err());
assert!(conn2
.query_row("select count(0) from test", (), |_| { Ok(()) })
.is_err());
conn1.execute("create table test (c)", ()).unwrap();
conn1
.query_row("select count(0) from test", (), |r| {
assert_eq!(r.get::<_, usize>(0).unwrap(), 0);
Ok(())
})
.unwrap();
conn2
.query_row("select count(0) from test", (), |r| {
assert_eq!(r.get::<_, usize>(0).unwrap(), 0);
Ok(())
})
.unwrap();
}
#[tokio::test]
async fn transaction_savepoints() {
let env = TestEnv::new();
let mut conn = env.open_conn("test");
let mut tx = conn.transaction().unwrap();
tx.execute("create table test (x)", ()).unwrap();
let mut s1 = tx.savepoint().unwrap();
s1.execute("insert into test values (42)", ()).unwrap();
s1.query_row("select count(0) from test", (), |r| {
assert_eq!(r.get::<_, usize>(0).unwrap(), 1);
Ok(())
})
.unwrap();
let mut s2 = s1.savepoint().unwrap();
s2.execute("insert into test values (42)", ()).unwrap();
s2.query_row("select count(0) from test", (), |r| {
assert_eq!(r.get::<_, usize>(0).unwrap(), 2);
Ok(())
})
.unwrap();
s2.rollback().unwrap();
drop(s2);
s1.query_row("select count(0) from test", (), |r| {
assert_eq!(r.get::<_, usize>(0).unwrap(), 1);
Ok(())
})
.unwrap();
s1.rollback().unwrap();
drop(s1);
tx.query_row("select count(0) from test", (), |r| {
assert_eq!(r.get::<_, usize>(0).unwrap(), 0);
Ok(())
})
.unwrap();
tx.commit().unwrap();
conn.query_row("select count(0) from test", (), |r| {
assert_eq!(r.get::<_, usize>(0).unwrap(), 0);
Ok(())
})
.unwrap();
}