thinp_xml 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDk0ZDhmMmUyM2I5MDVjYTgwZjQ0OTZmMTFkNThkODQwMzM1ODEzMQ==
4
+ MzdlNzA5ZjhiNjk5YzdkMTVkMmNlMzVhZTZmODZhY2IxNGI5M2ZkNA==
5
5
  data.tar.gz: !binary |-
6
- YWVmNWRkZDgyZWE5ZGJmNzkzNDIyNTQxY2E0Zjg4ZmQxN2FlMjg2OQ==
6
+ NDkyODA5MmY2NGE3MjEzNmM5NmNhOThiZWNlMTI4ZjRhMWNmODA4OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDkxNGE5MmEwMTM0YjM0ZGRlMzI5MDQ3NjRkZjcxNDM3ZTFjOTY2NzQ3Nzhm
10
- NWFhNGE0MDg2MGUyNzkxMWJkZTU2ZDBkMjU4MWMxMDQwYjNiZDA0NGU5ZTA4
11
- MWM1NDRkY2NjZjc4ZjQzYTg1ZDUyNDMwOWEyZTk4NzA3NmYzNDI=
9
+ NzdiMDY4ODdhZTdlOGI4OTYxYTE4YTcwYjg4ODlmNWFiNmVlNDI3YTgzNTRm
10
+ NGMzOTA2ODRjM2E0NDFkZGZiMmRkMTViYWExZjJhYjcyZTgwMmZkOWI0ZDEw
11
+ NGNmMmEzYmQ5NjIwNzM0MWE3ZWRiMTM1NzNlYWI3YzFlMzExMzI=
12
12
  data.tar.gz: !binary |-
13
- OTNjZGI5MjU5ZGExNmU1YzY5MGU3OTBjOTc0ODNhYWNlNTk2ZmQ0ZjdiYzRl
14
- ZjM4NjM2YTYyNWU3NjE3YjE0ODVlYjQxMWYzMGU2ZmVlNzJhZDNlY2JmZmEz
15
- MjA2MzU0Y2I0ZmJlODdhM2Q4ZmUxMWE2MWM5OTY2ODlkYmI4ZTU=
13
+ MjJjM2M2ZjA5OTE5ODhmODg1YmExYjAzMGY5OTcxYzExY2VlMDU4ZGZjYTdi
14
+ YmI4ZjMzNDZlMzdmZWZlNWI0MmE0NzNkMDMyMGI0YWMwZmM2ZTRlYThkMGMx
15
+ OTkyNzkxNjhkOWZmMTE5ODBiMjRmMjc1ODA1OGExNzU5MGNmNTc=
data/bin/cache_xml CHANGED
@@ -100,7 +100,20 @@ class Dispatcher
100
100
  def help(out)
101
101
  out.write <<EOF
102
102
  Manipulation of cache xml format metadata
103
- --help, -h: Show this message
103
+
104
+ Usage:
105
+ cache_xml [options]
106
+ --help, -h: Show this message
107
+
108
+ cache_xml create [options]
109
+ --uuid: Set the uuid
110
+ --block-size: In 512 byte sectors
111
+ --nr-cache-blocks: Set the nr of blocks in the cache device
112
+ --nr-mappings: Set the nr of mappings, either a number or distribution (eg, 'uniform[45..100]')
113
+ --dirty-percentage: What percentage of the cache should be marked dirty
114
+ --policy-name: Set the name of the cache policy (eg, 'mq')
115
+ --hint-width: Set the hint width (current kernels only support 4 bytes)
116
+ --mapping-policy: Changes how the mappings are generated; 'random' or 'linear'
104
117
  EOF
105
118
  end
106
119
  end
@@ -114,6 +127,7 @@ def top_level_handler(&block)
114
127
  block.call
115
128
  rescue => e
116
129
  STDERR.puts e.message
130
+ STDERR.puts e.backtrace.join("\n")
117
131
  exit 1
118
132
  end
119
133
 
data/bin/era_xml ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'thinp_xml/era_xml'
4
+ require 'ejt_command_line'
5
+
6
+ include EraXML
7
+
8
+ #----------------------------------------------------------------
9
+
10
+ EraCommandLine = CommandLine::Parser.new do
11
+ value_type :string do |str|
12
+ str
13
+ end
14
+
15
+ value_type :int do |str|
16
+ Integer(str)
17
+ end
18
+
19
+ simple_switch :help, '--help', '-h'
20
+ value_switch :uuid, :string, '--uuid'
21
+ value_switch :block_size, :int, '--block-size'
22
+ value_switch :nr_blocks, :int, '--nr-blocks'
23
+ value_switch :current_era, :int, '--current-era'
24
+ value_switch :nr_writesets, :int, '--nr-writesets'
25
+
26
+ global do
27
+ switches :help
28
+ end
29
+
30
+ command :create do
31
+ switches :uuid, :block_size, :nr_blocks, :current_era, :nr_writesets
32
+ end
33
+ end
34
+
35
+ #----------------------------------------------------------------
36
+
37
+ class Dispatcher
38
+ include EraXML
39
+
40
+ def global_command(opts, args)
41
+ if args.size > 0
42
+ die "unknown command '#{args[0]}'"
43
+ else
44
+ if opts[:help]
45
+ help(STDOUT)
46
+ else
47
+ die "no command given"
48
+ end
49
+ end
50
+ end
51
+
52
+ def create(opts, args)
53
+ b = Builder.new
54
+ b.uuid = opts.fetch(:uuid, '')
55
+ b.block_size = opts.fetch(:block_size, 128)
56
+ b.nr_blocks = opts.fetch(:nr_blocks, 0)
57
+ b.current_era = opts.fetch(:current_era, 0)
58
+ b.nr_writesets = opts.fetch(:nr_writesets, 0)
59
+
60
+ md = b.generate
61
+ write_xml(md, STDOUT)
62
+ end
63
+
64
+ private
65
+ def die(msg)
66
+ STDERR.puts msg
67
+ exit(1)
68
+ end
69
+
70
+ def help(out)
71
+ # FIXME: inadequate
72
+ out.write <<EOF
73
+ Manipulation of era xml format metadata
74
+
75
+ Usage:
76
+ era_xml [options]
77
+ --help, -h: Show this message
78
+
79
+ era_xml create [options]
80
+ --uuid: Set the uuid for the metadata
81
+ --block-size: Set the block size, in 512 byte sectors
82
+ --nr-blocks: Set the number of blocks
83
+ --current-era: Set the current era
84
+
85
+ --nr-writesets: Output a number of undigested writesets (you
86
+ probably don't need this unless you're debugging).
87
+ EOF
88
+ end
89
+ end
90
+
91
+ def parse_command_line(dispatcher, *args)
92
+ EraCommandLine.parse(dispatcher, *args)
93
+ end
94
+
95
+ def top_level_handler(&block)
96
+ begin
97
+ block.call
98
+ rescue => e
99
+ STDERR.puts e.message
100
+ STDERR.puts e.backtrace.join("\n")
101
+ exit 1
102
+ end
103
+
104
+ exit 0
105
+ end
106
+
107
+ #----------------------------------------------------------------
108
+
109
+ top_level_handler do
110
+ dispatcher = Dispatcher.new
111
+ parse_command_line(dispatcher, *ARGV)
112
+ end
113
+
114
+ #----------------------------------------------------------------
data/bin/thinp_xml CHANGED
@@ -86,6 +86,7 @@ def top_level_handler(&block)
86
86
  block.call
87
87
  rescue => e
88
88
  STDERR.puts e.message
89
+ STDERR.puts e.backtrace.join("\n")
89
90
  exit 1
90
91
  end
91
92
 
@@ -5,7 +5,20 @@ Feature: The tool should be helpful
5
5
  Then the stdout should contain:
6
6
  """
7
7
  Manipulation of cache xml format metadata
8
- --help, -h: Show this message
8
+
9
+ Usage:
10
+ cache_xml [options]
11
+ --help, -h: Show this message
12
+
13
+ cache_xml create [options]
14
+ --uuid: Set the uuid
15
+ --block-size: In 512 byte sectors
16
+ --nr-cache-blocks: Set the nr of blocks in the cache device
17
+ --nr-mappings: Set the nr of mappings, either a number or distribution (eg, 'uniform[45..100]')
18
+ --dirty-percentage: What percentage of the cache should be marked dirty
19
+ --policy-name: Set the name of the cache policy (eg, 'mq')
20
+ --hint-width: Set the hint width (current kernels only support 4 bytes)
21
+ --mapping-policy: Changes how the mappings are generated; 'random' or 'linear'
9
22
  """
10
23
 
11
24
  Scenario: Unknown sub commands cause fail
@@ -0,0 +1,59 @@
1
+ Feature: I can create new metadata
2
+
3
+ Scenario: Create a valid superblock with no blocks
4
+ When I era_xml create
5
+ Then the stdout should contain:
6
+ """
7
+ <superblock uuid="" block_size="128" nr_blocks="0" current_era="0">
8
+ <era_array>
9
+ </era_array>
10
+ </superblock>
11
+ """
12
+
13
+ Scenario: Create a valid superblock with specified uuid
14
+ When I era_xml create --uuid 'one two three'
15
+ Then the stdout should contain:
16
+ """
17
+ <superblock uuid="one two three" block_size="128" nr_blocks="0" current_era="0">
18
+ <era_array>
19
+ </era_array>
20
+ </superblock>
21
+ """
22
+
23
+ Scenario: Create a superblock with specified block size
24
+ When I era_xml create --block-size 512
25
+ Then the stdout should contain:
26
+ """
27
+ <superblock uuid="" block_size="512" nr_blocks="0" current_era="0">
28
+ <era_array>
29
+ </era_array>
30
+ </superblock>
31
+ """
32
+
33
+ Scenario: Fail if the block size is not an integer
34
+ When I era_xml create --block-size large
35
+ Then it should fail
36
+
37
+ Scenario: Accept --nr-blocks
38
+ When I era_xml create --nr-blocks 8
39
+ Then it should pass
40
+
41
+ Scenario: Fail if the nr blocks is not an integer
42
+ When I era_xml create --nr-blocks loads
43
+ Then it should fail
44
+
45
+ Scenario: Accept --current-era
46
+ When I era_xml create --current-era 1000
47
+ Then it should pass
48
+
49
+ Scenario: Fail if the current era is not an integer
50
+ When I era_xml create --current-era peistocene
51
+ Then it should fail
52
+
53
+ Scenario: Accept --nr-writesets
54
+ When I era_xml create --nr-writesets 56 --current-era 100
55
+ Then it should pass
56
+
57
+ Scenario: Fail if the nr writesets is not an integer
58
+ When I era_xml create --nr-writesets lots --current-era 1000
59
+ Then it should fail
@@ -0,0 +1,29 @@
1
+ Feature: The tool should be helpful
2
+
3
+ Scenario: --help prints usage to stdout
4
+ When I era_xml --help
5
+ Then the stdout should contain:
6
+ """
7
+ Manipulation of era xml format metadata
8
+
9
+ Usage:
10
+ era_xml [options]
11
+ --help, -h: Show this message
12
+
13
+ era_xml create [options]
14
+ --uuid: Set the uuid for the metadata
15
+ --block-size: Set the block size, in 512 byte sectors
16
+ --nr-blocks: Set the number of blocks
17
+ --current-era: Set the current era
18
+
19
+ --nr-writesets: Output a number of undigested writesets (you
20
+ probably don't need this unless you're debugging).
21
+ """
22
+
23
+ Scenario: Unknown sub commands cause fail
24
+ When I era_xml unleashtheearwigs
25
+ Then it should fail
26
+ And the stderr should contain:
27
+ """
28
+ unknown command 'unleashtheearwigs'
29
+ """
@@ -6,6 +6,10 @@ When(/^I cache_xml (.*)$/) do |cmd|
6
6
  run_simple(unescape("cache_xml #{cmd}"), false)
7
7
  end
8
8
 
9
+ When(/^I era_xml (.*)$/) do |cmd|
10
+ run_simple(unescape("era_xml #{cmd}"), false)
11
+ end
12
+
9
13
  Then(/^it should pass$/) do
10
14
  assert_success(true)
11
15
  end
@@ -0,0 +1,47 @@
1
+ require 'thinp_xml/era/metadata'
2
+
3
+ #----------------------------------------------------------------
4
+
5
+ module EraXML
6
+ class Builder
7
+ attr_accessor :uuid, :block_size, :nr_blocks, :current_era, :nr_writesets
8
+
9
+ def initialize
10
+ @uuid = ''
11
+ @block_size = 128
12
+ @nr_blocks = 0
13
+ @current_era = 0
14
+ @nr_writesets = 0
15
+ end
16
+
17
+ def generate
18
+ s = Superblock.new(@uuid, @block_size, @nr_blocks, @current_era)
19
+
20
+ if @nr_writesets > @current_era
21
+ raise "can't have more writesets than eras"
22
+ end
23
+
24
+ era_array_limit = @current_era - @nr_writesets
25
+
26
+ writesets = (0..@nr_writesets - 1).map do |i|
27
+ bits = (0..@nr_blocks - 1).map do |block|
28
+ WritesetBit.new(block, rand(2) == 0 ? false : true)
29
+ end
30
+
31
+ Writeset.new(era_array_limit + i, @nr_blocks, bits)
32
+ end
33
+
34
+ era_array = (0..@nr_blocks - 1).map do |block|
35
+ if @current_era > 0
36
+ rand(era_array_limit)
37
+ else
38
+ 0
39
+ end
40
+ end
41
+
42
+ Metadata.new(s, writesets, era_array)
43
+ end
44
+ end
45
+ end
46
+
47
+ #----------------------------------------------------------------
@@ -0,0 +1,52 @@
1
+ require 'thinp_xml/era/metadata'
2
+ require 'thinp_xml/emitter'
3
+
4
+ #----------------------------------------------------------------
5
+
6
+ module EraXML
7
+ module EraEmitterDetail
8
+ class EraEmitter
9
+ def initialize(out)
10
+ @e = ThinpXML::Base::Emitter.new(out)
11
+ end
12
+
13
+ def emit_superblock(sb, &block)
14
+ @e.emit_tag(sb, 'superblock', :uuid, :block_size, :nr_blocks, :current_era, &block)
15
+ end
16
+
17
+ def emit_writesets(sets)
18
+ sets.each do |ws|
19
+ block = lambda do
20
+ ws.bits.each do |b|
21
+ @e.emit_tag(b, :block, :value)
22
+ end
23
+ end
24
+
25
+ @e.emit_tag(ws, 'writeset', :era, :nr_blocks, &block)
26
+ end
27
+ end
28
+
29
+ def emit_era_array(ea)
30
+ block = lambda do
31
+ ea.each_index do |b|
32
+ @e.emit_line("<era block=\"#{b}\" era=\"#{ea[b]}\"\\>")
33
+ end
34
+ end
35
+
36
+ @e.emit_tag(ea, 'era_array', &block)
37
+ end
38
+ end
39
+ end
40
+
41
+ #--------------------------------
42
+
43
+ def write_xml(md, io)
44
+ e = EraEmitterDetail::EraEmitter.new(io)
45
+ e.emit_superblock(md.superblock) do
46
+ e.emit_writesets(md.writesets)
47
+ e.emit_era_array(md.era_array)
48
+ end
49
+ end
50
+ end
51
+
52
+ #----------------------------------------------------------------
@@ -0,0 +1,22 @@
1
+ module EraXML
2
+ SUPERBLOCK_FIELDS = [[:uuid, :string],
3
+ [:block_size, :int],
4
+ [:nr_blocks, :int],
5
+ [:current_era, :int]]
6
+
7
+ WRITESET_FIELDS = [[:era, :int],
8
+ [:nr_blocks, :int],
9
+ [:bits, :array]]
10
+
11
+ BIT_FIELDS = [[:block, :int],
12
+ [:value, :bool]]
13
+
14
+ def self.field_names(flds)
15
+ flds.map {|p| p[0]}
16
+ end
17
+
18
+ Superblock = Struct.new(*field_names(SUPERBLOCK_FIELDS))
19
+ Writeset = Struct.new(*field_names(WRITESET_FIELDS))
20
+ WritesetBit = Struct.new(*field_names(BIT_FIELDS))
21
+ Metadata = Struct.new(:superblock, :writesets, :era_array)
22
+ end
@@ -0,0 +1,4 @@
1
+ require 'thinp_xml/era/builder'
2
+ require 'thinp_xml/era/emit'
3
+ require 'thinp_xml/era/metadata'
4
+ require 'thinp_xml/version'
@@ -1,3 +1,3 @@
1
1
  module ThinpXml
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
data/spec/builder_spec.rb CHANGED
@@ -13,58 +13,58 @@ describe "ThinpXML::Builder" do
13
13
 
14
14
  describe "uuid" do
15
15
  it "should be an empty string by default" do
16
- @b.uuid.should == ''
16
+ expect(@b.uuid).to eq('')
17
17
  end
18
18
 
19
19
  it "should reflect any changes" do
20
20
  uuid = 'one two three'
21
21
  @b.uuid = uuid
22
- @b.uuid.should == uuid
22
+ expect(@b.uuid).to eq(uuid)
23
23
  end
24
24
 
25
25
  it "should generate the correct uuid" do
26
26
  uuid = 'one two three'
27
27
  @b.uuid = uuid
28
28
  md = @b.generate
29
- md.superblock.uuid.should == uuid
29
+ expect(md.superblock.uuid).to eq(uuid)
30
30
  end
31
31
  end
32
32
 
33
33
  describe "block_size" do
34
34
  it "should be 128 by default" do
35
- @b.block_size.should == 128
35
+ expect(@b.block_size).to eq(128)
36
36
  end
37
37
 
38
38
  it "should reflect any changes" do
39
39
  @b.block_size = 512
40
- @b.block_size.should == 512
40
+ expect(@b.block_size).to eq(512)
41
41
  end
42
42
 
43
43
  it "should generate the correct block size" do
44
44
  bs = 1024
45
45
  @b.block_size = bs
46
46
  md = @b.generate
47
- md.superblock.data_block_size.should == bs
47
+ expect(md.superblock.data_block_size).to eq(bs)
48
48
  end
49
49
  end
50
50
 
51
51
  describe "nr of thins" do
52
52
  it "zero by default" do
53
- @b.nr_thins.should == 0
53
+ expect(@b.nr_thins).to eq(0)
54
54
  end
55
55
 
56
56
  it "should reflect any changes" do
57
57
  @b.nr_thins = 5
58
- @b.nr_thins.should == 5
58
+ expect(@b.nr_thins).to eq(5)
59
59
  end
60
60
 
61
61
  it "should generate the correct nr" do
62
62
  @b.nr_thins = 5
63
63
  md = @b.generate
64
64
 
65
- md.should have(5).devices
65
+ expect(md.devices.size).to eq(5)
66
66
  0.upto(4) do |n|
67
- md.devices[n].should_not == nil
67
+ expect(md.devices[n]).not_to eq(nil)
68
68
  end
69
69
  end
70
70
 
@@ -72,20 +72,20 @@ describe "ThinpXML::Builder" do
72
72
  @b.nr_thins = UniformDistribution.new(2, 6)
73
73
  md = @b.generate
74
74
 
75
- md.should have_at_most(5).devices
76
- md.should have_at_least(2).devices
75
+ expect(md.devices.size).to be <= 5
76
+ expect(md.size).to be >= 2
77
77
  end
78
78
  end
79
79
 
80
80
  describe "nr of mappings" do
81
81
  it "none by default" do
82
82
  @b.nr_thins = 1
83
- @b.generate.devices[0].should have(0).mappings
83
+ expect(@b.generate.devices[0].mappings.size).to eq(0)
84
84
  end
85
85
 
86
86
  it "should reflect any changes" do
87
87
  @b.nr_mappings = 101
88
- @b.nr_mappings.should == 101
88
+ expect(@b.nr_mappings).to eq(101)
89
89
  end
90
90
 
91
91
  it "should generate the correct nr" do
@@ -96,8 +96,8 @@ describe "ThinpXML::Builder" do
96
96
  0.upto(@b.nr_thins - 1) do |n|
97
97
  dev = md.devices[n]
98
98
  total = total_mapped(dev)
99
- total.should == 101
100
- dev.mapped_blocks.should == 101
99
+ expect(total).to eq(101)
100
+ expect(dev.mapped_blocks).to eq(101)
101
101
  end
102
102
  end
103
103
 
@@ -106,7 +106,7 @@ describe "ThinpXML::Builder" do
106
106
  @b.nr_mappings = 101
107
107
  md = @b.generate
108
108
 
109
- md.devices[0].should have(1).mappings
109
+ expect(md.devices[0].mappings.size).to eq(1)
110
110
  end
111
111
 
112
112
  it "should be used to calculate the nr data blocks" do
@@ -114,7 +114,7 @@ describe "ThinpXML::Builder" do
114
114
  @b.nr_mappings = 117
115
115
  md = @b.generate
116
116
 
117
- md.superblock.nr_data_blocks.should == 234
117
+ expect(md.superblock.nr_data_blocks).to eq(234)
118
118
  end
119
119
  end
120
120
  end
@@ -18,80 +18,80 @@ describe "CacheXML::Builder" do
18
18
 
19
19
  describe "uuid" do
20
20
  it "should be an empty string by default" do
21
- @b.uuid.should == ''
21
+ expect(@b.uuid).to eq('')
22
22
  end
23
23
 
24
24
  it "should reflect any changes" do
25
25
  uuid = 'one two three'
26
26
  @b.uuid = uuid
27
- @b.uuid.should == uuid
27
+ expect(@b.uuid).to eq(uuid)
28
28
  end
29
29
 
30
30
  it "should generate the correct uuid" do
31
31
  uuid = 'one two three'
32
32
  @b.uuid = uuid
33
33
  md = @b.generate
34
- md.superblock.uuid.should == uuid
34
+ expect(md.superblock.uuid).to eq(uuid)
35
35
  end
36
36
  end
37
37
 
38
38
  describe "block_size" do
39
39
  it "should be 128 by default" do
40
- @b.block_size.should == 128
40
+ expect(@b.block_size).to eq(128)
41
41
  end
42
42
 
43
43
  it "should reflect any changes" do
44
44
  @b.block_size = 512
45
- @b.block_size.should == 512
45
+ expect(@b.block_size).to eq(512)
46
46
  end
47
47
 
48
48
  it "should generate the correct block size" do
49
49
  bs = 1024
50
50
  @b.block_size = bs
51
51
  md = @b.generate
52
- md.superblock.block_size.should == bs
52
+ expect(md.superblock.block_size).to eq(bs)
53
53
  end
54
54
  end
55
55
 
56
56
  describe "nr cache blocks" do
57
57
  it "should be zero by default" do
58
- @b.nr_cache_blocks.should == 0
59
- @b.generate.should have(0).mappings
58
+ expect(@b.nr_cache_blocks).to eq(0)
59
+ expect(@b.generate.mappings.size).to eq(0)
60
60
  end
61
61
 
62
62
  it "should reflect any changes" do
63
63
  n = rand(1000)
64
64
  @b.nr_cache_blocks = n
65
- @b.nr_cache_blocks.should == n
66
- @b.generate.superblock.nr_cache_blocks.should == n
65
+ expect(@b.nr_cache_blocks).to eq(n)
66
+ expect(@b.generate.superblock.nr_cache_blocks).to eq(n)
67
67
  end
68
68
  end
69
69
 
70
70
  describe "policy name" do
71
71
  it "should be 'mq' by default" do
72
- @b.policy_name.should == 'mq'
73
- @b.generate.superblock.policy.should == 'mq'
72
+ expect(@b.policy_name).to eq('mq')
73
+ expect(@b.generate.superblock.policy).to eq('mq')
74
74
  end
75
75
 
76
76
  it "should reflect changes" do
77
77
  n = 'most_recently_not_used_least'
78
78
  @b.policy_name = n
79
- @b.policy_name.should == n
80
- @b.generate.superblock.policy.should == n
79
+ expect(@b.policy_name).to eq(n)
80
+ expect(@b.generate.superblock.policy).to eq(n)
81
81
  end
82
82
  end
83
83
 
84
84
  describe "hint width" do
85
85
  it "should be '4' by default" do
86
- @b.hint_width.should == 4
87
- @b.generate.superblock.hint_width.should == 4
86
+ expect(@b.hint_width).to eq(4)
87
+ expect(@b.generate.superblock.hint_width).to eq(4)
88
88
  end
89
89
 
90
90
  it "should allow a hint size between 4 and 128, mod 4" do
91
91
  0.upto(132) do |n|
92
92
  if (((n % 4) == 0) && n <= 128)
93
93
  @b.hint_width = n
94
- @b.hint_width.should == n
94
+ expect(@b.hint_width).to eq(n)
95
95
  end
96
96
  end
97
97
  end
@@ -106,14 +106,14 @@ describe "CacheXML::Builder" do
106
106
 
107
107
  it "should reflect changes" do
108
108
  @b.hint_width = 12
109
- @b.generate.superblock.hint_width.should == 12
109
+ expect(@b.generate.superblock.hint_width).to eq(12)
110
110
  end
111
111
  end
112
112
 
113
113
  describe "mappings" do
114
114
  describe "mapping policy" do
115
115
  it "should default to :random" do
116
- @b.mapping_policy.should == :random
116
+ expect(@b.mapping_policy).to eq(:random)
117
117
  end
118
118
 
119
119
  it "should only accept :random, or :linear" do
@@ -125,7 +125,7 @@ describe "CacheXML::Builder" do
125
125
 
126
126
  describe "nr mappings" do
127
127
  it "should default to zero" do
128
- @b.nr_mappings.should == 0
128
+ expect(@b.nr_mappings).to eq(0)
129
129
  end
130
130
 
131
131
  it "should never be bigger than the nr_cache_blocks" do
@@ -140,14 +140,14 @@ describe "CacheXML::Builder" do
140
140
  100.times do
141
141
  @b.nr_cache_blocks = rand(1000)
142
142
  @b.nr_mappings = rand(@b.nr_cache_blocks)
143
- @b.generate.should have(@b.nr_mappings).mappings
143
+ expect(@b.generate.mappings.size).to eq(@b.nr_mappings)
144
144
  end
145
145
  end
146
146
  end
147
147
 
148
148
  describe "dirty percentage" do
149
149
  it "should default to zero" do
150
- @b.dirty_percentage.should == 0
150
+ expect(@b.dirty_percentage).to eq(0)
151
151
  end
152
152
 
153
153
  it "should throw if set to a negative number" do
@@ -165,7 +165,7 @@ describe "CacheXML::Builder" do
165
165
  it "should accept a valid value" do
166
166
  [0, 1, 34, 78, 99, 100].each do |valid_value|
167
167
  @b.dirty_percentage = valid_value
168
- @b.dirty_percentage.should == valid_value
168
+ expect(@b.dirty_percentage).to eq(valid_value)
169
169
  end
170
170
  end
171
171
 
@@ -182,7 +182,7 @@ describe "CacheXML::Builder" do
182
182
  nr_dirty += 1 if m.dirty
183
183
  end
184
184
 
185
- approx_percentage(nr_dirty, n_mappings, p).should be_true
185
+ expect(approx_percentage(nr_dirty, n_mappings, p)).to be_truthy
186
186
  end
187
187
  end
188
188
  end
@@ -199,7 +199,7 @@ describe "CacheXML::Builder" do
199
199
 
200
200
  cb = 0
201
201
  mappings.each do |m|
202
- m.cache_block.should == cb
202
+ expect(m.cache_block).to eq(cb)
203
203
  cb += 1
204
204
  end
205
205
  end
@@ -214,7 +214,7 @@ describe "CacheXML::Builder" do
214
214
  if b.nil?
215
215
  b = m.origin_block
216
216
  else
217
- m.origin_block.should == b
217
+ expect(m.origin_block).to eq(b)
218
218
  end
219
219
 
220
220
  b += 1
@@ -234,7 +234,7 @@ describe "CacheXML::Builder" do
234
234
 
235
235
  cb = 0
236
236
  mappings.each do |m|
237
- m.cache_block.should == cb
237
+ expect(m.cache_block).to eq(cb)
238
238
  cb += 1
239
239
  end
240
240
  end
@@ -258,7 +258,7 @@ describe "CacheXML::Builder" do
258
258
  b += 1
259
259
  end
260
260
 
261
- in_order.should be_false
261
+ expect(in_order).to be_falsey
262
262
  end
263
263
  end
264
264
  end
@@ -35,12 +35,12 @@ describe "integer distributions" do
35
35
  it "should always return it's given value" do
36
36
  dist = ConstDistribution.new(5)
37
37
  10.times do
38
- dist.generate.should == 5
38
+ expect(dist.generate).to eq(5)
39
39
  end
40
40
 
41
41
  dist = ConstDistribution.new(11)
42
42
  10.times do
43
- dist.generate.should == 11
43
+ expect(dist.generate).to eq(11)
44
44
  end
45
45
  end
46
46
 
@@ -75,12 +75,12 @@ describe "integer distributions" do
75
75
  buckets[dist.generate] += 1
76
76
  end
77
77
 
78
- buckets[0].should == 0
79
- buckets[10].should == 0
78
+ expect(buckets[0]).to eq(0)
79
+ expect(buckets[10]).to eq(0)
80
80
 
81
81
  1.upto(9) do |n|
82
- buckets[n].should_not == 0
83
- buckets[n].should be_approx(1000, 200)
82
+ expect(buckets[n]).not_to eq(0)
83
+ expect(buckets[n]).to be_approx(1000, 200)
84
84
  end
85
85
  end
86
86
 
@@ -96,7 +96,7 @@ describe "integer distributions" do
96
96
  end
97
97
 
98
98
  dist.to_i
99
- $called456.should be_true
99
+ expect($called456).to be_truthy
100
100
  end
101
101
  end
102
102
 
@@ -107,16 +107,16 @@ describe "integer distributions" do
107
107
  it "should parse a const expression" do
108
108
  10.times do
109
109
  n = rand(50)
110
- parse_distribution(n.to_s).to_i.should == n
111
- parse_distribution(n.to_s).to_i.should == n
110
+ expect(parse_distribution(n.to_s).to_i).to eq(n)
111
+ expect(parse_distribution(n.to_s).to_i).to eq(n)
112
112
  end
113
113
  end
114
114
  end
115
115
 
116
116
  describe "uniform expression" do
117
117
  def check_range(b, e, n)
118
- n.should >= b
119
- n.should < e
118
+ expect(n).to be >= b
119
+ expect(n).to be < e
120
120
  end
121
121
 
122
122
  it "should accept well formed expressions" do
@@ -0,0 +1,154 @@
1
+ require 'thinp_xml/era/builder'
2
+
3
+ require 'set'
4
+
5
+ #----------------------------------------------------------------
6
+
7
+ describe "EraXML::Builder" do
8
+ before :each do
9
+ @b = EraXML::Builder.new
10
+ end
11
+
12
+ describe "uuid" do
13
+ it "should be an empty string by default" do
14
+ expect(@b.uuid).to eq('')
15
+ end
16
+
17
+ it "should reflect any changes" do
18
+ uuid = 'one two three'
19
+ @b.uuid = uuid
20
+ expect(@b.uuid).to eq(uuid)
21
+ end
22
+
23
+ it "should generate the correct uuid" do
24
+ uuid = 'one two three'
25
+ @b.uuid = uuid
26
+ md = @b.generate
27
+ expect(md.superblock.uuid).to eq(uuid)
28
+ end
29
+ end
30
+
31
+ describe "block_size" do
32
+ it "should be 128 by default" do
33
+ expect(@b.block_size).to eq(128)
34
+ end
35
+
36
+ it "should reflect any changes" do
37
+ @b.block_size = 512
38
+ expect(@b.block_size).to eq(512)
39
+ end
40
+
41
+ it "should generate the correct block size" do
42
+ bs = 1024
43
+ @b.block_size = bs
44
+ md = @b.generate
45
+ expect(md.superblock.block_size).to eq(bs)
46
+ end
47
+ end
48
+
49
+ describe "nr_blocks" do
50
+ it "should be 0 by default" do
51
+ expect(@b.nr_blocks).to eq(0)
52
+ end
53
+
54
+ it "should reflect any changes" do
55
+ @b.nr_blocks = 1234
56
+ expect(@b.nr_blocks).to eq(1234)
57
+ end
58
+
59
+ it "should generate the correct nr blocks" do
60
+ n = 1234
61
+ @b.nr_blocks = n
62
+ md = @b.generate
63
+ expect(md.superblock.nr_blocks).to eq(n)
64
+ end
65
+ end
66
+
67
+ describe "current_era" do
68
+ it "should be 0 by default" do
69
+ expect(@b.current_era).to eq(0)
70
+ end
71
+
72
+ it "should reflect any changes" do
73
+ @b.current_era = 678
74
+ expect(@b.current_era).to eq(678)
75
+ end
76
+
77
+ it "should generate the correct current_era" do
78
+ @b.current_era = 678
79
+ md = @b.generate
80
+ expect(md.superblock.current_era).to eq(678)
81
+ end
82
+ end
83
+
84
+ describe "nr_writesets" do
85
+ it "should be 0 by default" do
86
+ expect(@b.nr_writesets).to eq(0)
87
+ end
88
+
89
+ it "should reflect any changes" do
90
+ @b.nr_writesets = 34
91
+ expect(@b.nr_writesets).to eq(34)
92
+ end
93
+
94
+ it "should generate the correct nr writesets" do
95
+ @b.current_era = 100
96
+ @b.nr_writesets = 34
97
+ md = @b.generate
98
+ expect(md.writesets.size).to eq(34)
99
+ end
100
+
101
+ it "should raise if asked to generate more writesets than eras" do
102
+ @b.nr_writesets = 50
103
+ @b.current_era = 40
104
+ expect do
105
+ @b.generate
106
+ end.to raise_error(RuntimeError)
107
+ end
108
+ end
109
+
110
+ describe "generated metadata" do
111
+ before :each do
112
+ @b.nr_blocks = 1234
113
+ @b.nr_writesets = 50
114
+ @b.current_era = 100
115
+ @md = @b.generate
116
+ end
117
+
118
+ describe "era array" do
119
+ it "should have nr_blocks entries" do
120
+ expect(@md.era_array.size).to eq(@b.nr_blocks)
121
+ end
122
+
123
+ it "should have no value higher than the current era" do
124
+ @md.era_array.each do |era|
125
+ expect(era).to be <= @b.current_era
126
+ end
127
+ end
128
+ end
129
+
130
+ describe "generated writesets" do
131
+ it "should not have an era higher than the current era" do
132
+ @md.writesets.each do |ws|
133
+ expect(ws.era).to be <= @b.current_era
134
+ end
135
+ end
136
+
137
+ it "should not have duplicate eras" do
138
+ seen = Set.new
139
+ @md.writesets.each do |ws|
140
+ expect(seen.member?(ws.era)).to be false
141
+ seen.add(ws.era)
142
+ end
143
+ end
144
+
145
+ it "should have the correct number of bits" do
146
+ @md.writesets.each do |ws|
147
+ expect(ws.bits.size).to eq(@b.nr_blocks)
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
153
+
154
+ #----------------------------------------------------------------
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thinp_xml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Thornber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-13 00:00:00.000000000 Z
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ejt_command_line
@@ -115,6 +115,7 @@ email:
115
115
  executables:
116
116
  - analyse_metadata
117
117
  - cache_xml
118
+ - era_xml
118
119
  - thinp_xml
119
120
  extensions: []
120
121
  extra_rdoc_files: []
@@ -127,9 +128,12 @@ files:
127
128
  - Rakefile
128
129
  - bin/analyse_metadata
129
130
  - bin/cache_xml
131
+ - bin/era_xml
130
132
  - bin/thinp_xml
131
133
  - features/cache_create.feature
132
134
  - features/cache_usage.feature
135
+ - features/era_create.feature
136
+ - features/era_usage.feature
133
137
  - features/step_definitions/thinp_xml.rb
134
138
  - features/support/env.rb
135
139
  - features/thinp_create.feature
@@ -142,6 +146,10 @@ files:
142
146
  - lib/thinp_xml/cache_xml.rb
143
147
  - lib/thinp_xml/distribution.rb
144
148
  - lib/thinp_xml/emitter.rb
149
+ - lib/thinp_xml/era/builder.rb
150
+ - lib/thinp_xml/era/emit.rb
151
+ - lib/thinp_xml/era/metadata.rb
152
+ - lib/thinp_xml/era_xml.rb
145
153
  - lib/thinp_xml/listener.rb
146
154
  - lib/thinp_xml/thinp/analysis.rb
147
155
  - lib/thinp_xml/thinp/builder.rb
@@ -155,6 +163,7 @@ files:
155
163
  - spec/cache_builder_spec.rb
156
164
  - spec/cache_parse_spec.rb
157
165
  - spec/distribution_spec.rb
166
+ - spec/era_builder_spec.rb
158
167
  - thinp_xml.gemspec
159
168
  homepage: ''
160
169
  licenses:
@@ -183,6 +192,8 @@ summary: Thin provisioning xml
183
192
  test_files:
184
193
  - features/cache_create.feature
185
194
  - features/cache_usage.feature
195
+ - features/era_create.feature
196
+ - features/era_usage.feature
186
197
  - features/step_definitions/thinp_xml.rb
187
198
  - features/support/env.rb
188
199
  - features/thinp_create.feature
@@ -191,3 +202,4 @@ test_files:
191
202
  - spec/cache_builder_spec.rb
192
203
  - spec/cache_parse_spec.rb
193
204
  - spec/distribution_spec.rb
205
+ - spec/era_builder_spec.rb