2017-12-07 20:09:34 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
#include "database/graph_db.hpp"
|
|
|
|
#include "database/graph_db_accessor.hpp"
|
|
|
|
#include "database/state_delta.hpp"
|
|
|
|
|
|
|
|
TEST(StateDelta, CreateVertex) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::SingleNode db;
|
2017-12-28 17:35:12 +08:00
|
|
|
gid::Generator generator(0);
|
|
|
|
auto gid0 = generator.Next();
|
2017-12-07 20:09:34 +08:00
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto delta = database::StateDelta::CreateVertex(dba.transaction_id(), gid0);
|
|
|
|
delta.Apply(dba);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto vertex = dba.FindVertex(gid0, false);
|
|
|
|
EXPECT_TRUE(vertex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(StateDelta, RemoveVertex) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::SingleNode db;
|
2017-12-28 17:35:12 +08:00
|
|
|
gid::Generator generator(0);
|
|
|
|
auto gid0 = generator.Next();
|
2017-12-07 20:09:34 +08:00
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
dba.InsertVertex(gid0);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2018-03-02 00:39:22 +08:00
|
|
|
auto delta =
|
|
|
|
database::StateDelta::RemoveVertex(dba.transaction_id(), gid0, true);
|
2017-12-07 20:09:34 +08:00
|
|
|
delta.Apply(dba);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto vertex = dba.FindVertex(gid0, false);
|
|
|
|
EXPECT_FALSE(vertex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(StateDelta, CreateEdge) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::SingleNode db;
|
2017-12-28 17:35:12 +08:00
|
|
|
gid::Generator generator(0);
|
|
|
|
auto gid0 = generator.Next();
|
|
|
|
auto gid1 = generator.Next();
|
|
|
|
auto gid2 = generator.Next();
|
2017-12-07 20:09:34 +08:00
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
dba.InsertVertex(gid0);
|
|
|
|
dba.InsertVertex(gid1);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2018-02-02 17:34:09 +08:00
|
|
|
auto delta = database::StateDelta::CreateEdge(
|
|
|
|
dba.transaction_id(), gid2, gid0, gid1, dba.EdgeType("edge"), "edge");
|
2017-12-07 20:09:34 +08:00
|
|
|
delta.Apply(dba);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto edge = dba.FindEdge(gid2, false);
|
|
|
|
EXPECT_TRUE(edge);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(StateDelta, RemoveEdge) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::SingleNode db;
|
2017-12-28 17:35:12 +08:00
|
|
|
gid::Generator generator(0);
|
|
|
|
auto gid0 = generator.Next();
|
|
|
|
auto gid1 = generator.Next();
|
|
|
|
auto gid2 = generator.Next();
|
2017-12-07 20:09:34 +08:00
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto v0 = dba.InsertVertex(gid0);
|
|
|
|
auto v1 = dba.InsertVertex(gid1);
|
|
|
|
dba.InsertEdge(v0, v1, dba.EdgeType("edge"), gid2);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto delta = database::StateDelta::RemoveEdge(dba.transaction_id(), gid2);
|
|
|
|
delta.Apply(dba);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto edge = dba.FindEdge(gid2, false);
|
|
|
|
EXPECT_FALSE(edge);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(StateDelta, AddLabel) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::SingleNode db;
|
2017-12-28 17:35:12 +08:00
|
|
|
gid::Generator generator(0);
|
|
|
|
auto gid0 = generator.Next();
|
2017-12-07 20:09:34 +08:00
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
dba.InsertVertex(gid0);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2018-02-02 17:34:09 +08:00
|
|
|
auto delta = database::StateDelta::AddLabel(dba.transaction_id(), gid0,
|
|
|
|
dba.Label("label"), "label");
|
2017-12-07 20:09:34 +08:00
|
|
|
delta.Apply(dba);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto vertex = dba.FindVertex(gid0, false);
|
|
|
|
EXPECT_TRUE(vertex);
|
|
|
|
auto labels = vertex->labels();
|
|
|
|
EXPECT_EQ(labels.size(), 1);
|
|
|
|
EXPECT_EQ(labels[0], dba.Label("label"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(StateDelta, RemoveLabel) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::SingleNode db;
|
2017-12-28 17:35:12 +08:00
|
|
|
gid::Generator generator(0);
|
|
|
|
auto gid0 = generator.Next();
|
2017-12-07 20:09:34 +08:00
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto vertex = dba.InsertVertex(gid0);
|
|
|
|
vertex.add_label(dba.Label("label"));
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2018-02-02 17:34:09 +08:00
|
|
|
auto delta = database::StateDelta::RemoveLabel(dba.transaction_id(), gid0,
|
|
|
|
dba.Label("label"), "label");
|
2017-12-07 20:09:34 +08:00
|
|
|
delta.Apply(dba);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto vertex = dba.FindVertex(gid0, false);
|
|
|
|
EXPECT_TRUE(vertex);
|
|
|
|
auto labels = vertex->labels();
|
|
|
|
EXPECT_EQ(labels.size(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(StateDelta, SetPropertyVertex) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::SingleNode db;
|
2017-12-28 17:35:12 +08:00
|
|
|
gid::Generator generator(0);
|
|
|
|
auto gid0 = generator.Next();
|
2017-12-07 20:09:34 +08:00
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
dba.InsertVertex(gid0);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto delta = database::StateDelta::PropsSetVertex(
|
2018-02-02 17:34:09 +08:00
|
|
|
dba.transaction_id(), gid0, dba.Property("property"), "property",
|
|
|
|
PropertyValue(2212));
|
2017-12-07 20:09:34 +08:00
|
|
|
delta.Apply(dba);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto vertex = dba.FindVertex(gid0, false);
|
|
|
|
EXPECT_TRUE(vertex);
|
|
|
|
auto prop = vertex->PropsAt(dba.Property("property"));
|
|
|
|
EXPECT_EQ(prop.Value<int64_t>(), 2212);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(StateDelta, SetPropertyEdge) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::SingleNode db;
|
2017-12-28 17:35:12 +08:00
|
|
|
gid::Generator generator(0);
|
|
|
|
auto gid0 = generator.Next();
|
|
|
|
auto gid1 = generator.Next();
|
|
|
|
auto gid2 = generator.Next();
|
2017-12-07 20:09:34 +08:00
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto v0 = dba.InsertVertex(gid0);
|
|
|
|
auto v1 = dba.InsertVertex(gid1);
|
|
|
|
dba.InsertEdge(v0, v1, dba.EdgeType("edge"), gid2);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto delta = database::StateDelta::PropsSetEdge(
|
2018-02-02 17:34:09 +08:00
|
|
|
dba.transaction_id(), gid2, dba.Property("property"), "property",
|
|
|
|
PropertyValue(2212));
|
2017-12-07 20:09:34 +08:00
|
|
|
delta.Apply(dba);
|
|
|
|
dba.Commit();
|
|
|
|
}
|
|
|
|
{
|
2018-01-12 22:17:04 +08:00
|
|
|
database::GraphDbAccessor dba(db);
|
2017-12-07 20:09:34 +08:00
|
|
|
auto edge = dba.FindEdge(gid2, false);
|
|
|
|
EXPECT_TRUE(edge);
|
|
|
|
auto prop = edge->PropsAt(dba.Property("property"));
|
|
|
|
EXPECT_EQ(prop.Value<int64_t>(), 2212);
|
|
|
|
}
|
|
|
|
}
|