memgraph/tests/integration/cleaning.cpp

109 lines
3.5 KiB
C++
Raw Normal View History

#include "_hardcoded_query/basic.hpp"
2016-08-31 06:07:42 +08:00
#include "logging/default.hpp"
#include "logging/streams/stdout.hpp"
2016-12-20 01:32:44 +08:00
#include "query/preprocesor.hpp"
#include "query/strip/stripper.hpp"
2016-12-20 01:32:44 +08:00
#include "utils/assert.hpp"
2016-08-31 06:07:42 +08:00
#include "utils/sysinfo/memory.hpp"
2016-12-20 01:32:44 +08:00
QueryPreprocessor preprocessor;
template <class Q>
void run(size_t n, std::string &query, Q &qf)
2016-08-31 06:07:42 +08:00
{
2016-12-20 01:32:44 +08:00
auto stripped = preprocessor.preprocess(query);
logging::info("Running query [{}] x {}.", stripped.hash, n);
for (int i = 0; i < n; i++)
{
properties_t vec = stripped.arguments;
2016-12-20 01:32:44 +08:00
permanent_assert(qf[stripped.hash](std::move(vec)), "Query failed!");
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>());
2016-09-10 03:44:34 +08:00
Db db("cleaning");
2016-08-31 06:07:42 +08:00
2016-12-20 01:32:44 +08:00
size_t entities_number = 1000;
auto query_functions = hardcode::load_basic_functions(db);
2016-08-31 06:07:42 +08:00
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";
2016-08-31 06:07:42 +08:00
// ******************************* TEST 1 ********************************//
// add vertices a
// clean vertices
// delete vertices a
// clean vertices
2016-12-20 01:32:44 +08:00
run(entities_number, create_vertex_label, query_functions);
permanent_assert(db.graph.vertices.access().size() == entities_number,
"Entities number doesn't match");
2016-08-31 06:07:42 +08:00
clean_vertex(db);
2016-12-20 01:32:44 +08:00
permanent_assert(db.graph.vertices.access().size() == entities_number,
"Entities number doesn't match (after cleaning)");
2016-08-31 06:07:42 +08:00
2016-12-20 01:32:44 +08:00
run(1, delete_label_vertices, query_functions);
permanent_assert(db.graph.vertices.access().size() == entities_number,
"Entities number doesn't match (delete label vertices)");
2016-08-31 06:07:42 +08:00
clean_vertex(db);
2016-12-20 01:32:44 +08:00
permanent_assert(db.graph.vertices.access().size() == 0,
"Db should be empty");
2016-08-31 06:07:42 +08:00
// ******************************* TEST 2 ********************************//
// add vertices a
// add vertices b
// clean vertices
// delete vertices a
// clean vertices
// delete vertices all
2016-12-20 01:32:44 +08:00
run(entities_number, create_vertex_label, query_functions);
permanent_assert(db.graph.vertices.access().size() == entities_number,
"Entities number doesn't match");
2016-08-31 06:07:42 +08:00
2016-12-20 01:32:44 +08:00
run(entities_number, create_vertex_other, query_functions);
permanent_assert(db.graph.vertices.access().size() == entities_number * 2,
"Entities number doesn't match");
2016-08-31 06:07:42 +08:00
clean_vertex(db);
2016-12-20 01:32:44 +08:00
permanent_assert(db.graph.vertices.access().size() == entities_number * 2,
"Entities number doesn't match");
2016-08-31 06:07:42 +08:00
2016-12-20 01:32:44 +08:00
run(1, delete_label_vertices, query_functions);
permanent_assert(db.graph.vertices.access().size() == entities_number * 2,
"Entities number doesn't match");
2016-08-31 06:07:42 +08:00
clean_vertex(db);
2016-12-20 01:32:44 +08:00
permanent_assert(db.graph.vertices.access().size() == entities_number,
"Entities number doesn't match");
2016-08-31 06:07:42 +08:00
2016-12-20 01:32:44 +08:00
run(1, delete_all_vertices, query_functions);
permanent_assert(db.graph.vertices.access().size() == entities_number,
"Entities number doesn't match");
2016-08-31 06:07:42 +08:00
clean_vertex(db);
2016-12-20 01:32:44 +08:00
permanent_assert(db.graph.vertices.access().size() == 0,
"Db should be empty");
2016-08-31 06:07:42 +08:00
2016-08-31 06:09:56 +08:00
// TODO: more tests
2016-08-31 06:07:42 +08:00
return 0;
}