From: Sebastian Harl Date: Fri, 16 Jan 2015 20:22:06 +0000 (+0100) Subject: t/integration: Add a simple time-series fetcher test. X-Git-Tag: sysdb-0.7.0~63 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c679bdcebdb5212071f32cad6b9ec1497a99cb49;p=sysdb.git t/integration: Add a simple time-series fetcher test. --- diff --git a/t/integration/config.sh b/t/integration/config.sh index 3bdb104..b25e950 100755 --- a/t/integration/config.sh +++ b/t/integration/config.sh @@ -91,3 +91,4 @@ wait_for_sysdbd stop_sysdbd +# vim: set tw=78 sw=4 ts=4 noexpandtab : diff --git a/t/integration/filter.sh b/t/integration/filter.sh index da75b9a..ddcf785 100755 --- a/t/integration/filter.sh +++ b/t/integration/filter.sh @@ -77,3 +77,4 @@ echo $output | grep -E '^\[\]$' stop_sysdbd +# vim: set tw=78 sw=4 ts=4 noexpandtab : diff --git a/t/integration/matching.sh b/t/integration/matching.sh index 8b25ed3..34e7c54 100755 --- a/t/integration/matching.sh +++ b/t/integration/matching.sh @@ -117,3 +117,4 @@ echo $output | grep -E '^\[\]$' stop_sysdbd +# vim: set tw=78 sw=4 ts=4 noexpandtab : diff --git a/t/integration/mock_plugin.c b/t/integration/mock_plugin.c index 1fb59fc..8041c0d 100644 --- a/t/integration/mock_plugin.c +++ b/t/integration/mock_plugin.c @@ -57,21 +57,21 @@ static struct { sdb_metric_store_t store; } metrics[] = { { "some.host.name", "foo/bar/qux", - { "dummy", "/var/lib/collectd/rrd/foo/bar/qux.rrd" } }, + { "mock", "/var/lib/collectd/rrd/foo/bar/qux.rrd" } }, { "some.host.name", "foo/bar/baz", - { "dummy", "/var/lib/collectd/rrd/foo/bar/baz.rrd" } }, + { "mock", "/var/lib/collectd/rrd/foo/bar/baz.rrd" } }, { "some.host.name", "foo2/bar/qux", - { "dummy", "/var/lib/collectd/rrd/foo2/bar/qux.rrd" } }, + { "mock", "/var/lib/collectd/rrd/foo2/bar/qux.rrd" } }, { "some.host.name", "foo2/bar/baz", - { "dummy", "/var/lib/collectd/rrd/foo2/bar/baz.rrd" } }, + { "mock", "/var/lib/collectd/rrd/foo2/bar/baz.rrd" } }, { "other.host.name", "foo/bar/qux", - { "dummy", "/var/lib/collectd/rrd/foo/bar/qux.rrd" } }, + { "mock", "/var/lib/collectd/rrd/foo/bar/qux.rrd" } }, { "other.host.name", "foo/bar/baz", - { "dummy", "/var/lib/collectd/rrd/foo/bar/baz.rrd" } }, + { "mock", "/var/lib/collectd/rrd/foo/bar/baz.rrd" } }, { "other.host.name", "foo2/bar/qux", - { "dummy", "/var/lib/collectd/rrd/foo2/bar/qux.rrd" } }, + { "mock", "/var/lib/collectd/rrd/foo2/bar/qux.rrd" } }, { "other.host.name", "foo2/bar/baz", - { "dummy", "/var/lib/collectd/rrd/foo2/bar/baz.rrd" } }, + { "mock", "/var/lib/collectd/rrd/foo2/bar/baz.rrd" } }, }; static struct { @@ -192,6 +192,42 @@ mock_collect(sdb_object_t *user_data) return 0; } /* mock_collect */ +static sdb_timeseries_t * +mock_fetch_ts(const char *id, sdb_timeseries_opts_t *opts, + sdb_object_t *user_data) +{ + sdb_timeseries_t *ts; + const char *names[] = { "nameA", "nameB" }; + size_t i, j; + + if (*id != '/') { + sdb_log(SDB_LOG_ERR, "mock::plugin: Invalid time-series %s", id); + exit(1); + } + + if (SDB_OBJ_WRAPPER(user_data)->data != MAGIC_DATA) { + sdb_log(SDB_LOG_ERR, "mock::plugin: Invalid user data %p " + "passed to collect", SDB_OBJ_WRAPPER(user_data)->data); + exit(1); + } + + ts = sdb_timeseries_create(SDB_STATIC_ARRAY_LEN(names), names, 10); + if (! ts) + return NULL; + + ts->start = opts->start; + ts->end = opts->end; + + for (i = 0; i < 10; ++i) { + for (j = 0; j < SDB_STATIC_ARRAY_LEN(names); ++j) { + ts->data[j][i].timestamp = ts->start + + i * (ts->end - ts->start) / 10; + ts->data[j][i].value = (double)(i + j); + } + } + return ts; +} /* mock_fetch_ts */ + static int mock_config(oconfig_item_t *ci) { @@ -220,6 +256,8 @@ mock_config(oconfig_item_t *ci) sdb_plugin_register_collector("main", mock_collect, /* interval = */ NULL, user_data); + sdb_plugin_register_ts_fetcher("mock", mock_fetch_ts, user_data); + sdb_object_deref(user_data); return 0; } /* mock_config */ diff --git a/t/integration/query.sh b/t/integration/query.sh index eb4ccd8..b2e6ed8 100755 --- a/t/integration/query.sh +++ b/t/integration/query.sh @@ -115,8 +115,20 @@ run_sysdb -H "$SOCKET_FILE" \ -c "TIMESERIES 'invalid.host'.'invalid-metric'" && exit 1 # Does not work yet since there is no fetcher plugin. -run_sysdb -H "$SOCKET_FILE" \ - -c "TIMESERIES 'some.host.name'.'foo/bar/qux'" && exit 1 +output="$( run_sysdb -H "$SOCKET_FILE" \ + -c "TIMESERIES 'some.host.name'.'foo/bar/qux'" )" +echo "$output" \ + | grep -F '"value": "1.000000"' \ + | grep -F '"value": "2.000000"' \ + | grep -F '"value": "3.000000"' \ + | grep -F '"value": "4.000000"' \ + | grep -F '"value": "5.000000"' \ + | grep -F '"value": "6.000000"' \ + | grep -F '"value": "7.000000"' \ + | grep -F '"value": "8.000000"' \ + | grep -F '"value": "9.000000"' \ + | grep -F '"value": "10.000000"' stop_sysdbd +# vim: set tw=78 sw=4 ts=4 noexpandtab : diff --git a/t/integration/test_lib.sh b/t/integration/test_lib.sh index f6898e4..8206ddf 100644 --- a/t/integration/test_lib.sh +++ b/t/integration/test_lib.sh @@ -94,3 +94,4 @@ function wait_for_sysdbd() { fi } +# vim: set tw=78 sw=4 ts=4 noexpandtab :