2017-08-16 22:25:57 +08:00
|
|
|
#include <memory>
|
|
|
|
|
2018-10-04 21:23:07 +08:00
|
|
|
#include <gtest/gtest.h>
|
2017-08-16 22:25:57 +08:00
|
|
|
|
2018-10-05 18:37:23 +08:00
|
|
|
#include "database/single_node/graph_db.hpp"
|
|
|
|
#include "database/single_node/graph_db_accessor.hpp"
|
2018-11-07 01:15:55 +08:00
|
|
|
#include "storage/common/types/types.hpp"
|
2018-10-04 21:23:07 +08:00
|
|
|
#include "storage/single_node/indexes/label_property_index.hpp"
|
2017-08-16 22:25:57 +08:00
|
|
|
|
2017-10-06 03:19:32 +08:00
|
|
|
TEST(GraphDbTest, GarbageCollectIndices) {
|
2018-01-12 22:17:04 +08:00
|
|
|
database::Config config;
|
2017-11-20 18:58:05 +08:00
|
|
|
config.gc_cycle_sec = -1;
|
2018-10-09 17:09:10 +08:00
|
|
|
database::GraphDb graph_db{config};
|
2019-04-15 17:36:43 +08:00
|
|
|
auto dba = graph_db.Access();
|
2017-08-16 22:25:57 +08:00
|
|
|
|
2017-10-06 03:19:32 +08:00
|
|
|
auto commit = [&] {
|
2019-04-15 17:36:43 +08:00
|
|
|
dba.Commit();
|
2018-07-26 15:08:21 +08:00
|
|
|
dba = graph_db.Access();
|
2017-10-06 03:19:32 +08:00
|
|
|
};
|
2019-04-15 17:36:43 +08:00
|
|
|
auto label = dba.Label("label");
|
|
|
|
auto property = dba.Property("property");
|
|
|
|
dba.BuildIndex(label, property, false);
|
2017-10-06 03:19:32 +08:00
|
|
|
commit();
|
2017-08-16 22:25:57 +08:00
|
|
|
|
2019-04-15 17:36:43 +08:00
|
|
|
auto vertex = dba.InsertVertex();
|
2017-08-16 22:25:57 +08:00
|
|
|
vertex.add_label(label);
|
|
|
|
vertex.PropsSet(property, 42);
|
2017-10-06 03:19:32 +08:00
|
|
|
commit();
|
2017-08-16 22:25:57 +08:00
|
|
|
|
2019-04-15 17:36:43 +08:00
|
|
|
EXPECT_EQ(dba.VerticesCount(label, property), 1);
|
|
|
|
auto vertex_transferred = dba.Transfer(vertex);
|
|
|
|
dba.RemoveVertex(vertex_transferred.value());
|
|
|
|
EXPECT_EQ(dba.VerticesCount(label, property), 1);
|
2017-10-06 03:19:32 +08:00
|
|
|
commit();
|
2019-04-15 17:36:43 +08:00
|
|
|
EXPECT_EQ(dba.VerticesCount(label, property), 1);
|
2017-08-16 22:25:57 +08:00
|
|
|
graph_db.CollectGarbage();
|
2019-04-15 17:36:43 +08:00
|
|
|
EXPECT_EQ(dba.VerticesCount(label, property), 0);
|
2017-08-16 22:25:57 +08:00
|
|
|
}
|