OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import functools | 5 import functools |
6 import operator | 6 import operator |
7 import time | 7 import time |
8 import unittest | 8 import unittest |
9 | 9 |
10 import mock | 10 import mock |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 self.store.set('foo', (('field', 'value'),), 42) | 126 self.store.set('foo', (('field', 'value'),), 42) |
127 self.store.reset_for_unittest(name='bar') | 127 self.store.reset_for_unittest(name='bar') |
128 self.assertEquals(42, self.store.get('foo', (('field', 'value'),))) | 128 self.assertEquals(42, self.store.get('foo', (('field', 'value'),))) |
129 | 129 |
130 self.store.reset_for_unittest(name='foo') | 130 self.store.reset_for_unittest(name='foo') |
131 self.assertIsNone(self.store.get('foo', (('field', 'value'),))) | 131 self.assertIsNone(self.store.get('foo', (('field', 'value'),))) |
132 | 132 |
133 | 133 |
134 class InProcessMetricStoreTest(MetricStoreTestBase, unittest.TestCase): | 134 class InProcessMetricStoreTest(MetricStoreTestBase, unittest.TestCase): |
135 METRIC_STORE_CLASS = metric_store.InProcessMetricStore | 135 METRIC_STORE_CLASS = metric_store.InProcessMetricStore |
136 | |
137 | |
138 class CombineModificationsTest(unittest.TestCase): | |
139 def test_set_set(self): | |
140 self.assertEqual( | |
141 metric_store.Modification('two', (), 'set', (2, False)), | |
142 metric_store.combine_modifications( | |
143 metric_store.Modification('one', (), 'set', (1, False)), | |
144 metric_store.Modification('two', (), 'set', (2, False)))) | |
145 | |
146 def test_set_incr(self): | |
147 self.assertEqual( | |
148 metric_store.Modification('one', (), 'set', (3, False)), | |
149 metric_store.combine_modifications( | |
150 metric_store.Modification('one', (), 'set', (1, False)), | |
151 metric_store.Modification('two', (), 'incr', (2, operator.add)))) | |
152 | |
153 def test_incr_set(self): | |
154 self.assertEqual( | |
155 metric_store.Modification('two', (), 'set', (2, False)), | |
156 metric_store.combine_modifications( | |
157 metric_store.Modification('one', (), 'incr', (1, operator.add)), | |
158 metric_store.Modification('two', (), 'set', (2, False)))) | |
159 | |
160 def test_incr_incr(self): | |
161 self.assertEqual( | |
162 metric_store.Modification('one', (), 'incr', (3, operator.add)), | |
163 metric_store.combine_modifications( | |
164 metric_store.Modification('one', (), 'incr', (1, operator.add)), | |
165 metric_store.Modification('two', (), 'incr', (2, operator.add)))) | |
166 | |
167 def test_none_set(self): | |
168 self.assertEqual( | |
169 metric_store.Modification('two', (), 'set', (2, False)), | |
170 metric_store.combine_modifications( | |
171 None, | |
172 metric_store.Modification('two', (), 'set', (2, False)))) | |
173 | |
174 def test_none_incr(self): | |
175 self.assertEqual( | |
176 metric_store.Modification('two', (), 'incr', (2, operator.add)), | |
177 metric_store.combine_modifications( | |
178 None, | |
179 metric_store.Modification('two', (), 'incr', (2, operator.add)))) | |
180 | |
181 def test_bad_type(self): | |
182 with self.assertRaises(errors.UnknownModificationTypeError): | |
183 metric_store.combine_modifications( | |
184 metric_store.Modification('one', (), 'set', (1, False)), | |
185 metric_store.Modification('two', (), 'bad', (2, False))) | |
OLD | NEW |