X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=t%2Funit%2Ffrontend%2Fquery_test.c;h=7640511b692f7bfaa68f5a627066d7b5afa0bf90;hp=8872e5b6e13a0f2879430e20e65f7c7f1bf27ebf;hb=026ce2bb377f4055e3a0a1d20a2f91e5a73a49b0;hpb=299d8ae505f7c7262a8faa7564839322c26a1ffb diff --git a/t/unit/frontend/query_test.c b/t/unit/frontend/query_test.c index 8872e5b..7640511 100644 --- a/t/unit/frontend/query_test.c +++ b/t/unit/frontend/query_test.c @@ -29,6 +29,7 @@ # include "config.h" #endif +#include "core/plugin.h" #include "frontend/connection.h" #include "frontend/connection-private.h" #include "testutils.h" @@ -42,36 +43,56 @@ static void populate(void) { + sdb_store_t *store; sdb_data_t datum; - sdb_store_host("h1", 1 * SDB_INTERVAL_SECOND); - sdb_store_host("h2", 3 * SDB_INTERVAL_SECOND); + /* the frontend accesses the store via the plugin API */ + store = sdb_store_create(); + ck_assert(store != NULL); + ck_assert(sdb_plugin_register_writer("test-writer", + &sdb_store_writer, SDB_OBJ(store)) == 0); + ck_assert(sdb_plugin_register_reader("test-reader", + &sdb_store_reader, SDB_OBJ(store)) == 0); + sdb_object_deref(SDB_OBJ(store)); + + /* populate the store */ + sdb_plugin_store_host("h1", 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_host("h2", 3 * SDB_INTERVAL_SECOND); datum.type = SDB_TYPE_STRING; datum.data.string = "v1"; - sdb_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND); datum.data.string = "v2"; - sdb_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND); datum.data.string = "v3"; - sdb_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND); - sdb_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND); - sdb_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); - sdb_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND); datum.type = SDB_TYPE_INTEGER; datum.data.integer = 42; - sdb_store_metric_attr("h1", "m1", "k3", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_metric_attribute("h1", "m1", "k3", + &datum, 2 * SDB_INTERVAL_SECOND); - sdb_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND); - sdb_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND); datum.data.integer = 123; - sdb_store_service_attr("h2", "s2", "k1", &datum, 2 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service_attribute("h2", "s2", "k1", + &datum, 2 * SDB_INTERVAL_SECOND); datum.data.integer = 4711; - sdb_store_service_attr("h2", "s2", "k2", &datum, 1 * SDB_INTERVAL_SECOND); + sdb_plugin_store_service_attribute("h2", "s2", "k2", + &datum, 1 * SDB_INTERVAL_SECOND); } /* populate */ +static void +turndown(void) +{ + sdb_plugin_unregister_all(); +} /* turndown */ + #define HOST_H1 \ "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \ "\"update_interval\": \"0s\", \"backends\": [], " \ @@ -103,7 +124,38 @@ populate(void) "{\"name\": \"hostname\", \"value\": \"h1\", " \ "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \ "\"update_interval\": \"0s\", \"backends\": []}]}]}" +#define HOST_H2 \ + "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " \ + "\"update_interval\": \"0s\", \"backends\": [], " \ + "\"metrics\": [" \ + "{\"name\": \"m1\", \"timeseries\": false, " \ + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \ + "\"update_interval\": \"0s\", \"backends\": [], " \ + "\"attributes\": [" \ + "{\"name\": \"hostname\", \"value\": \"h2\", " \ + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \ + "\"update_interval\": \"0s\", \"backends\": []}]}], " \ + "\"services\": [" \ + "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \ + "\"update_interval\": \"0s\", \"backends\": [], " \ + "\"attributes\": [" \ + "{\"name\": \"hostname\", \"value\": \"h2\", " \ + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \ + "\"update_interval\": \"0s\", \"backends\": []}]}," \ + "{\"name\": \"s2\", \"last_update\": \"1970-01-01 00:00:02 +0000\", " \ + "\"update_interval\": \"0s\", \"backends\": [], " \ + "\"attributes\": [" \ + "{\"name\": \"hostname\", \"value\": \"h2\", " \ + "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \ + "\"update_interval\": \"0s\", \"backends\": []}," \ + "{\"name\": \"k1\", \"value\": 123, " \ + "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \ + "\"update_interval\": \"0s\", \"backends\": []}," \ + "{\"name\": \"k2\", \"value\": 4711, " \ + "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \ + "\"update_interval\": \"0s\", \"backends\": []}]}]}" #define HOST_H1_ARRAY "["HOST_H1"]" +#define HOST_H12_ARRAY "["HOST_H1","HOST_H2"]" #define HOST_H1_LISTING \ "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \ "\"update_interval\": \"0s\", \"backends\": []}" @@ -350,6 +402,14 @@ static struct { SDB_CONNECTION_QUERY, "LOOKUP hosts MATCHING name = 'h1' FILTER age >= 0s", -1, /* always matches */ 0, SDB_CONNECTION_DATA, 1112, SDB_CONNECTION_LOOKUP, HOST_H1_ARRAY, }, + { + SDB_CONNECTION_QUERY, "LOOKUP hosts MATCHING ANY backend = 'b'", -1, + 0, SDB_CONNECTION_DATA, 6, SDB_CONNECTION_LOOKUP, "[]", + }, + { + SDB_CONNECTION_QUERY, "LOOKUP hosts MATCHING ANY backend || 'b' = 'b'", -1, + 0, SDB_CONNECTION_DATA, 2205, SDB_CONNECTION_LOOKUP, HOST_H12_ARRAY, + }, { SDB_CONNECTION_QUERY, "FETCH host 'h1' FILTER age < 0s", -1, /* never matches */ -1, UINT32_MAX, 0, 0, NULL, /* FETCH fails if the object doesn't exist */ @@ -648,7 +708,7 @@ START_TEST(test_query) const char *data; ssize_t tmp; size_t len; - int check; + int check = -1; conn->cmd = query_data[_i].cmd; if (query_data[_i].query_len < 0) @@ -659,27 +719,27 @@ START_TEST(test_query) switch (conn->cmd) { case SDB_CONNECTION_QUERY: - check = sdb_fe_query(conn); + check = sdb_conn_query(conn); break; case SDB_CONNECTION_FETCH: - check = sdb_fe_fetch(conn); + check = sdb_conn_fetch(conn); break; case SDB_CONNECTION_LIST: - check = sdb_fe_list(conn); + check = sdb_conn_list(conn); break; case SDB_CONNECTION_LOOKUP: - check = sdb_fe_lookup(conn); + check = sdb_conn_lookup(conn); break; /* SDB_CONNECTION_TIMESERIES not supported yet */ case SDB_CONNECTION_STORE: - check = sdb_fe_store(conn); + check = sdb_conn_store(conn); break; default: fail("Invalid command %#x", conn->cmd); } fail_unless(check == query_data[_i].expected, - "sdb_fe_query(%s) = %d; expected: %d (err: %s)", + "sdb_conn_query(%s) = %d; expected: %d (err: %s)", query_data[_i].query, check, query_data[_i].expected, sdb_strbuf_string(conn->errbuf)); @@ -688,7 +748,7 @@ START_TEST(test_query) if (query_data[_i].code == UINT32_MAX) { fail_unless(len == 0, - "sdb_fe_query(%s) returned data on error: '%s'", + "sdb_conn_query(%s) returned data on error: '%s'", query_data[_i].query, data); mock_conn_destroy(conn); return; @@ -701,14 +761,14 @@ START_TEST(test_query) fail_unless((code == query_data[_i].code) && ((size_t)msg_len == query_data[_i].len), - "sdb_fe_query(%s) returned %u, %u; expected: %u, %zu", + "sdb_conn_query(%s) returned %u, %u; expected: %u, %zu", query_data[_i].query, code, msg_len, query_data[_i].code, query_data[_i].len); if (code == SDB_CONNECTION_DATA) { tmp = sdb_proto_unmarshal_int32(data, len, &code); fail_unless(code == query_data[_i].type, - "sdb_fe_query(%s) returned %s object; expected: %s", + "sdb_conn_query(%s) returned %s object; expected: %s", query_data[_i].query, SDB_CONN_MSGTYPE_TO_STRING((int)code), SDB_CONN_MSGTYPE_TO_STRING((int)query_data[_i].type)); data += tmp; @@ -716,7 +776,7 @@ START_TEST(test_query) } fail_if_strneq(data, query_data[_i].data, (size_t)msg_len, - "sdb_fe_query(%s) returned unexpected data", + "sdb_conn_query(%s) returned unexpected data", query_data[_i].query, data, query_data[_i].data); mock_conn_destroy(conn); @@ -726,7 +786,7 @@ END_TEST TEST_MAIN("frontend::query") { TCase *tc = tcase_create("core"); - tcase_add_checked_fixture(tc, populate, sdb_store_clear); + tcase_add_checked_fixture(tc, populate, turndown); TC_ADD_LOOP_TEST(tc, query); ADD_TCASE(tc); }