/*- * Public Domain 2014-present MongoDB, Inc. * Public Domain 2008-2014 WiredTiger, Inc. * * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ /* * This file provides an example of how to create a test in C++ using a few features from the * framework if any. This file can be used as a template for quick testing and/or when stress * testing is not required. For any stress testing, it is encouraged to use the framework, see * test_template.cpp and create_script.sh. */ #include "src/common/constants.h" #include "src/common/logger.h" #include "src/common/random_generator.h" #include "src/common/thread_manager.h" #include "src/storage/connection_manager.h" extern "C" { #include "wiredtiger.h" #include "test_util.h" } using namespace test_harness; /* Declarations to avoid the error raised by -Werror=missing-prototypes. */ void insert_op(WT_SESSION *session, const std::string& uri); bool do_inserts = false; void insert_op(WT_SESSION *session, const std::string& uri) { logger::log_msg(LOG_INFO, "called insert_op"); /* Insert random data. */ while (do_inserts) { testutil_check(session->compact(session, uri.c_str(), nullptr)); } } int main(int argc, char *argv[]) { /* Set the program name for error messages. */ const std::string progname = testutil_set_progname(argv); /* Set the tracing level for the logger component. */ logger::trace_level = LOG_INFO; /* Printing some messages. */ logger::log_msg(LOG_INFO, "Starting " + progname); logger::log_msg(LOG_ERROR, "This could be an error."); /* Create a connection, set the cache size and specify the home directory. */ const std::string conn_config = CONNECTION_CREATE + ",cache_size=500MB"; const std::string home_dir = std::string(DEFAULT_DIR) + '_' + progname; /* Create connection. */ connection_manager::instance().create(conn_config, home_dir); WT_CONNECTION *conn = connection_manager::instance().get_connection(); /* Open different sessions. */ WT_SESSION *insert_session, *read_session; testutil_check(conn->open_session(conn, nullptr, nullptr, &insert_session)); testutil_check(conn->open_session(conn, nullptr, nullptr, &read_session)); /* Create a collection. */ const std::string collection_name = "table:my_collection"; const std::string collection_name_2 = "table:my_collection_2"; testutil_check(insert_session->create( insert_session, collection_name.c_str(), DEFAULT_FRAMEWORK_SCHEMA.c_str())); testutil_check(insert_session->create( insert_session, collection_name_2.c_str(), DEFAULT_FRAMEWORK_SCHEMA.c_str())); /* Create a thread manager and spawn some threads that will work. */ thread_manager t; do_inserts = true; // Same sessions, same collection -> __wt_txn_context_check, 33: not permitted in a running transaction: Invalid argument // t.add_thread(insert_op, insert_session, collection_name); // t.add_thread(insert_op, insert_session, collection_name); // Same sessions, different collections -> Segmentation fault (core dumped) // t.add_thread(insert_op, insert_session, collection_name); // t.add_thread(insert_op, insert_session, collection_name_2); // Different sessions, same collection, working but should it? // t.add_thread(insert_op, insert_session, collection_name); // t.add_thread(insert_op, read_session, collection_name); // Different sessions, different collections, working as expected. // t.add_thread(insert_op, insert_session, collection_name); // t.add_thread(insert_op, read_session, collection_name_2); /* Sleep for the test duration. */ int test_duration_s = 10; std::this_thread::sleep_for(std::chrono::seconds(test_duration_s)); /* Stop the threads. */ do_inserts = false; t.join(); /* Another message. */ logger::log_msg(LOG_INFO, "End of test."); return (0); }