Add e2e tests and fix clearing of constriants

This commit is contained in:
Josip Mrden 2024-03-12 14:07:14 +01:00
parent 57794828e3
commit 4a6f062ef1
14 changed files with 139 additions and 10 deletions

View File

@ -3269,15 +3269,7 @@ Callback DropGraph(memgraph::dbms::DatabaseAccess &db) {
storage->DropGraph();
auto trigger_store = db->trigger_store();
if (trigger_store->HasTriggers()) {
std::vector<std::string> trigger_names;
for (auto const &trigger_info : trigger_store->GetTriggerInfo()) {
trigger_names.push_back(trigger_info.name);
}
for (auto const &trigger_name : trigger_names) {
trigger_store->DropTrigger(trigger_name);
}
}
trigger_store->DropAll();
auto streams = db->streams();
streams->DropAll();

View File

@ -432,6 +432,21 @@ void TriggerStore::DropTrigger(const std::string &name) {
storage_.Delete(name);
}
void TriggerStore::DropAll() {
std::unique_lock store_guard{store_lock_};
std::vector<std::string> trigger_names{};
for (auto &[name, trigger_data] : storage_) {
trigger_names.push_back(name);
}
for (const auto &trigger_name : trigger_names) {
storage_.Delete(trigger_name);
}
before_commit_triggers_.clear();
after_commit_triggers_.clear();
}
std::vector<TriggerStore::TriggerInfo> TriggerStore::GetTriggerInfo() const {
std::vector<TriggerInfo> info;
info.reserve(before_commit_triggers_.size() + after_commit_triggers_.size());

View File

@ -90,6 +90,7 @@ struct TriggerStore {
const InterpreterConfig::Query &query_config, std::shared_ptr<QueryUserOrRole> owner);
void DropTrigger(const std::string &name);
void DropAll();
struct TriggerInfo {
std::string name;

View File

@ -36,6 +36,7 @@ void Constraints::AbortEntries(std::span<Vertex const *const> vertices, uint64_t
void Constraints::DropGraphClearConstraints() const {
static_cast<InMemoryUniqueConstraints *>(unique_constraints_.get())->DropGraphClearConstraints();
existence_constraints_.get()->DropGraphClearConstraints();
}
} // namespace memgraph::storage

View File

@ -1,4 +1,4 @@
// Copyright 2023 Memgraph Ltd.
// Copyright 2024 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -122,4 +122,6 @@ std::optional<ConstraintViolation> ExistenceConstraints::SingleThreadConstraintV
return std::nullopt;
}
void ExistenceConstraints::DropGraphClearConstraints() { constraints_.clear(); }
} // namespace memgraph::storage

View File

@ -67,6 +67,8 @@ class ExistenceConstraints {
std::vector<std::pair<LabelId, PropertyId>> ListConstraints() const;
void LoadExistenceConstraints(const std::vector<std::string> &keys);
void DropGraphClearConstraints();
};
} // namespace memgraph::storage

View File

@ -240,6 +240,8 @@ void InMemoryLabelIndex::DropGraphClearIndices() {
for (auto &[label, storage] : index_) {
storage.clear();
}
index_.clear();
stats_->clear();
}
} // namespace memgraph::storage

View File

@ -503,6 +503,9 @@ void InMemoryLabelPropertyIndex::DropGraphClearIndices() {
for (auto &[label_prop, storage] : index_) {
storage.clear();
}
index_.clear();
indices_by_property_.clear();
stats_->clear();
}
} // namespace memgraph::storage

View File

@ -528,5 +528,7 @@ void InMemoryUniqueConstraints::DropGraphClearConstraints() {
for (auto &[label_props, storage] : constraints_) {
storage.clear();
};
constraints_.clear();
constraints_by_label_.clear();
}
} // namespace memgraph::storage

View File

@ -77,6 +77,7 @@ add_subdirectory(garbage_collection)
add_subdirectory(query_planning)
add_subdirectory(awesome_functions)
add_subdirectory(high_availability)
add_subdirectory(drop_graph)
add_subdirectory(replication_experimental)

View File

@ -0,0 +1,6 @@
function(copy_drop_graph_e2e_python_files FILE_NAME)
copy_e2e_python_files(drop_graph ${FILE_NAME})
endfunction()
copy_drop_graph_e2e_python_files(common.py)
copy_drop_graph_e2e_python_files(drop_graph.py)

View File

@ -0,0 +1,40 @@
# Copyright 2023 Memgraph Ltd.
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
# License, and you may not use this file except in compliance with the Business Source License.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0, included in the file
# licenses/APL.txt.
import pytest
from gqlalchemy import Memgraph
def get_results_length(memgraph, query):
return len(list(memgraph.execute_and_fetch(query)))
@pytest.fixture
def memgraph(**kwargs) -> Memgraph:
memgraph = Memgraph()
memgraph.execute("STORAGE MODE IN_MEMORY_TRANSACTIONAL")
memgraph.drop_indexes()
memgraph.ensure_constraints([])
trigger_names = [x["trigger name"] for x in list(memgraph.execute_and_fetch("SHOW TRIGGERS"))]
for trigger_name in trigger_names:
memgraph.execute(f"DROP TRIGGER {trigger_name}")
yield memgraph
memgraph.execute("STORAGE MODE IN_MEMORY_TRANSACTIONAL")
memgraph.drop_indexes()
memgraph.ensure_constraints([])
trigger_names = [x["trigger name"] for x in list(memgraph.execute_and_fetch("SHOW TRIGGERS"))]
for trigger_name in trigger_names:
memgraph.execute(f"DROP TRIGGER {trigger_name}")
memgraph.drop_database()

View File

@ -0,0 +1,48 @@
# Copyright 2023 Memgraph Ltd.
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
# License, and you may not use this file except in compliance with the Business Source License.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0, included in the file
# licenses/APL.txt.
import sys
import pytest
from common import get_results_length, memgraph
from gqlalchemy import GQLAlchemyError
def test_create_everything_then_drop_graph(memgraph):
memgraph.execute("CREATE (:Node {id:1})-[:TYPE {id:2}]->(:Node {id:3})")
memgraph.execute("CREATE INDEX ON :Node")
memgraph.execute("CREATE INDEX ON :Node(id)")
memgraph.execute("CREATE CONSTRAINT ON (n:Node) ASSERT n.id IS UNIQUE;")
memgraph.execute("CREATE CONSTRAINT ON (n:Node) ASSERT EXISTS (n.id);")
memgraph.execute("CREATE TRIGGER t1 ON () UPDATE BEFORE COMMIT EXECUTE RETURN 1")
memgraph.execute("CREATE TRIGGER t2 ON () UPDATE AFTER COMMIT EXECUTE RETURN 1")
assert get_results_length(memgraph, "MATCH (n) RETURN n") == 2
assert get_results_length(memgraph, "MATCH (n)-[r]->(m) RETURN r") == 1
assert get_results_length(memgraph, "SHOW INDEX INFO") == 2
assert get_results_length(memgraph, "SHOW CONSTRAINT INFO") == 2
assert get_results_length(memgraph, "SHOW TRIGGERS") == 2
with pytest.raises(GQLAlchemyError):
memgraph.execute("DROP GRAPH")
memgraph.execute("STORAGE MODE IN_MEMORY_ANALYTICAL")
memgraph.execute("DROP GRAPH")
assert get_results_length(memgraph, "MATCH (n) RETURN n") == 0
assert get_results_length(memgraph, "MATCH (n)-[r]->(m) RETURN r") == 0
assert get_results_length(memgraph, "SHOW INDEX INFO") == 0
assert get_results_length(memgraph, "SHOW CONSTRAINT INFO") == 0
assert get_results_length(memgraph, "SHOW TRIGGERS") == 0
if __name__ == "__main__":
sys.exit(pytest.main([__file__, "-rA"]))

View File

@ -0,0 +1,14 @@
drop_graph_cluster: &drop_graph_cluster
cluster:
main:
args: ["--bolt-port", "7687", "--log-level=TRACE"]
log_file: "drop_graph.log"
setup_queries: []
validation_queries: []
workloads:
- name: "Drop graph"
binary: "tests/e2e/pytest_runner.sh"
args: ["drop_graph/drop_graph.py"]
<<: *drop_graph_cluster