Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndris Zeila <andris.zeila@zabbix.com>2018-05-14 15:49:16 +0300
committerAndris Zeila <andris.zeila@zabbix.com>2018-05-14 15:49:16 +0300
commit563805c935c094bc0d77ac767a23a951d2e8570a (patch)
treefe72111ba1249e1affa5c79fbcb31206c4e3fb45 /tests/libs/zbxdbcache
parentbb3026f766f2b8ca7f87dbffef410918b26b6f13 (diff)
....I..... [DEV-845] added zbx_vc_get_value() function test suite, added test case to zbx_vc_get_values()
Diffstat (limited to 'tests/libs/zbxdbcache')
-rw-r--r--tests/libs/zbxdbcache/Makefile.am32
-rwxr-xr-xtests/libs/zbxdbcache/zbx_vc_get_valuebin0 -> 933080 bytes
-rw-r--r--tests/libs/zbxdbcache/zbx_vc_get_value.c183
-rw-r--r--tests/libs/zbxdbcache/zbx_vc_get_value.yaml263
-rw-r--r--tests/libs/zbxdbcache/zbx_vc_get_values.yaml71
5 files changed, 548 insertions, 1 deletions
diff --git a/tests/libs/zbxdbcache/Makefile.am b/tests/libs/zbxdbcache/Makefile.am
index ada333fa5c3..26e009995bc 100644
--- a/tests/libs/zbxdbcache/Makefile.am
+++ b/tests/libs/zbxdbcache/Makefile.am
@@ -1,4 +1,4 @@
-noinst_PROGRAMS = zbx_vc_get_values zbx_vc_add_values
+noinst_PROGRAMS = zbx_vc_get_values zbx_vc_add_values zbx_vc_get_value
VALUECACHE_LIBS = \
$(top_srcdir)/tests/libzbxmocktest.a \
@@ -69,3 +69,33 @@ zbx_vc_add_values_CFLAGS = \
-I@top_srcdir@/src/libs/zbxhistory \
-I@top_srcdir@/tests
+zbx_vc_get_value_SOURCES = \
+ zbx_vc_get_value.c \
+ valuecache_mock.c \
+ @top_srcdir@/src/libs/zbxdbcache/valuecache.c \
+ @top_srcdir@/src/libs/zbxhistory/history.c \
+ ../../zbxmocktest.h
+
+zbx_vc_get_value_WRAP_FUNCS = \
+ -Wl,--wrap=zbx_mutex_create \
+ -Wl,--wrap=zbx_mutex_destroy \
+ -Wl,--wrap=zbx_mem_create \
+ -Wl,--wrap=__zbx_mem_malloc \
+ -Wl,--wrap=__zbx_mem_realloc \
+ -Wl,--wrap=__zbx_mem_free \
+ -Wl,--wrap=zbx_history_get_values \
+ -Wl,--wrap=zbx_history_add_values \
+ -Wl,--wrap=zbx_history_sql_init \
+ -Wl,--wrap=zbx_history_elastic_init \
+ -Wl,--wrap=time
+
+zbx_vc_get_value_LDADD = $(VALUECACHE_LIBS)
+
+zbx_vc_get_value_CFLAGS = \
+ $(zbx_vc_get_value_WRAP_FUNCS) \
+ -I@top_srcdir@/src/libs/zbxalgo \
+ -I@top_srcdir@/src/libs/zbxdbcache \
+ -I@top_srcdir@/src/libs/zbxhistory \
+ -I@top_srcdir@/tests
+
+
diff --git a/tests/libs/zbxdbcache/zbx_vc_get_value b/tests/libs/zbxdbcache/zbx_vc_get_value
new file mode 100755
index 00000000000..30dc71e70ae
--- /dev/null
+++ b/tests/libs/zbxdbcache/zbx_vc_get_value
Binary files differ
diff --git a/tests/libs/zbxdbcache/zbx_vc_get_value.c b/tests/libs/zbxdbcache/zbx_vc_get_value.c
new file mode 100644
index 00000000000..a2f1853e2b9
--- /dev/null
+++ b/tests/libs/zbxdbcache/zbx_vc_get_value.c
@@ -0,0 +1,183 @@
+/*
+** Zabbix
+** Copyright (C) 2001-2018 Zabbix SIA
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+**/
+
+#include "zbxmocktest.h"
+#include "zbxmockdata.h"
+#include "zbxmockassert.h"
+#include "zbxmockutil.h"
+
+#include "common.h"
+#include "valuecache.h"
+#include "valuecache_test.h"
+#include "valuecache_mock.h"
+
+extern zbx_uint64_t CONFIG_VALUE_CACHE_SIZE;
+
+/******************************************************************************
+ * *
+ * Function: zbx_mock_test_entry *
+ * *
+ ******************************************************************************/
+void zbx_mock_test_entry(void **state)
+{
+ char *error = NULL;
+ const char *data;
+ int err, seconds, count, item_status, item_active_range, item_db_cached_from,
+ item_values_total, cache_mode;
+ zbx_vector_history_record_t expected, returned;
+ zbx_timespec_t ts;
+ zbx_uint64_t itemid, cache_hits, cache_misses, expected_hits, expected_misses;
+ unsigned char value_type;
+ zbx_mock_handle_t handle, hitems, hitem, hstatus;
+ zbx_mock_error_t mock_err;
+
+ ZBX_UNUSED(state);
+
+ /* set small cache size to force smaller cache free request size (5% of cache size) */
+ CONFIG_VALUE_CACHE_SIZE = ZBX_KIBIBYTE;
+
+ err = zbx_vc_init(&error);
+ zbx_mock_assert_result_eq("Value cache initialization failed", SUCCEED, err);
+
+ zbx_vc_enable();
+
+ zbx_vcmock_ds_init();
+ zbx_history_record_vector_create(&expected);
+ zbx_history_record_vector_create(&returned);
+
+ /* precache values */
+ if (ZBX_MOCK_SUCCESS == zbx_mock_parameter("in.precache", &handle))
+ {
+ while (ZBX_MOCK_END_OF_VECTOR != (mock_err = (zbx_mock_vector_element(handle, &hitem))))
+ {
+ zbx_vcmock_set_time(hitem, "time");
+ zbx_vcmock_set_mode(hitem, "cache mode");
+ zbx_vcmock_set_cache_size(hitem, "cache size");
+
+ zbx_vcmock_get_request_params(hitem, &itemid, &value_type, &seconds, &count, &ts);
+ zbx_vc_precache_values(itemid, value_type, seconds, count, &ts);
+ }
+ }
+
+ /* perform request */
+
+ handle = zbx_mock_get_parameter_handle("in.test");
+ zbx_vcmock_set_time(handle, "time");
+ zbx_vcmock_set_mode(handle, "cache mode");
+
+ if (FAIL == is_uint64(zbx_mock_get_object_member_string(handle, "itemid"), &itemid))
+ fail_msg("Invalid itemid value");
+
+ value_type = zbx_mock_str_to_value_type(zbx_mock_get_object_member_string(handle, "value type"));
+ zbx_strtime_to_timespec(zbx_mock_get_object_member_string(handle, "end"), &ts);
+
+ zbx_vector_history_record_reserve(&returned, 1);
+ err = zbx_vc_get_value(itemid, value_type, &ts, &returned.values[0]);
+ returned.values_num = 1;
+ zbx_mock_assert_result_eq("zbx_vc_get_values() return value", SUCCEED, err);
+
+ /* validate results */
+
+ zbx_vcmock_read_values(zbx_mock_get_parameter_handle("out.values"), value_type, &expected);
+ zbx_vcmock_check_records("Returned values", value_type, &expected, &returned);
+
+ zbx_history_record_vector_clean(&returned, value_type);
+ zbx_history_record_vector_clean(&expected, value_type);
+
+ /* validate cache contents */
+
+ hitems = zbx_mock_get_parameter_handle("out.cache.items");
+
+ while (ZBX_MOCK_END_OF_VECTOR != (mock_err = (zbx_mock_vector_element(hitems, &hitem))))
+ {
+ if (ZBX_MOCK_NOT_A_VECTOR == mock_err)
+ fail_msg("out.cache.items parameter is not a vector");
+
+ data = zbx_mock_get_object_member_string(hitem, "itemid");
+ if (SUCCEED != is_uint64(data, &itemid))
+ fail_msg("Invalid itemid \"%s\"", data);
+
+ err = zbx_vc_get_item_state(itemid, &item_status, &item_active_range, &item_values_total,
+ &item_db_cached_from);
+
+ mock_err = zbx_mock_object_member(hitem, "status", &hstatus);
+
+ if (ZBX_MOCK_SUCCESS == mock_err)
+ {
+ zbx_mock_assert_result_eq("zbx_vc_get_item_state() return value", SUCCEED, err);
+
+ if (ZBX_MOCK_SUCCESS != (mock_err = zbx_mock_string(hstatus, &data)))
+ fail_msg("Cannot read item status: %s", zbx_mock_error_string(mock_err));
+
+ zbx_mock_assert_int_eq("item.status", zbx_vcmock_str_to_item_status(data), item_status);
+
+ data = zbx_mock_get_object_member_string(hitem, "active_range");
+ zbx_mock_assert_int_eq("item.active_range", atoi(data), item_active_range);
+
+ data = zbx_mock_get_object_member_string(hitem, "values_total");
+ zbx_mock_assert_int_eq("item.values_total", atoi(data), item_values_total);
+
+ if (ZBX_MOCK_SUCCESS != (mock_err = zbx_strtime_to_timespec(
+ zbx_mock_get_object_member_string(hitem, "db_cached_from"), &ts)))
+ {
+ fail_msg("Cannot read out.item.db_cached_from timestamp: %s",
+ zbx_mock_error_string(mock_err));
+ }
+
+ zbx_mock_assert_time_eq("item.db_cached_from", ts.sec, item_db_cached_from);
+
+ value_type = zbx_mock_str_to_value_type(zbx_mock_get_object_member_string(hitem, "value type"));
+
+ zbx_vcmock_read_values(zbx_mock_get_object_member_handle(hitem, "data"), value_type, &expected);
+ zbx_vc_get_cached_values(itemid, value_type, &returned);
+
+ zbx_vcmock_check_records("Cached values", value_type, &expected, &returned);
+
+ zbx_history_record_vector_clean(&expected, value_type);
+ zbx_history_record_vector_clean(&returned, value_type);
+ }
+ else
+ zbx_mock_assert_result_eq("zbx_vc_get_item_state() return value", FAIL, err);
+ }
+
+ /* validate cache state */
+
+ zbx_vc_get_cache_state(&cache_mode, &cache_hits, &cache_misses);
+ zbx_mock_assert_int_eq("cache.mode", zbx_vcmock_str_to_cache_mode(zbx_mock_get_parameter_string("out.cache.mode")),
+ cache_mode);
+
+ if (FAIL == is_uint64(zbx_mock_get_parameter_string("out.cache.hits"), &expected_hits))
+ fail_msg("Invalid out.cache.hits value");
+ zbx_mock_assert_uint64_eq("cache.hits", expected_hits, cache_hits);
+
+ if (FAIL == is_uint64(zbx_mock_get_parameter_string("out.cache.misses"), &expected_misses))
+ fail_msg("Invalid out.cache.misses value");
+ zbx_mock_assert_uint64_eq("cache.misses", expected_misses, cache_misses);
+
+ /* cleanup */
+
+ zbx_vector_history_record_destroy(&returned);
+ zbx_vector_history_record_destroy(&expected);
+
+ zbx_vcmock_ds_destroy();
+
+ zbx_vc_reset();
+ zbx_vc_destroy();
+}
+
diff --git a/tests/libs/zbxdbcache/zbx_vc_get_value.yaml b/tests/libs/zbxdbcache/zbx_vc_get_value.yaml
new file mode 100644
index 00000000000..67e89468558
--- /dev/null
+++ b/tests/libs/zbxdbcache/zbx_vc_get_value.yaml
@@ -0,0 +1,263 @@
+---
+# TC0
+# Test that single value from the end of second interval is returned
+test case: Get last value from second interval
+in:
+ history:
+ - itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ data:
+ - &row12
+ value: value 1.2
+ ts: 2017-01-10 10:00:01.200000000 +00:00
+ - &row15
+ value: value 1.5
+ ts: 2017-01-10 10:00:01.500000000 +00:00
+ - &row17
+ value: value 1.7
+ ts: 2017-01-10 10:00:01.700000000 +00:00
+ - &row22
+ value: value 2.2
+ ts: 2017-01-10 10:00:02.200000000 +00:00
+ - &row25
+ value: value 2.5
+ ts: 2017-01-10 10:00:02.500000000 +00:00
+ - &row27
+ value: value 2.7
+ ts: 2017-01-10 10:00:02.700000000 +00:00
+ - &row32
+ value: value 3.2
+ ts: 2017-01-10 10:00:03.200000000 +00:00
+ - &row35
+ value: value 3.5
+ ts: 2017-01-10 10:00:03.500000000 +00:00
+ - &row37
+ value: value 3.7
+ ts: 2017-01-10 10:00:03.700000000 +00:00
+ - &row42
+ value: value 4.2
+ ts: 2017-01-10 10:00:04.200000000 +00:00
+ - &row45
+ value: value 4.5
+ ts: 2017-01-10 10:00:04.500000000 +00:00
+ - &row47
+ value: value 4.7
+ ts: 2017-01-10 10:00:04.700000000 +00:00
+ - &row52
+ value: value 5.2
+ ts: 2017-01-10 10:00:05.200000000 +00:00
+ - &row55
+ value: value 5.5
+ ts: 2017-01-10 10:00:05.500000000 +00:00
+ - &row57
+ value: value 5.7
+ ts: 2017-01-10 10:00:05.700000000 +00:00
+ precache:
+ - time: 2017-01-10 10:10:00.000000000 +00:00
+ itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ seconds: 0
+ count: 1
+ end: 2017-01-10 10:00:04.999999999 +00:00
+ test:
+ time: 2017-01-10 10:10:00.000000000 +00:00
+ itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ end: 2017-01-10 10:00:04.999999999 +00:00
+out:
+ values:
+ - *row47
+ cache:
+ items:
+ - itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ data:
+ - *row42
+ - *row45
+ - *row47
+ - *row52
+ - *row55
+ - *row57
+ status:
+ active_range: 597
+ values_total: 6
+ db_cached_from: 2017-01-10 10:00:04.000000000 +00:00
+ mode: ZBX_VC_MODE_NORMAL
+ hits: 1
+ misses: 0
+---
+# TC1
+# Test that single value from the middle of second interval is returned
+test case: Get middle value from second interval
+in:
+ history:
+ - itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ data:
+ - &row12
+ value: value 1.2
+ ts: 2017-01-10 10:00:01.200000000 +00:00
+ - &row15
+ value: value 1.5
+ ts: 2017-01-10 10:00:01.500000000 +00:00
+ - &row17
+ value: value 1.7
+ ts: 2017-01-10 10:00:01.700000000 +00:00
+ - &row22
+ value: value 2.2
+ ts: 2017-01-10 10:00:02.200000000 +00:00
+ - &row25
+ value: value 2.5
+ ts: 2017-01-10 10:00:02.500000000 +00:00
+ - &row27
+ value: value 2.7
+ ts: 2017-01-10 10:00:02.700000000 +00:00
+ - &row32
+ value: value 3.2
+ ts: 2017-01-10 10:00:03.200000000 +00:00
+ - &row35
+ value: value 3.5
+ ts: 2017-01-10 10:00:03.500000000 +00:00
+ - &row37
+ value: value 3.7
+ ts: 2017-01-10 10:00:03.700000000 +00:00
+ - &row42
+ value: value 4.2
+ ts: 2017-01-10 10:00:04.200000000 +00:00
+ - &row45
+ value: value 4.5
+ ts: 2017-01-10 10:00:04.500000000 +00:00
+ - &row47
+ value: value 4.7
+ ts: 2017-01-10 10:00:04.700000000 +00:00
+ - &row52
+ value: value 5.2
+ ts: 2017-01-10 10:00:05.200000000 +00:00
+ - &row55
+ value: value 5.5
+ ts: 2017-01-10 10:00:05.500000000 +00:00
+ - &row57
+ value: value 5.7
+ ts: 2017-01-10 10:00:05.700000000 +00:00
+ precache:
+ - time: 2017-01-10 10:10:00.000000000 +00:00
+ itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ seconds: 0
+ count: 1
+ end: 2017-01-10 10:00:04.999999999 +00:00
+ test:
+ time: 2017-01-10 10:10:00.000000000 +00:00
+ itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ end: 2017-01-10 10:00:04.500000000 +00:00
+out:
+ values:
+ - *row45
+ cache:
+ items:
+ - itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ data:
+ - *row42
+ - *row45
+ - *row47
+ - *row52
+ - *row55
+ - *row57
+ status:
+ active_range: 597
+ values_total: 6
+ db_cached_from: 2017-01-10 10:00:04.000000000 +00:00
+ mode: ZBX_VC_MODE_NORMAL
+ hits: 1
+ misses: 0
+---
+# TC1
+# Test that single value from the beginning of second interval is returned
+test case: Get first value from second interval
+in:
+ history:
+ - itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ data:
+ - &row12
+ value: value 1.2
+ ts: 2017-01-10 10:00:01.200000000 +00:00
+ - &row15
+ value: value 1.5
+ ts: 2017-01-10 10:00:01.500000000 +00:00
+ - &row17
+ value: value 1.7
+ ts: 2017-01-10 10:00:01.700000000 +00:00
+ - &row22
+ value: value 2.2
+ ts: 2017-01-10 10:00:02.200000000 +00:00
+ - &row25
+ value: value 2.5
+ ts: 2017-01-10 10:00:02.500000000 +00:00
+ - &row27
+ value: value 2.7
+ ts: 2017-01-10 10:00:02.700000000 +00:00
+ - &row32
+ value: value 3.2
+ ts: 2017-01-10 10:00:03.200000000 +00:00
+ - &row35
+ value: value 3.5
+ ts: 2017-01-10 10:00:03.500000000 +00:00
+ - &row37
+ value: value 3.7
+ ts: 2017-01-10 10:00:03.700000000 +00:00
+ - &row42
+ value: value 4.2
+ ts: 2017-01-10 10:00:04.200000000 +00:00
+ - &row45
+ value: value 4.5
+ ts: 2017-01-10 10:00:04.500000000 +00:00
+ - &row47
+ value: value 4.7
+ ts: 2017-01-10 10:00:04.700000000 +00:00
+ - &row52
+ value: value 5.2
+ ts: 2017-01-10 10:00:05.200000000 +00:00
+ - &row55
+ value: value 5.5
+ ts: 2017-01-10 10:00:05.500000000 +00:00
+ - &row57
+ value: value 5.7
+ ts: 2017-01-10 10:00:05.700000000 +00:00
+ precache:
+ - time: 2017-01-10 10:10:00.000000000 +00:00
+ itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ seconds: 0
+ count: 1
+ end: 2017-01-10 10:00:04.999999999 +00:00
+ test:
+ time: 2017-01-10 10:10:00.000000000 +00:00
+ itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ end: 2017-01-10 10:00:04.400000000 +00:00
+out:
+ values:
+ - *row42
+ cache:
+ items:
+ - itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ data:
+ - *row42
+ - *row45
+ - *row47
+ - *row52
+ - *row55
+ - *row57
+ status:
+ active_range: 597
+ values_total: 6
+ db_cached_from: 2017-01-10 10:00:04.000000000 +00:00
+ mode: ZBX_VC_MODE_NORMAL
+ hits: 1
+ misses: 0
+...
+
diff --git a/tests/libs/zbxdbcache/zbx_vc_get_values.yaml b/tests/libs/zbxdbcache/zbx_vc_get_values.yaml
index 76a06b71883..fc2a57459bb 100644
--- a/tests/libs/zbxdbcache/zbx_vc_get_values.yaml
+++ b/tests/libs/zbxdbcache/zbx_vc_get_values.yaml
@@ -4051,4 +4051,75 @@ out:
mode: ZBX_VC_MODE_LOWMEM
hits: 0
misses: 0
+---
+# TC29
+# Test that value in a middle of second interval is returned.
+test case: Get 1 item value when cache working in low memory mode
+in:
+ history:
+ - itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ data:
+ - &row12
+ value: value 1.2
+ ts: 2017-01-10 10:00:01.200000000 +00:00
+ - &row15
+ value: value 1.5
+ ts: 2017-01-10 10:00:01.500000000 +00:00
+ - &row17
+ value: value 1.7
+ ts: 2017-01-10 10:00:01.700000000 +00:00
+ - &row22
+ value: value 2.2
+ ts: 2017-01-10 10:00:02.200000000 +00:00
+ - &row25
+ value: value 2.5
+ ts: 2017-01-10 10:00:02.500000000 +00:00
+ - &row27
+ value: value 2.7
+ ts: 2017-01-10 10:00:02.700000000 +00:00
+ - &row32
+ value: value 3.2
+ ts: 2017-01-10 10:00:03.200000000 +00:00
+ - &row35
+ value: value 3.5
+ ts: 2017-01-10 10:00:03.500000000 +00:00
+ - &row37
+ value: value 3.7
+ ts: 2017-01-10 10:00:03.700000000 +00:00
+ - &row42
+ value: value 4.2
+ ts: 2017-01-10 10:00:04.200000000 +00:00
+ - &row45
+ value: value 4.5
+ ts: 2017-01-10 10:00:04.500000000 +00:00
+ - &row47
+ value: value 4.7
+ ts: 2017-01-10 10:00:04.700000000 +00:00
+ - &row52
+ value: value 5.2
+ ts: 2017-01-10 10:00:05.200000000 +00:00
+ - &row55
+ value: value 5.5
+ ts: 2017-01-10 10:00:05.500000000 +00:00
+ - &row57
+ value: value 5.7
+ ts: 2017-01-10 10:00:05.700000000 +00:00
+ test:
+ cache mode: ZBX_VC_MODE_LOWMEM
+ time: 2017-01-10 10:10:00.000000000 +00:00
+ itemid: 1
+ value type: ITEM_VALUE_TYPE_STR
+ seconds: 0
+ count: 1
+ end: 2017-01-10 10:00:05.600000000 +00:00
+out:
+ values:
+ - *row55
+ cache:
+ items:
+ - itemid: 1
+ mode: ZBX_VC_MODE_LOWMEM
+ hits: 0
+ misses: 1
...