aboutsummaryrefslogtreecommitdiff
path: root/icing/index/numeric/integer-index_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'icing/index/numeric/integer-index_test.cc')
-rw-r--r--icing/index/numeric/integer-index_test.cc137
1 files changed, 135 insertions, 2 deletions
diff --git a/icing/index/numeric/integer-index_test.cc b/icing/index/numeric/integer-index_test.cc
index b2e3fbe..3b60001 100644
--- a/icing/index/numeric/integer-index_test.cc
+++ b/icing/index/numeric/integer-index_test.cc
@@ -14,6 +14,7 @@
#include "icing/index/numeric/integer-index.h"
+#include <cstdint>
#include <limits>
#include <memory>
#include <string>
@@ -140,7 +141,7 @@ class NumericIndexIntegerTest : public ::testing::Test {
return absl_ports::InternalError("Unable to create compact directory");
}
ICING_ASSIGN_OR_RETURN(
- std::vector<DocumentId> docid_map,
+ DocumentStore::OptimizeResult doc_store_optimize_result,
doc_store_->OptimizeInto(document_store_compact_dir, nullptr));
doc_store_.reset();
@@ -164,7 +165,7 @@ class NumericIndexIntegerTest : public ::testing::Test {
DocumentWrapper>::kDeflateCompressionLevel,
/*initialize_stats=*/nullptr));
doc_store_ = std::move(doc_store_create_result.document_store);
- return docid_map;
+ return std::move(doc_store_optimize_result.document_id_old_to_new);
}
libtextclassifier3::StatusOr<std::vector<DocHitInfo>> Query(
@@ -2444,6 +2445,138 @@ TEST_P(IntegerIndexTest, WildcardStorageAvailableIndicesAfterOptimize) {
/*document_id=*/7, expected_sections_typea))));
}
+TEST_P(IntegerIndexTest, IteratorCallStats) {
+ ICING_ASSERT_OK_AND_ASSIGN(
+ std::unique_ptr<IntegerIndex> integer_index,
+ IntegerIndex::Create(filesystem_, working_path_,
+ GetParam().num_data_threshold_for_bucket_split,
+ GetParam().pre_mapping_fbv));
+
+ Index(integer_index.get(), kDefaultTestPropertyPath, /*document_id=*/0,
+ kDefaultSectionId, /*keys=*/{1});
+ Index(integer_index.get(), kDefaultTestPropertyPath, /*document_id=*/1,
+ kDefaultSectionId, /*keys=*/{3});
+ Index(integer_index.get(), kDefaultTestPropertyPath, /*document_id=*/2,
+ kDefaultSectionId, /*keys=*/{2});
+ Index(integer_index.get(), kDefaultTestPropertyPath, /*document_id=*/3,
+ kDefaultSectionId, /*keys=*/{0});
+
+ // GetIterator for range [INT_MIN, INT_MAX] and Advance all. Those 4 keys are
+ // in 1 single bucket, so there will be only 1 posting list (and 1 block).
+ ICING_ASSERT_OK_AND_ASSIGN(
+ std::unique_ptr<DocHitInfoIterator> iter,
+ integer_index->GetIterator(
+ kDefaultTestPropertyPath,
+ /*key_lower=*/std::numeric_limits<int64_t>::min(),
+ /*key_upper=*/std::numeric_limits<int64_t>::max(), *doc_store_,
+ *schema_store_, clock_.GetSystemTimeMilliseconds()));
+
+ // 1 block should be read even without calling Advance(), since we read the
+ // posting list and put bucket into the priority queue in ctor.
+ EXPECT_THAT(iter->GetCallStats(),
+ EqualsDocHitInfoIteratorCallStats(
+ /*num_leaf_advance_calls_lite_index=*/0,
+ /*num_leaf_advance_calls_main_index=*/0,
+ /*num_leaf_advance_calls_integer_index=*/1,
+ /*num_leaf_advance_calls_no_index=*/0,
+ /*num_blocks_inspected=*/1));
+
+ // 1st Advance().
+ ICING_ASSERT_OK(iter->Advance());
+ EXPECT_THAT(iter->GetCallStats(),
+ EqualsDocHitInfoIteratorCallStats(
+ /*num_leaf_advance_calls_lite_index=*/0,
+ /*num_leaf_advance_calls_main_index=*/0,
+ /*num_leaf_advance_calls_integer_index=*/2,
+ /*num_leaf_advance_calls_no_index=*/0,
+ /*num_blocks_inspected=*/1));
+
+ // 2nd Advance().
+ ICING_ASSERT_OK(iter->Advance());
+ EXPECT_THAT(iter->GetCallStats(),
+ EqualsDocHitInfoIteratorCallStats(
+ /*num_leaf_advance_calls_lite_index=*/0,
+ /*num_leaf_advance_calls_main_index=*/0,
+ /*num_leaf_advance_calls_integer_index=*/3,
+ /*num_leaf_advance_calls_no_index=*/0,
+ /*num_blocks_inspected=*/1));
+
+ // 3rd Advance().
+ ICING_ASSERT_OK(iter->Advance());
+ EXPECT_THAT(iter->GetCallStats(),
+ EqualsDocHitInfoIteratorCallStats(
+ /*num_leaf_advance_calls_lite_index=*/0,
+ /*num_leaf_advance_calls_main_index=*/0,
+ /*num_leaf_advance_calls_integer_index=*/4,
+ /*num_leaf_advance_calls_no_index=*/0,
+ /*num_blocks_inspected=*/1));
+
+ // 4th Advance().
+ ICING_ASSERT_OK(iter->Advance());
+ EXPECT_THAT(iter->GetCallStats(),
+ EqualsDocHitInfoIteratorCallStats(
+ /*num_leaf_advance_calls_lite_index=*/0,
+ /*num_leaf_advance_calls_main_index=*/0,
+ /*num_leaf_advance_calls_integer_index=*/4,
+ /*num_leaf_advance_calls_no_index=*/0,
+ /*num_blocks_inspected=*/1));
+
+ // 5th Advance().
+ ASSERT_THAT(iter->Advance(),
+ StatusIs(libtextclassifier3::StatusCode::RESOURCE_EXHAUSTED));
+ EXPECT_THAT(iter->GetCallStats(),
+ EqualsDocHitInfoIteratorCallStats(
+ /*num_leaf_advance_calls_lite_index=*/0,
+ /*num_leaf_advance_calls_main_index=*/0,
+ /*num_leaf_advance_calls_integer_index=*/4,
+ /*num_leaf_advance_calls_no_index=*/0,
+ /*num_blocks_inspected=*/1));
+}
+
+TEST_P(IntegerIndexTest, IteratorCallStatsNonExistingProperty) {
+ ICING_ASSERT_OK_AND_ASSIGN(
+ std::unique_ptr<IntegerIndex> integer_index,
+ IntegerIndex::Create(filesystem_, working_path_,
+ GetParam().num_data_threshold_for_bucket_split,
+ GetParam().pre_mapping_fbv));
+
+ Index(integer_index.get(), kDefaultTestPropertyPath, /*document_id=*/0,
+ kDefaultSectionId, /*keys=*/{1});
+ Index(integer_index.get(), kDefaultTestPropertyPath, /*document_id=*/1,
+ kDefaultSectionId, /*keys=*/{3});
+ Index(integer_index.get(), kDefaultTestPropertyPath, /*document_id=*/2,
+ kDefaultSectionId, /*keys=*/{2});
+ Index(integer_index.get(), kDefaultTestPropertyPath, /*document_id=*/3,
+ kDefaultSectionId, /*keys=*/{0});
+
+ // GetIterator for property "otherProperty1".
+ ICING_ASSERT_OK_AND_ASSIGN(
+ std::unique_ptr<DocHitInfoIterator> iter,
+ integer_index->GetIterator(
+ "otherProperty1", /*key_lower=*/std::numeric_limits<int64_t>::min(),
+ /*key_upper=*/std::numeric_limits<int64_t>::max(), *doc_store_,
+ *schema_store_, clock_.GetSystemTimeMilliseconds()));
+
+ EXPECT_THAT(iter->GetCallStats(),
+ EqualsDocHitInfoIteratorCallStats(
+ /*num_leaf_advance_calls_lite_index=*/0,
+ /*num_leaf_advance_calls_main_index=*/0,
+ /*num_leaf_advance_calls_integer_index=*/0,
+ /*num_leaf_advance_calls_no_index=*/0,
+ /*num_blocks_inspected=*/0));
+
+ // 1st Advance().
+ ASSERT_THAT(iter->Advance(),
+ StatusIs(libtextclassifier3::StatusCode::RESOURCE_EXHAUSTED));
+ EXPECT_THAT(iter->GetCallStats(),
+ EqualsDocHitInfoIteratorCallStats(
+ /*num_leaf_advance_calls_lite_index=*/0,
+ /*num_leaf_advance_calls_main_index=*/0,
+ /*num_leaf_advance_calls_integer_index=*/0,
+ /*num_leaf_advance_calls_no_index=*/0,
+ /*num_blocks_inspected=*/0));
+}
+
INSTANTIATE_TEST_SUITE_P(
IntegerIndexTest, IntegerIndexTest,
testing::Values(