summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Chen <luke.chen@mongodb.com>2021-09-20 16:30:47 +1000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-09-20 06:57:27 +0000
commitf9a68c4193761922593728bdfa2a72dcfba0fc8d (patch)
treec27119d5a5757c9244d34144ee29ca44a87dc8e3
parenta0ca315a73a8028eb0ffd00531fd98638bc7608a (diff)
downloadmongo-f9a68c4193761922593728bdfa2a72dcfba0fc8d.tar.gz
Import wiredtiger: b97d0cdf23ad071e6dc02902293942ec3f9d07a3 from branch mongodb-master
ref: 4d3742e1be..b97d0cdf23 for: 5.1.0 WT-8093 Improve the CPP testing framework for better flexibility
-rw-r--r--src/third_party/wiredtiger/import.data2
-rwxr-xr-xsrc/third_party/wiredtiger/test/cppsuite/create_test.sh8
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.cxx3
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload/random_generator.cxx62
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload/random_generator.h26
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.cxx20
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.h8
-rw-r--r--src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx15
8 files changed, 108 insertions, 36 deletions
diff --git a/src/third_party/wiredtiger/import.data b/src/third_party/wiredtiger/import.data
index cfcf1723696..bf8e1e6be95 100644
--- a/src/third_party/wiredtiger/import.data
+++ b/src/third_party/wiredtiger/import.data
@@ -2,5 +2,5 @@
"vendor": "wiredtiger",
"github": "wiredtiger/wiredtiger.git",
"branch": "mongodb-master",
- "commit": "4d3742e1bed1e3b52913abf9cb47b6e214e480ec"
+ "commit": "b97d0cdf23ad071e6dc02902293942ec3f9d07a3"
}
diff --git a/src/third_party/wiredtiger/test/cppsuite/create_test.sh b/src/third_party/wiredtiger/test/cppsuite/create_test.sh
index 2af77e4f584..00941911629 100755
--- a/src/third_party/wiredtiger/test/cppsuite/create_test.sh
+++ b/src/third_party/wiredtiger/test/cppsuite/create_test.sh
@@ -52,14 +52,14 @@ VALUE="#include \"$1.cxx\""
sed -i "/$SEARCH/a $VALUE" $FILE
# Add the new test to the run_test() method
-SEARCH="example_test(test_harness::test_args{config, test_name, wt_open_config}).run();"
+SEARCH="example_test("
LINE_1="\else if (test_name == \"$1\")\n"
-LINE_2="\\$1(test_harness::test_args{config, test_name, wt_open_config}).run();"
+LINE_2="\ $1(test_harness::test_args{config, test_name, wt_open_config}).run();"
sed -i "/$SEARCH/a $LINE_1$LINE_2" $FILE
# Add the new test to all existing tests.
-SEARCH="all_tests = {\"example_test\""
-REPLACE="$SEARCH, \"$1\""
+SEARCH="all_tests = {"
+REPLACE="$SEARCH\"$1\", "
sed -i "s/$SEARCH/$REPLACE/" $FILE
echo "Updated $FILE."
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.cxx b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.cxx
index ebd73acf286..fc1f39dee23 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.cxx
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/database_operation.cxx
@@ -156,7 +156,6 @@ database_operation::insert_operation(thread_context *tc)
while (tc->running()) {
uint64_t start_key = ccv[counter].coll.get_key_count();
uint64_t added_count = 0;
- bool committed = true;
tc->transaction.begin();
/* Collection cursor. */
@@ -189,7 +188,7 @@ database_operation::insert_operation(thread_context *tc)
/* Reset our cursor to avoid pinning content. */
testutil_check(cc.cursor->reset(cc.cursor.get()));
counter++;
- if (counter == collections_per_thread)
+ if (counter >= collections_per_thread)
counter = 0;
}
/* Make sure the last transaction is rolled back now the work is finished. */
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/random_generator.cxx b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/random_generator.cxx
index 8a551b80a75..c539fbc34fc 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/random_generator.cxx
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/random_generator.cxx
@@ -27,6 +27,11 @@
*/
#include "random_generator.h"
+#include <algorithm>
+
+extern "C" {
+#include "test_util.h"
+}
namespace test_harness {
random_generator &
@@ -37,25 +42,28 @@ random_generator::instance()
}
std::string
-random_generator::generate_string(std::size_t length)
+random_generator::generate_random_string(std::size_t length, characters_type type)
{
- std::string random_string;
+ std::string str;
- for (std::size_t i = 0; i < length; ++i)
- random_string += _characters[_distribution(_generator)];
+ while (str.size() < length)
+ str += get_characters(type);
- return (random_string);
+ std::shuffle(str.begin(), str.end(), _generator);
+ return (str.substr(0, length));
}
std::string
-random_generator::generate_pseudo_random_string(std::size_t length)
+random_generator::generate_pseudo_random_string(std::size_t length, characters_type type)
{
std::string random_string;
- std::size_t start_location = _distribution(_generator);
+ std::uniform_int_distribution<> &distribution = get_distribution(type);
+ std::size_t start_location = distribution(_generator);
+ const std::string &characters = get_characters(type);
for (std::size_t i = 0; i < length; ++i) {
- random_string += _characters[start_location];
- if (start_location == _characters.size() - 1)
+ random_string += characters[start_location];
+ if (start_location == characters.size() - 1)
start_location = 0;
else
start_location++;
@@ -66,6 +74,40 @@ random_generator::generate_pseudo_random_string(std::size_t length)
random_generator::random_generator()
{
_generator = std::mt19937(std::random_device{}());
- _distribution = std::uniform_int_distribution<>(0, _characters.size() - 1);
+ _alphanum_distrib = std::uniform_int_distribution<>(0, _pseudo_alphanum.size() - 1);
+ _alpha_distrib = std::uniform_int_distribution<>(0, _alphabet.size() - 1);
}
+
+std::uniform_int_distribution<> &
+random_generator::get_distribution(characters_type type)
+{
+ switch (type) {
+ case characters_type::ALPHABET:
+ return (_alpha_distrib);
+ break;
+ case characters_type::PSEUDO_ALPHANUMERIC:
+ return (_alphanum_distrib);
+ break;
+ default:
+ testutil_die(type, "Unexpected characters_type");
+ break;
+ }
+}
+
+const std::string &
+random_generator::get_characters(characters_type type)
+{
+ switch (type) {
+ case characters_type::ALPHABET:
+ return (_alphabet);
+ break;
+ case characters_type::PSEUDO_ALPHANUMERIC:
+ return (_pseudo_alphanum);
+ break;
+ default:
+ testutil_die(type, "Unexpected characters_type");
+ break;
+ }
+}
+
} // namespace test_harness
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/random_generator.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/random_generator.h
index cd6d7d4d7ec..31f44bbe98e 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/random_generator.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/random_generator.h
@@ -29,25 +29,36 @@
#ifndef RANDOM_GENERATOR_H
#define RANDOM_GENERATOR_H
+/* Following definitions are required in order to use printing format specifiers in C++. */
+#define __STDC_LIMIT_MACROS
+#define __STDC_FORMAT_MACROS
+
#include <random>
#include <string>
namespace test_harness {
/* Helper class to generate random values using uniform distributions. */
+
+enum characters_type { PSEUDO_ALPHANUMERIC, ALPHABET };
+
class random_generator {
public:
static random_generator &instance();
- public:
/* No copies of the singleton allowed. */
random_generator(random_generator const &) = delete;
random_generator &operator=(random_generator const &) = delete;
/* Generate a random string of a given length. */
- std::string generate_string(std::size_t length);
+ std::string generate_random_string(
+ std::size_t length, characters_type type = PSEUDO_ALPHANUMERIC);
- /* Generate a pseudo random string which compresses better. */
- std::string generate_pseudo_random_string(std::size_t length);
+ /*
+ * Generate a pseudo random string which compresses better. It should not be used to generate
+ * keys due to the limited randomness.
+ */
+ std::string generate_pseudo_random_string(
+ std::size_t length, characters_type type = PSEUDO_ALPHANUMERIC);
/* Generate a random integer between min and max. */
template <typename T>
@@ -60,10 +71,13 @@ class random_generator {
private:
random_generator();
+ std::uniform_int_distribution<> &get_distribution(characters_type type);
+ const std::string &get_characters(characters_type type);
std::mt19937 _generator;
- std::uniform_int_distribution<> _distribution;
- const std::string _characters =
+ std::uniform_int_distribution<> _alphanum_distrib, _alpha_distrib;
+ const std::string _alphabet = "abcdefghijklmnopqrstuvwxyz";
+ const std::string _pseudo_alphanum =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
};
} // namespace test_harness
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.cxx b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.cxx
index aadf992133e..6216f8f25b5 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.cxx
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.cxx
@@ -219,21 +219,29 @@ thread_context::update(scoped_cursor &cursor, uint64_t collection_id, const std:
}
bool
-thread_context::insert(scoped_cursor &cursor, uint64_t collection_id, uint64_t key_id)
+thread_context::insert(
+ scoped_cursor &cursor, uint64_t collection_id, uint64_t key_id, wt_timestamp_t ts)
+{
+ return insert(cursor, collection_id, key_to_string(key_id), ts);
+}
+
+bool
+thread_context::insert(
+ scoped_cursor &cursor, uint64_t collection_id, const std::string &key, wt_timestamp_t ts)
{
WT_DECL_RET;
- std::string key, value;
+ std::string value;
testutil_assert(tracking != nullptr);
testutil_assert(cursor.get() != nullptr);
/*
- * Get a timestamp to apply to the update. We still do this even if timestamps aren't enabled as
- * it will return a value for the tracking table.
+ * When no timestamp is specified, get one to apply to the update. We still do this even if the
+ * timestamp manager is not enabled as it will return a value for the tracking table.
*/
- wt_timestamp_t ts = tsm->get_next_ts();
+ if (ts == 0)
+ ts = tsm->get_next_ts();
transaction.set_commit_timestamp(ts);
- key = key_to_string(key_id);
value = random_generator::instance().generate_pseudo_random_string(value_size);
cursor->set_key(cursor.get(), key.c_str());
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.h
index 7bb6ac66cb6..e530ce9e111 100644
--- a/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.h
+++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/workload/thread_context.h
@@ -141,11 +141,15 @@ class thread_context {
bool update(scoped_cursor &cursor, uint64_t collection_id, const std::string &key);
/*
- * Generic insert function, takes a collection_id and key_id, will generate the value.
+ * Generic insert function, takes a collection_id and key_id, will generate the value. If a
+ * timestamp is not specified, the timestamp manager will generate one.
*
* Returns true if a rollback is required.
*/
- bool insert(scoped_cursor &cursor, uint64_t collection_id, uint64_t key_id);
+ bool insert(
+ scoped_cursor &cursor, uint64_t collection_id, uint64_t key_id, wt_timestamp_t ts = 0);
+ bool insert(
+ scoped_cursor &cursor, uint64_t collection_id, const std::string &key, wt_timestamp_t ts = 0);
void sleep();
bool running() const;
diff --git a/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx b/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx
index a226fa33ff3..5a1996b45a1 100644
--- a/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx
+++ b/src/third_party/wiredtiger/test/cppsuite/tests/example_test.cxx
@@ -37,21 +37,26 @@ class example_test : public test_harness::test {
example_test(const test_harness::test_args &args) : test(args) {}
void
- populate(test_harness::database &database, test_harness::timestamp_manager *_timestamp_manager,
- test_harness::configuration *_config,
- test_harness::workload_tracking *tracking) override final
+ populate(test_harness::database &, test_harness::timestamp_manager *,
+ test_harness::configuration *, test_harness::workload_tracking *) override final
{
std::cout << "populate: nothing done." << std::endl;
}
void
- read_operation(test_harness::thread_context *context) override final
+ insert_operation(test_harness::thread_context *) override final
+ {
+ std::cout << "insert_operation: nothing done." << std::endl;
+ }
+
+ void
+ read_operation(test_harness::thread_context *) override final
{
std::cout << "read_operation: nothing done." << std::endl;
}
void
- update_operation(test_harness::thread_context *context) override final
+ update_operation(test_harness::thread_context *) override final
{
std::cout << "update_operation: nothing done." << std::endl;
}