Code

store: All store functions now accept a store object.
[sysdb.git] / t / unit / core / store_test.c
index 1eb5262ffaa758c2e49be9489ad2b93094acc9d6..1d524b6070bb966ca8c7ae74b3963fd3bd00281b 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"
 #include <string.h>
 #include <strings.h>
 
+static sdb_store_t *store;
+
+static void
+init(void)
+{
+       store = sdb_store_create();
+       ck_assert(store != NULL);
+}
+
 static void
 populate(void)
 {
        sdb_data_t datum;
 
-       sdb_store_host("h1", 1);
-       sdb_store_host("h2", 3);
+       sdb_store_host(store, "h1", 1);
+       sdb_store_host(store, "h2", 3);
 
        datum.type = SDB_TYPE_STRING;
        datum.data.string = "v1";
-       sdb_store_attribute("h1", "k1", &datum, 1);
+       sdb_store_attribute(store, "h1", "k1", &datum, 1);
        datum.data.string = "v2";
-       sdb_store_attribute("h1", "k2", &datum, 2);
+       sdb_store_attribute(store, "h1", "k2", &datum, 2);
        datum.data.string = "v3";
-       sdb_store_attribute("h1", "k3", &datum, 2);
+       sdb_store_attribute(store, "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_store_attribute(store, "h1", "k2", &datum, 1);
+       sdb_store_attribute(store, "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_store_metric(store, "h1", "m1", /* store */ NULL, 2);
+       sdb_store_metric(store, "h1", "m2", /* store */ NULL, 1);
+       sdb_store_metric(store, "h2", "m1", /* store */ NULL, 1);
 
-       sdb_store_service("h2", "s1", 1);
-       sdb_store_service("h2", "s2", 2);
+       sdb_store_service(store, "h2", "s1", 1);
+       sdb_store_service(store, "h2", "s2", 2);
 
        datum.type = SDB_TYPE_INTEGER;
        datum.data.integer = 42;
-       sdb_store_metric_attr("h1", "m1", "k3", &datum, 2);
+       sdb_store_metric_attr(store, "h1", "m1", "k3", &datum, 2);
 
        datum.data.integer = 123;
-       sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+       sdb_store_service_attr(store, "h2", "s2", "k1", &datum, 2);
        datum.data.integer = 4711;
-       sdb_store_service_attr("h2", "s2", "k2", &datum, 1);
+       sdb_store_service_attr(store, "h2", "s2", "k2", &datum, 1);
 
        /* don't overwrite k1 */
        datum.data.integer = 666;
-       sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+       sdb_store_service_attr(store, "h2", "s2", "k1", &datum, 2);
 } /* populate */
 
+static void
+turndown(void)
+{
+       sdb_object_deref(SDB_OBJ(store));
+       store = NULL;
+} /* turndown */
+
 START_TEST(test_store_host)
 {
        struct {
@@ -97,7 +114,7 @@ START_TEST(test_store_host)
 
        struct {
                const char *name;
-               _Bool       has;
+               bool        have;
        } golden_hosts[] = {
                { "a", 1 == 1 },
                { "b", 1 == 1 },
@@ -110,7 +127,7 @@ 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_store_host(store, golden_data[i].name,
                                golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
                                "sdb_store_host(%s, %d) = %d; expected: %d",
@@ -119,12 +136,14 @@ START_TEST(test_store_host)
        }
 
        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(store, 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
@@ -136,7 +155,7 @@ 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_store_host(store, golden_hosts[i], 1);
                fail_unless(status >= 0,
                                "sdb_store_host(%s) = %d; expected: >=0",
                                golden_hosts[i], status);
@@ -146,11 +165,7 @@ 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]);
+               sobj1 = sdb_store_get_host(store, golden_hosts[i]);
                fail_unless(sobj1 != NULL,
                                "sdb_store_get_host(%s) = NULL; expected: <host>",
                                golden_hosts[i]);
@@ -160,7 +175,7 @@ START_TEST(test_store_get_host)
                                "sdb_store_get_host(%s) did not increment ref count: "
                                "got: %d; expected: >1", golden_hosts[i], ref_cnt);
 
-               sobj2 = sdb_store_get_host(golden_hosts[i]);
+               sobj2 = sdb_store_get_host(store, golden_hosts[i]);
                fail_unless(sobj2 != NULL,
                                "sdb_store_get_host(%s) = NULL; expected: <host>",
                                golden_hosts[i]);
@@ -179,11 +194,7 @@ 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]);
+               sobj = sdb_store_get_host(store, unknown_hosts[i]);
                fail_unless(!sobj, "sdb_store_get_host(%s) = <host:%s>; expected: NULL",
                                unknown_hosts[i], sobj ? SDB_OBJ(sobj)->name : "NULL");
        }
@@ -211,8 +222,8 @@ START_TEST(test_store_attr)
 
        size_t i;
 
-       sdb_store_host("l", 1);
-       sdb_store_host("m", 1);
+       sdb_store_host(store, "l", 1);
+       sdb_store_host(store, "m", 1);
        for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
                sdb_data_t datum;
                int status;
@@ -221,7 +232,7 @@ 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_store_attribute(store, golden_data[i].host,
                                golden_data[i].key, &datum,
                                golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
@@ -264,12 +275,12 @@ START_TEST(test_store_metric)
 
        size_t i;
 
-       sdb_store_host("m", 1);
-       sdb_store_host("l", 1);
+       sdb_store_host(store, "m", 1);
+       sdb_store_host(store, "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_store_metric(store, golden_data[i].host,
                                golden_data[i].metric, golden_data[i].store,
                                golden_data[i].last_update);
                fail_unless(status == golden_data[i].expected,
@@ -308,16 +319,16 @@ 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_store_host(store, "m", 1);
+       sdb_store_host(store, "l", 1);
+       sdb_store_metric(store, "m", "m1", NULL, 1);
+       sdb_store_metric(store, "l", "m1", NULL, 1);
+       sdb_store_metric(store, "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_store_metric_attr(store, 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,
@@ -349,12 +360,12 @@ START_TEST(test_store_service)
 
        size_t i;
 
-       sdb_store_host("m", 1);
-       sdb_store_host("l", 1);
+       sdb_store_host(store, "m", 1);
+       sdb_store_host(store, "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_store_service(store, 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",
@@ -391,16 +402,16 @@ 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_store_host(store, "m", 1);
+       sdb_store_host(store, "l", 1);
+       sdb_store_service(store, "m", "s1", 1);
+       sdb_store_service(store, "l", "s1", 1);
+       sdb_store_service(store, "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_store_service_attr(store, 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,
@@ -414,50 +425,90 @@ END_TEST
 
 static struct {
        const char *hostname;
+       const char *attr; /* optional */
        int field;
        int expected;
        sdb_data_t value;
 } get_field_data[] = {
-       { NULL,   0, -1, { SDB_TYPE_NULL, { 0 } } },
-       { NULL,   SDB_FIELD_LAST_UPDATE, -1, { SDB_TYPE_NULL, { 0 } } },
-       { NULL,   SDB_FIELD_NAME,        -1, { SDB_TYPE_NULL, { 0 } } },
-       { "host", SDB_FIELD_LAST_UPDATE,  0, { SDB_TYPE_DATETIME, { .datetime = 20 } } },
-       { "host", SDB_FIELD_INTERVAL,     0, { SDB_TYPE_DATETIME, { .datetime = 10 } } },
+       { NULL,   NULL, 0, -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_LAST_UPDATE, -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_INTERVAL,    -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_AGE,         -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_NAME,        -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_BACKEND,     -1, { SDB_TYPE_NULL, { 0 } } },
+       { NULL,   NULL,   SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", NULL,   SDB_FIELD_LAST_UPDATE,  0, { SDB_TYPE_DATETIME, { .datetime = 20 } } },
+       { "host", NULL,   SDB_FIELD_INTERVAL,     0, { SDB_TYPE_DATETIME, { .datetime = 10 } } },
+       /* the test will handle AGE specially */
+       { "host", NULL,   SDB_FIELD_AGE,          0, { SDB_TYPE_NULL, { 0 } } },
+       { "host", NULL,   SDB_FIELD_NAME,         0, { SDB_TYPE_STRING, { .string = "host" } } },
+       { "host", NULL,   SDB_FIELD_BACKEND,      0, { SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } } },
+       { "host", NULL,   SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "attr", SDB_FIELD_LAST_UPDATE,  0, { SDB_TYPE_DATETIME, { .datetime = 20 } } },
+       { "host", "attr", SDB_FIELD_INTERVAL,     0, { SDB_TYPE_DATETIME, { .datetime = 10 } } },
        /* the test will handle AGE specially */
-       { "host", SDB_FIELD_AGE,          0, { SDB_TYPE_NULL, { 0 } } },
-       { "host", SDB_FIELD_NAME,         0, { SDB_TYPE_STRING, { .string = "host" } } },
-       { "host", SDB_FIELD_BACKEND,      0, { SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } } },
+       { "host", "attr", SDB_FIELD_AGE,          0, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "attr", SDB_FIELD_NAME,         0, { SDB_TYPE_STRING, { .string = "attr" } } },
+       { "host", "attr", SDB_FIELD_BACKEND,      0, { SDB_TYPE_ARRAY | SDB_TYPE_STRING, { .array = { 0, NULL } } } },
+       { "host", "attr", SDB_FIELD_VALUE,        0, { SDB_TYPE_INTEGER, { .integer = 1 } } },
+       { "host", "attr", SDB_FIELD_VALUE,        0, { SDB_TYPE_DECIMAL, { .decimal = 2.0 } } },
+       { "host", "attr", SDB_FIELD_VALUE,        0, { SDB_TYPE_STRING, { .string = "foo" } } },
+       { "host", "attr", SDB_FIELD_VALUE,        0, { SDB_TYPE_DATETIME, { .datetime = 1234567890L } } },
+       { "host", "a",    SDB_FIELD_LAST_UPDATE, -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_INTERVAL,    -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_AGE,         -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_NAME,        -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_BACKEND,     -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
+       { "host", "a",    SDB_FIELD_VALUE,       -1, { SDB_TYPE_NULL, { 0 } } },
 };
 
+/* returns a tuple <type> <name> */
+#define OBJ_NAME(obj) \
+       (obj) ? SDB_STORE_TYPE_TO_NAME(obj->type) : "NULL", \
+       (obj) ? SDB_OBJ(obj)->name : ""
 START_TEST(test_get_field)
 {
-       sdb_store_obj_t *host = NULL;
+       sdb_store_obj_t *obj = NULL;
        sdb_data_t value = SDB_DATA_INIT;
        char value_str[128], expected_value_str[128];
        sdb_time_t now = sdb_gettime();
        int check;
 
-       sdb_store_host("host", 10);
-       sdb_store_host("host", 20);
+       sdb_store_host(store, "host", 10);
+       sdb_store_host(store, "host", 20);
+       sdb_store_attribute(store, "host", "attr", &get_field_data[_i].value, 10);
+       sdb_store_attribute(store, "host", "attr", &get_field_data[_i].value, 20);
 
        if (get_field_data[_i].hostname) {
-               host = sdb_store_get_host(get_field_data[_i].hostname);
-               ck_assert(host != NULL);
+               obj = sdb_store_get_host(store, get_field_data[_i].hostname);
+               ck_assert(obj != NULL);
+
+               if (get_field_data[_i].attr) {
+                       sdb_store_obj_t *tmp = sdb_store_get_child(obj,
+                                       SDB_ATTRIBUTE, get_field_data[_i].attr);
+                       sdb_object_deref(SDB_OBJ(obj));
+                       obj = tmp;
+               }
        }
 
-       check = sdb_store_get_field(host, get_field_data[_i].field, NULL);
+       check = sdb_store_get_field(obj, get_field_data[_i].field, NULL);
        fail_unless(check == get_field_data[_i].expected,
-                       "sdb_store_get_field(%s, %s, NULL) = %d; expected: %d",
-                       host ? "<host>" : "NULL", SDB_FIELD_TO_NAME(get_field_data[_i].field),
+                       "sdb_store_get_field(%s %s, %s, NULL) = %d; expected: %d",
+                       OBJ_NAME(obj), SDB_FIELD_TO_NAME(get_field_data[_i].field),
                        check, get_field_data[_i].expected);
-       check = sdb_store_get_field(host, get_field_data[_i].field, &value);
+       check = sdb_store_get_field(obj, get_field_data[_i].field, &value);
        fail_unless(check == get_field_data[_i].expected,
-                       "sdb_store_get_field(%s, %s, <value>) = %d; expected: %d",
-                       host ? "<host>" : "NULL", SDB_FIELD_TO_NAME(get_field_data[_i].field),
+                       "sdb_store_get_field(%s %s, %s, <value>) = %d; expected: %d",
+                       OBJ_NAME(obj), SDB_FIELD_TO_NAME(get_field_data[_i].field),
                        check, get_field_data[_i].expected);
 
-       if (get_field_data[_i].expected)
+       if (get_field_data[_i].expected) {
+               sdb_object_deref(SDB_OBJ(obj));
                return;
+       }
 
        if (get_field_data[_i].field == SDB_FIELD_AGE) {
                get_field_data[_i].value.type = SDB_TYPE_DATETIME;
@@ -471,21 +522,23 @@ START_TEST(test_get_field)
        if (get_field_data[_i].field == SDB_FIELD_AGE) {
                fail_unless((value.type == SDB_TYPE_DATETIME)
                                && (value.data.datetime >= now),
-                               "sdb_store_get_field(<host>, %s, <value>) "
-                               "returned value %s; expected >=%s",
+                               "sdb_store_get_field(%s %s, %s, <value>) "
+                               "returned value %s; expected >=%s", OBJ_NAME(obj),
                                SDB_FIELD_TO_NAME(get_field_data[_i].field),
                                value_str, expected_value_str);
        }
        else {
                fail_unless(! sdb_data_cmp(&value, &get_field_data[_i].value),
-                               "sdb_store_get_field(<host>, %s, <value>) "
-                               "returned value %s; expected %s",
+                               "sdb_store_get_field(%s %s, %s, <value>) "
+                               "returned value %s; expected %s", OBJ_NAME(obj),
                                SDB_FIELD_TO_NAME(get_field_data[_i].field),
                                value_str, expected_value_str);
        }
        sdb_data_free_datum(&value);
+       sdb_object_deref(SDB_OBJ(obj));
 }
 END_TEST
+#undef OBJ_NAME
 
 START_TEST(test_get_child)
 {
@@ -523,7 +576,7 @@ START_TEST(test_get_child)
                sdb_store_obj_t *obj;
                const char *expected_name = golden_data[i].host;
 
-               obj = sdb_store_get_host(golden_data[i].host);
+               obj = sdb_store_get_host(store, golden_data[i].host);
                if (golden_data[i].expected && (golden_data[i].type == SDB_HOST))
                        fail_unless(obj == NULL,
                                        "sdb_store_get_host(%s) = %p; expected: NULL",
@@ -581,12 +634,12 @@ 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_store_host(store, "host", 10);
+       sdb_store_host(store, "host", 20);
+       sdb_store_host(store, "host", 30);
+       sdb_store_host(store, "host", 40);
 
-       host = sdb_store_get_host("host");
+       host = sdb_store_get_host(store, "host");
        fail_unless(host != NULL,
                        "INTERNAL ERROR: store doesn't have host after adding it");
 
@@ -595,10 +648,10 @@ START_TEST(test_interval)
                        "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_store_host(store, "host", 40);
+       sdb_store_host(store, "host", 40);
+       sdb_store_host(store, "host", 40);
+       sdb_store_host(store, "host", 40);
 
        fail_unless(host->interval == 10,
                        "sdb_store_host() changed interval when doing multiple updates "
@@ -606,10 +659,10 @@ START_TEST(test_interval)
                        "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_store_host(store, "host", 20);
+       sdb_store_host(store, "host", 20);
+       sdb_store_host(store, "host", 20);
+       sdb_store_host(store, "host", 20);
 
        fail_unless(host->interval == 10,
                        "sdb_store_host() changed interval when doing multiple updates "
@@ -617,13 +670,13 @@ START_TEST(test_interval)
                        host->interval, 10);
 
        /* new interval: 20 us */
-       sdb_store_host("host", 60);
+       sdb_store_host(store, "host", 60);
        fail_unless(host->interval == 11,
                        "sdb_store_host() did not calculate interval correctly: "
                        "got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11);
 
        /* new interval: 40 us */
-       sdb_store_host("host", 100);
+       sdb_store_host(store, "host", 100);
        fail_unless(host->interval == 13,
                        "sdb_store_host() did not calculate interval correctly: "
                        "got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11);
@@ -676,7 +729,7 @@ START_TEST(test_scan)
        int check;
 
        /* empty store */
-       check = sdb_store_scan(SDB_HOST, /* m, filter = */ NULL, NULL,
+       check = sdb_store_scan(store, SDB_HOST, /* m, filter = */ NULL, NULL,
                        scan_count, &i);
        fail_unless(check == 0,
                        "sdb_store_scan(HOST), empty store = %d; expected: 0", check);
@@ -686,7 +739,7 @@ START_TEST(test_scan)
 
        populate();
 
-       check = sdb_store_scan(SDB_HOST, /* m, filter = */ NULL, NULL,
+       check = sdb_store_scan(store, SDB_HOST, /* m, filter = */ NULL, NULL,
                        scan_count, &i);
        fail_unless(check == 0,
                        "sdb_store_scan(HOST) = %d; expected: 0", check);
@@ -695,7 +748,7 @@ START_TEST(test_scan)
                        "expected: 1", (int)i);
 
        i = 0;
-       check = sdb_store_scan(SDB_HOST, /* m, filter = */ NULL, NULL,
+       check = sdb_store_scan(store, SDB_HOST, /* m, filter = */ NULL, NULL,
                        scan_error, &i);
        fail_unless(check == -1,
                        "sdb_store_scan(HOST), error callback = %d; expected: -1", check);
@@ -704,7 +757,7 @@ START_TEST(test_scan)
                        "(callback returned error); expected: 1", (int)i);
 
        i = 0;
-       check = sdb_store_scan(SDB_SERVICE, /* m, filter = */ NULL, NULL,
+       check = sdb_store_scan(store, SDB_SERVICE, /* m, filter = */ NULL, NULL,
                        scan_count, &i);
        fail_unless(check == 0,
                        "sdb_store_scan(SERVICE) = %d; expected: 0", check);
@@ -713,7 +766,7 @@ START_TEST(test_scan)
                        "expected: 2", (int)i);
 
        i = 0;
-       check = sdb_store_scan(SDB_METRIC, /* m, filter = */ NULL, NULL,
+       check = sdb_store_scan(store, SDB_METRIC, /* m, filter = */ NULL, NULL,
                        scan_count, &i);
        fail_unless(check == 0,
                        "sdb_store_scan(METRIC) = %d; expected: 0", check);
@@ -726,6 +779,7 @@ END_TEST
 TEST_MAIN("core::store")
 {
        TCase *tc = tcase_create("core");
+       tcase_add_unchecked_fixture(tc, init, turndown);
        tcase_add_test(tc, test_store_host);
        tcase_add_test(tc, test_store_get_host);
        tcase_add_test(tc, test_store_attr);
@@ -737,7 +791,6 @@ TEST_MAIN("core::store")
        tcase_add_test(tc, test_get_child);
        tcase_add_test(tc, test_interval);
        tcase_add_test(tc, test_scan);
-       tcase_add_unchecked_fixture(tc, NULL, sdb_store_clear);
        ADD_TCASE(tc);
 }
 TEST_MAIN_END