aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/state_server/state_server_test.cpp
blob: b6bfcbcc2039b9c40e3d92ea53c18b43a47624b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/net/connection_auth_context.h>
#include <vespa/vespalib/net/http/state_server.h>
#include <vespa/vespalib/net/http/simple_health_producer.h>
#include <vespa/vespalib/net/http/simple_metrics_producer.h>
#include <vespa/vespalib/net/http/simple_component_config_producer.h>
#include <vespa/vespalib/net/http/state_explorer.h>
#include <vespa/vespalib/net/http/slime_explorer.h>
#include <vespa/vespalib/net/http/generic_state_handler.h>
#include <vespa/vespalib/util/stringfmt.h>
#include <vespa/vespalib/util/host_name.h>
#include <vespa/vespalib/process/process.h>
#include <sys/stat.h>

using namespace vespalib;

//-----------------------------------------------------------------------------

vespalib::string root_path = "/state/v1/";
vespalib::string short_root_path = "/state/v1";
vespalib::string metrics_path = "/state/v1/metrics";
vespalib::string health_path = "/state/v1/health";
vespalib::string config_path = "/state/v1/config";

vespalib::string total_metrics_path = "/metrics/total";

vespalib::string unknown_path = "/this/path/is/not/known";
vespalib::string unknown_state_path = "/state/v1/this/path/is/not/known";
vespalib::string my_path = "/my/path";

vespalib::string host_tag = "HOST";
std::map<vespalib::string,vespalib::string> empty_params;

//-----------------------------------------------------------------------------

vespalib::string run_cmd(const vespalib::string &cmd) {
    vespalib::string out;
    ASSERT_TRUE(Process::run(cmd.c_str(), out));
    return out;
}

vespalib::string getPage(int port, const vespalib::string &path, const vespalib::string &extra_params = "") {
    return run_cmd(make_string("curl -s %s 'http://localhost:%d%s'", extra_params.c_str(), port, path.c_str()));
}

vespalib::string getFull(int port, const vespalib::string &path) { return getPage(port, path, "-D -"); }

vespalib::string get_json(const JsonGetHandler &handler,
                          const vespalib::string &host,
                          const vespalib::string &path,
                          const std::map<vespalib::string,vespalib::string> &params)
{
    net::ConnectionAuthContext dummy_ctx(net::tls::PeerCredentials(), net::tls::CapabilitySet::all());
    auto res = handler.get(host, path, params, dummy_ctx);
    if (res.ok()) {
        return res.payload();
    }
    return {};
}

//-----------------------------------------------------------------------------

struct DummyHandler : JsonGetHandler {
    vespalib::string result;
    DummyHandler(const vespalib::string &result_in) : result(result_in) {}
    Response get(const vespalib::string &, const vespalib::string &,
                 const std::map<vespalib::string,vespalib::string> &,
                 const net::ConnectionAuthContext &) const override
    {
        if (!result.empty()) {
            return Response::make_ok_with_json(result);
        } else {
            return Response::make_not_found();
        }
    }
};

//-----------------------------------------------------------------------------

TEST_F("require that unknown url returns 404 response", HttpServer(0)) {
    std::string expect("HTTP/1.1 404 Not Found\r\n"
                       "Connection: close\r\n"
                       "\r\n");
    std::string actual = getFull(f1.port(), unknown_path);
    EXPECT_EQUAL(expect, actual);
}

TEST_FF("require that handler can return a 404 response", DummyHandler(""), HttpServer(0)) {
    auto token = f2.repo().bind(my_path, f1);
    std::string expect("HTTP/1.1 404 Not Found\r\n"
                       "Connection: close\r\n"
                       "\r\n");
    std::string actual = getFull(f2.port(), my_path);
    EXPECT_EQUAL(expect, actual);
}

TEST_FF("require that non-empty known url returns expected headers", DummyHandler("[123]"), HttpServer(0)) {
    auto token = f2.repo().bind(my_path, f1);
    vespalib::string expect("HTTP/1.1 200 OK\r\n"
                            "Connection: close\r\n"
                            "Content-Type: application/json\r\n"
                            "Content-Length: 5\r\n"
                            "X-XSS-Protection: 1; mode=block\r\n"
                            "X-Frame-Options: DENY\r\n"
                            "Content-Security-Policy: default-src 'none'; frame-ancestors 'none'\r\n"
                            "X-Content-Type-Options: nosniff\r\n"
                            "Cache-Control: no-store\r\n"
                            "Pragma: no-cache\r\n"
                            "\r\n"
                            "[123]");
    std::string actual = getFull(f2.port(), my_path);
    EXPECT_EQUAL(expect, actual);
}

TEST_FFFF("require that handler is selected based on longest matching url prefix",
          DummyHandler("[1]"), DummyHandler("[2]"), DummyHandler("[3]"),
          HttpServer(0))
{
    auto token2 = f4.repo().bind("/foo/bar", f2);
    auto token1 = f4.repo().bind("/foo", f1);
    auto token3 = f4.repo().bind("/foo/bar/baz", f3);
    int port = f4.port();
    EXPECT_EQUAL("", getPage(port, "/fox"));
    EXPECT_EQUAL("[1]", getPage(port, "/foo"));
    EXPECT_EQUAL("[1]", getPage(port, "/foo/fox"));
    EXPECT_EQUAL("[2]", getPage(port, "/foo/bar"));
    EXPECT_EQUAL("[2]", getPage(port, "/foo/bar/fox"));
    EXPECT_EQUAL("[3]", getPage(port, "/foo/bar/baz"));
    EXPECT_EQUAL("[3]", getPage(port, "/foo/bar/baz/fox"));
}

struct EchoHost : JsonGetHandler {
    ~EchoHost() override;
    Response get(const vespalib::string &host, const vespalib::string &,
                 const std::map<vespalib::string,vespalib::string> &,
                 const net::ConnectionAuthContext &) const override
    {
        return Response::make_ok_with_json("[\"" + host + "\"]");
    }
};

EchoHost::~EchoHost() = default;

TEST_FF("require that host is passed correctly", EchoHost(), HttpServer(0)) {
    auto token = f2.repo().bind(my_path, f1);
    EXPECT_EQUAL(make_string("%s:%d", HostName::get().c_str(), f2.port()), f2.host());
    vespalib::string default_result = make_string("[\"%s\"]", f2.host().c_str());
    vespalib::string localhost_result = make_string("[\"%s:%d\"]", "localhost", f2.port());
    vespalib::string silly_result = "[\"sillyserver\"]";
    EXPECT_EQUAL(localhost_result, run_cmd(make_string("curl -s http://localhost:%d/my/path", f2.port())));
    EXPECT_EQUAL(silly_result, run_cmd(make_string("curl -s http://localhost:%d/my/path -H \"Host: sillyserver\"", f2.port())));
    EXPECT_EQUAL(default_result, run_cmd(make_string("curl -s http://localhost:%d/my/path -H \"Host:\"", f2.port())));
}

struct SamplingHandler : JsonGetHandler {
    mutable std::mutex my_lock;
    mutable vespalib::string my_host;
    mutable vespalib::string my_path;
    mutable std::map<vespalib::string,vespalib::string> my_params;
    ~SamplingHandler() override;
    Response get(const vespalib::string &host, const vespalib::string &path,
                 const std::map<vespalib::string,vespalib::string> &params,
                 const net::ConnectionAuthContext &) const override
    {
        {
            auto guard = std::lock_guard(my_lock);
            my_host = host;
            my_path = path;
            my_params = params;
        }
        return Response::make_ok_with_json("[]");
    }
};

SamplingHandler::~SamplingHandler() = default;

TEST_FF("require that request parameters can be inspected", SamplingHandler(), HttpServer(0))
{
    auto token = f2.repo().bind("/foo", f1);
    EXPECT_EQUAL("[]", getPage(f2.port(), "/foo?a=b&x=y&z"));
    {
        auto guard = std::lock_guard(f1.my_lock);
        EXPECT_EQUAL(f1.my_path, "/foo");
        EXPECT_EQUAL(f1.my_params.size(), 3u);
        EXPECT_EQUAL(f1.my_params["a"], "b");
        EXPECT_EQUAL(f1.my_params["x"], "y");
        EXPECT_EQUAL(f1.my_params["z"], "");
        EXPECT_EQUAL(f1.my_params.size(), 3u); // "z" was present
    }
}

TEST_FF("require that request path is dequoted", SamplingHandler(), HttpServer(0))
{
    auto token = f2.repo().bind("/[foo]", f1);
    EXPECT_EQUAL("[]", getPage(f2.port(), "/%5bfoo%5D"));
    {
        auto guard = std::lock_guard(f1.my_lock);
        EXPECT_EQUAL(f1.my_path, "/[foo]");
        EXPECT_EQUAL(f1.my_params.size(), 0u);
    }
}

//-----------------------------------------------------------------------------

TEST_FFFF("require that the state server wires the appropriate url prefixes",
          SimpleHealthProducer(), SimpleMetricsProducer(), SimpleComponentConfigProducer(),
          StateServer(0, f1, f2, f3))
{
    f2.setTotalMetrics("{}"); // avoid empty result
    int port = f4.getListenPort();
    EXPECT_TRUE(getFull(port, short_root_path).find("HTTP/1.1 200 OK") == 0);
    EXPECT_TRUE(getFull(port, total_metrics_path).find("HTTP/1.1 200 OK") == 0);
    EXPECT_TRUE(getFull(port, unknown_path).find("HTTP/1.1 404 Not Found") == 0);
}

TEST_FFFF("require that the state server exposes the state api handler repo",
          SimpleHealthProducer(), SimpleMetricsProducer(), SimpleComponentConfigProducer(),
          StateServer(0, f1, f2, f3))
{
    int port = f4.getListenPort();
    vespalib::string page1 = getPage(port, root_path);
    auto token = f4.repo().add_root_resource("state/v1/custom");
    vespalib::string page2 = getPage(port, root_path);
    EXPECT_NOT_EQUAL(page1, page2);
    token.reset();
    vespalib::string page3 = getPage(port, root_path);
    EXPECT_EQUAL(page3, page1);
}

//-----------------------------------------------------------------------------

TEST_FFFF("require that json handlers can be removed from repo",
          DummyHandler("[1]"), DummyHandler("[2]"), DummyHandler("[3]"),
          JsonHandlerRepo())
{
    auto token1 = f4.bind("/foo", f1);
    auto token2 = f4.bind("/foo/bar", f2);
    auto token3 = f4.bind("/foo/bar/baz", f3);
    std::map<vespalib::string,vespalib::string> params;
    EXPECT_EQUAL("[1]", get_json(f4, "", "/foo", params));
    EXPECT_EQUAL("[2]", get_json(f4, "", "/foo/bar", params));
    EXPECT_EQUAL("[3]", get_json(f4, "", "/foo/bar/baz", params));
    token2.reset();
    EXPECT_EQUAL("[1]", get_json(f4, "", "/foo", params));
    EXPECT_EQUAL("[1]", get_json(f4, "", "/foo/bar", params));
    EXPECT_EQUAL("[3]", get_json(f4, "", "/foo/bar/baz", params));
}

TEST_FFFF("require that json handlers can be shadowed",
          DummyHandler("[1]"), DummyHandler("[2]"), DummyHandler("[3]"),
          JsonHandlerRepo())
{
    auto token1 = f4.bind("/foo", f1);
    auto token2 = f4.bind("/foo/bar", f2);
    std::map<vespalib::string,vespalib::string> params;
    EXPECT_EQUAL("[1]", get_json(f4, "", "/foo", params));
    EXPECT_EQUAL("[2]", get_json(f4, "", "/foo/bar", params));
    auto token3 = f4.bind("/foo/bar", f3);
    EXPECT_EQUAL("[3]", get_json(f4, "", "/foo/bar", params));
    token3.reset();
    EXPECT_EQUAL("[2]", get_json(f4, "", "/foo/bar", params));
}

TEST_F("require that root resources can be tracked", JsonHandlerRepo())
{
    EXPECT_TRUE(std::vector<vespalib::string>({}) == f1.get_root_resources());
    auto token1 = f1.add_root_resource("/health");
    EXPECT_TRUE(std::vector<vespalib::string>({"/health"}) == f1.get_root_resources());
    auto token2 = f1.add_root_resource("/config");
    EXPECT_TRUE(std::vector<vespalib::string>({"/health", "/config"}) == f1.get_root_resources());
    auto token3 = f1.add_root_resource("/custom/foo");
    EXPECT_TRUE(std::vector<vespalib::string>({"/health", "/config", "/custom/foo"}) == f1.get_root_resources());    
    token2.reset();
    EXPECT_TRUE(std::vector<vespalib::string>({"/health", "/custom/foo"}) == f1.get_root_resources());
}

//-----------------------------------------------------------------------------

TEST_FFFF("require that state api responds to the expected paths",
          SimpleHealthProducer(), SimpleMetricsProducer(), SimpleComponentConfigProducer(),
          StateApi(f1, f2, f3))
{
    f2.setTotalMetrics("{}"); // avoid empty result
    EXPECT_TRUE(!get_json(f4, host_tag, short_root_path, empty_params).empty());
    EXPECT_TRUE(!get_json(f4, host_tag, root_path, empty_params).empty());
    EXPECT_TRUE(!get_json(f4, host_tag, health_path, empty_params).empty());
    EXPECT_TRUE(!get_json(f4, host_tag, metrics_path, empty_params).empty());
    EXPECT_TRUE(!get_json(f4, host_tag, config_path, empty_params).empty());
    EXPECT_TRUE(!get_json(f4, host_tag, total_metrics_path, empty_params).empty());
    EXPECT_TRUE(get_json(f4, host_tag, unknown_path, empty_params).empty());
    EXPECT_TRUE(get_json(f4, host_tag, unknown_state_path, empty_params).empty());
}

TEST_FFFF("require that top-level urls are generated correctly",
          SimpleHealthProducer(), SimpleMetricsProducer(), SimpleComponentConfigProducer(),
          StateApi(f1, f2, f3))
{
    EXPECT_EQUAL("{\"resources\":["
                 "{\"url\":\"http://HOST/state/v1/health\"},"
                 "{\"url\":\"http://HOST/state/v1/metrics\"},"
                 "{\"url\":\"http://HOST/state/v1/config\"}]}",
                 get_json(f4, host_tag, root_path, empty_params));
    EXPECT_EQUAL(get_json(f4, host_tag, root_path, empty_params),
                 get_json(f4, host_tag, short_root_path, empty_params));
}

TEST_FFFF("require that top-level resource list can be extended",
          SimpleHealthProducer(), SimpleMetricsProducer(), SimpleComponentConfigProducer(),
          StateApi(f1, f2, f3))
{
    auto token = f4.repo().add_root_resource("/state/v1/custom");
    EXPECT_EQUAL("{\"resources\":["
                 "{\"url\":\"http://HOST/state/v1/health\"},"
                 "{\"url\":\"http://HOST/state/v1/metrics\"},"
                 "{\"url\":\"http://HOST/state/v1/config\"},"
                 "{\"url\":\"http://HOST/state/v1/custom\"}]}",
                 get_json(f4, host_tag, root_path, empty_params));
}

TEST_FFFF("require that health resource works as expected",
          SimpleHealthProducer(), SimpleMetricsProducer(), SimpleComponentConfigProducer(),
          StateApi(f1, f2, f3))
{
    EXPECT_EQUAL("{\"status\":{\"code\":\"up\"}}",
                 get_json(f4, host_tag, health_path, empty_params));
    f1.setFailed("FAIL MSG");
    EXPECT_EQUAL("{\"status\":{\"code\":\"down\",\"message\":\"FAIL MSG\"}}",
                 get_json(f4, host_tag, health_path, empty_params));
}

TEST_FFFF("require that metrics resource works as expected",
          SimpleHealthProducer(), SimpleMetricsProducer(), SimpleComponentConfigProducer(),
          StateApi(f1, f2, f3))
{
    EXPECT_EQUAL("{\"status\":{\"code\":\"up\"}}",
                 get_json(f4, host_tag, metrics_path, empty_params));
    f1.setFailed("FAIL MSG");
    EXPECT_EQUAL("{\"status\":{\"code\":\"down\",\"message\":\"FAIL MSG\"}}",
                 get_json(f4, host_tag, metrics_path, empty_params));
    f1.setOk();
    f2.setMetrics("{\"foo\":\"bar\"}");
    EXPECT_EQUAL("{\"status\":{\"code\":\"up\"},\"metrics\":{\"foo\":\"bar\"}}",
                 get_json(f4, host_tag, metrics_path, empty_params));
}

TEST_FFFF("require that config resource works as expected",
          SimpleHealthProducer(), SimpleMetricsProducer(), SimpleComponentConfigProducer(),
          StateApi(f1, f2, f3))
{
    EXPECT_EQUAL("{\"config\":{}}",
                 get_json(f4, host_tag, config_path, empty_params));
    f3.addConfig(SimpleComponentConfigProducer::Config("foo", 3));
    EXPECT_EQUAL("{\"config\":{\"generation\":3,\"foo\":{\"generation\":3}}}",
                 get_json(f4, host_tag, config_path, empty_params));
    f3.addConfig(SimpleComponentConfigProducer::Config("foo", 4));
    f3.addConfig(SimpleComponentConfigProducer::Config("bar", 4, "error"));
    EXPECT_EQUAL("{\"config\":{\"generation\":4,\"bar\":{\"generation\":4,\"message\":\"error\"},\"foo\":{\"generation\":4}}}",
                 get_json(f4, host_tag, config_path, empty_params));
    f3.removeConfig("bar");
    EXPECT_EQUAL("{\"config\":{\"generation\":4,\"foo\":{\"generation\":4}}}",
                 get_json(f4, host_tag, config_path, empty_params));
}

TEST_FFFF("require that state api also can return total metric",
          SimpleHealthProducer(), SimpleMetricsProducer(), SimpleComponentConfigProducer(),
          StateApi(f1, f2, f3))
{
    f2.setTotalMetrics("{\"foo\":\"bar\"}");
    EXPECT_EQUAL("{\"foo\":\"bar\"}",
                 get_json(f4, host_tag, total_metrics_path, empty_params));
}

TEST_FFFFF("require that custom handlers can be added to the state server",
          SimpleHealthProducer(), SimpleMetricsProducer(), SimpleComponentConfigProducer(),
          StateApi(f1, f2, f3), DummyHandler("[123]"))
{
    EXPECT_EQUAL("", get_json(f4, host_tag, my_path, empty_params));
    auto token = f4.repo().bind(my_path, f5);
    EXPECT_EQUAL("[123]", get_json(f4, host_tag, my_path, empty_params));
    token.reset();
    EXPECT_EQUAL("", get_json(f4, host_tag, my_path, empty_params));
}

struct EchoConsumer : MetricsProducer {
    ~EchoConsumer() override;
    vespalib::string getMetrics(const vespalib::string &consumer) override {
        return "[\"" + consumer + "\"]";
    }
    vespalib::string getTotalMetrics(const vespalib::string &consumer) override {
        return "[\"" + consumer + "\"]";
    }
};

EchoConsumer::~EchoConsumer() = default;

TEST_FFFF("require that empty v1 metrics consumer defaults to 'statereporter'",
          SimpleHealthProducer(), EchoConsumer(), SimpleComponentConfigProducer(),
          StateApi(f1, f2, f3))
{
    std::map<vespalib::string,vespalib::string> my_params;
    EXPECT_EQUAL("{\"status\":{\"code\":\"up\"},\"metrics\":[\"statereporter\"]}",
                 get_json(f4, host_tag, metrics_path, empty_params));
}

TEST_FFFF("require that empty total metrics consumer defaults to the empty string",
          SimpleHealthProducer(), EchoConsumer(), SimpleComponentConfigProducer(),
          StateApi(f1, f2, f3))
{
    std::map<vespalib::string,vespalib::string> my_params;
    EXPECT_EQUAL("[\"\"]", get_json(f4, host_tag, total_metrics_path, empty_params));
}

TEST_FFFF("require that metrics consumer is passed correctly",
          SimpleHealthProducer(), EchoConsumer(), SimpleComponentConfigProducer(),
          StateApi(f1, f2, f3))
{
    std::map<vespalib::string,vespalib::string> my_params;
    my_params["consumer"] = "ME";
    EXPECT_EQUAL("{\"status\":{\"code\":\"up\"},\"metrics\":[\"ME\"]}", get_json(f4, host_tag, metrics_path, my_params));
    EXPECT_EQUAL("[\"ME\"]", get_json(f4, host_tag, total_metrics_path, my_params));
}

void check_json(const vespalib::string &expect_json, const vespalib::string &actual_json) {
    Slime expect_slime;
    Slime actual_slime;
    EXPECT_TRUE(slime::JsonFormat::decode(expect_json, expect_slime) > 0);
    EXPECT_TRUE(slime::JsonFormat::decode(actual_json, actual_slime) > 0);
    EXPECT_EQUAL(expect_slime, actual_slime);
}

TEST("require that generic state can be explored") {
    vespalib::string json_model =
        "{"
        "  foo: 'bar',"
        "  cnt: 123,"
        "  engine: {"
        "    up: 'yes',"
        "    stats: {"
        "      latency: 5,"
        "      qps: 100"
        "    }"
        "  },"
        "  list: {"
        "    one: {"
        "      size: {"
        "        value: 1"
        "      }"
        "    },"
        "    two: {"
        "      size: 2"
        "    }"
        "  }"
        "}";
    vespalib::string json_root =
        "{"
        "  full: true,"
        "  foo: 'bar',"
        "  cnt: 123,"
        "  engine: {"
        "    up: 'yes',"
        "    url: 'http://HOST/state/v1/engine'"
        "  },"
        "  list: {"
        "    one: {"
        "      size: {"
        "        value: 1,"
        "        url: 'http://HOST/state/v1/list/one/size'"
        "      }"
        "    },"
        "    two: {"
        "      size: 2,"
        "      url: 'http://HOST/state/v1/list/two'"
        "    }"
        "  }"
        "}";
    vespalib::string json_engine =
        "{"
        "  full: true,"
        "  up: 'yes',"
        "  stats: {"
        "    latency: 5,"
        "    qps: 100,"
        "    url: 'http://HOST/state/v1/engine/stats'"
        "  }"
        "}";
    vespalib::string json_engine_stats =
        "{"
        "  full: true,"
        "  latency: 5,"
        "  qps: 100"
        "}";
    vespalib::string json_list =
        "{"
        "  one: {"
        "    size: {"
        "      value: 1,"
        "      url: 'http://HOST/state/v1/list/one/size'"
        "    }"
        "  },"
        "  two: {"
        "    size: 2,"
        "    url: 'http://HOST/state/v1/list/two'"
        "  }"
        "}";
    vespalib::string json_list_one =
        "{"
        "  size: {"
        "    value: 1,"
        "    url: 'http://HOST/state/v1/list/one/size'"
        "  }"
        "}";
    vespalib::string json_list_one_size = "{ full: true, value: 1 }";
    vespalib::string json_list_two = "{ full: true, size: 2 }";
    //-------------------------------------------------------------------------
    Slime slime_state;
    EXPECT_TRUE(slime::JsonFormat::decode(json_model, slime_state) > 0);
    SlimeExplorer slime_explorer(slime_state.get());
    GenericStateHandler state_handler(short_root_path, slime_explorer);
    EXPECT_EQUAL("", get_json(state_handler, host_tag, unknown_path, empty_params));
    EXPECT_EQUAL("", get_json(state_handler, host_tag, unknown_state_path, empty_params));
    check_json(json_root, get_json(state_handler, host_tag, root_path, empty_params));
    check_json(json_engine, get_json(state_handler, host_tag, root_path + "engine", empty_params));
    check_json(json_engine_stats, get_json(state_handler, host_tag, root_path + "engine/stats", empty_params));
    check_json(json_list, get_json(state_handler, host_tag, root_path + "list", empty_params));
    check_json(json_list_one, get_json(state_handler, host_tag, root_path + "list/one", empty_params));
    check_json(json_list_one_size, get_json(state_handler, host_tag, root_path + "list/one/size", empty_params));
    check_json(json_list_two, get_json(state_handler, host_tag, root_path + "list/two", empty_params));
}

TEST_MAIN() {
    mkdir("var", S_IRWXU);
    mkdir("var/run", S_IRWXU);
    TEST_RUN_ALL();
    rmdir("var/run");
    rmdir("var");
}