2017-10-25 21:28:10 +08:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "gflags/gflags.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2017-10-30 17:43:25 +08:00
|
|
|
#include "database/graph_db.hpp"
|
2017-11-20 18:58:05 +08:00
|
|
|
#include "database/graph_db_accessor.hpp"
|
2017-10-30 17:43:25 +08:00
|
|
|
#include "durability/recovery.hpp"
|
2017-10-25 21:28:10 +08:00
|
|
|
#include "query/typed_value.hpp"
|
|
|
|
|
|
|
|
static const char *usage =
|
2017-11-20 18:58:05 +08:00
|
|
|
"--durability-dir DURABILITY_DIR\n"
|
|
|
|
"Check that Memgraph can recover the snapshot. This tool should be "
|
2017-10-25 21:28:10 +08:00
|
|
|
"invoked through 'test_mg_import' wrapper, so as to check that 'mg_import' "
|
|
|
|
"tools work correctly.\n";
|
|
|
|
|
2017-11-20 18:58:05 +08:00
|
|
|
DEFINE_string(durability_dir, "", "Path to where the durability directory");
|
2017-10-25 21:28:10 +08:00
|
|
|
|
|
|
|
class RecoveryTest : public ::testing::Test {
|
|
|
|
protected:
|
|
|
|
void SetUp() override {
|
2017-11-20 18:58:05 +08:00
|
|
|
std::string durability_dir(FLAGS_durability_dir);
|
|
|
|
durability::Recover(durability_dir, db_);
|
2017-10-25 21:28:10 +08:00
|
|
|
}
|
|
|
|
|
2018-01-12 22:17:04 +08:00
|
|
|
database::SingleNode db_;
|
2017-10-25 21:28:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(RecoveryTest, TestVerticesRecovered) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db_);
|
2017-10-30 17:43:25 +08:00
|
|
|
EXPECT_EQ(dba.VerticesCount(), 10);
|
|
|
|
EXPECT_EQ(dba.VerticesCount(dba.Label("Comment")), 5);
|
|
|
|
for (const auto &vertex : dba.Vertices(dba.Label("Comment"), false)) {
|
|
|
|
EXPECT_TRUE(vertex.has_label(dba.Label("Message")));
|
2017-10-25 21:28:10 +08:00
|
|
|
}
|
2017-10-30 17:43:25 +08:00
|
|
|
EXPECT_EQ(dba.VerticesCount(dba.Label("Forum")), 5);
|
2017-10-25 21:28:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(RecoveryTest, TestPropertyNull) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db_);
|
2017-10-25 21:28:10 +08:00
|
|
|
bool found = false;
|
2017-10-30 17:43:25 +08:00
|
|
|
for (const auto &vertex : dba.Vertices(dba.Label("Comment"), false)) {
|
|
|
|
auto id_prop = query::TypedValue(vertex.PropsAt(dba.Property("id")));
|
|
|
|
auto browser = query::TypedValue(vertex.PropsAt(dba.Property("browser")));
|
2017-10-25 21:28:10 +08:00
|
|
|
if (id_prop.IsString() && id_prop.Value<std::string>() == "2") {
|
|
|
|
EXPECT_FALSE(found);
|
|
|
|
found = true;
|
|
|
|
EXPECT_TRUE(browser.IsNull());
|
|
|
|
} else {
|
|
|
|
EXPECT_FALSE(browser.IsNull());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT_TRUE(found);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(RecoveryTest, TestEdgesRecovered) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db_);
|
2017-10-30 17:43:25 +08:00
|
|
|
EXPECT_EQ(dba.EdgesCount(), 5);
|
|
|
|
for (const auto &edge : dba.Edges(false)) {
|
|
|
|
EXPECT_TRUE(edge.EdgeType() == dba.EdgeType("POSTED_ON"));
|
2017-10-25 21:28:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
gflags::SetUsageMessage(usage);
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|