0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-01-09 05:18:59 +00:00
ad hoc 96a977862d libsql wal refactors (#1539)
* introduce IoBuf::map_slice

* rename db_size to size_after

* introduce Segment trait

* implement Segment for Arc<T>

* make SealedSegment clone

* implement Segment for SealedSegment

* rename bottomless to storage

- introduce `Storage` trait
- rename old `Storage` to `Backend`
- introduce `AsyncStorage` (former bottomless)

* add Storage to WalRegistry

remove namespace resolver from registry

* add async_get to registry

* decouple shared wal from registry

* move CompactedSegment headers to own module

* refactor SegmentList

* add durable frame_no to shared_wal

* make shared_wal checkpoint async

* expose TestEnv

create test environment for libsql-wal

* ignore dead_code

stuff still need to be wired

* let LibsqlWalManager resolve namespace name

* fix tests

* fix libsql-server

* fmt

* fix bench

* fix conflicts

* fmt
2024-07-10 13:20:01 +00:00

103 lines
2.6 KiB
Rust

use libsql_wal::test::TestEnv;
#[test]
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();
}
#[test]
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();
}