diff options
Diffstat (limited to '')
| -rw-r--r-- | test/CursorManager.cpp | 86 |
1 files changed, 39 insertions, 47 deletions
diff --git a/test/CursorManager.cpp b/test/CursorManager.cpp index 8c7de1a..c823ec5 100644 --- a/test/CursorManager.cpp +++ b/test/CursorManager.cpp @@ -27,55 +27,48 @@ // the handle's death is degenerate but safe. // --------------------------------------------------------------------------- -namespace -{ - std::unique_ptr<nt::ObjectManager::object_type> make_type(OBJECT_TYPE label) - { - auto t = std::make_unique<nt::ObjectManager::object_type>(); - t->label = label; - t->methods = { OPEN, CLOSE }; +namespace { + std::unique_ptr<nt::ObjectManager::object_type> make_type(OBJECT_TYPE label) { + auto t = std::make_unique<nt::ObjectManager::object_type>(); + t->label = label; + t->methods = {OPEN, CLOSE}; return t; } std::unique_ptr<nt::ObjectManager::ephemeral_object_type> - make_constant_eph_type(std::vector<nt::Attribute> attrs) - { - auto t = std::make_unique<nt::ObjectManager::ephemeral_object_type>(); - t->label = EPHEMERAL_RELATION; - t->methods = { OPEN, CLOSE }; + make_constant_eph_type(std::vector<nt::Attribute> attrs) { + auto t = std::make_unique<nt::ObjectManager::ephemeral_object_type>(); + t->label = EPHEMERAL_RELATION; + t->methods = {OPEN, CLOSE}; t->cardinality = nt::ObjectManager::ephemeral_object_type::Cardinality::Finite; - t->generator = [attrs](const std::vector<std::string>&, - std::size_t offset, std::size_t limit) - -> std::vector<nt::Tuple> - { - if (offset > 0 || limit == 0) return {}; - return { nt::Tuple(attrs) }; + t->generator = [attrs](const std::vector<std::string>&, std::size_t offset, + std::size_t limit) -> std::vector<nt::Tuple> { + if (offset > 0 || limit == 0) + return {}; + return {nt::Tuple(attrs)}; }; return t; } struct Stack { - nt::InMemoryBackend backend; - nt::ObjectManager objects; - nt::PermissionsManager permissions; - nt::IdentityManager identities; - nt::LifecycleManager lifecycles { objects, backend }; - nt::NamespaceReferenceManager references { objects, backend }; - nt::HandlerManager handler { objects, permissions, identities, - lifecycles, references }; - nt::CursorManager cursors { backend, &lifecycles, &objects }; + nt::InMemoryBackend backend; + nt::ObjectManager objects; + nt::PermissionsManager permissions; + nt::IdentityManager identities; + nt::LifecycleManager lifecycles{objects, backend}; + nt::NamespaceReferenceManager references{objects, backend}; + nt::HandlerManager handler{objects, permissions, identities, lifecycles, references}; + nt::CursorManager cursors{backend, &lifecycles, &objects}; }; -} +} // namespace -TEST_CASE("Cursor pins the parent snapshot and unpins on close", - "[step6][cursor][pin]") -{ +TEST_CASE("Cursor pins the parent snapshot and unpins on close", "[step6][cursor][pin]") { Stack s; // Stand up a minimal snapshot with one relation. auto& om = s.objects; - om.Register({"system", "snapshots", "Hcur"}, - std::make_unique<nt::ObjectManager::Multigroup>(), make_type(MULTIGROUP)); + om.Register({"system", "snapshots", "Hcur"}, std::make_unique<nt::ObjectManager::Multigroup>(), + make_type(MULTIGROUP)); om.Register({"system", "snapshots", "Hcur", "relations", "items"}, std::make_unique<nt::ObjectManager::Relation>(), make_type(RELATION)); @@ -93,27 +86,25 @@ TEST_CASE("Cursor pins the parent snapshot and unpins on close", int conn = 1; auto* h = s.handler.Open({"system", "snapshots", "Hcur", "relations", "items"}, &conn); REQUIRE(h != nullptr); - REQUIRE(mg_entry->head->reference_count == 1); // external pin only + REQUIRE(mg_entry->head->reference_count == 1); // external pin only auto* c = s.cursors.Open(h); REQUIRE(c != nullptr); REQUIRE(c->pinned_snapshot == mg_entry); - REQUIRE(mg_entry->head->reference_count == 2); // external + cursor pin + REQUIRE(mg_entry->head->reference_count == 2); // external + cursor pin s.cursors.Close(c); - REQUIRE(mg_entry->head->reference_count == 1); // back to external only + REQUIRE(mg_entry->head->reference_count == 1); // back to external only s.handler.Close(h); - s.lifecycles.Unpin(mg_entry); // releases the external pin; cascade-collects. + s.lifecycles.Unpin(mg_entry); // releases the external pin; cascade-collects. } TEST_CASE("Closing the handle mid-iteration does not crash an ephemeral cursor", - "[step6][cursor][handle-independence]") -{ + "[step6][cursor][handle-independence]") { Stack s; // Register an ephemeral relation; its generator yields one tuple. - s.objects.Register({"eph"}, - std::make_unique<nt::ObjectManager::Relation>(), + s.objects.Register({"eph"}, std::make_unique<nt::ObjectManager::Relation>(), make_constant_eph_type({{"k", "v"}})); int conn = 1; @@ -124,7 +115,7 @@ TEST_CASE("Closing the handle mid-iteration does not crash an ephemeral cursor", // Ephemeral cursors start exhausted; reset to simulate a JOIN probe. c->exhausted = false; - c->args = {}; + c->args = {}; // Now violate the documented contract: close the handle BEFORE Next(). // The cursor must still produce its tuple from the captured generator @@ -135,18 +126,19 @@ TEST_CASE("Closing the handle mid-iteration does not crash an ephemeral cursor", REQUIRE(tuple != nullptr); bool found = false; for (const auto& a : tuple->attrs()) - if (a.name == "k" && a.value == "v") { found = true; break; } + if (a.name == "k" && a.value == "v") { + found = true; + break; + } REQUIRE(found); s.cursors.Close(c); } TEST_CASE("Cursor opened against a non-snapshot relation does not pin anything", - "[step6][cursor][pin]") -{ + "[step6][cursor][pin]") { Stack s; - s.objects.Register({"plain", "rel"}, - std::make_unique<nt::ObjectManager::Relation>(), + s.objects.Register({"plain", "rel"}, std::make_unique<nt::ObjectManager::Relation>(), make_type(RELATION)); int conn = 1; auto* h = s.handler.Open({"plain", "rel"}, &conn); |
