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-10-04 21:23:07 +08:00
|
|
|
#include "storage/common/types.hpp"
|
|
|
|
#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-01-12 22:17:04 +08:00
|
|
|
database::SingleNode graph_db{config};
|
2018-07-26 15:08:21 +08:00
|
|
|
std::unique_ptr<database::GraphDbAccessor> dba = graph_db.Access();
|
2017-08-16 22:25:57 +08:00
|
|
|
|
2017-10-06 03:19:32 +08:00
|
|
|
auto commit = [&] {
|
2017-08-16 22:25:57 +08:00
|
|
|
dba->Commit();
|
2018-07-26 15:08:21 +08:00
|
|
|
dba = graph_db.Access();
|
2017-10-06 03:19:32 +08:00
|
|
|
};
|
2017-08-16 22:25:57 +08:00
|
|
|
auto label = dba->Label("label");
|
|
|
|
auto property = dba->Property("property");
|
|
|
|
dba->BuildIndex(label, property);
|
2017-10-06 03:19:32 +08:00
|
|
|
commit();
|
2017-08-16 22:25:57 +08:00
|
|
|
|
|
|
|
auto vertex = dba->InsertVertex();
|
|
|
|
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
|
|
|
|
|
|
|
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();
|
2017-08-16 22:25:57 +08:00
|
|
|
EXPECT_EQ(dba->VerticesCount(label, property), 1);
|
|
|
|
graph_db.CollectGarbage();
|
|
|
|
EXPECT_EQ(dba->VerticesCount(label, property), 0);
|
|
|
|
}
|