@@ -626,7 +626,7 @@ impl<CT: ComponentType> Graph<CT> {
626626 std:: fs:: create_dir_all ( & current_path) ?;
627627
628628 // If successfull write log
629- let log_path = location . join ( "update_log.bin" ) ;
629+ let log_path = current_path . join ( "update_log.bin" ) ;
630630
631631 // Create a temporary directory in the same file system as the output
632632 let temporary_dir = tempfile:: tempdir_in ( & current_path) ?;
@@ -1155,4 +1155,62 @@ mod tests {
11551155 db. ensure_loaded_parallel ( & [ component] ) . unwrap ( ) ;
11561156 assert_eq ! ( 0 , db. components. len( ) ) ;
11571157 }
1158+
1159+ #[ test]
1160+ fn load_with_wal_file ( ) {
1161+ let mut db = Graph :: < DefaultComponentType > :: new ( false ) . unwrap ( ) ;
1162+ let example_node = 0 ;
1163+ db. node_annos
1164+ . insert (
1165+ example_node,
1166+ Annotation {
1167+ key : NODE_TYPE_KEY . as_ref ( ) . clone ( ) ,
1168+ val : "corpus" . into ( ) ,
1169+ } ,
1170+ )
1171+ . unwrap ( ) ;
1172+ db. node_annos
1173+ . insert (
1174+ example_node,
1175+ Annotation {
1176+ key : NODE_NAME_KEY . as_ref ( ) . clone ( ) ,
1177+ val : "root" . into ( ) ,
1178+ } ,
1179+ )
1180+ . unwrap ( ) ;
1181+
1182+ let tmp = tempfile:: tempdir ( ) . unwrap ( ) ;
1183+ // Save and remember the location, so that updates are recorded in a WAL
1184+ // file
1185+ db. persist_to ( tmp. path ( ) ) . unwrap ( ) ;
1186+
1187+ // Add an node annotation with apply_update
1188+ let mut u = GraphUpdate :: new ( ) ;
1189+ u. add_event ( UpdateEvent :: AddNodeLabel {
1190+ node_name : "root" . into ( ) ,
1191+ anno_ns : "example" . into ( ) ,
1192+ anno_name : "anno-name" . into ( ) ,
1193+ anno_value : "anno-value" . into ( ) ,
1194+ } )
1195+ . unwrap ( ) ;
1196+ db. apply_update ( & mut u, |_| { } ) . unwrap ( ) ;
1197+
1198+ std:: mem:: drop ( db) ;
1199+
1200+ // Check that loading the database again contains the changes
1201+ let mut db = Graph :: < DefaultComponentType > :: new ( false ) . unwrap ( ) ;
1202+ db. load_from ( tmp. path ( ) , true ) . unwrap ( ) ;
1203+ let anno_value = db
1204+ . node_annos
1205+ . get_value_for_item (
1206+ & example_node,
1207+ & AnnoKey {
1208+ name : "anno-name" . into ( ) ,
1209+ ns : "example" . into ( ) ,
1210+ } ,
1211+ )
1212+ . unwrap ( )
1213+ . unwrap ( ) ;
1214+ assert_eq ! ( "anno-value" , anno_value) ;
1215+ }
11581216}
0 commit comments