Skip to content

Commit e029904

Browse files
committed
Replace json with simplejson (if available)
1 parent 056d862 commit e029904

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

hawkular/metrics.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@
1717
from __future__ import unicode_literals
1818

1919
import codecs
20-
import json
2120
import time
2221
import collections
2322

23+
try:
24+
import simplejson as json
25+
except ImportError:
26+
import json
27+
2428
try:
2529
# Python 3
2630
from urllib.request import Request, urlopen, build_opener, install_opener, HTTPErrorProcessor

hawkular/metrics_test.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,22 @@ class MetricsTestCase(TestMetricFunctionsBase):
5757
Metric definition creation should also test fetching the definition, while
5858
metric inserts should test also fetching the metric data.
5959
"""
60+
61+
def find_metric(self, name, definitions):
62+
for defin in definitions:
63+
if defin['id'] == name:
64+
return defin
6065

6166
def test_gauge_creation(self):
6267
"""
6368
Test creating gauge metric definitions with different tags and definition.
6469
"""
6570
# Create gauge metrics with empty details and added details
66-
md1 = self.client.create_metric_definition(MetricType.Gauge, 'test.create.gauge.1')
67-
md2 = self.client.create_metric_definition(MetricType.Gauge, 'test.create.gauge.2', dataRetention=90)
68-
md3 = self.client.create_metric_definition(MetricType.Gauge, 'test.create.gauge.3', dataRetention=90, units='bytes', env='qa')
71+
id_name = 'test.create.gauge.{}'
72+
73+
md1 = self.client.create_metric_definition(MetricType.Gauge, id_name.format('1'))
74+
md2 = self.client.create_metric_definition(MetricType.Gauge, id_name.format('2'), dataRetention=90)
75+
md3 = self.client.create_metric_definition(MetricType.Gauge, id_name.format('3'), dataRetention=90, units='bytes', env='qa')
6976
self.assertTrue(md1)
7077
self.assertTrue(md2)
7178
self.assertTrue(md3)
@@ -74,7 +81,10 @@ def test_gauge_creation(self):
7481
m = self.client.query_metric_definitions(MetricType.Gauge)
7582
self.assertEqual(3, len(m))
7683
self.assertEqual(self.test_tenant, m[0]['tenantId'])
77-
self.assertEqual('bytes', m[2]['tags']['units'])
84+
85+
md3_f = self.find_metric(id_name.format('3'), m)
86+
87+
self.assertEqual('bytes', md3_f['tags']['units'])
7888

7989
# This is what the returned dict should look like
8090
expect = [
@@ -87,19 +97,22 @@ def test_gauge_creation(self):
8797
self.assertEqual(m, expect) # Did it?
8898

8999
# Lets try creating a duplicate metric
90-
md4 = self.client.create_metric_definition(MetricType.Gauge, 'test.create.gauge.1')
100+
md4 = self.client.create_metric_definition(MetricType.Gauge, id_name.format('1'))
91101
self.assertFalse(md4, 'Should have received an exception, metric with the same name was already created')
92102

93103
def test_availability_creation(self):
104+
id_name = 'test.create.avail.{}'
94105
# Create availability metric
95106
# Fetch mterics and check that it did appear
96-
self.client.create_metric_definition(MetricType.Availability, 'test.create.avail.1')
97-
self.client.create_metric_definition(MetricType.Availability, 'test.create.avail.2', dataRetention=90)
98-
self.client.create_metric_definition(MetricType.Availability, 'test.create.avail.3', dataRetention=94, env='qa')
107+
self.client.create_metric_definition(MetricType.Availability, id_name.format('1'))
108+
self.client.create_metric_definition(MetricType.Availability, id_name.format('2'), dataRetention=90)
109+
self.client.create_metric_definition(MetricType.Availability, id_name.format('3'), dataRetention=94, env='qa')
99110
# Fetch metrics and check that it did appear
100111
m = self.client.query_metric_definitions(MetricType.Availability)
101112
self.assertEqual(3, len(m))
102-
self.assertEqual(94, m[2]['dataRetention'])
113+
114+
avail_3 = self.find_metric(id_name.format('3'), m)
115+
self.assertEqual(94, avail_3['dataRetention'])
103116

104117
def test_tags_modifications(self):
105118
m = 'test.create.tags.1'

0 commit comments

Comments
 (0)