Added stress test for ConncurentList.

This commit is contained in:
Kruno Tomola Fabro 2016-09-13 17:53:40 +01:00
parent e22074ad9f
commit a6f72dc3fd
4 changed files with 106 additions and 1 deletions

View File

@ -27,6 +27,11 @@ void add_scores(Db &db, double max_value, std::string const &property_name)
t.commit();
}
// Tool to add double propertys to all vertices.
// // Accepts flags for csv import.
// -db name , will create database with that name.
// -pn name , will name property with that name,default: name=score.
// -max number , will set range of property [0,max], default: max=1
int main(int argc, char **argv)
{
logging::init_async();

View File

@ -292,7 +292,8 @@ std::string SnapshotEngine::snapshot_file(std::time_t const &now,
auto now_nano = std::chrono::time_point_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now())
.time_since_epoch()
.count();
.count() %
(1000 * 1000 * 1000);
return snapshot_db_dir() + "/" + std::to_string(now) + "_" +
std::to_string(now_nano) + "_" + type;
}

View File

@ -13,6 +13,7 @@
#include "data_structures/concurrent/concurrent_multiset.hpp"
#include "data_structures/concurrent/concurrent_set.hpp"
#include "data_structures/concurrent/skiplist.hpp"
#include "data_structures/concurrent/concurrent_list.hpp"
#include "data_structures/static_array.hpp"
#include "utils/assert.hpp"
#include "logging/default.hpp"
@ -64,6 +65,26 @@ void check_present_same(typename S::Accessor &acc,
// Checks if reported size and traversed size are equal to given size.
template <typename S>
void check_size_list(S &acc, long long size)
{
// check size
permanent_assert(acc.size() == size, "Size should be " << size
<< ", but size is "
<< acc.size());
// check count
size_t iterator_counter = 0;
for (auto elem : acc) {
++iterator_counter;
}
permanent_assert(iterator_counter == size, "Iterator count should be "
<< size << ", but size is "
<< iterator_counter);
}
template <typename S>
void check_size(typename S::Accessor &acc, long long size)
{
// check size
@ -83,6 +104,7 @@ void check_size(typename S::Accessor &acc, long long size)
<< size << ", but size is "
<< iterator_counter);
}
// Checks if order in list is maintened. It expects map
template <typename S>
void check_order(typename S::Accessor &acc)

View File

@ -0,0 +1,77 @@
#include "common.h"
#define THREADS_NO 8
constexpr size_t key_range = 1e2;
constexpr size_t op_per_thread = 1e5;
// Depending on value there is a possiblity of numerical overflow
constexpr size_t max_number = 10;
constexpr size_t no_find_per_change = 2;
constexpr size_t no_insert_for_one_delete = 1;
// This test simulates behavior of transactions.
// Each thread makes a series of finds interleaved with method which change.
// Exact ratio of finds per change and insert per delete can be regulated with
// no_find_per_change and no_insert_for_one_delete.
int main()
{
init_log();
memory_check(THREADS_NO, [] {
ConcurrentList<std::pair<int, int>> list;
auto futures = run<std::pair<long long, long long>>(
THREADS_NO, [&](auto index) mutable {
auto rand = rand_gen(key_range);
auto rand_change = rand_gen_bool(no_find_per_change);
auto rand_delete = rand_gen_bool(no_insert_for_one_delete);
long long sum = 0;
long long count = 0;
for (int i = 0; i < op_per_thread; i++) {
auto num = rand();
auto data = num % max_number;
if (rand_change()) {
if (rand_delete()) {
for (auto it = list.begin(); it != list.end();
it++) {
if (it->first == num) {
if (it.remove()) {
sum -= data;
count--;
}
break;
}
}
} else {
list.begin().push(std::make_pair(num, data));
sum += data;
count++;
}
} else {
for (auto &v : list) {
if (v.first == num) {
permanent_assert(v.second == data,
"Data is invalid");
break;
}
}
}
}
return std::pair<long long, long long>(sum, count);
});
auto it = list.begin();
long long sums = 0;
long long counters = 0;
for (auto &data : collect(futures)) {
sums += data.second.first;
counters += data.second.second;
}
for (auto &e : list) {
sums -= e.second;
}
permanent_assert(sums == 0, "Same values aren't present");
check_size_list<ConcurrentList<std::pair<int, int>>>(list, counters);
});
}