Code

Drop sdb_store_get_host() from tests.
[sysdb.git] / t / unit / core / store_test.c
index 8308f3334f39d7c2c8cd71362f5903eab399c412..6d528dede366fe9bce639e9e6eb10eba4cb7a268 100644 (file)
@@ -29,6 +29,7 @@
 #      include "config.h"
 #endif
 
+#include "core/plugin.h"
 #include "core/store.h"
 #include "core/store-private.h"
 #include "testutils.h"
@@ -48,43 +49,41 @@ populate(void)
 {
        sdb_data_t datum;
 
-       sdb_store_init();
-
-       sdb_store_host("h1", 1);
-       sdb_store_host("h2", 3);
+       sdb_plugin_store_host("h1", 1);
+       sdb_plugin_store_host("h2", 3);
 
        datum.type = SDB_TYPE_STRING;
        datum.data.string = "v1";
-       sdb_store_attribute("h1", "k1", &datum, 1);
+       sdb_plugin_store_attribute("h1", "k1", &datum, 1);
        datum.data.string = "v2";
-       sdb_store_attribute("h1", "k2", &datum, 2);
+       sdb_plugin_store_attribute("h1", "k2", &datum, 2);
        datum.data.string = "v3";
-       sdb_store_attribute("h1", "k3", &datum, 2);
+       sdb_plugin_store_attribute("h1", "k3", &datum, 2);
 
        /* make sure that older updates don't overwrite existing values */
        datum.data.string = "fail";
-       sdb_store_attribute("h1", "k2", &datum, 1);
-       sdb_store_attribute("h1", "k3", &datum, 2);
+       sdb_plugin_store_attribute("h1", "k2", &datum, 1);
+       sdb_plugin_store_attribute("h1", "k3", &datum, 2);
 
-       sdb_store_metric("h1", "m1", /* store */ NULL, 2);
-       sdb_store_metric("h1", "m2", /* store */ NULL, 1);
-       sdb_store_metric("h2", "m1", /* store */ NULL, 1);
+       sdb_plugin_store_metric("h1", "m1", /* store */ NULL, 2);
+       sdb_plugin_store_metric("h1", "m2", /* store */ NULL, 1);
+       sdb_plugin_store_metric("h2", "m1", /* store */ NULL, 1);
 
-       sdb_store_service("h2", "s1", 1);
-       sdb_store_service("h2", "s2", 2);
+       sdb_plugin_store_service("h2", "s1", 1);
+       sdb_plugin_store_service("h2", "s2", 2);
 
        datum.type = SDB_TYPE_INTEGER;
        datum.data.integer = 42;
-       sdb_store_metric_attr("h1", "m1", "k3", &datum, 2);
+       sdb_plugin_store_metric_attribute("h1", "m1", "k3", &datum, 2);
 
        datum.data.integer = 123;
-       sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+       sdb_plugin_store_service_attribute("h2", "s2", "k1", &datum, 2);
        datum.data.integer = 4711;
-       sdb_store_service_attr("h2", "s2", "k2", &datum, 1);
+       sdb_plugin_store_service_attribute("h2", "s2", "k2", &datum, 1);
 
        /* don't overwrite k1 */
        datum.data.integer = 666;
-       sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+       sdb_plugin_store_service_attribute("h2", "s2", "k1", &datum, 2);
 } /* populate */
 
 START_TEST(test_store_host)
@@ -105,7 +104,7 @@ START_TEST(test_store_host)
 
        struct {
                const char *name;
-               _Bool       has;
+               bool        have;
        } golden_hosts[] = {
                { "a", 1 == 1 },
                { "b", 1 == 1 },
@@ -118,21 +117,23 @@ START_TEST(test_store_host)
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                int status;
 
-               status = sdb_store_host(golden_data[i].name,
+               status = sdb_plugin_store_host(golden_data[i].name,
                                golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_host(%s, %d) = %d; expected: %d",
+                               "sdb_plugin_store_host(%s, %d) = %d; expected: %d",
                                golden_data[i].name, (int)golden_data[i].last_update,
                                status, golden_data[i].expected);
        }
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) {
-               _Bool has;
-
-               has = sdb_store_has_host(golden_hosts[i].name);
-               fail_unless(has == golden_hosts[i].has,
-                               "sdb_store_has_host(%s) = %d; expected: %d",
-                               golden_hosts[i].name, has, golden_hosts[i].has);
+               sdb_store_obj_t *have;
+
+               have = sdb_store_get_host(golden_hosts[i].name);
+               fail_unless((have != NULL) == golden_hosts[i].have,
+                               "sdb_store_get_host(%s) = %p; expected: %s",
+                               golden_hosts[i].name, have,
+                               golden_hosts[i].have ? "<host>" : "NULL");
+               sdb_object_deref(SDB_OBJ(have));
        }
 }
 END_TEST
@@ -144,9 +145,9 @@ START_TEST(test_store_get_host)
        size_t i;
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) {
-               int status = sdb_store_host(golden_hosts[i], 1);
+               int status = sdb_plugin_store_host(golden_hosts[i], 1);
                fail_unless(status >= 0,
-                               "sdb_store_host(%s) = %d; expected: >=0",
+                               "sdb_plugin_store_host(%s) = %d; expected: >=0",
                                golden_hosts[i], status);
        }
 
@@ -154,10 +155,6 @@ START_TEST(test_store_get_host)
                sdb_store_obj_t *sobj1, *sobj2;
                int ref_cnt;
 
-               fail_unless(sdb_store_has_host(golden_hosts[i]),
-                               "sdb_store_has_host(%s) = FALSE; expected: TRUE",
-                               golden_hosts[i]);
-
                sobj1 = sdb_store_get_host(golden_hosts[i]);
                fail_unless(sobj1 != NULL,
                                "sdb_store_get_host(%s) = NULL; expected: <host>",
@@ -187,10 +184,6 @@ START_TEST(test_store_get_host)
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(unknown_hosts); ++i) {
                sdb_store_obj_t *sobj;
 
-               fail_unless(!sdb_store_has_host(unknown_hosts[i]),
-                               "sdb_store_has_host(%s) = TRUE; expected: FALSE",
-                               unknown_hosts[i]);
-
                sobj = sdb_store_get_host(unknown_hosts[i]);
                fail_unless(!sobj, "sdb_store_get_host(%s) = <host:%s>; expected: NULL",
                                unknown_hosts[i], sobj ? SDB_OBJ(sobj)->name : "NULL");
@@ -219,8 +212,8 @@ START_TEST(test_store_attr)
 
        size_t i;
 
-       sdb_store_host("l", 1);
-       sdb_store_host("m", 1);
+       sdb_plugin_store_host("l", 1);
+       sdb_plugin_store_host("m", 1);
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                sdb_data_t datum;
                int status;
@@ -229,11 +222,11 @@ START_TEST(test_store_attr)
                datum.type = SDB_TYPE_STRING;
                datum.data.string = golden_data[i].value;
 
-               status = sdb_store_attribute(golden_data[i].host,
+               status = sdb_plugin_store_attribute(golden_data[i].host,
                                golden_data[i].key, &datum,
                                golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_attribute(%s, %s, %s, %d) = %d; expected: %d",
+                               "sdb_plugin_store_attribute(%s, %s, %s, %d) = %d; expected: %d",
                                golden_data[i].host, golden_data[i].key, golden_data[i].value,
                                golden_data[i].last_update, status, golden_data[i].expected);
        }
@@ -272,16 +265,16 @@ START_TEST(test_store_metric)
 
        size_t i;
 
-       sdb_store_host("m", 1);
-       sdb_store_host("l", 1);
+       sdb_plugin_store_host("m", 1);
+       sdb_plugin_store_host("l", 1);
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                int status;
 
-               status = sdb_store_metric(golden_data[i].host,
+               status = sdb_plugin_store_metric(golden_data[i].host,
                                golden_data[i].metric, golden_data[i].store,
                                golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_metric(%s, %s, %p, %d) = %d; expected: %d",
+                               "sdb_plugin_store_metric(%s, %s, %p, %d) = %d; expected: %d",
                                golden_data[i].host, golden_data[i].metric,
                                golden_data[i].store, golden_data[i].last_update,
                                status, golden_data[i].expected);
@@ -316,20 +309,20 @@ START_TEST(test_store_metric_attr)
 
        size_t i;
 
-       sdb_store_host("m", 1);
-       sdb_store_host("l", 1);
-       sdb_store_metric("m", "m1", NULL, 1);
-       sdb_store_metric("l", "m1", NULL, 1);
-       sdb_store_metric("l", "m2", NULL, 1);
+       sdb_plugin_store_host("m", 1);
+       sdb_plugin_store_host("l", 1);
+       sdb_plugin_store_metric("m", "m1", NULL, 1);
+       sdb_plugin_store_metric("l", "m1", NULL, 1);
+       sdb_plugin_store_metric("l", "m2", NULL, 1);
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                int status;
 
-               status = sdb_store_metric_attr(golden_data[i].host,
+               status = sdb_plugin_store_metric_attribute(golden_data[i].host,
                                golden_data[i].metric, golden_data[i].attr,
                                &golden_data[i].value, golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_metric_attr(%s, %s, %s, %d, %d) = %d; "
+                               "sdb_plugin_store_metric_attribute(%s, %s, %s, %d, %d) = %d; "
                                "expected: %d", golden_data[i].host, golden_data[i].metric,
                                golden_data[i].attr, golden_data[i].value.data.integer,
                                golden_data[i].last_update, status, golden_data[i].expected);
@@ -357,15 +350,15 @@ START_TEST(test_store_service)
 
        size_t i;
 
-       sdb_store_host("m", 1);
-       sdb_store_host("l", 1);
+       sdb_plugin_store_host("m", 1);
+       sdb_plugin_store_host("l", 1);
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                int status;
 
-               status = sdb_store_service(golden_data[i].host,
+               status = sdb_plugin_store_service(golden_data[i].host,
                                golden_data[i].svc, golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_service(%s, %s, %d) = %d; expected: %d",
+                               "sdb_plugin_store_service(%s, %s, %d) = %d; expected: %d",
                                golden_data[i].host, golden_data[i].svc,
                                golden_data[i].last_update, status, golden_data[i].expected);
        }
@@ -399,20 +392,20 @@ START_TEST(test_store_service_attr)
 
        size_t i;
 
-       sdb_store_host("m", 1);
-       sdb_store_host("l", 1);
-       sdb_store_service("m", "s1", 1);
-       sdb_store_service("l", "s1", 1);
-       sdb_store_service("l", "s2", 1);
+       sdb_plugin_store_host("m", 1);
+       sdb_plugin_store_host("l", 1);
+       sdb_plugin_store_service("m", "s1", 1);
+       sdb_plugin_store_service("l", "s1", 1);
+       sdb_plugin_store_service("l", "s2", 1);
 
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                int status;
 
-               status = sdb_store_service_attr(golden_data[i].host,
+               status = sdb_plugin_store_service_attribute(golden_data[i].host,
                                golden_data[i].svc, golden_data[i].attr,
                                &golden_data[i].value, golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
-                               "sdb_store_service_attr(%s, %s, %s, %d, %d) = %d; "
+                               "sdb_plugin_store_service_attribute(%s, %s, %s, %d, %d) = %d; "
                                "expected: %d", golden_data[i].host, golden_data[i].svc,
                                golden_data[i].attr, golden_data[i].value.data.integer,
                                golden_data[i].last_update, status, golden_data[i].expected);
@@ -474,10 +467,10 @@ START_TEST(test_get_field)
        sdb_time_t now = sdb_gettime();
        int check;
 
-       sdb_store_host("host", 10);
-       sdb_store_host("host", 20);
-       sdb_store_attribute("host", "attr", &get_field_data[_i].value, 10);
-       sdb_store_attribute("host", "attr", &get_field_data[_i].value, 20);
+       sdb_plugin_store_host("host", 10);
+       sdb_plugin_store_host("host", 20);
+       sdb_plugin_store_attribute("host", "attr", &get_field_data[_i].value, 10);
+       sdb_plugin_store_attribute("host", "attr", &get_field_data[_i].value, 20);
 
        if (get_field_data[_i].hostname) {
                obj = sdb_store_get_host(get_field_data[_i].hostname);
@@ -631,51 +624,51 @@ START_TEST(test_interval)
        sdb_store_obj_t *host;
 
        /* 10 us interval */
-       sdb_store_host("host", 10);
-       sdb_store_host("host", 20);
-       sdb_store_host("host", 30);
-       sdb_store_host("host", 40);
+       sdb_plugin_store_host("host", 10);
+       sdb_plugin_store_host("host", 20);
+       sdb_plugin_store_host("host", 30);
+       sdb_plugin_store_host("host", 40);
 
        host = sdb_store_get_host("host");
        fail_unless(host != NULL,
                        "INTERNAL ERROR: store doesn't have host after adding it");
 
        fail_unless(host->interval == 10,
-                       "sdb_store_host() did not calculate interval correctly: "
+                       "sdb_plugin_store_host() did not calculate interval correctly: "
                        "got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 10);
 
        /* multiple updates for the same timestamp don't modify the interval */
-       sdb_store_host("host", 40);
-       sdb_store_host("host", 40);
-       sdb_store_host("host", 40);
-       sdb_store_host("host", 40);
+       sdb_plugin_store_host("host", 40);
+       sdb_plugin_store_host("host", 40);
+       sdb_plugin_store_host("host", 40);
+       sdb_plugin_store_host("host", 40);
 
        fail_unless(host->interval == 10,
-                       "sdb_store_host() changed interval when doing multiple updates "
+                       "sdb_plugin_store_host() changed interval when doing multiple updates "
                        "using the same timestamp; got: %"PRIsdbTIME"; "
                        "expected: %"PRIsdbTIME, host->interval, 10);
 
        /* multiple updates using an timestamp don't modify the interval */
-       sdb_store_host("host", 20);
-       sdb_store_host("host", 20);
-       sdb_store_host("host", 20);
-       sdb_store_host("host", 20);
+       sdb_plugin_store_host("host", 20);
+       sdb_plugin_store_host("host", 20);
+       sdb_plugin_store_host("host", 20);
+       sdb_plugin_store_host("host", 20);
 
        fail_unless(host->interval == 10,
-                       "sdb_store_host() changed interval when doing multiple updates "
+                       "sdb_plugin_store_host() changed interval when doing multiple updates "
                        "using an old timestamp; got: %"PRIsdbTIME"; expected: %"PRIsdbTIME,
                        host->interval, 10);
 
        /* new interval: 20 us */
-       sdb_store_host("host", 60);
+       sdb_plugin_store_host("host", 60);
        fail_unless(host->interval == 11,
-                       "sdb_store_host() did not calculate interval correctly: "
+                       "sdb_plugin_store_host() did not calculate interval correctly: "
                        "got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11);
 
        /* new interval: 40 us */
-       sdb_store_host("host", 100);
+       sdb_plugin_store_host("host", 100);
        fail_unless(host->interval == 13,
-                       "sdb_store_host() did not calculate interval correctly: "
+                       "sdb_plugin_store_host() did not calculate interval correctly: "
                        "got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11);
 
        sdb_object_deref(SDB_OBJ(host));