1
+ // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2
+ // This source code is licensed under both the GPLv2 (found in the
3
+ // COPYING file in the root directory) and Apache 2.0 License
4
+ // (found in the LICENSE.Apache file in the root directory).
5
+ //
6
+
1
7
/* *
2
8
* An persistent map : key -> (list of strings), using rocksdb merge.
3
9
* This file is a test-harness / use-case for the StringAppendOperator.
6
12
* Copyright 2013 Facebook, Inc.
7
13
*/
8
14
15
+ #include " utilities/merge_operators/string_append/stringappend.h"
16
+
9
17
#include < iostream>
10
18
#include < map>
19
+ #include < tuple>
11
20
21
+ #include " port/stack_trace.h"
12
22
#include " rocksdb/db.h"
13
23
#include " rocksdb/merge_operator.h"
14
24
#include " rocksdb/utilities/db_ttl.h"
15
25
#include " test_util/testharness.h"
16
26
#include " util/random.h"
17
27
#include " utilities/merge_operators.h"
18
- #include " utilities/merge_operators/string_append/stringappend.h"
19
28
#include " utilities/merge_operators/string_append/stringappend2.h"
20
29
21
30
using namespace ROCKSDB_NAMESPACE ;
@@ -108,12 +117,26 @@ class StringLists {
108
117
109
118
110
119
// The class for unit-testing
111
- class StringAppendOperatorTest : public testing ::Test {
120
+ class StringAppendOperatorTest : public testing ::Test,
121
+ public ::testing::WithParamInterface<bool > {
112
122
public:
113
123
StringAppendOperatorTest () {
114
124
DestroyDB (kDbName , Options ()); // Start each test with a fresh DB
115
125
}
116
126
127
+ void SetUp () override {
128
+ #ifndef ROCKSDB_LITE // TtlDb is not supported in Lite
129
+ bool if_use_ttl = GetParam ();
130
+ if (if_use_ttl) {
131
+ fprintf (stderr, " Running tests with ttl db and generic operator.\n " );
132
+ StringAppendOperatorTest::SetOpenDbFunction (&OpenTtlDb);
133
+ return ;
134
+ }
135
+ #endif // !ROCKSDB_LITE
136
+ fprintf (stderr, " Running tests with regular db and operator.\n " );
137
+ StringAppendOperatorTest::SetOpenDbFunction (&OpenNormalDb);
138
+ }
139
+
117
140
typedef std::shared_ptr<DB> (* OpenFuncPtr)(char );
118
141
119
142
// Allows user to open databases with different configurations.
@@ -129,7 +152,7 @@ StringAppendOperatorTest::OpenFuncPtr StringAppendOperatorTest::OpenDb = nullptr
129
152
130
153
// THE TEST CASES BEGIN HERE
131
154
132
- TEST_F (StringAppendOperatorTest, IteratorTest) {
155
+ TEST_P (StringAppendOperatorTest, IteratorTest) {
133
156
auto db_ = OpenDb (' ,' );
134
157
StringLists slists (db_);
135
158
@@ -220,10 +243,9 @@ TEST_F(StringAppendOperatorTest, IteratorTest) {
220
243
ASSERT_EQ (res, " g1" );
221
244
}
222
245
}
223
-
224
246
}
225
247
226
- TEST_F (StringAppendOperatorTest, SimpleTest) {
248
+ TEST_P (StringAppendOperatorTest, SimpleTest) {
227
249
auto db = OpenDb (' ,' );
228
250
StringLists slists (db);
229
251
@@ -238,7 +260,7 @@ TEST_F(StringAppendOperatorTest, SimpleTest) {
238
260
ASSERT_EQ (res, " v1,v2,v3" );
239
261
}
240
262
241
- TEST_F (StringAppendOperatorTest, SimpleDelimiterTest) {
263
+ TEST_P (StringAppendOperatorTest, SimpleDelimiterTest) {
242
264
auto db = OpenDb (' |' );
243
265
StringLists slists (db);
244
266
@@ -251,7 +273,7 @@ TEST_F(StringAppendOperatorTest, SimpleDelimiterTest) {
251
273
ASSERT_EQ (res, " v1|v2|v3" );
252
274
}
253
275
254
- TEST_F (StringAppendOperatorTest, OneValueNoDelimiterTest) {
276
+ TEST_P (StringAppendOperatorTest, OneValueNoDelimiterTest) {
255
277
auto db = OpenDb (' !' );
256
278
StringLists slists (db);
257
279
@@ -262,7 +284,7 @@ TEST_F(StringAppendOperatorTest, OneValueNoDelimiterTest) {
262
284
ASSERT_EQ (res, " single_val" );
263
285
}
264
286
265
- TEST_F (StringAppendOperatorTest, VariousKeys) {
287
+ TEST_P (StringAppendOperatorTest, VariousKeys) {
266
288
auto db = OpenDb (' \n ' );
267
289
StringLists slists (db);
268
290
@@ -288,7 +310,7 @@ TEST_F(StringAppendOperatorTest, VariousKeys) {
288
310
}
289
311
290
312
// Generate semi random keys/words from a small distribution.
291
- TEST_F (StringAppendOperatorTest, RandomMixGetAppend) {
313
+ TEST_P (StringAppendOperatorTest, RandomMixGetAppend) {
292
314
auto db = OpenDb (' ' );
293
315
StringLists slists (db);
294
316
@@ -336,10 +358,9 @@ TEST_F(StringAppendOperatorTest, RandomMixGetAppend) {
336
358
}
337
359
338
360
}
339
-
340
361
}
341
362
342
- TEST_F (StringAppendOperatorTest, BIGRandomMixGetAppend) {
363
+ TEST_P (StringAppendOperatorTest, BIGRandomMixGetAppend) {
343
364
auto db = OpenDb (' ' );
344
365
StringLists slists (db);
345
366
@@ -387,10 +408,9 @@ TEST_F(StringAppendOperatorTest, BIGRandomMixGetAppend) {
387
408
}
388
409
389
410
}
390
-
391
411
}
392
412
393
- TEST_F (StringAppendOperatorTest, PersistentVariousKeys) {
413
+ TEST_P (StringAppendOperatorTest, PersistentVariousKeys) {
394
414
// Perform the following operations in limited scope
395
415
{
396
416
auto db = OpenDb (' \n ' );
@@ -457,7 +477,7 @@ TEST_F(StringAppendOperatorTest, PersistentVariousKeys) {
457
477
}
458
478
}
459
479
460
- TEST_F (StringAppendOperatorTest, PersistentFlushAndCompaction) {
480
+ TEST_P (StringAppendOperatorTest, PersistentFlushAndCompaction) {
461
481
// Perform the following operations in limited scope
462
482
{
463
483
auto db = OpenDb (' \n ' );
@@ -553,7 +573,7 @@ TEST_F(StringAppendOperatorTest, PersistentFlushAndCompaction) {
553
573
}
554
574
}
555
575
556
- TEST_F (StringAppendOperatorTest, SimpleTestNullDelimiter) {
576
+ TEST_P (StringAppendOperatorTest, SimpleTestNullDelimiter) {
557
577
auto db = OpenDb (' \0 ' );
558
578
StringLists slists (db);
559
579
@@ -576,26 +596,13 @@ TEST_F(StringAppendOperatorTest, SimpleTestNullDelimiter) {
576
596
ASSERT_EQ (res, checker);
577
597
}
578
598
599
+ INSTANTIATE_TEST_CASE_P (StringAppendOperatorTest, StringAppendOperatorTest,
600
+ testing::Bool ());
601
+
579
602
} // namespace ROCKSDB_NAMESPACE
580
603
581
604
int main (int argc, char ** argv) {
605
+ ROCKSDB_NAMESPACE::port::InstallStackTraceHandler ();
582
606
::testing::InitGoogleTest (&argc, argv);
583
- // Run with regular database
584
- int result;
585
- {
586
- fprintf (stderr, " Running tests with regular db and operator.\n " );
587
- StringAppendOperatorTest::SetOpenDbFunction (&OpenNormalDb);
588
- result = RUN_ALL_TESTS ();
589
- }
590
-
591
- #ifndef ROCKSDB_LITE // TtlDb is not supported in Lite
592
- // Run with TTL
593
- {
594
- fprintf (stderr, " Running tests with ttl db and generic operator.\n " );
595
- StringAppendOperatorTest::SetOpenDbFunction (&OpenTtlDb);
596
- result |= RUN_ALL_TESTS ();
597
- }
598
- #endif // !ROCKSDB_LITE
599
-
600
- return result;
607
+ return RUN_ALL_TESTS ();
601
608
}
0 commit comments