memgraph/tests/integration/cleaning.cpp

104 lines
3.0 KiB
C++
Raw Normal View History

2016-08-31 06:07:42 +08:00
#include "query_engine/hardcode/queries.hpp"
#ifdef BARRIER
2016-08-31 06:07:42 +08:00
#include "barrier/barrier.cpp"
#endif
2016-08-31 06:07:42 +08:00
#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++) {
properties_t vec = stripped.arguments;
assert(qf[stripped.hash](std::move(vec)));
2016-08-31 06:07:42 +08:00
}
}
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 entities_number = 1000;
2016-08-31 06:07:42 +08:00
2016-09-10 03:44:34 +08:00
Db db("cleaning");
2016-08-31 06:07:42 +08:00
#ifdef BARRIER
2016-08-31 06:07:42 +08:00
auto query_functions = load_queries(barrier::trans(db));
#else
auto query_functions = load_queries(db);
#endif
2016-08-31 06:07:42 +08:00
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(entities_number, create_vertex_label, stripper, query_functions);
assert(db.graph.vertices.access().size() == entities_number);
2016-08-31 06:07:42 +08:00
clean_vertex(db);
assert(db.graph.vertices.access().size() == entities_number);
2016-08-31 06:07:42 +08:00
run(1, delete_label_vertices, stripper, query_functions);
assert(db.graph.vertices.access().size() == entities_number);
2016-08-31 06:07:42 +08:00
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(entities_number, create_vertex_label, stripper, query_functions);
assert(db.graph.vertices.access().size() == entities_number);
2016-08-31 06:07:42 +08:00
run(entities_number, create_vertex_other, stripper, query_functions);
assert(db.graph.vertices.access().size() == entities_number * 2);
2016-08-31 06:07:42 +08:00
clean_vertex(db);
assert(db.graph.vertices.access().size() == entities_number * 2);
2016-08-31 06:07:42 +08:00
run(1, delete_label_vertices, stripper, query_functions);
assert(db.graph.vertices.access().size() == entities_number * 2);
2016-08-31 06:07:42 +08:00
clean_vertex(db);
assert(db.graph.vertices.access().size() == entities_number);
2016-08-31 06:07:42 +08:00
run(1, delete_all_vertices, stripper, query_functions);
assert(db.graph.vertices.access().size() == entities_number);
2016-08-31 06:07:42 +08:00
clean_vertex(db);
assert(db.graph.vertices.access().size() == 0);
2016-08-31 06:09:56 +08:00
// TODO: more tests
2016-08-31 06:07:42 +08:00
return 0;
}