summaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/server/disk_mem_usage_filter
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /searchcore/src/tests/proton/server/disk_mem_usage_filter
Publish
Diffstat (limited to 'searchcore/src/tests/proton/server/disk_mem_usage_filter')
-rw-r--r--searchcore/src/tests/proton/server/disk_mem_usage_filter/.gitignore1
-rw-r--r--searchcore/src/tests/proton/server/disk_mem_usage_filter/CMakeLists.txt10
-rw-r--r--searchcore/src/tests/proton/server/disk_mem_usage_filter/DESC1
-rw-r--r--searchcore/src/tests/proton/server/disk_mem_usage_filter/FILES1
-rw-r--r--searchcore/src/tests/proton/server/disk_mem_usage_filter/disk_mem_usage_filter_test.cpp113
5 files changed, 126 insertions, 0 deletions
diff --git a/searchcore/src/tests/proton/server/disk_mem_usage_filter/.gitignore b/searchcore/src/tests/proton/server/disk_mem_usage_filter/.gitignore
new file mode 100644
index 00000000000..ec8610c93cf
--- /dev/null
+++ b/searchcore/src/tests/proton/server/disk_mem_usage_filter/.gitignore
@@ -0,0 +1 @@
+searchcore_disk_mem_usage_filter_test_app
diff --git a/searchcore/src/tests/proton/server/disk_mem_usage_filter/CMakeLists.txt b/searchcore/src/tests/proton/server/disk_mem_usage_filter/CMakeLists.txt
new file mode 100644
index 00000000000..1d9b0234d76
--- /dev/null
+++ b/searchcore/src/tests/proton/server/disk_mem_usage_filter/CMakeLists.txt
@@ -0,0 +1,10 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(searchcore_disk_mem_usage_filter_test_app
+ SOURCES
+ disk_mem_usage_filter_test.cpp
+ DEPENDS
+ searchcore_server
+)
+vespa_add_target_system_dependency(searchcore_disk_mem_usage_filter_test_app boost boost_system-mt-d)
+vespa_add_target_system_dependency(searchcore_disk_mem_usage_filter_test_app boost boost_filesystem-mt-d)
+vespa_add_test(NAME searchcore_disk_mem_usage_filter_test_app COMMAND searchcore_disk_mem_usage_filter_test_app)
diff --git a/searchcore/src/tests/proton/server/disk_mem_usage_filter/DESC b/searchcore/src/tests/proton/server/disk_mem_usage_filter/DESC
new file mode 100644
index 00000000000..fca9e3b7656
--- /dev/null
+++ b/searchcore/src/tests/proton/server/disk_mem_usage_filter/DESC
@@ -0,0 +1 @@
+DiskMemUsageFilter test. Take a look at disk_mem_usage_filter_test.cpp for details.
diff --git a/searchcore/src/tests/proton/server/disk_mem_usage_filter/FILES b/searchcore/src/tests/proton/server/disk_mem_usage_filter/FILES
new file mode 100644
index 00000000000..b6cdfc4bffc
--- /dev/null
+++ b/searchcore/src/tests/proton/server/disk_mem_usage_filter/FILES
@@ -0,0 +1 @@
+disk_mem_usage_filter_test.cpp
diff --git a/searchcore/src/tests/proton/server/disk_mem_usage_filter/disk_mem_usage_filter_test.cpp b/searchcore/src/tests/proton/server/disk_mem_usage_filter/disk_mem_usage_filter_test.cpp
new file mode 100644
index 00000000000..70e559e2d23
--- /dev/null
+++ b/searchcore/src/tests/proton/server/disk_mem_usage_filter/disk_mem_usage_filter_test.cpp
@@ -0,0 +1,113 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("disk_mem_usage_filter_test");
+#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/searchcore/proton/server/disk_mem_usage_filter.h>
+
+using proton::DiskMemUsageFilter;
+
+namespace fs = boost::filesystem;
+
+namespace
+{
+
+struct Fixture
+{
+ DiskMemUsageFilter _filter;
+ using State = DiskMemUsageFilter::State;
+ using Config = DiskMemUsageFilter::Config;
+
+ Fixture()
+ : _filter(64 * 1024 * 1024)
+ {
+ _filter.setDiskStats({.capacity = 100, .free = 100, .available=100});
+ _filter.setMemoryStats(vespalib::ProcessMemoryStats(10000000,
+ 10000001,
+ 10000002,
+ 10000003));
+ }
+
+ void testWrite(const vespalib::string &exp) {
+ if (exp.empty()) {
+ 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(state.acceptWriteOperation());
+ EXPECT_EQUAL(exp, state.message());
+ }
+ }
+
+ void triggerDiskLimit() {
+ _filter.setDiskStats({.capacity = 100, .free = 20, .available=10});
+ }
+
+ void triggerMemoryLimit()
+ {
+ _filter.setMemoryStats(vespalib::ProcessMemoryStats(58720259,
+ 58720258,
+ 58720257,
+ 58720256));
+ }
+};
+
+}
+
+TEST_F("Check that default filter allows write", Fixture)
+{
+ f.testWrite("");
+}
+
+
+TEST_F("Check that disk limit can be reached", Fixture)
+{
+ f._filter.setConfig(Fixture::Config(1.0, 0.8));
+ f.triggerDiskLimit();
+ f.testWrite("diskLimitReached: { "
+ "action: \"add more content nodes\", "
+ "reason: \""
+ "disk used (0.9) > disk limit (0.8)"
+ "\", "
+ "capacity: 100, free: 20, available: 10, diskLimit: 0.8}");
+}
+
+TEST_F("Check that memory limit can be reached", Fixture)
+{
+ f._filter.setConfig(Fixture::Config(0.8, 1.0));
+ f.triggerMemoryLimit();
+ f.testWrite("memoryLimitReached: { "
+ "action: \"add more content nodes\", "
+ "reason: \""
+ "memory used (0.875) > memory limit (0.8)"
+ "\", "
+ "mapped: { virt: 58720259, rss: 58720258}, "
+ "anonymous: { virt: 58720257, rss: 58720256}, "
+ "physicalMemory: 67108864, memoryLimit : 0.8}");
+}
+
+TEST_F("Check that both disk limit and memory limit can be reached", Fixture)
+{
+ f._filter.setConfig(Fixture::Config(0.8, 0.8));
+ f.triggerMemoryLimit();
+ f.triggerDiskLimit();
+ f.testWrite("memoryLimitReached: { "
+ "action: \"add more content nodes\", "
+ "reason: \""
+ "memory used (0.875) > memory limit (0.8)"
+ "\", "
+ "mapped: { virt: 58720259, rss: 58720258}, "
+ "anonymous: { virt: 58720257, rss: 58720256}, "
+ "physicalMemory: 67108864, memoryLimit : 0.8}, "
+ "diskLimitReached: { "
+ "action: \"add more content nodes\", "
+ "reason: \""
+ "disk used (0.9) > disk limit (0.8)"
+ "\", "
+ "capacity: 100, free: 20, available: 10, diskLimit: 0.8}");
+}
+
+TEST_MAIN() { TEST_RUN_ALL(); }