Ver Fonte

test: migrate test callsites to Document binary accessors (phase B T7)

Tests that compile memory_store/history_store/snapshot directly now also
need doc_binary.cpp linked in. Added it to TEST_VECTOR_SOURCES,
TEST_TIMESTAMP_PRECISION_SOURCES, TEST_SNAPSHOT_DURABILITY_SOURCES, and
TEST_EVICTION_SOURCES.

Test-source updates:
- test_vector_storage.cpp: set_data() for doc construction; verify the
  stripped _vector via doc.field("_vector").has_value()==false and read
  content via doc.data()["content"].
- test_snapshot_durability.cpp: makeDoc() uses set_data; field-mutation
  sites (padding) materialise via doc.data(), mutate, set_data once.
- test_eviction.cpp / test_timestamp_precision.cpp: makeDoc uses
  set_data.

ctest output: test_doc_binary, test_views, test_config_dropins,
test_json_parse, test_eviction, test_timestamp_precision,
test_vector_storage, test_snapshot_durability — all pass.
fszontagh há 2 meses atrás
pai
commit
eaceb7eb55

+ 4 - 0
tests/CMakeLists.txt

@@ -19,6 +19,7 @@ set(TEST_VECTOR_SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
 )
 
 add_executable(test_vector_storage ${TEST_VECTOR_SOURCES})
@@ -77,6 +78,7 @@ set(TEST_TIMESTAMP_PRECISION_SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
 )
 
 add_executable(test_timestamp_precision ${TEST_TIMESTAMP_PRECISION_SOURCES})
@@ -116,6 +118,7 @@ set(TEST_SNAPSHOT_DURABILITY_SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
 )
 
 add_executable(test_snapshot_durability ${TEST_SNAPSHOT_DURABILITY_SOURCES})
@@ -193,6 +196,7 @@ set(TEST_EVICTION_SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/history_store.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/persistence/wal.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/json_parse.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/../service/src/doc_binary.cpp
 )
 
 add_executable(test_eviction ${TEST_EVICTION_SOURCES})

+ 1 - 1
tests/test_eviction.cpp

@@ -44,7 +44,7 @@ Document makeDoc(const std::string& id, size_t bytes = 1024) {
     Document d;
     d.id = id;
     std::string pad(bytes, 'x');
-    d.data = nlohmann::json{{"value", pad}};
+    d.set_data(nlohmann::json{{"value", pad}});
     return d;
 }
 

+ 18 - 6
tests/test_snapshot_durability.cpp

@@ -54,7 +54,7 @@ fs::path makeSnapshotDir(const std::string& name) {
 Document makeDoc(const std::string& id) {
     Document d;
     d.id = id;
-    d.data = nlohmann::json{{"value", id}};
+    d.set_data(nlohmann::json{{"value", id}});
     return d;
 }
 
@@ -299,7 +299,7 @@ void test_v4_format_roundtrip_at_scale() {
     for (int i = 0; i < 10000; i++) {
         Document d;
         d.id = "d" + std::to_string(i);
-        d.data = nlohmann::json{{"value", bigString}, {"i", i}};
+        d.set_data(nlohmann::json{{"value", bigString}, {"i", i}});
         store.insert("docs", d);
     }
 
@@ -312,7 +312,7 @@ void test_v4_format_roundtrip_at_scale() {
     assert(seq == 1);
     auto d = store2.get("docs", "d9999");
     assert(d.has_value());
-    assert((*d).data["i"].get<int>() == 9999);
+    assert((*d).data()["i"].get<int>() == 9999);
     store2.stop();
 
     fs::remove_all(dir);
@@ -458,7 +458,11 @@ void test_snapshot_includes_evicted_documents() {
     constexpr int N = 100;
     for (int i = 0; i < N; ++i) {
         Document d = makeDoc("doc-" + std::to_string(i));
-        d.data["padding"] = std::string(300, 'x');  // make eviction meaningful
+        {
+            auto tree = d.data();
+            tree["padding"] = std::string(300, 'x');  // make eviction meaningful
+            d.set_data(tree);
+        }
         wal.append(WriteAheadLog::makeInsertEntry("docs", d, "test"));
         store.insert("docs", d);
     }
@@ -559,7 +563,11 @@ void test_evict_stub_carries_real_wal_sequence() {
     std::unordered_map<std::string, uint64_t> expectedSeq;
     for (int i = 0; i < N; ++i) {
         Document d = makeDoc("doc-" + std::to_string(i));
-        d.data["padding"] = std::string(300, 'x');
+        {
+            auto tree = d.data();
+            tree["padding"] = std::string(300, 'x');
+            d.set_data(tree);
+        }
         uint64_t seq = wal.append(WriteAheadLog::makeInsertEntry("docs", d, "test"));
         store.insert("docs", d);
         store.recordWalSequence("docs", d.id, seq);
@@ -570,7 +578,11 @@ void test_evict_stub_carries_real_wal_sequence() {
     // append, not the first one.
     for (int i = 0; i < 5; ++i) {
         Document d = makeDoc("doc-" + std::to_string(i));
-        d.data["padding"] = std::string(400, 'y');
+        {
+            auto tree = d.data();
+            tree["padding"] = std::string(400, 'y');
+            d.set_data(tree);
+        }
         d.version = 2;
         uint64_t seq = wal.append(WriteAheadLog::makeUpdateEntry("docs", d, "test"));
         store.update("docs", d.id, d);

+ 1 - 1
tests/test_timestamp_precision.cpp

@@ -45,7 +45,7 @@ MemoryStore::Config defaultConfig() {
 Document makeDoc(const std::string& id = "") {
     Document d;
     if (!id.empty()) d.id = id;
-    d.data = nlohmann::json{{"value", "x"}};
+    d.set_data(nlohmann::json{{"value", "x"}});
     return d;
 }
 

+ 7 - 7
tests/test_vector_storage.cpp

@@ -56,19 +56,19 @@ int main() {
     Document doc1;
     doc1.id         = "doc1";
     doc1.collection = "test_vectors";
-    doc1.data       = {{"content", "hello"}, {"_vector", {1.0f, 0.0f, 0.0f}}};
+    doc1.set_data({{"content", "hello"}, {"_vector", {1.0f, 0.0f, 0.0f}}});
     store.insert("test_vectors", doc1);
 
     Document doc2;
     doc2.id         = "doc2";
     doc2.collection = "test_vectors";
-    doc2.data       = {{"content", "world"}, {"_vector", {0.0f, 1.0f, 0.0f}}};
+    doc2.set_data({{"content", "world"}, {"_vector", {0.0f, 1.0f, 0.0f}}});
     store.insert("test_vectors", doc2);
 
     Document doc3;
     doc3.id         = "doc3";
     doc3.collection = "test_vectors";
-    doc3.data       = {{"content", "similar"}, {"_vector", {0.9f, 0.1f, 0.0f}}};
+    doc3.set_data({{"content", "similar"}, {"_vector", {0.9f, 0.1f, 0.0f}}});
     store.insert("test_vectors", doc3);
 
     // ---------------------------------------------------------------
@@ -88,8 +88,8 @@ int main() {
     // ---------------------------------------------------------------
     auto stored = store.get("test_vectors", "doc1");
     check(stored.has_value(),                   "doc1 should exist after insert");
-    check(!stored->data.contains("_vector"),    "_vector should be stripped from stored doc");
-    check(stored->data["content"] == "hello",   "doc1 content should be 'hello'");
+    check(!stored->field("_vector").has_value(),"_vector should be stripped from stored doc");
+    check(stored->data()["content"] == "hello", "doc1 content should be 'hello'");
     std::cout << "PASS: _vector stripped from document data\n";
 
     // ---------------------------------------------------------------
@@ -99,7 +99,7 @@ int main() {
         Document bad;
         bad.id         = "bad";
         bad.collection = "test_vectors";
-        bad.data       = {{"_vector", {1.0f, 2.0f}}};  // wrong dim (2 instead of 3)
+        bad.set_data({{"_vector", {1.0f, 2.0f}}});  // wrong dim (2 instead of 3)
         store.insert("test_vectors", bad);
         check(false, "dimension mismatch should have thrown");
     } catch (const std::invalid_argument& e) {
@@ -137,7 +137,7 @@ int main() {
     Document doc2_updated;
     doc2_updated.id         = "doc2";
     doc2_updated.collection = "test_vectors";
-    doc2_updated.data       = {{"content", "updated"}, {"_vector", {1.0f, 0.0f, 0.0f}}};
+    doc2_updated.set_data({{"content", "updated"}, {"_vector", {1.0f, 0.0f, 0.0f}}});
     store.update("test_vectors", "doc2", doc2_updated);
 
     auto after_update = store.similaritySearch("test_vectors", {1.0f, 0.0f, 0.0f}, 1);