summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authormbeierl <mark.beierl@emc.com>2015-10-07 19:19:22 -0700
committerMark Beierl <mark.beierl@emc.com>2015-10-15 18:56:19 +0000
commit371588881746509fa5ca50be0939a14391099680 (patch)
tree471959a9130a22b91c482b523a702495e32f51c9 /tests
parent003e39f7afa940febcb93a6b16b86893c5dd97db (diff)
Creation of converters
JIRA: STORPERF-6 Change-Id: Id81a129807a984ad4af669e3f0f84c1e7ced5552 Signed-off-by: mbeierl <mark.beierl@emc.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/carbon/json_to_carbon_test.py120
1 files changed, 120 insertions, 0 deletions
diff --git a/tests/carbon/json_to_carbon_test.py b/tests/carbon/json_to_carbon_test.py
new file mode 100644
index 0000000..ea261af
--- /dev/null
+++ b/tests/carbon/json_to_carbon_test.py
@@ -0,0 +1,120 @@
+##############################################################################
+# Copyright (c) 2015 EMC and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import unittest
+
+import json
+
+import carbon.converter
+
+class JSONToCarbonTest(unittest.TestCase):
+
+ single_json_text_element = """{ "timestamp" : "timestamp", "key" : "value" }"""
+ single_json_numeric_element = """{ "timestamp" : "timestamp", "key" : 123 }"""
+ single_json_key_with_spaces = """{ "timestamp" : "timestamp", "key with spaces" : "value" }"""
+ single_json_value_with_spaces = """{ "timestamp" : "timestamp", "key" : "value with spaces" }"""
+ json_map_name_with_spaces = """{ "timestamp" : "timestamp", "map with spaces" : { "key" : "value" } }"""
+ json_list_name_with_spaces = """{ "timestamp" : "timestamp", "list with spaces" : [{ "key" : "value" }] }"""
+
+ sample_json = """
+{
+ "colorsArray":[{
+ "colorName":"red",
+ "hexValue":"#f00"
+ },
+ {
+ "colorName":"green",
+ "hexValue":"#0f0"
+ },
+ {
+ "colorName":"blue",
+ "hexValue":"#00f"
+ }
+ ]
+}"""
+
+ simple_fio_json = """
+{
+ "fio version" : "fio-2.2.10",
+ "timestamp" : 1444144664,
+ "time" : "Tue Oct 6 11:17:44 2015",
+ "jobs" : [
+ {
+ "jobname" : "random-read",
+ "groupid" : 0,
+ "error" : 0,
+ "eta" : 0,
+ "elapsed" : 26,
+ "read" : {
+ "io_bytes" : 7116,
+ "bw" : 275,
+ "iops" : 68.99,
+ "runtime" : 25788,
+ "total_ios" : 1779,
+ "short_ios" : 0,
+ "drop_ios" : 0,
+ "slat" : {
+ "min" : 0,
+ "max" : 0,
+ "mean" : 0.00,
+ "stddev" : 0.00
+ }
+ }
+ }]
+}
+"""
+
+ def setUp(self):
+ pass
+
+ def test_to_string(self):
+ testconv = carbon.converter.JSONToCarbon()
+ json_object = json.loads(self.simple_fio_json)
+ result = testconv.convert_to_dictionary(json_object, "host.run-name")
+ self.assertEqual("7116 1444144664", result["host.run-name.jobs.1.read.io_bytes"], result["host.run-name.jobs.1.read.io_bytes"])
+
+ def test_single_text_element_no_prefix(self):
+ testconv = carbon.converter.JSONToCarbon()
+ result = testconv.convert_to_dictionary(json.loads(self.single_json_text_element))
+
+ self.assertEqual("value timestamp", result["key"], result["key"])
+
+ def test_single_numeric_element_no_prefix(self):
+ testconv = carbon.converter.JSONToCarbon()
+ result = testconv.convert_to_dictionary(json.loads(self.single_json_numeric_element))
+
+ self.assertEqual("123 timestamp", result["key"], result["key"])
+
+ def test_single_text_key_space_element_no_prefix(self):
+ testconv = carbon.converter.JSONToCarbon()
+ result = testconv.convert_to_dictionary(json.loads(self.single_json_key_with_spaces))
+
+ self.assertEqual("value timestamp", result["key_with_spaces"], result["key_with_spaces"])
+
+ def test_single_text_value_space_element_no_prefix(self):
+ testconv = carbon.converter.JSONToCarbon()
+ result = testconv.convert_to_dictionary(json.loads(self.single_json_value_with_spaces))
+
+ self.assertEqual("value_with_spaces timestamp", result["key"], result["key"])
+
+ def test_map_name_with_space_no_prefix(self):
+ testconv = carbon.converter.JSONToCarbon()
+ result = testconv.convert_to_dictionary(json.loads(self.json_map_name_with_spaces))
+
+ self.assertEqual("value timestamp", result["map_with_spaces.key"], result["map_with_spaces.key"])
+
+ def test_list_name_with_space_no_prefix(self):
+ testconv = carbon.converter.JSONToCarbon()
+ result = testconv.convert_to_dictionary(json.loads(self.json_list_name_with_spaces))
+
+ self.assertEqual("value timestamp", result["list_with_spaces.1.key"], result["list_with_spaces.1.key"])
+
+
+if __name__ == '__main__':
+ unittest.main() \ No newline at end of file