summaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/attribute/attribute_usage_filter/attribute_usage_filter_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'searchcore/src/tests/proton/attribute/attribute_usage_filter/attribute_usage_filter_test.cpp')
-rw-r--r--searchcore/src/tests/proton/attribute/attribute_usage_filter/attribute_usage_filter_test.cpp47
1 files changed, 37 insertions, 10 deletions
diff --git a/searchcore/src/tests/proton/attribute/attribute_usage_filter/attribute_usage_filter_test.cpp b/searchcore/src/tests/proton/attribute/attribute_usage_filter/attribute_usage_filter_test.cpp
index 0fced6e0bff..b35027eac2a 100644
--- a/searchcore/src/tests/proton/attribute/attribute_usage_filter/attribute_usage_filter_test.cpp
+++ b/searchcore/src/tests/proton/attribute/attribute_usage_filter/attribute_usage_filter_test.cpp
@@ -3,9 +3,13 @@
LOG_SETUP("attribute_usage_filter_test");
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/searchcore/proton/attribute/attribute_usage_filter.h>
+#include <vespa/searchcore/proton/attribute/i_attribute_usage_listener.h>
using proton::AttributeUsageFilter;
using proton::AttributeUsageStats;
+using proton::IAttributeUsageListener;
+using search::AddressSpaceUsage;
+using vespalib::AddressSpace;
namespace
{
@@ -38,33 +42,47 @@ public:
}
};
+class MyListener : public IAttributeUsageListener {
+public:
+ AttributeUsageStats stats;
+ MyListener() : stats() {}
+ void notify_attribute_usage(const AttributeUsageStats &stats_in) override {
+ stats = stats_in;
+ }
+};
+
struct Fixture
{
- AttributeUsageFilter _filter;
+ AttributeUsageFilter filter;
+ const MyListener* listener;
using State = AttributeUsageFilter::State;
using Config = AttributeUsageFilter::Config;
Fixture()
- : _filter()
+ : filter(),
+ listener()
{
+ auto my_listener = std::make_unique<MyListener>();
+ listener = my_listener.get();
+ filter.set_listener(std::move(my_listener));
}
void testWrite(const vespalib::string &exp) {
if (exp.empty()) {
- EXPECT_TRUE(_filter.acceptWriteOperation());
- State state = _filter.getAcceptState();
+ EXPECT_TRUE(filter.acceptWriteOperation());
+ State state = filter.getAcceptState();
EXPECT_TRUE(state.acceptWriteOperation());
EXPECT_EQUAL(exp, state.message());
} else {
- EXPECT_FALSE(_filter.acceptWriteOperation());
- State state = _filter.getAcceptState();
+ EXPECT_FALSE(filter.acceptWriteOperation());
+ State state = filter.getAcceptState();
EXPECT_FALSE(state.acceptWriteOperation());
EXPECT_EQUAL(exp, state.message());
}
}
void setAttributeStats(const AttributeUsageStats &stats) {
- _filter.setAttributeStats(stats);
+ filter.setAttributeStats(stats);
}
};
@@ -78,7 +96,7 @@ TEST_F("Check that default filter allows write", Fixture)
TEST_F("Check that enum store limit can be reached", Fixture)
{
- f._filter.setConfig(Fixture::Config(0.8, 1.0));
+ f.filter.setConfig(Fixture::Config(0.8, 1.0));
MyAttributeStats stats;
stats.triggerEnumStoreLimit();
f.setAttributeStats(stats);
@@ -95,7 +113,7 @@ TEST_F("Check that enum store limit can be reached", Fixture)
TEST_F("Check that multivalue limit can be reached", Fixture)
{
- f._filter.setConfig(Fixture::Config(1.0, 0.8));
+ f.filter.setConfig(Fixture::Config(1.0, 0.8));
MyAttributeStats stats;
stats.triggerMultiValueLimit();
f.setAttributeStats(stats);
@@ -113,7 +131,7 @@ TEST_F("Check that multivalue limit can be reached", Fixture)
TEST_F("Check that both enumstore limit and multivalue limit can be reached",
Fixture)
{
- f._filter.setConfig(Fixture::Config(0.8, 0.8));
+ f.filter.setConfig(Fixture::Config(0.8, 0.8));
MyAttributeStats stats;
stats.triggerEnumStoreLimit();
stats.triggerMultiValueLimit();
@@ -139,4 +157,13 @@ TEST_F("Check that both enumstore limit and multivalue limit can be reached",
"attributeName: \"multiValueName\", subdb: \"ready\"}");
}
+TEST_F("listener is updated when attribute stats change", Fixture)
+{
+ AttributeUsageStats stats;
+ AddressSpaceUsage usage(AddressSpace(12, 10, 15), AddressSpace(22, 20, 25));
+ stats.merge(usage, "my_attr", "my_subdb");
+ f.setAttributeStats(stats);
+ EXPECT_EQUAL(stats, f.listener->stats);
+}
+
TEST_MAIN() { TEST_RUN_ALL(); }