Skip to content

Commit aa92b2d

Browse files
mr-czaidoon1
authored andcommitted
More temp directories for tests
1 parent a0ffb19 commit aa92b2d

9 files changed

+98
-22
lines changed

src/db_iterator.rs

+30-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ pub type DBRawIterator<'a> = DBRawIteratorWithThreadMode<'a, DB>;
3333
/// ```
3434
/// use rust_rocksdb::{DB, Options};
3535
///
36-
/// let path = "_path_for_rocksdb_storage4";
36+
/// let tempdir = tempfile::Builder::new()
37+
/// .prefix("_path_for_rocksdb_storage4")
38+
/// .tempdir()
39+
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage4.");
40+
/// let path = tempdir.path();
3741
/// {
3842
/// let db = DB::open_default(path).unwrap();
3943
/// let mut iter = db.raw_iterator();
@@ -143,7 +147,11 @@ impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> {
143147
/// ```rust
144148
/// use rust_rocksdb::{DB, Options};
145149
///
146-
/// let path = "_path_for_rocksdb_storage5";
150+
/// let tempdir = tempfile::Builder::new()
151+
/// .prefix("_path_for_rocksdb_storage5")
152+
/// .tempdir()
153+
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage5.");
154+
/// let path = tempdir.path();
147155
/// {
148156
/// let db = DB::open_default(path).unwrap();
149157
/// let mut iter = db.raw_iterator();
@@ -180,7 +188,11 @@ impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> {
180188
/// ```rust
181189
/// use rust_rocksdb::{DB, Options};
182190
///
183-
/// let path = "_path_for_rocksdb_storage6";
191+
/// let tempdir = tempfile::Builder::new()
192+
/// .prefix("_path_for_rocksdb_storage6")
193+
/// .tempdir()
194+
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage6.");
195+
/// let path = tempdir.path();
184196
/// {
185197
/// let db = DB::open_default(path).unwrap();
186198
/// let mut iter = db.raw_iterator();
@@ -220,7 +232,11 @@ impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> {
220232
/// ```rust
221233
/// use rust_rocksdb::{DB, Options};
222234
///
223-
/// let path = "_path_for_rocksdb_storage7";
235+
/// let tempdir = tempfile::Builder::new()
236+
/// .prefix("_path_for_rocksdb_storage7")
237+
/// .tempdir()
238+
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage7.");
239+
/// let path = tempdir.path();
224240
/// {
225241
/// let db = DB::open_default(path).unwrap();
226242
/// let mut iter = db.raw_iterator();
@@ -259,7 +275,11 @@ impl<'a, D: DBAccess> DBRawIteratorWithThreadMode<'a, D> {
259275
/// ```rust
260276
/// use rust_rocksdb::{DB, Options};
261277
///
262-
/// let path = "_path_for_rocksdb_storage8";
278+
/// let tempdir = tempfile::Builder::new()
279+
/// .prefix("_path_for_rocksdb_storage8")
280+
/// .tempdir()
281+
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage8.");
282+
/// let path = tempdir.path();
263283
/// {
264284
/// let db = DB::open_default(path).unwrap();
265285
/// let mut iter = db.raw_iterator();
@@ -377,7 +397,11 @@ pub type DBIterator<'a> = DBIteratorWithThreadMode<'a, DB>;
377397
/// ```
378398
/// use rust_rocksdb::{DB, Direction, IteratorMode, Options};
379399
///
380-
/// let path = "_path_for_rocksdb_storage2";
400+
/// let tempdir = tempfile::Builder::new()
401+
/// .prefix("_path_for_rocksdb_storage2")
402+
/// .tempdir()
403+
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage2.");
404+
/// let path = tempdir.path();
381405
/// {
382406
/// let db = DB::open_default(path).unwrap();
383407
/// let mut iter = db.iterator(IteratorMode::Start); // Always iterates forward

src/db_options.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ pub struct Options {
299299
/// ```
300300
/// use rust_rocksdb::{DB, Options, WriteBatch, WriteOptions};
301301
///
302-
/// let path = "_path_for_rocksdb_storageY1";
302+
/// let tempdir = tempfile::Builder::new()
303+
/// .prefix("_path_for_rocksdb_storageY1")
304+
/// .tempdir()
305+
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storageY1");
306+
/// let path = tempdir.path();
303307
/// {
304308
/// let db = DB::open_default(path).unwrap();
305309
/// let mut batch = WriteBatch::default();
@@ -332,7 +336,11 @@ pub struct LruCacheOptions {
332336
/// ```
333337
/// use rust_rocksdb::{DB, Options, FlushOptions};
334338
///
335-
/// let path = "_path_for_rocksdb_storageY2";
339+
/// let tempdir = tempfile::Builder::new()
340+
/// .prefix("_path_for_rocksdb_storageY2")
341+
/// .tempdir()
342+
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storageY2");
343+
/// let path = tempdir.path();
336344
/// {
337345
/// let db = DB::open_default(path).unwrap();
338346
///
@@ -381,18 +389,26 @@ pub struct CuckooTableOptions {
381389
///
382390
/// let writer_opts = Options::default();
383391
/// let mut writer = SstFileWriter::create(&writer_opts);
384-
/// writer.open("_path_for_sst_file").unwrap();
392+
/// let tempdir = tempfile::Builder::new()
393+
/// .tempdir()
394+
/// .expect("Failed to create temporary folder for the _path_for_sst_file");
395+
/// let path1 = tempdir.path().join("_path_for_sst_file");
396+
/// writer.open(path1.clone()).unwrap();
385397
/// writer.put(b"k1", b"v1").unwrap();
386398
/// writer.finish().unwrap();
387399
///
388-
/// let path = "_path_for_rocksdb_storageY3";
400+
/// let tempdir2 = tempfile::Builder::new()
401+
/// .prefix("_path_for_rocksdb_storageY3")
402+
/// .tempdir()
403+
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storageY3");
404+
/// let path2 = tempdir2.path();
389405
/// {
390-
/// let db = DB::open_default(&path).unwrap();
406+
/// let db = DB::open_default(&path2).unwrap();
391407
/// let mut ingest_opts = IngestExternalFileOptions::default();
392408
/// ingest_opts.set_move_files(true);
393-
/// db.ingest_external_file_opts(&ingest_opts, vec!["_path_for_sst_file"]).unwrap();
409+
/// db.ingest_external_file_opts(&ingest_opts, vec![path1]).unwrap();
394410
/// }
395-
/// let _ = DB::destroy(&Options::default(), path);
411+
/// let _ = DB::destroy(&Options::default(), path2);
396412
/// ```
397413
pub struct IngestExternalFileOptions {
398414
pub(crate) inner: *mut ffi::rocksdb_ingestexternalfileoptions_t,

src/lib.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
//! ```
2121
//! use rust_rocksdb::{DB, Options};
2222
//! // NB: db is automatically closed at end of lifetime
23-
//! let path = "_path_for_rocksdb_storage";
23+
//! let tempdir = tempfile::Builder::new()
24+
//! .prefix("_path_for_rocksdb_storage")
25+
//! .tempdir()
26+
//! .expect("Failed to create temporary path for the _path_for_rocksdb_storage");
27+
//! let path = tempdir.path();
2428
//! {
2529
//! let db = DB::open_default(path).unwrap();
2630
//! db.put(b"my key", b"my value").unwrap();
@@ -39,7 +43,11 @@
3943
//! ```
4044
//! use rust_rocksdb::{DB, ColumnFamilyDescriptor, Options};
4145
//!
42-
//! let path = "_path_for_rocksdb_storage_with_cfs";
46+
//! let tempdir = tempfile::Builder::new()
47+
//! .prefix("_path_for_rocksdb_storage_with_cfs")
48+
//! .tempdir()
49+
//! .expect("Failed to create temporary path for the _path_for_rocksdb_storage_with_cfs.");
50+
//! let path = tempdir.path();
4351
//! let mut cf_opts = Options::default();
4452
//! cf_opts.set_max_write_buffer_number(16);
4553
//! let cf = ColumnFamilyDescriptor::new("cf1", cf_opts);

src/merge_operator.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
//! Some(result)
3838
//! }
3939
//!
40-
//!let path = "_rust_path_to_rocksdb";
40+
//!let tempdir = tempfile::Builder::new()
41+
//! .prefix("_rust_path_to_rocksdb")
42+
//! .tempdir()
43+
//! .expect("Failed to create temporary path for the _rust_path_to_rocksdb");
44+
//!let path = tempdir.path();
4145
//!let mut opts = Options::default();
4246
//!
4347
//!opts.create_if_missing(true);

src/snapshot.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ pub type Snapshot<'a> = SnapshotWithThreadMode<'a, DB>;
2727
/// ```
2828
/// use rust_rocksdb::{DB, IteratorMode, Options};
2929
///
30-
/// let path = "_path_for_rocksdb_storage3";
30+
/// let tempdir = tempfile::Builder::new()
31+
/// .prefix("_path_for_rocksdb_storage3")
32+
/// .tempdir()
33+
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage3");
34+
/// let path = tempdir.path();
3135
/// {
3236
/// let db = DB::open_default(path).unwrap();
3337
/// let snapshot = db.snapshot(); // Creates a longer-term snapshot of the DB, but closed when goes out of scope

src/transactions/optimistic_transaction_db.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ use crate::{
4141
///
4242
/// ```
4343
/// use rust_rocksdb::{DB, Options, OptimisticTransactionDB, SingleThreaded};
44-
/// let path = "_path_for_optimistic_transaction_db";
44+
/// let tempdir = tempfile::Builder::new()
45+
/// .prefix("_path_for_optimistic_transaction_db")
46+
/// .tempdir()
47+
/// .expect("Failed to create temporary path for the _path_for_optimistic_transaction_db");
48+
/// let path = tempdir.path();
4549
/// {
4650
/// let db: OptimisticTransactionDB = OptimisticTransactionDB::open_default(path).unwrap();
4751
/// db.put(b"my key", b"my value").unwrap();

src/transactions/transaction_db.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ type DefaultThreadMode = crate::MultiThreaded;
5656
///
5757
/// ```
5858
/// use rust_rocksdb::{DB, Options, TransactionDB, SingleThreaded};
59-
/// let path = "_path_for_transaction_db";
59+
/// let tempdir = tempfile::Builder::new()
60+
/// .prefix("_path_for_transaction_db")
61+
/// .tempdir()
62+
/// .expect("Failed to create temporary path for the _path_for_transaction_db");
63+
/// let path = tempdir.path();
6064
/// {
6165
/// let db: TransactionDB = TransactionDB::open_default(path).unwrap();
6266
/// db.put(b"my key", b"my value").unwrap();

src/write_batch.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ pub type WriteBatch = WriteBatchWithTransaction<false>;
2828
/// ```
2929
/// use rust_rocksdb::{DB, Options, WriteBatchWithTransaction};
3030
///
31-
/// let path = "_path_for_rocksdb_storage1";
31+
/// let tempdir = tempfile::Builder::new()
32+
/// .prefix("_path_for_rocksdb_storage1")
33+
/// .tempdir()
34+
/// .expect("Failed to create temporary path for the _path_for_rocksdb_storage1");
35+
/// let path = tempdir.path();
3236
/// {
3337
/// let db = DB::open_default(path).unwrap();
3438
/// let mut batch = WriteBatchWithTransaction::<false>::default();

tests/test_comparator.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ fn test_comparator() {
8181

8282
#[test]
8383
fn test_comparator_with_ts() {
84-
let path = "_path_for_rocksdb_storage_with_ts";
84+
let tempdir = tempfile::Builder::new()
85+
.prefix("_path_for_rocksdb_storage_with_ts")
86+
.tempdir()
87+
.expect("Failed to create temporary path for the _path_for_rocksdb_storage_with_ts.");
88+
let path = tempdir.path();
8589
let _ = DB::destroy(&Options::default(), path);
8690

8791
{
@@ -169,7 +173,11 @@ fn test_comparator_with_ts() {
169173

170174
#[test]
171175
fn test_comparator_with_column_family_with_ts() {
172-
let path = "_path_for_rocksdb_storage_with_column_family_with_ts";
176+
let tempdir = tempfile::Builder::new()
177+
.prefix("_path_for_rocksdb_storage_with_column_family_with_ts")
178+
.tempdir()
179+
.expect("Failed to create temporary path for the _path_for_rocksdb_storage_with_column_family_with_ts.");
180+
let path = tempdir.path();
173181
let _ = DB::destroy(&Options::default(), path);
174182

175183
{

0 commit comments

Comments
 (0)