12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
+ use std:: fmt;
15
16
use std:: fs;
16
17
use std:: io;
17
18
use std:: io:: BufReader ;
@@ -28,7 +29,7 @@ use crate::raft_types::SnapshotMeta;
28
29
use crate :: sys_data:: SysData ;
29
30
30
31
/// A readonly leveled map that owns the data.
31
- #[ derive( Debug , Clone ) ]
32
+ #[ derive( Clone ) ]
32
33
pub struct DB {
33
34
pub storage_path : String ,
34
35
pub rel_path : String ,
@@ -37,6 +38,17 @@ pub struct DB {
37
38
pub rotbl : Arc < Rotbl > ,
38
39
}
39
40
41
+ impl fmt:: Debug for DB {
42
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
43
+ f. debug_struct ( "DB" )
44
+ . field ( "storage_path" , & self . storage_path )
45
+ . field ( "rel_path" , & self . rel_path )
46
+ . field ( "meta" , & self . meta )
47
+ . field ( "sys_data" , & self . sys_data )
48
+ . finish ( )
49
+ }
50
+ }
51
+
40
52
impl AsRef < SysData > for DB {
41
53
fn as_ref ( & self ) -> & SysData {
42
54
& self . sys_data
@@ -163,3 +175,37 @@ pub struct DBStat {
163
175
/// Total number of read block from disk.
164
176
pub read_block_from_disk : u64 ,
165
177
}
178
+
179
+ #[ cfg( test) ]
180
+ mod tests {
181
+
182
+ use rotbl:: storage:: impls:: fs:: FsStorage ;
183
+ use rotbl:: v001:: Config ;
184
+ use rotbl:: v001:: RotblMeta ;
185
+
186
+ use super :: * ;
187
+
188
+ /// Debug should not output db cache data.
189
+ #[ test]
190
+ fn test_db_debug ( ) {
191
+ let tmp_dir = tempfile:: tempdir ( ) . unwrap ( ) ;
192
+ let storage = FsStorage :: new ( tmp_dir. path ( ) . to_path_buf ( ) ) ;
193
+ let config = Config :: default ( ) ;
194
+ let path = "test_rotbl" ;
195
+ let rotbl =
196
+ Rotbl :: create_table ( storage, config, path, RotblMeta :: new ( 1 , "foo" ) , [ ] ) . unwrap ( ) ;
197
+
198
+ let db = DB {
199
+ storage_path : "a" . to_string ( ) ,
200
+ rel_path : "b" . to_string ( ) ,
201
+ meta : Default :: default ( ) ,
202
+ sys_data : Default :: default ( ) ,
203
+ rotbl : Arc :: new ( rotbl) ,
204
+ } ;
205
+
206
+ assert_eq ! (
207
+ format!( "{:?}" , db) ,
208
+ r#"DB { storage_path: "a", rel_path: "b", meta: SnapshotMeta { last_log_id: None, last_membership: StoredMembership { log_id: None, membership: Membership { configs: [], nodes: {} } }, snapshot_id: "" }, sys_data: SysData { last_applied: None, last_membership: StoredMembership { log_id: None, membership: Membership { configs: [], nodes: {} } }, nodes: {}, sequence: 0, key_counts: {}, sm_features: {} } }"#
209
+ ) ;
210
+ }
211
+ }
0 commit comments