Added partial test for cleaner.
This commit is contained in:
parent
ae4e52ff69
commit
2ab3600117
@ -5,6 +5,7 @@
|
||||
#include <utility>
|
||||
#include "utils/crtp.hpp"
|
||||
|
||||
// TODO: reimplement this
|
||||
template <class T>
|
||||
class List
|
||||
{
|
||||
@ -183,19 +184,23 @@ private:
|
||||
private:
|
||||
void find_and_disconnect()
|
||||
{
|
||||
auto it = It(list);
|
||||
Node *bef = nullptr;
|
||||
auto now = load(list->head);
|
||||
auto next = load(curr->next);
|
||||
while (it.valid()) {
|
||||
if (it.curr == curr) {
|
||||
if (it.disconnect()) {
|
||||
while (now != nullptr) {
|
||||
if (now == curr) {
|
||||
prev = bef;
|
||||
if (disconnect()) {
|
||||
return;
|
||||
}
|
||||
it.reset();
|
||||
} else if (it.curr == next) { // Comparison with next is
|
||||
// optimization for early return.
|
||||
bef = nullptr;
|
||||
now = load(list->head);
|
||||
} else if (now == next) { // Comparison with next is
|
||||
// optimization for early return.
|
||||
return;
|
||||
} else {
|
||||
it++;
|
||||
bef = now;
|
||||
now = load(now->next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,18 @@ auto load_queries(Db &db)
|
||||
return t.commit();
|
||||
};
|
||||
|
||||
auto create_labeled_and_named_node_v2 = [&db](const properties_t &args) {
|
||||
DbAccessor t(db);
|
||||
auto prop_key = t.vertex_property_key("name", args[0]->flags);
|
||||
auto &label = t.label_find_or_create("OTHER");
|
||||
|
||||
auto vertex_accessor = t.vertex_insert();
|
||||
vertex_accessor.set(prop_key, args[0]);
|
||||
vertex_accessor.add_label(label);
|
||||
// cout_properties(vertex_accessor.properties());
|
||||
return t.commit();
|
||||
};
|
||||
|
||||
auto create_account = [&db](const properties_t &args) {
|
||||
DbAccessor t(db);
|
||||
auto prop_id = t.vertex_property_key("id", args[0]->flags);
|
||||
@ -393,6 +405,7 @@ auto load_queries(Db &db)
|
||||
queries[15648836733456301916u] = create_edge_v2;
|
||||
queries[10597108978382323595u] = create_account;
|
||||
queries[5397556489557792025u] = create_labeled_and_named_node;
|
||||
queries[16090682663946456821u] = create_labeled_and_named_node_v2;
|
||||
queries[7939106225150551899u] = create_edge;
|
||||
queries[6579425155585886196u] = create_edge;
|
||||
queries[11198568396549106428u] = find_node_by_internal_id;
|
||||
|
@ -17,8 +17,12 @@ public:
|
||||
{
|
||||
// use a slow, more complex rnd generator to initialize a fast one
|
||||
// make sure to call this before requesting any random numbers!
|
||||
std::random_device rd;
|
||||
std::mt19937_64 gen(rd());
|
||||
|
||||
// NOTE: Valgird complanis to next instruction
|
||||
// std::random_device rd;
|
||||
// std::mt19937_64 gen(rd());
|
||||
std::mt19937_64 gen(time(0));
|
||||
|
||||
std::uniform_int_distribution<unsigned long long> dist;
|
||||
|
||||
// the number generated by MT can be full of zeros and xorshift
|
||||
|
@ -19,6 +19,7 @@ Cleaning::Cleaning(ConcurrentMap<std::string, Db> &dbs) : dbms(dbs)
|
||||
DbTransaction t(db.second);
|
||||
t.clean_edge_section();
|
||||
t.clean_vertex_section();
|
||||
t.trans.commit();
|
||||
}
|
||||
last_clean = now;
|
||||
} else {
|
||||
|
@ -2,8 +2,7 @@
|
||||
#include "storage/label/label.hpp"
|
||||
|
||||
Label::Label(const char *name)
|
||||
: name(std::string(name)),
|
||||
index_v(std::unique_ptr<label_index_t>(new label_index_t()))
|
||||
: name(std::string(name)), index_v(std::make_unique<label_index_t>())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,14 @@ target_link_libraries(integration_queries ${fmt_static_lib})
|
||||
add_test(NAME integration_queries COMMAND integration_queries)
|
||||
set_property(TARGET integration_queries PROPERTY CXX_STANDARD 14)
|
||||
|
||||
# test cleaning methods
|
||||
add_executable(cleaning integration/cleaning.cpp)
|
||||
target_link_libraries(cleaning memgraph)
|
||||
target_link_libraries(cleaning Threads::Threads)
|
||||
target_link_libraries(cleaning ${fmt_static_lib})
|
||||
add_test(NAME cleaning COMMAND cleaning)
|
||||
set_property(TARGET cleaning PROPERTY CXX_STANDARD 14)
|
||||
|
||||
# test query engine
|
||||
add_executable(integration_query_engine integration/query_engine.cpp)
|
||||
target_link_libraries(integration_query_engine Threads::Threads)
|
||||
|
94
tests/integration/cleaning.cpp
Normal file
94
tests/integration/cleaning.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
#include "query_engine/hardcode/queries.hpp"
|
||||
|
||||
#include "barrier/barrier.cpp"
|
||||
|
||||
#include "logging/default.hpp"
|
||||
#include "logging/streams/stdout.hpp"
|
||||
#include "query_engine/query_stripper.hpp"
|
||||
#include "utils/sysinfo/memory.hpp"
|
||||
|
||||
template <class S, class Q>
|
||||
void run(size_t n, std::string &query, S &stripper, Q &qf)
|
||||
{
|
||||
auto stripped = stripper.strip(query);
|
||||
std::cout << "Running query [" << stripped.hash << "] for " << n << " time."
|
||||
<< std::endl;
|
||||
for (int i = 0; i < n; i++) {
|
||||
assert(qf[stripped.hash](stripped.arguments));
|
||||
}
|
||||
}
|
||||
|
||||
void clean_vertex(Db &db)
|
||||
{
|
||||
DbTransaction t(db);
|
||||
t.clean_vertex_section();
|
||||
t.trans.commit();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
logging::init_async();
|
||||
logging::log->pipe(std::make_unique<Stdout>());
|
||||
|
||||
size_t cvl_n = 1000;
|
||||
|
||||
Db db;
|
||||
|
||||
auto query_functions = load_queries(barrier::trans(db));
|
||||
|
||||
auto stripper = make_query_stripper(TK_LONG, TK_FLOAT, TK_STR, TK_BOOL);
|
||||
|
||||
std::string create_vertex_label =
|
||||
"CREATE (n:LABEL {name: \"cleaner_test\"}) RETURN n";
|
||||
std::string create_vertex_other =
|
||||
"CREATE (n:OTHER {name: \"cleaner_test\"}) RETURN n";
|
||||
std::string delete_label_vertices = "MATCH (n:LABEL) DELETE n";
|
||||
std::string delete_all_vertices = "MATCH (n) DELETE n";
|
||||
|
||||
// ******************************* TEST 1 ********************************//
|
||||
// add vertices a
|
||||
// clean vertices
|
||||
// delete vertices a
|
||||
// clean vertices
|
||||
run(cvl_n, create_vertex_label, stripper, query_functions);
|
||||
assert(db.graph.vertices.access().size() == cvl_n);
|
||||
|
||||
clean_vertex(db);
|
||||
assert(db.graph.vertices.access().size() == cvl_n);
|
||||
|
||||
run(1, delete_label_vertices, stripper, query_functions);
|
||||
assert(db.graph.vertices.access().size() == cvl_n);
|
||||
|
||||
clean_vertex(db);
|
||||
assert(db.graph.vertices.access().size() == 0);
|
||||
|
||||
// ******************************* TEST 2 ********************************//
|
||||
// add vertices a
|
||||
// add vertices b
|
||||
// clean vertices
|
||||
// delete vertices a
|
||||
// clean vertices
|
||||
// delete vertices all
|
||||
run(cvl_n, create_vertex_label, stripper, query_functions);
|
||||
assert(db.graph.vertices.access().size() == cvl_n);
|
||||
|
||||
run(cvl_n, create_vertex_other, stripper, query_functions);
|
||||
assert(db.graph.vertices.access().size() == cvl_n * 2);
|
||||
|
||||
clean_vertex(db);
|
||||
assert(db.graph.vertices.access().size() == cvl_n * 2);
|
||||
|
||||
run(1, delete_label_vertices, stripper, query_functions);
|
||||
assert(db.graph.vertices.access().size() == cvl_n * 2);
|
||||
|
||||
clean_vertex(db);
|
||||
assert(db.graph.vertices.access().size() == cvl_n);
|
||||
|
||||
run(1, delete_all_vertices, stripper, query_functions);
|
||||
assert(db.graph.vertices.access().size() == cvl_n);
|
||||
|
||||
clean_vertex(db);
|
||||
assert(db.graph.vertices.access().size() == 0);
|
||||
|
||||
return 0;
|
||||
}
|
@ -24,6 +24,7 @@ int main(void)
|
||||
"CREATE (n:LABEL {name: \"TEST1\"}) RETURN n",
|
||||
"CREATE (n:LABEL {name: \"TEST2\"}) RETURN n",
|
||||
"CREATE (n:LABEL {name: \"TEST3\"}) RETURN n",
|
||||
"CREATE (n:OTHER {name: \"TEST4\"}) RETURN n"
|
||||
"CREATE (n:ACCOUNT {id: 2322, name: \"TEST\", country: \"Croatia\", "
|
||||
"created_at: 2352352}) RETURN n",
|
||||
"MATCH (n {id: 0}) RETURN n", "MATCH (n {id: 1}) RETURN n",
|
||||
|
@ -1,14 +0,0 @@
|
||||
|
||||
#include "database/db.hpp"
|
||||
// #include "storage/edges.cpp"
|
||||
// #include "storage/edges.hpp"
|
||||
// #include "storage/vertices.cpp"
|
||||
// #include "storage/vertices.hpp"
|
||||
// #include "utils/assert.hpp"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
Db db;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user