summaryrefslogtreecommitdiffstats
path: root/config/src/tests/trace
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /config/src/tests/trace
Publish
Diffstat (limited to 'config/src/tests/trace')
-rw-r--r--config/src/tests/trace/.gitignore1
-rw-r--r--config/src/tests/trace/CMakeLists.txt8
-rw-r--r--config/src/tests/trace/trace.cpp70
3 files changed, 79 insertions, 0 deletions
diff --git a/config/src/tests/trace/.gitignore b/config/src/tests/trace/.gitignore
new file mode 100644
index 00000000000..d87470776bf
--- /dev/null
+++ b/config/src/tests/trace/.gitignore
@@ -0,0 +1 @@
+config_trace_test_app
diff --git a/config/src/tests/trace/CMakeLists.txt b/config/src/tests/trace/CMakeLists.txt
new file mode 100644
index 00000000000..b328f61abdc
--- /dev/null
+++ b/config/src/tests/trace/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(config_trace_test_app
+ SOURCES
+ trace.cpp
+ DEPENDS
+ config_cloudconfig
+)
+vespa_add_test(NAME config_trace_test_app COMMAND config_trace_test_app)
diff --git a/config/src/tests/trace/trace.cpp b/config/src/tests/trace/trace.cpp
new file mode 100644
index 00000000000..9945acae485
--- /dev/null
+++ b/config/src/tests/trace/trace.cpp
@@ -0,0 +1,70 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("frt");
+#include <vespa/vespalib/testkit/test_kit.h>
+#include <vespa/config/common/trace.h>
+#include <vespa/vespalib/trace/tracenode.h>
+
+
+using namespace config;
+using namespace vespalib;
+using namespace vespalib::slime;
+
+struct FixedClock : public Clock
+{
+ FixedClock() : currentTime(0) { }
+ int64_t currentTime;
+ int64_t currentTimeMillis() const { return currentTime; }
+};
+
+TEST("that trace can be serialized and deserialized") {
+ Trace trace(4);
+ trace.trace(4, "foo");
+ trace.trace(3, "bar");
+ trace.trace(5, "baz");
+
+ Slime slime;
+ Cursor & cursor(slime.setObject());
+ trace.serialize(cursor);
+
+ Trace trace2;
+ trace2.deserialize(slime.get());
+
+ Slime slime2;
+ trace2.serialize(slime2.setObject());
+ Trace trace3;
+ trace3.deserialize(slime2.get());
+
+ EXPECT_EQUAL(trace.toString(), trace3.toString());
+}
+
+TEST_F("that trace level is taken into account", FixedClock) {
+ f1.currentTime = 3;
+ Trace trace(4, f1);
+ trace.trace(4, "foo");
+ trace.trace(5, "bar");
+ EXPECT_EQUAL("[\n"
+" {\n"
+" \"timestamp\": 3,\n"
+" \"payload\": \"foo\"\n"
+" }\n"
+"]\n", trace.toString());
+}
+
+TEST("that trace can be copied") {
+ Trace trace(3);
+ trace.trace(2, "foo");
+ trace.trace(3, "bar");
+ Trace trace2(trace);
+ EXPECT_EQUAL(trace.toString(), trace2.toString());
+}
+
+TEST("ensure that system clock is used by default") {
+ Trace trace(2);
+ trace.trace(1, "foo");
+ TraceNode child(trace.getRoot().getChild(0));
+ EXPECT_TRUE(child.getTimestamp() > 0);
+}
+
+TEST_MAIN() { TEST_RUN_ALL(); }