@@ -12,7 +12,11 @@ pub struct DummyImmutablesDbBuilder {
12
12
immutables_to_write : Vec < ImmutableFileNumber > ,
13
13
non_immutables_to_write : Vec < String > ,
14
14
append_uncompleted_trio : bool ,
15
- file_size : Option < u64 > ,
15
+ immutable_file_size : Option < u64 > ,
16
+ ledger_files_to_write : Vec < String > ,
17
+ ledger_file_size : Option < u64 > ,
18
+ volatile_files_to_write : Vec < String > ,
19
+ volatile_file_size : Option < u64 > ,
16
20
}
17
21
18
22
/// A dummy cardano immutable db.
@@ -51,7 +55,11 @@ impl DummyImmutablesDbBuilder {
51
55
immutables_to_write : vec ! [ ] ,
52
56
non_immutables_to_write : vec ! [ ] ,
53
57
append_uncompleted_trio : false ,
54
- file_size : None ,
58
+ immutable_file_size : None ,
59
+ ledger_files_to_write : vec ! [ ] ,
60
+ ledger_file_size : None ,
61
+ volatile_files_to_write : vec ! [ ] ,
62
+ volatile_file_size : None ,
55
63
}
56
64
}
57
65
@@ -68,6 +76,30 @@ impl DummyImmutablesDbBuilder {
68
76
self
69
77
}
70
78
79
+ /// Set ledger files to write to the db in the 'ledger' subdirectory.
80
+ pub fn with_ledger_files ( & mut self , files : Vec < String > ) -> & mut Self {
81
+ self . ledger_files_to_write = files;
82
+ self
83
+ }
84
+
85
+ /// Set the size of all ledger files written by [build][Self::build] to the given `file_size` in bytes.
86
+ pub fn set_ledger_file_size ( & mut self , file_size : u64 ) -> & mut Self {
87
+ self . ledger_file_size = Some ( file_size) ;
88
+ self
89
+ }
90
+
91
+ /// Set volatile files to write to the db in the 'volatile' subdirectory.
92
+ pub fn with_volatile_files ( & mut self , files : Vec < String > ) -> & mut Self {
93
+ self . volatile_files_to_write = files;
94
+ self
95
+ }
96
+
97
+ /// Set the size of all volatile files written by [build][Self::build] to the given `file_size` in bytes.
98
+ pub fn set_volatile_file_size ( & mut self , file_size : u64 ) -> & mut Self {
99
+ self . volatile_file_size = Some ( file_size) ;
100
+ self
101
+ }
102
+
71
103
/// Makes [build][Self::build] add another trio of immutables file, that won't be included
72
104
/// in its returned vec, to simulate the last 3 'uncompleted / wip' files that can be found in
73
105
/// a cardano immutable db.
@@ -76,11 +108,11 @@ impl DummyImmutablesDbBuilder {
76
108
self
77
109
}
78
110
79
- /// Set the size of all files written by [build][Self::build] to the given `file_size` in bytes.
111
+ /// Set the size of all immutable files written by [build][Self::build] to the given `file_size` in bytes.
80
112
///
81
113
/// Note: by default the size of the produced files is less than a 1kb.
82
- pub fn set_file_size ( & mut self , file_size : u64 ) -> & mut Self {
83
- self . file_size = Some ( file_size) ;
114
+ pub fn set_immutable_file_size ( & mut self , file_size : u64 ) -> & mut Self {
115
+ self . immutable_file_size = Some ( file_size) ;
84
116
self
85
117
}
86
118
@@ -92,7 +124,7 @@ impl DummyImmutablesDbBuilder {
92
124
93
125
if self . append_uncompleted_trio {
94
126
write_immutable_trio (
95
- self . file_size ,
127
+ self . immutable_file_size ,
96
128
& self . dir ,
97
129
match immutable_numbers. last ( ) {
98
130
None => 0 ,
@@ -102,14 +134,34 @@ impl DummyImmutablesDbBuilder {
102
134
}
103
135
104
136
for non_immutable in & self . non_immutables_to_write {
105
- non_immutables_files. push ( write_dummy_file ( self . file_size , & self . dir , non_immutable) ) ;
137
+ non_immutables_files. push ( write_dummy_file (
138
+ self . immutable_file_size ,
139
+ & self . dir ,
140
+ non_immutable,
141
+ ) ) ;
142
+ }
143
+
144
+ if !self . ledger_files_to_write . is_empty ( ) {
145
+ let ledger_dir = self . dir . parent ( ) . unwrap ( ) . join ( "ledger" ) ;
146
+ std:: fs:: create_dir_all ( & ledger_dir) . unwrap ( ) ;
147
+ for filename in & self . ledger_files_to_write {
148
+ write_dummy_file ( self . ledger_file_size , & ledger_dir, filename) ;
149
+ }
150
+ } ;
151
+
152
+ if !self . volatile_files_to_write . is_empty ( ) {
153
+ let volatile_dir = self . dir . parent ( ) . unwrap ( ) . join ( "volatile" ) ;
154
+ std:: fs:: create_dir_all ( & volatile_dir) . unwrap ( ) ;
155
+ for filename in & self . volatile_files_to_write {
156
+ write_dummy_file ( self . volatile_file_size , & volatile_dir, filename) ;
157
+ }
106
158
}
107
159
108
160
DummyImmutableDb {
109
161
dir : self . dir . clone ( ) ,
110
162
immutables_files : immutable_numbers
111
163
. into_iter ( )
112
- . flat_map ( |ifn| write_immutable_trio ( self . file_size , & self . dir , ifn) )
164
+ . flat_map ( |ifn| write_immutable_trio ( self . immutable_file_size , & self . dir , ifn) )
113
165
. collect :: < Vec < _ > > ( ) ,
114
166
non_immutables_files,
115
167
}
0 commit comments