Code

Split the memstore module from the store module.
[sysdb.git] / t / unit / frontend / query_test.c
index 8ac497c3ecc0a4901b4bd23834625d89221d3418..52fd58a4e0c75256fb5e3f77e7db604854534831 100644 (file)
@@ -29,6 +29,7 @@
 #      include "config.h"
 #endif
 
+#include "core/memstore.h"
 #include "core/plugin.h"
 #include "frontend/connection.h"
 #include "frontend/connection-private.h"
 static void
 populate(void)
 {
-       sdb_store_t *store;
+       sdb_memstore_t *store;
        sdb_data_t datum;
 
        /* the frontend accesses the store via the plugin API */
-       store = sdb_store_create();
+       store = sdb_memstore_create();
        ck_assert(store != NULL);
        ck_assert(sdb_plugin_register_writer("test-writer",
-                               &sdb_store_writer, SDB_OBJ(store)) == 0);
+                               &sdb_memstore_writer, SDB_OBJ(store)) == 0);
        ck_assert(sdb_plugin_register_reader("test-reader",
-                               &sdb_store_reader, SDB_OBJ(store)) == 0);
+                               &sdb_memstore_reader, SDB_OBJ(store)) == 0);
        sdb_object_deref(SDB_OBJ(store));
 
        /* populate the store */
@@ -69,7 +70,8 @@ populate(void)
 
        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);
+       sdb_plugin_store_metric("h2", "m1", /* store */ NULL, 5 * SDB_INTERVAL_SECOND);
+       sdb_plugin_store_metric("h2", "m1", /* store */ NULL, 10 * SDB_INTERVAL_SECOND);
 
        datum.type = SDB_TYPE_INTEGER;
        datum.data.integer = 42;
@@ -129,12 +131,12 @@ turndown(void)
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"metrics\": [" \
                        "{\"name\": \"m1\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
-                               "\"update_interval\": \"0s\", \"backends\": [], " \
+                               "\"last_update\": \"1970-01-01 00:00:10 +0000\", " \
+                               "\"update_interval\": \"5s\", \"backends\": [], " \
                                "\"attributes\": [" \
                                        "{\"name\": \"hostname\", \"value\": \"h2\", " \
-                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
-                                               "\"update_interval\": \"0s\", \"backends\": []}]}], " \
+                                               "\"last_update\": \"1970-01-01 00:00:10 +0000\", " \
+                                               "\"update_interval\": \"5s\", \"backends\": []}]}], " \
                "\"services\": [" \
                        "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": [], " \
@@ -219,18 +221,19 @@ turndown(void)
                                        "{\"name\": \"k3\", \"value\": 42, " \
                                                "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}]}"
-#define METRIC_H12_M1_ARRAY \
-       "["METRIC_H1_M1"," \
+#define METRIC_H2_M1 \
        "{\"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\": [], " \
+                               "\"last_update\": \"1970-01-01 00:00:10 +0000\", " \
+                               "\"update_interval\": \"5s\", \"backends\": [], " \
                                "\"attributes\": [" \
                                        "{\"name\": \"hostname\", \"value\": \"h2\", " \
-                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
-                                               "\"update_interval\": \"0s\", \"backends\": []}]}]}]"
+                                               "\"last_update\": \"1970-01-01 00:00:10 +0000\", " \
+                                               "\"update_interval\": \"5s\", \"backends\": []}]}]}"
+#define METRIC_H12_M1_ARRAY \
+       "["METRIC_H1_M1","METRIC_H2_M1"]"
 #define METRIC_H12_M12_LISTING \
        "[{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
@@ -245,8 +248,8 @@ turndown(void)
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"metrics\": [" \
                        "{\"name\": \"m1\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
-                               "\"update_interval\": \"0s\", \"backends\": []}]}]"
+                               "\"last_update\": \"1970-01-01 00:00:10 +0000\", " \
+                               "\"update_interval\": \"5s\", \"backends\": []}]}]"
 
 typedef struct {
        sdb_conn_t conn;
@@ -502,7 +505,12 @@ static struct {
                0, SDB_CONNECTION_DATA, 825, SDB_CONNECTION_LOOKUP, "["SERVICE_H2_S12"]",
        },
        {
-               SDB_CONNECTION_QUERY, "LOOKUP services MATCHING ANY host.metric.last_update = 1s", -1,
+               SDB_CONNECTION_QUERY, "LOOKUP services MATCHING ANY host.metric.last_update = 10s", -1,
+               0, SDB_CONNECTION_DATA, 825, SDB_CONNECTION_LOOKUP, "["SERVICE_H2_S12"]",
+       },
+       {
+               /* stupid but valid ;-) */
+               SDB_CONNECTION_QUERY, "LOOKUP services MATCHING ANY host.host.metric.metric.interval = 5s", -1,
                0, SDB_CONNECTION_DATA, 825, SDB_CONNECTION_LOOKUP, "["SERVICE_H2_S12"]",
        },
        {
@@ -583,6 +591,16 @@ static struct {
                SDB_CONNECTION_QUERY, "LOOKUP metrics MATCHING name = 'm1'", -1,
                0, SDB_CONNECTION_DATA, 864, SDB_CONNECTION_LOOKUP, METRIC_H12_M1_ARRAY,
        },
+       {
+               /* stupid but valid ;-) */
+               SDB_CONNECTION_QUERY, "LOOKUP metrics MATCHING metric.metric.name = 'm1'", -1,
+               0, SDB_CONNECTION_DATA, 864, SDB_CONNECTION_LOOKUP, METRIC_H12_M1_ARRAY,
+       },
+       {
+               /* also stupid but valid ;-) */
+               SDB_CONNECTION_QUERY, "LOOKUP metrics MATCHING metric.metric.host.host.last_update = 3s", -1,
+               0, SDB_CONNECTION_DATA, 378, SDB_CONNECTION_LOOKUP, "["METRIC_H2_M1"]",
+       },
        {
                SDB_CONNECTION_LOOKUP, "\0\0\0\3""name = 'm1'", 16,
                0, SDB_CONNECTION_DATA, 864, SDB_CONNECTION_LOOKUP, METRIC_H12_M1_ARRAY,