Example #1
0
    def test_slices_are_sortable(self):
        ceres_slices = [
            CeresSlice(self.ceres_node, 300, 60),
            CeresSlice(self.ceres_node, 600, 60),
            CeresSlice(self.ceres_node, 0, 60)
        ]

        expected_order = [0, 300, 600]
        result_order = [slice.startTime for slice in sorted(ceres_slices)]
        self.assertEqual(expected_order, result_order)
Example #2
0
 def test_delete_before_seeks_to_time(self):
     ceres_slice = CeresSlice(self.ceres_node, 300, 60)
     open_mock = mock_open(read_data='foo')
     with patch.object(builtins, 'open', open_mock) as open_mock:
         ceres_slice.deleteBefore(360)
         # Seek from 300 (start of file) to 360 (1 datapointpoint)
         open_mock.return_value.seek.assert_any_call(1 * DATAPOINT_SIZE)
Example #3
0
 def test_delete_before_clears_slice_cache(self):
   ceres_slice = CeresSlice(self.ceres_node, 300, 60)
   open_mock = mock_open(read_data='foo')  # needs to be non-null for this test
   with patch('__builtin__.open', open_mock):
     with patch('ceres.CeresNode.clearSliceCache') as clear_slice_cache_mock:
       ceres_slice.deleteBefore(360)
       clear_slice_cache_mock.assert_called_once_with()
Example #4
0
 def setUp(self):
     with patch('ceres.isdir', new=Mock(return_value=True)):
         with patch('ceres.exists', new=Mock(return_value=True)):
             self.ceres_tree = CeresTree('/graphite/storage/ceres')
             self.ceres_node = CeresNode(
                 self.ceres_tree, 'sample_metric',
                 '/graphite/storage/ceres/sample_metric')
     self.ceres_slice = CeresSlice(self.ceres_node, 300, 60)
Example #5
0
 def test_delete_before_deletes_file_if_no_more_data(self, open_mock):
     ceres_slice = CeresSlice(self.ceres_node, 300, 60)
     with patch('ceres.os.unlink') as unlink_mock:
         try:
             ceres_slice.deleteBefore(360)
         except Exception:
             pass
         self.assertTrue(unlink_mock.called)
Example #6
0
 def test_delete_before_raises_slice_deleted_if_no_more_data(
         self, open_mock):
     ceres_slice = CeresSlice(self.ceres_node, 300, 60)
     self.assertRaises(SliceDeleted, ceres_slice.deleteBefore, 360)
Example #7
0
 def test_delete_before_returns_if_time_same_as_start(self, open_mock):
     ceres_slice = CeresSlice(self.ceres_node, 300, 60)
     ceres_slice.deleteBefore(300)
     open_mock.assert_has_calls([])
Example #8
0
 def test_delete_before_returns_if_time_less_than_step_earlier_than_start(
         self, open_mock):
     ceres_slice = CeresSlice(self.ceres_node, 300, 60)
     ceres_slice.deleteBefore(299)
     open_mock.assert_has_calls([])
Example #9
0
 def test_delete_before_returns_if_time_earlier_than_start(self, open_mock):
     ceres_slice = CeresSlice(self.ceres_node, 300, 60)
     # File starts at timestamp 300, delete points before timestamp 60
     ceres_slice.deleteBefore(60)
     open_mock.assert_has_calls([])  # no calls
Example #10
0
 def test_delete_before_raises_if_deleted(self, exists_mock):
     exists_mock.return_value = False
     ceres_slice = CeresSlice(self.ceres_node, 0, 60)
     self.assertRaises(SliceDeleted, ceres_slice.deleteBefore, 60)
Example #11
0
 def test_end_time_calculated_via_filesize(self, getsize_mock):
     getsize_mock.return_value = DATAPOINT_SIZE * 300
     ceres_slice = CeresSlice(self.ceres_node, 0, 60)
     # 300 points at 60 sec per point
     self.assertEqual(300 * 60, ceres_slice.endTime)
Example #12
0
 def test_init_sets_fspath_name(self):
     ceres_slice = CeresSlice(self.ceres_node, 0, 60)
     self.assertTrue(ceres_slice.fsPath.endswith('*****@*****.**'))