9f460914ed
Summary: GraphDbAccessor is now constructed only through GraphDb. This allows the concrete GraphDb to instantiate a concrete GraphDbAccessor. This allows us to use virtual calls, so that the implementation may be kept separate. The major downside of doing things this way is heap allocation of GraphDbAccessor. In case it turns out to be a real performance issues, another solution with pointer to static implementation may be used. InsertVertexIntoRemote is now a non-member function, which reduces coupling. It made no sense for it to be member function because it used only the public parts of GraphDbAccessor. Reviewers: msantl, mtomic, mferencevic Reviewed By: msantl Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1504
209 lines
5.2 KiB
C++
209 lines
5.2 KiB
C++
#include "gtest/gtest.h"
|
|
|
|
#include "database/graph_db.hpp"
|
|
#include "database/graph_db_accessor.hpp"
|
|
#include "database/state_delta.hpp"
|
|
|
|
TEST(StateDelta, CreateVertex) {
|
|
database::SingleNode db;
|
|
gid::Generator generator(0);
|
|
auto gid0 = generator.Next();
|
|
{
|
|
auto dba = db.Access();
|
|
auto delta =
|
|
database::StateDelta::CreateVertex(dba->transaction_id(), gid0, 0);
|
|
delta.Apply(*dba);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto vertex = dba->FindVertexOptional(gid0, false);
|
|
EXPECT_TRUE(vertex);
|
|
EXPECT_EQ(vertex->cypher_id(), 0);
|
|
}
|
|
}
|
|
|
|
TEST(StateDelta, RemoveVertex) {
|
|
database::SingleNode db;
|
|
gid::Generator generator(0);
|
|
auto gid0 = generator.Next();
|
|
{
|
|
auto dba = db.Access();
|
|
dba->InsertVertex(gid0);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto delta =
|
|
database::StateDelta::RemoveVertex(dba->transaction_id(), gid0, true);
|
|
delta.Apply(*dba);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto vertex = dba->FindVertexOptional(gid0, false);
|
|
EXPECT_FALSE(vertex);
|
|
}
|
|
}
|
|
|
|
TEST(StateDelta, CreateEdge) {
|
|
database::SingleNode db;
|
|
gid::Generator generator(0);
|
|
auto gid0 = generator.Next();
|
|
auto gid1 = generator.Next();
|
|
auto gid2 = generator.Next();
|
|
{
|
|
auto dba = db.Access();
|
|
dba->InsertVertex(gid0);
|
|
dba->InsertVertex(gid1);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto delta =
|
|
database::StateDelta::CreateEdge(dba->transaction_id(), gid2, 0, gid0,
|
|
gid1, dba->EdgeType("edge"), "edge");
|
|
delta.Apply(*dba);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto edge = dba->FindEdgeOptional(gid2, false);
|
|
EXPECT_TRUE(edge);
|
|
}
|
|
}
|
|
|
|
TEST(StateDelta, RemoveEdge) {
|
|
database::SingleNode db;
|
|
gid::Generator generator(0);
|
|
auto gid0 = generator.Next();
|
|
auto gid1 = generator.Next();
|
|
auto gid2 = generator.Next();
|
|
{
|
|
auto dba = db.Access();
|
|
auto v0 = dba->InsertVertex(gid0);
|
|
auto v1 = dba->InsertVertex(gid1);
|
|
dba->InsertEdge(v0, v1, dba->EdgeType("edge"), gid2);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto delta = database::StateDelta::RemoveEdge(dba->transaction_id(), gid2);
|
|
delta.Apply(*dba);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto edge = dba->FindEdgeOptional(gid2, false);
|
|
EXPECT_FALSE(edge);
|
|
}
|
|
}
|
|
|
|
TEST(StateDelta, AddLabel) {
|
|
database::SingleNode db;
|
|
gid::Generator generator(0);
|
|
auto gid0 = generator.Next();
|
|
{
|
|
auto dba = db.Access();
|
|
dba->InsertVertex(gid0);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto delta = database::StateDelta::AddLabel(dba->transaction_id(), gid0,
|
|
dba->Label("label"), "label");
|
|
delta.Apply(*dba);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto vertex = dba->FindVertexOptional(gid0, false);
|
|
EXPECT_TRUE(vertex);
|
|
auto labels = vertex->labels();
|
|
EXPECT_EQ(labels.size(), 1);
|
|
EXPECT_EQ(labels[0], dba->Label("label"));
|
|
}
|
|
}
|
|
|
|
TEST(StateDelta, RemoveLabel) {
|
|
database::SingleNode db;
|
|
gid::Generator generator(0);
|
|
auto gid0 = generator.Next();
|
|
{
|
|
auto dba = db.Access();
|
|
auto vertex = dba->InsertVertex(gid0);
|
|
vertex.add_label(dba->Label("label"));
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto delta = database::StateDelta::RemoveLabel(dba->transaction_id(), gid0,
|
|
dba->Label("label"), "label");
|
|
delta.Apply(*dba);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto vertex = dba->FindVertexOptional(gid0, false);
|
|
EXPECT_TRUE(vertex);
|
|
auto labels = vertex->labels();
|
|
EXPECT_EQ(labels.size(), 0);
|
|
}
|
|
}
|
|
|
|
TEST(StateDelta, SetPropertyVertex) {
|
|
database::SingleNode db;
|
|
gid::Generator generator(0);
|
|
auto gid0 = generator.Next();
|
|
{
|
|
auto dba = db.Access();
|
|
dba->InsertVertex(gid0);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto delta = database::StateDelta::PropsSetVertex(
|
|
dba->transaction_id(), gid0, dba->Property("property"), "property",
|
|
PropertyValue(2212));
|
|
delta.Apply(*dba);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto vertex = dba->FindVertexOptional(gid0, false);
|
|
EXPECT_TRUE(vertex);
|
|
auto prop = vertex->PropsAt(dba->Property("property"));
|
|
EXPECT_EQ(prop.Value<int64_t>(), 2212);
|
|
}
|
|
}
|
|
|
|
TEST(StateDelta, SetPropertyEdge) {
|
|
database::SingleNode db;
|
|
gid::Generator generator(0);
|
|
auto gid0 = generator.Next();
|
|
auto gid1 = generator.Next();
|
|
auto gid2 = generator.Next();
|
|
{
|
|
auto dba = db.Access();
|
|
auto v0 = dba->InsertVertex(gid0);
|
|
auto v1 = dba->InsertVertex(gid1);
|
|
dba->InsertEdge(v0, v1, dba->EdgeType("edge"), gid2);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto delta = database::StateDelta::PropsSetEdge(
|
|
dba->transaction_id(), gid2, dba->Property("property"), "property",
|
|
PropertyValue(2212));
|
|
delta.Apply(*dba);
|
|
dba->Commit();
|
|
}
|
|
{
|
|
auto dba = db.Access();
|
|
auto edge = dba->FindEdgeOptional(gid2, false);
|
|
EXPECT_TRUE(edge);
|
|
auto prop = edge->PropsAt(dba->Property("property"));
|
|
EXPECT_EQ(prop.Value<int64_t>(), 2212);
|
|
}
|
|
}
|