Code

data: Use a predefined format for sdb_strftime().
[sysdb.git] / t / unit / frontend / query_test.c
index 00a208fbc8bd2225cbd465dff735267f1ba87ee3..8872e5b6e13a0f2879430e20e65f7c7f1bf27ebf 100644 (file)
@@ -30,7 +30,6 @@
 #endif
 
 #include "frontend/connection.h"
-#include "frontend/parser.h"
 #include "frontend/connection-private.h"
 #include "testutils.h"
 
@@ -45,134 +44,134 @@ populate(void)
 {
        sdb_data_t datum;
 
-       sdb_store_host("h1", 1);
-       sdb_store_host("h2", 3);
+       sdb_store_host("h1", 1 * SDB_INTERVAL_SECOND);
+       sdb_store_host("h2", 3 * SDB_INTERVAL_SECOND);
 
        datum.type = SDB_TYPE_STRING;
        datum.data.string = "v1";
-       sdb_store_attribute("h1", "k1", &datum, 1);
+       sdb_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND);
        datum.data.string = "v2";
-       sdb_store_attribute("h1", "k2", &datum, 2);
+       sdb_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND);
        datum.data.string = "v3";
-       sdb_store_attribute("h1", "k3", &datum, 2);
+       sdb_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
 
-       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("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);
 
        datum.type = SDB_TYPE_INTEGER;
        datum.data.integer = 42;
-       sdb_store_metric_attr("h1", "m1", "k3", &datum, 2);
+       sdb_store_metric_attr("h1", "m1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
 
-       sdb_store_service("h2", "s1", 1);
-       sdb_store_service("h2", "s2", 2);
+       sdb_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND);
+       sdb_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND);
 
        datum.data.integer = 123;
-       sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+       sdb_store_service_attr("h2", "s2", "k1", &datum, 2 * SDB_INTERVAL_SECOND);
        datum.data.integer = 4711;
-       sdb_store_service_attr("h2", "s2", "k2", &datum, 1);
+       sdb_store_service_attr("h2", "s2", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
 } /* populate */
 
 #define HOST_H1 \
-       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"attributes\": [" \
                        "{\"name\": \"k1\", \"value\": \"v1\", " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}," \
                        "{\"name\": \"k2\", \"value\": \"v2\", " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}," \
                        "{\"name\": \"k3\", \"value\": \"v3\", " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}], " \
                "\"metrics\": [" \
                        "{\"name\": \"m1\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": [], " \
                                "\"attributes\": [" \
                                        "{\"name\": \"hostname\", \"value\": \"h1\", " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}," \
                                        "{\"name\": \"k3\", \"value\": 42, " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}," \
                        "{\"name\": \"m2\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": [], " \
                                "\"attributes\": [" \
                                        "{\"name\": \"hostname\", \"value\": \"h1\", " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}]}"
 #define HOST_H1_ARRAY "["HOST_H1"]"
 #define HOST_H1_LISTING \
-       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": []}"
 #define HOST_H2_LISTING \
-       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": []}"
 
 #define SERVICE_H2_S1 \
-       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"services\": [" \
-                       "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                       "{\"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:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}]}"
 #define SERVICE_H2_S1_ARRAY "["SERVICE_H2_S1"]"
 #define SERVICE_H2_S12_LISTING \
-       "[{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "[{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"services\": [" \
-                       "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                       "{\"name\": \"s1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}," \
-                       "{\"name\": \"s2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                       "{\"name\": \"s2\", \"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}]}]"
 
 #define METRIC_H1_M1 \
-       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"metrics\": [" \
                        "{\"name\": \"m1\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": [], " \
                                "\"attributes\": [" \
                                        "{\"name\": \"hostname\", \"value\": \"h1\", " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}," \
                                        "{\"name\": \"k3\", \"value\": 42, " \
-                                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}]}"
 #define METRIC_H12_M1_ARRAY \
        "["METRIC_H1_M1"," \
-       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"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:00 +0000\", " \
+                               "\"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:00 +0000\", " \
+                                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                                "\"update_interval\": \"0s\", \"backends\": []}]}]}]"
 #define METRIC_H12_M12_LISTING \
-       "[{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "[{\"name\": \"h1\", \"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                        "\"update_interval\": \"0s\", \"backends\": [], " \
                "\"metrics\": [" \
                        "{\"name\": \"m1\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:02 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}," \
                        "{\"name\": \"m2\", \"timeseries\": false, " \
-                               "\"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}]}," \
-       "{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:00 +0000\", " \
+       "{\"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:00 +0000\", " \
+                               "\"last_update\": \"1970-01-01 00:00:01 +0000\", " \
                                "\"update_interval\": \"0s\", \"backends\": []}]}]"
 
 typedef struct {
@@ -283,7 +282,7 @@ fail_if_strneq(const char *got, const char *expected, size_t n, const char *fmt,
  * tests
  */
 
-#define VALUE "\0\0\0\3""v1"
+#define VALUE "\0\0\0\4""v1"
 #define VALUE_LEN 7
 
 static struct {
@@ -597,8 +596,7 @@ static struct {
        },
        {
                SDB_CONNECTION_STORE, "\0\0\0\x12""\0\0\0\0\xd6\x93\xa4\0""h2\0s1\0aA\0"VALUE,27+VALUE_LEN,
-               0, SDB_CONNECTION_OK, 43, 0, "Successfully stored service attribute s1.aA",
-               /* TODO: 46, h2.s1.aA */
+               0, SDB_CONNECTION_OK, 46, 0, "Successfully stored service attribute h2.s1.aA",
        },
        {
                SDB_CONNECTION_QUERY, "STORE service attribute 'h2'.'x1'.'aA' 'vA'", -1,
@@ -630,8 +628,7 @@ static struct {
        },
        {
                SDB_CONNECTION_STORE, "\0\0\0\x13""\0\0\0\0\xd6\x93\xa4\0""h1\0m1\0aA\0"VALUE, 27+VALUE_LEN,
-               0, SDB_CONNECTION_OK, 42, 0, "Successfully stored metric attribute m1.aA",
-               /* TODO: 45, h1.m1.aA */
+               0, SDB_CONNECTION_OK, 45, 0, "Successfully stored metric attribute h1.m1.aA",
        },
        {
                SDB_CONNECTION_QUERY, "STORE metric attribute 'h1'.'x1'.'aA' 'vA'", -1,