rroonga 7.0.2 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,37 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License version 2.1 as published by the Free Software Foundation.
8
- #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
-
18
- module Groonga
19
- # Measures statistic.
20
- class StatisticMeasurer
21
- MAX_N_ADDITIONAL_PATHS = 4096
22
-
23
- # @param path [String, nil] Measures disk usage of the path.
24
- # @return [Integer] 0 if path is @nil@, disk usage of the path otherwise.
25
- def measure_disk_usage(path)
26
- return 0 if path.nil?
27
-
28
- usage = File.size(path)
29
- 1.step(MAX_N_ADDITIONAL_PATHS) do |i|
30
- additional_path = "%s.%03X" % [path, i]
31
- break unless File.exist?(additional_path)
32
- usage += File.size(additional_path)
33
- end
34
- usage
35
- end
36
- end
37
- end
@@ -1,25 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
4
- #
5
- # This library is free software; you can redistribute it and/or
6
- # modify it under the terms of the GNU Lesser General Public
7
- # License version 2.1 as published by the Free Software Foundation.
8
- #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
-
18
- module Groonga
19
- class Table
20
- def disk_usage
21
- measurer = StatisticMeasurer.new
22
- measurer.measure_disk_usage(path)
23
- end
24
- end
25
- end
@@ -1,55 +0,0 @@
1
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
2
- #
3
- # This library is free software; you can redistribute it and/or
4
- # modify it under the terms of the GNU Lesser General Public
5
- # License version 2.1 as published by the Free Software Foundation.
6
- #
7
- # This library is distributed in the hope that it will be useful,
8
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
- # Lesser General Public License for more details.
11
- #
12
- # You should have received a copy of the GNU Lesser General Public
13
- # License along with this library; if not, write to the Free Software
14
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
-
16
- class StatisticMeasurerTest < Test::Unit::TestCase
17
- include GroongaTestUtils
18
-
19
- def setup
20
- @measurer = Groonga::StatisticMeasurer.new
21
- end
22
-
23
- class DiskUsageTest < self
24
- def test_nil
25
- assert_equal(0, disk_usage(nil))
26
- end
27
-
28
- def test_path_only
29
- size = 5
30
- path = File.join(@tmp_dir, "db")
31
- write(path, "X" * size)
32
- assert_equal(size, disk_usage(path))
33
- end
34
-
35
- def test_additional_path
36
- size_per_file = 5
37
- path = File.join(@tmp_dir, "db")
38
- write(path, "X" * size_per_file)
39
- write("#{path}.001", "X" * size_per_file)
40
- write("#{path}.002", "X" * size_per_file)
41
- assert_equal(3 * size_per_file, disk_usage(path))
42
- end
43
-
44
- private
45
- def disk_usage(path)
46
- @measurer.measure_disk_usage(path)
47
- end
48
-
49
- def write(path, content)
50
- File.open(path, "w") do |file|
51
- file.write(content)
52
- end
53
- end
54
- end
55
- end