masamune 0.17.12 → 0.17.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -3
  3. data/bin/masamune-aws-emr +1 -1
  4. data/bin/masamune-dump +1 -1
  5. data/bin/masamune-hive +1 -1
  6. data/bin/masamune-psql +1 -1
  7. data/bin/masamune-shell +1 -1
  8. data/lib/masamune.rb +1 -1
  9. data/lib/masamune/actions/aws_emr.rb +2 -2
  10. data/lib/masamune/actions/data_flow.rb +10 -10
  11. data/lib/masamune/actions/date_parse.rb +4 -6
  12. data/lib/masamune/actions/execute.rb +3 -3
  13. data/lib/masamune/actions/filesystem.rb +1 -1
  14. data/lib/masamune/actions/hadoop_filesystem.rb +2 -2
  15. data/lib/masamune/actions/hive.rb +5 -5
  16. data/lib/masamune/actions/invoke_parallel.rb +5 -5
  17. data/lib/masamune/actions/postgres.rb +6 -6
  18. data/lib/masamune/actions/postgres_admin.rb +1 -1
  19. data/lib/masamune/actions/s3cmd.rb +3 -3
  20. data/lib/masamune/actions/transform.rb +4 -4
  21. data/lib/masamune/after_initialize_callbacks.rb +4 -4
  22. data/lib/masamune/cached_filesystem.rb +7 -11
  23. data/lib/masamune/commands/aws_emr.rb +12 -12
  24. data/lib/masamune/commands/hadoop_filesystem.rb +8 -8
  25. data/lib/masamune/commands/hadoop_streaming.rb +16 -16
  26. data/lib/masamune/commands/hive.rb +31 -35
  27. data/lib/masamune/commands/postgres.rb +30 -32
  28. data/lib/masamune/commands/postgres_admin.rb +17 -16
  29. data/lib/masamune/commands/postgres_common.rb +1 -1
  30. data/lib/masamune/commands/retry_with_backoff.rb +19 -19
  31. data/lib/masamune/commands/s3cmd.rb +7 -7
  32. data/lib/masamune/commands/shell.rb +25 -38
  33. data/lib/masamune/configuration.rb +8 -9
  34. data/lib/masamune/data_plan/builder.rb +5 -5
  35. data/lib/masamune/data_plan/elem.rb +7 -7
  36. data/lib/masamune/data_plan/engine.rb +12 -15
  37. data/lib/masamune/data_plan/rule.rb +14 -12
  38. data/lib/masamune/data_plan/set.rb +13 -13
  39. data/lib/masamune/environment.rb +3 -3
  40. data/lib/masamune/filesystem.rb +29 -28
  41. data/lib/masamune/helpers/postgres.rb +8 -5
  42. data/lib/masamune/io.rb +2 -2
  43. data/lib/masamune/last_element.rb +3 -3
  44. data/lib/masamune/method_logger.rb +1 -1
  45. data/lib/masamune/schema/catalog.rb +9 -12
  46. data/lib/masamune/schema/column.rb +12 -10
  47. data/lib/masamune/schema/dimension.rb +5 -4
  48. data/lib/masamune/schema/fact.rb +2 -2
  49. data/lib/masamune/schema/map.rb +9 -13
  50. data/lib/masamune/schema/row.rb +3 -2
  51. data/lib/masamune/schema/store.rb +13 -14
  52. data/lib/masamune/schema/table.rb +24 -28
  53. data/lib/masamune/schema/table_reference.rb +7 -7
  54. data/lib/masamune/spec_helper.rb +1 -1
  55. data/lib/masamune/string_format.rb +1 -1
  56. data/lib/masamune/tasks/aws_emr_thor.rb +9 -9
  57. data/lib/masamune/tasks/dump_thor.rb +5 -5
  58. data/lib/masamune/tasks/hive_thor.rb +13 -13
  59. data/lib/masamune/tasks/postgres_thor.rb +8 -8
  60. data/lib/masamune/tasks/shell_thor.rb +3 -3
  61. data/lib/masamune/template.rb +4 -4
  62. data/lib/masamune/thor.rb +26 -25
  63. data/lib/masamune/transform/common/denormalize_table.rb +6 -6
  64. data/lib/masamune/transform/define_table.rb +1 -1
  65. data/lib/masamune/transform/hive/define_table.rb +0 -2
  66. data/lib/masamune/transform/insert_reference_values.rb +1 -1
  67. data/lib/masamune/transform/operator.rb +3 -2
  68. data/lib/masamune/transform/postgres/bulk_upsert.rb +0 -3
  69. data/lib/masamune/transform/postgres/deduplicate_dimension.rb +4 -6
  70. data/lib/masamune/transform/postgres/define_table.rb +2 -2
  71. data/lib/masamune/transform/postgres/insert_reference_values.rb +1 -4
  72. data/lib/masamune/transform/postgres/relabel_dimension.rb +1 -3
  73. data/lib/masamune/transform/postgres/rollup_fact.rb +3 -5
  74. data/lib/masamune/transform/postgres/snapshot_dimension.rb +1 -4
  75. data/lib/masamune/transform/postgres/stage_dimension.rb +8 -10
  76. data/lib/masamune/transform/postgres/stage_fact.rb +15 -14
  77. data/lib/masamune/version.rb +1 -1
  78. data/spec/masamune/actions/aws_emr_spec.rb +8 -8
  79. data/spec/masamune/actions/execute_spec.rb +6 -6
  80. data/spec/masamune/actions/hive_spec.rb +20 -15
  81. data/spec/masamune/actions/postgres_spec.rb +17 -10
  82. data/spec/masamune/after_initialization_callbacks_spec.rb +13 -7
  83. data/spec/masamune/commands/aws_emr_spec.rb +10 -10
  84. data/spec/masamune/commands/hadoop_filesystem_spec.rb +3 -3
  85. data/spec/masamune/commands/hadoop_streaming_spec.rb +4 -4
  86. data/spec/masamune/commands/hive_spec.rb +11 -11
  87. data/spec/masamune/commands/postgres_admin_spec.rb +9 -9
  88. data/spec/masamune/commands/postgres_spec.rb +15 -15
  89. data/spec/masamune/commands/retry_with_backoff_spec.rb +10 -7
  90. data/spec/masamune/commands/s3cmd_spec.rb +3 -3
  91. data/spec/masamune/commands/shell_spec.rb +16 -16
  92. data/spec/masamune/data_plan/builder_spec.rb +22 -19
  93. data/spec/masamune/data_plan/elem_spec.rb +20 -20
  94. data/spec/masamune/data_plan/engine_spec.rb +41 -33
  95. data/spec/masamune/data_plan/rule_spec.rb +19 -19
  96. data/spec/masamune/data_plan/set_spec.rb +8 -6
  97. data/spec/masamune/environment_spec.rb +5 -5
  98. data/spec/masamune/filesystem_spec.rb +87 -87
  99. data/spec/masamune/helpers/postgres_spec.rb +1 -1
  100. data/spec/masamune/rspec/job_fixture_spec.rb +0 -1
  101. data/spec/masamune/schema/catalog_spec.rb +16 -16
  102. data/spec/masamune/schema/column_spec.rb +19 -19
  103. data/spec/masamune/schema/dimension_spec.rb +2 -2
  104. data/spec/masamune/schema/fact_spec.rb +3 -3
  105. data/spec/masamune/schema/map_spec.rb +41 -41
  106. data/spec/masamune/schema/table_spec.rb +16 -16
  107. data/spec/masamune/string_format_spec.rb +7 -7
  108. data/spec/masamune/tasks/dump_thor_spec.rb +6 -6
  109. data/spec/masamune/tasks/hive_thor_spec.rb +2 -2
  110. data/spec/masamune/template_spec.rb +3 -2
  111. data/spec/masamune/thor_spec.rb +8 -8
  112. data/spec/masamune/transform/bulk_upsert.dimension_spec.rb +3 -3
  113. data/spec/masamune/transform/define_table.dimension_spec.rb +3 -3
  114. data/spec/masamune/transform/define_table.fact_spec.rb +5 -5
  115. data/spec/masamune/transform/define_table.table_spec.rb +6 -6
  116. data/spec/masamune/transform/denormalize_table_spec.rb +15 -15
  117. data/spec/masamune/transform/insert_reference_values.dimension_spec.rb +1 -1
  118. data/spec/masamune/transform/load_dimension_spec.rb +1 -1
  119. data/spec/masamune/transform/load_fact_spec.rb +1 -1
  120. data/spec/masamune/transform/rollup_fact_spec.rb +4 -4
  121. data/spec/masamune/transform/stage_dimension_spec.rb +3 -3
  122. data/spec/masamune/transform/stage_fact_spec.rb +4 -4
  123. data/spec/spec_helper.rb +1 -1
  124. data/spec/support/masamune/example_group.rb +2 -2
  125. data/spec/support/masamune/job_example_group.rb +3 -3
  126. data/spec/support/masamune/job_fixture.rb +4 -4
  127. data/spec/support/masamune/mock_command.rb +10 -10
  128. data/spec/support/masamune/mock_delegate.rb +2 -2
  129. data/spec/support/masamune/mock_filesystem.rb +3 -3
  130. data/spec/support/masamune/shared_example_group.rb +14 -16
  131. data/spec/support/masamune/step_example_group.rb +4 -4
  132. data/spec/support/masamune/step_fixture.rb +1 -1
  133. data/spec/support/masamune/task_example_group.rb +1 -1
  134. data/spec/support/masamune/thor_mute.rb +3 -2
  135. data/spec/support/rspec/example/action_example_group.rb +1 -1
  136. data/spec/support/rspec/example/task_example_group.rb +7 -4
  137. data/spec/support/rspec/example/transform_example_group.rb +1 -1
  138. data/spec/support/shared_examples/postgres_common_examples.rb +2 -2
  139. metadata +16 -2
@@ -35,16 +35,14 @@ module Masamune::Transform::Postgres
35
35
  TargetPresenter.new(@target)
36
36
  end
37
37
 
38
- private
39
-
40
38
  class TargetPresenter < SimpleDelegator
41
39
  include Masamune::LastElement
42
40
 
43
41
  def insert_columns(source)
44
42
  shared_columns(source).values.map do |columns|
45
43
  column = columns.first
46
- if reference = column.reference
47
- reference.foreign_key_name
44
+ if column.reference
45
+ column.reference.foreign_key_name
48
46
  else
49
47
  column.name
50
48
  end
@@ -54,8 +52,8 @@ module Masamune::Transform::Postgres
54
52
  def insert_values(source)
55
53
  shared_columns(source).values.map do |columns|
56
54
  column = columns.first
57
- if reference = column.reference
58
- reference.surrogate_key.qualified_name(reference.label)
55
+ if column.reference
56
+ column.reference.surrogate_key.qualified_name(column.reference.label)
59
57
  elsif column.type == :json || column.type == :yaml || column.type == :key_value
60
58
  "json_to_hstore(#{column.qualified_name})"
61
59
  else
@@ -67,10 +65,10 @@ module Masamune::Transform::Postgres
67
65
 
68
66
  def join_conditions(source)
69
67
  join_columns = shared_columns(source).values.flatten
70
- join_columns = join_columns.select { |column| column.reference }
71
- join_columns = join_columns.group_by { |column| column.reference }
68
+ join_columns = join_columns.select(&:reference)
69
+ join_columns = join_columns.group_by(&:reference)
72
70
 
73
- conditions = Hash.new { |h,k| h[k] = Set.new }
71
+ conditions = Hash.new { |h, k| h[k] = Set.new }
74
72
  join_columns.each do |reference, columns|
75
73
  left_uniq = Set.new
76
74
  (columns + lateral_references(source, reference)).each do |column|
@@ -83,7 +81,7 @@ module Masamune::Transform::Postgres
83
81
  end
84
82
 
85
83
  def lateral_references(source, reference)
86
- source.shared_columns(reference).keys.reject { |column| column.auto_reference }
84
+ source.shared_columns(reference).keys.reject(&:auto_reference)
87
85
  end
88
86
  end
89
87
  end
@@ -36,16 +36,14 @@ module Masamune::Transform::Postgres
36
36
  TargetPresenter.new(@target)
37
37
  end
38
38
 
39
- private
40
-
41
39
  class TargetPresenter < SimpleDelegator
42
40
  include Masamune::LastElement
43
41
 
44
42
  def insert_columns(source)
45
43
  shared_columns(source).values.map do |columns|
46
44
  column = columns.first
47
- if reference = column.reference
48
- reference.foreign_key_name
45
+ if column.reference
46
+ column.reference.foreign_key_name
49
47
  else
50
48
  column.name
51
49
  end
@@ -55,8 +53,8 @@ module Masamune::Transform::Postgres
55
53
  def insert_values(source)
56
54
  shared_columns(source).values.map do |columns|
57
55
  column = columns.first
58
- if !column.degenerate? && reference = column.reference
59
- value = reference.surrogate_key.qualified_name(column.reference.label)
56
+ if !column.degenerate? && column.reference
57
+ value = column.reference.surrogate_key.qualified_name(column.reference.label)
60
58
  column.reference.unknown ? "COALESCE(#{value}, #{column.reference.unknown})" : value
61
59
  else
62
60
  column.qualified_name
@@ -71,11 +69,11 @@ module Masamune::Transform::Postgres
71
69
 
72
70
  def join_conditions(source)
73
71
  join_columns = shared_columns(source).values.flatten
74
- join_columns = join_columns.select { |column| column.reference }
75
- join_columns = join_columns.group_by { |column| column.reference }
72
+ join_columns = join_columns.select(&:reference)
73
+ join_columns = join_columns.group_by(&:reference)
76
74
 
77
75
  dependencies = Masamune::TopologicalHash.new
78
- conditions = Hash.new { |h,k| h[k] = OpenStruct.new(type: 'INNER', conditions: []) }
76
+ conditions = Hash.new { |h, k| h[k] = OpenStruct.new(type: 'INNER', conditions: []) }
79
77
  join_columns.each do |reference, columns|
80
78
  reference_name = join_alias(reference)
81
79
  columns.each do |column|
@@ -86,8 +84,8 @@ module Masamune::Transform::Postgres
86
84
  coalesce_values = []
87
85
 
88
86
  if cross_references.any?
89
- dependencies[reference_name] += cross_references.map { |reference, _| join_alias(reference) }
90
- coalesce_values << cross_references.map { |reference, column| column.qualified_name(reference.label) }
87
+ dependencies[reference_name] += cross_references.map { |cross_reference, _| join_alias(cross_reference) }
88
+ coalesce_values << cross_references.map { |cross_reference, cross_column| cross_column.qualified_name(cross_reference.label) }
91
89
  end
92
90
 
93
91
  column.reference.auto_surrogate_keys.each do |auto_surrogate_key|
@@ -101,9 +99,12 @@ module Masamune::Transform::Postgres
101
99
  coalesce_values << column.adjacent.sql_value(column.adjacent.default)
102
100
  end
103
101
 
104
- conditions[reference_name].conditions << (coalesce_values.any? ?
105
- "#{column.foreign_key_name} = COALESCE(#{column.qualified_name}, #{coalesce_values.join(', ')})" :
106
- "#{column.foreign_key_name} = #{column.qualified_name}")
102
+ conditions[reference_name].conditions <<
103
+ if coalesce_values.any?
104
+ "#{column.foreign_key_name} = COALESCE(#{column.qualified_name}, #{coalesce_values.join(', ')})"
105
+ else
106
+ "#{column.foreign_key_name} = #{column.qualified_name}"
107
+ end
107
108
  end
108
109
 
109
110
  if reference.type == :two || reference.type == :four
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Masamune
24
- VERSION = '0.17.12'
24
+ VERSION = '0.17.13'.freeze
25
25
  end
@@ -56,7 +56,7 @@ describe Masamune::Actions::AwsEmr do
56
56
  end
57
57
 
58
58
  describe '.after_initialize' do
59
- let(:options) { {initialize: true} }
59
+ let(:options) { { initialize: true } }
60
60
 
61
61
  subject(:after_initialize_invoke) do
62
62
  instance.after_initialize_invoke(options)
@@ -67,13 +67,13 @@ describe Masamune::Actions::AwsEmr do
67
67
  end
68
68
 
69
69
  context 'when cluster_id is missing' do
70
- let(:configuration) { {enabled: true} }
70
+ let(:configuration) { { enabled: true } }
71
71
  it { expect { subject }.to raise_error Thor::RequiredArgumentMissingError, /No value provided for required options '--cluster-id'/ }
72
72
  end
73
73
 
74
74
  context 'when cluster_id is present without initialize' do
75
- let(:configuration) { {enabled: true} }
76
- let(:options) { {cluster_id: 'j-XYZ'} }
75
+ let(:configuration) { { enabled: true } }
76
+ let(:options) { { cluster_id: 'j-XYZ' } }
77
77
  before do
78
78
  expect(instance).to_not receive(:aws_emr)
79
79
  end
@@ -84,8 +84,8 @@ describe Masamune::Actions::AwsEmr do
84
84
  end
85
85
 
86
86
  context 'when cluster_id does not exist' do
87
- let(:configuration) { {enabled: true} }
88
- let(:options) { {initialize: true, cluster_id: 'j-XYZ'} }
87
+ let(:configuration) { { enabled: true } }
88
+ let(:options) { { initialize: true, cluster_id: 'j-XYZ' } }
89
89
  before do
90
90
  mock_command(/\Aaws emr/, mock_failure)
91
91
  end
@@ -93,8 +93,8 @@ describe Masamune::Actions::AwsEmr do
93
93
  end
94
94
 
95
95
  context 'when cluster_id exists' do
96
- let(:configuration) { {enabled: true} }
97
- let(:options) { {initialize: true, cluster_id: 'j-XYZ'} }
96
+ let(:configuration) { { enabled: true } }
97
+ let(:options) { { initialize: true, cluster_id: 'j-XYZ' } }
98
98
  before do
99
99
  mock_command(/\Aaws emr/, mock_success)
100
100
  end
@@ -27,11 +27,11 @@ describe Masamune::Actions::Execute do
27
27
  include Masamune::Actions::Execute
28
28
 
29
29
  def before_execute
30
- fail
30
+ raise
31
31
  end
32
32
 
33
33
  def after_execute
34
- fail
34
+ raise
35
35
  end
36
36
  end
37
37
  end
@@ -45,21 +45,21 @@ describe Masamune::Actions::Execute do
45
45
 
46
46
  context 'with a simple command' do
47
47
  let(:command) { %w(echo ping) }
48
- let(:options) { {fail_fast: true} }
48
+ let(:options) { { fail_fast: true } }
49
49
 
50
50
  it { expect { |b| instance.execute(*command, options, &b) }.to yield_with_args('ping', 0) }
51
51
  end
52
52
 
53
53
  context 'with a simple command with input' do
54
54
  let(:command) { %w(cat) }
55
- let(:options) { {input: 'pong', fail_fast: true} }
55
+ let(:options) { { input: 'pong', fail_fast: true } }
56
56
 
57
57
  it { expect { |b| instance.execute(*command, options, &b) }.to yield_with_args('pong', 0) }
58
58
  end
59
59
 
60
60
  context 'with a simple command with env' do
61
- let(:command) { %Q(bash -c "echo $MESSAGE") }
62
- let(:options) { {env: { 'MESSAGE' => 'pong' }, fail_fast: true} }
61
+ let(:command) { %(bash -c "echo $MESSAGE") }
62
+ let(:options) { { env: { 'MESSAGE' => 'pong' }, fail_fast: true } }
63
63
 
64
64
  it { expect { |b| instance.execute(*command, options, &b) }.to yield_with_args('pong', 0) }
65
65
  end
@@ -31,7 +31,7 @@ describe Masamune::Actions::Hive do
31
31
 
32
32
  let(:filesystem) { Masamune::MockFilesystem.new }
33
33
  let(:instance) { klass.new }
34
- let(:configuration) { {database: 'test'} }
34
+ let(:configuration) { { database: 'test' } }
35
35
 
36
36
  before do
37
37
  filesystem.add_path(:tmp_dir, File.join(Dir.tmpdir, SecureRandom.hex))
@@ -53,7 +53,7 @@ describe Masamune::Actions::Hive do
53
53
 
54
54
  context 'with cluster_id' do
55
55
  before do
56
- allow(instance).to receive_message_chain(:configuration, :aws_emr).and_return({cluster_id: 'j-XYZ'})
56
+ allow(instance).to receive_message_chain(:configuration, :aws_emr).and_return(cluster_id: 'j-XYZ')
57
57
  mock_command(/\Ahive/, mock_failure)
58
58
  mock_command(/\Aaws emr/, mock_success, StringIO.new('ssh fakehost exit'))
59
59
  mock_command(/\Assh fakehost hive/, mock_success)
@@ -75,8 +75,8 @@ describe Masamune::Actions::Hive do
75
75
  end
76
76
 
77
77
  describe '.after_initialize' do
78
- let(:options) { {initialize: true} }
79
- let(:configuration) { {database: 'test'} }
78
+ let(:options) { { initialize: true } }
79
+ let(:configuration) { { database: 'test' } }
80
80
 
81
81
  subject(:after_initialize_invoke) do
82
82
  instance.after_initialize_invoke(options)
@@ -88,46 +88,51 @@ describe Masamune::Actions::Hive do
88
88
  expect(instance).to_not receive(:hive)
89
89
  after_initialize_invoke
90
90
  end
91
- it 'should not call hive' do; end
91
+ it 'should not call hive' do
92
+ end
92
93
  end
93
94
 
94
95
  context 'with default database' do
95
- let(:configuration) { {database: 'default'} }
96
+ let(:configuration) { { database: 'default' } }
96
97
  before do
97
98
  expect(instance).to receive(:hive).with(exec: an_instance_of(String)).never
98
99
  after_initialize_invoke
99
100
  end
100
- it 'should not call hive with create database' do; end
101
+ it 'should not call hive with create database' do
102
+ end
101
103
  end
102
104
 
103
105
  context 'with database' do
104
106
  before do
105
- expect(instance).to receive(:hive).with(exec: 'CREATE DATABASE IF NOT EXISTS test;', :database => nil).once.and_return(mock_success)
107
+ expect(instance).to receive(:hive).with(exec: 'CREATE DATABASE IF NOT EXISTS test;', database: nil).once.and_return(mock_success)
106
108
  expect(instance).to receive(:hive).with(file: an_instance_of(String)).once.and_return(mock_success)
107
109
  after_initialize_invoke
108
110
  end
109
- it 'should call hive with create database' do; end
111
+ it 'should call hive with create database' do
112
+ end
110
113
  end
111
114
 
112
115
  context 'with location' do
113
- let(:configuration) { {database: 'test', location: '/tmp'} }
116
+ let(:configuration) { { database: 'test', location: '/tmp' } }
114
117
  before do
115
- expect(instance).to receive(:hive).with(exec: 'CREATE DATABASE IF NOT EXISTS test LOCATION "/tmp";', :database => nil).once.and_return(mock_success)
118
+ expect(instance).to receive(:hive).with(exec: 'CREATE DATABASE IF NOT EXISTS test LOCATION "/tmp";', database: nil).once.and_return(mock_success)
116
119
  expect(instance).to receive(:hive).with(file: an_instance_of(String)).once.and_return(mock_success)
117
120
  after_initialize_invoke
118
121
  end
119
- it 'should call hive with create database' do; end
122
+ it 'should call hive with create database' do
123
+ end
120
124
  end
121
125
 
122
126
  context 'with dry_run' do
123
- let(:options) { {initialize: true, dry_run: true} }
127
+ let(:options) { { initialize: true, dry_run: true } }
124
128
  before do
125
- expect(instance).to receive(:hive).with(exec: 'CREATE DATABASE IF NOT EXISTS test;', :database => nil).once.and_return(mock_success)
129
+ expect(instance).to receive(:hive).with(exec: 'CREATE DATABASE IF NOT EXISTS test;', database: nil).once.and_return(mock_success)
126
130
  expect(instance).to receive(:hive).with(file: an_instance_of(String)).once.and_return(mock_success)
127
131
  expect(instance).to receive(:hive).with(exec: 'SHOW TABLES;', safe: true, fail_fast: false).once.and_return(mock_success)
128
132
  after_initialize_invoke
129
133
  end
130
- it 'should call hive with show tables' do; end
134
+ it 'should call hive with show tables' do
135
+ end
131
136
  end
132
137
  end
133
138
  end
@@ -32,7 +32,7 @@ describe Masamune::Actions::Postgres do
32
32
  end
33
33
 
34
34
  let(:instance) { klass.new }
35
- let(:configuration) { {database: 'test'} }
35
+ let(:configuration) { { database: 'test' } }
36
36
  let(:postgres_helper) { double }
37
37
  let(:catalog) { double }
38
38
 
@@ -65,10 +65,10 @@ describe Masamune::Actions::Postgres do
65
65
  end
66
66
 
67
67
  describe '.after_initialize' do
68
- let(:options) { {initialize: true} }
68
+ let(:options) { { initialize: true } }
69
69
  let(:setup_files) { [] }
70
70
  let(:schema_files) { [] }
71
- let(:configuration) { {database: 'test', setup_files: setup_files, schema_files: schema_files} }
71
+ let(:configuration) { { database: 'test', setup_files: setup_files, schema_files: schema_files } }
72
72
 
73
73
  subject(:after_initialize_invoke) do
74
74
  instance.after_initialize_invoke(options)
@@ -81,7 +81,8 @@ describe Masamune::Actions::Postgres do
81
81
  expect(instance).to_not receive(:postgres)
82
82
  after_initialize_invoke
83
83
  end
84
- it 'should not call postgres_admin or postgres' do; end
84
+ it 'should not call postgres_admin or postgres' do
85
+ end
85
86
  end
86
87
 
87
88
  context 'when database does not exist' do
@@ -91,7 +92,8 @@ describe Masamune::Actions::Postgres do
91
92
  expect(instance).to receive(:postgres).with(file: 'catalog.psql', retries: 0).once
92
93
  after_initialize_invoke
93
94
  end
94
- it 'should call posgres_admin once' do; end
95
+ it 'should call posgres_admin once' do
96
+ end
95
97
  end
96
98
 
97
99
  context 'when database exists' do
@@ -101,7 +103,8 @@ describe Masamune::Actions::Postgres do
101
103
  expect(instance).to receive(:postgres).with(file: 'catalog.psql', retries: 0).once
102
104
  after_initialize_invoke
103
105
  end
104
- it 'should not call postgres_admin' do; end
106
+ it 'should not call postgres_admin' do
107
+ end
105
108
  end
106
109
 
107
110
  context 'when setup_files are configured' do
@@ -112,7 +115,8 @@ describe Masamune::Actions::Postgres do
112
115
  expect(instance).to receive(:postgres).with(file: 'catalog.psql', retries: 0).once
113
116
  after_initialize_invoke
114
117
  end
115
- it 'should call postgres with setup_files' do; end
118
+ it 'should call postgres with setup_files' do
119
+ end
116
120
  end
117
121
 
118
122
  context 'when schema_files are configured' do
@@ -123,7 +127,8 @@ describe Masamune::Actions::Postgres do
123
127
  expect(instance).to receive(:postgres).once
124
128
  after_initialize_invoke
125
129
  end
126
- it 'should call postgres with schema_files' do; end
130
+ it 'should call postgres with schema_files' do
131
+ end
127
132
  end
128
133
 
129
134
  context 'when schema_files that are globs are configured' do
@@ -134,7 +139,8 @@ describe Masamune::Actions::Postgres do
134
139
  expect(instance).to receive(:postgres).with(file: 'catalog.psql', retries: 0).once
135
140
  after_initialize_invoke
136
141
  end
137
- it 'should call postgres with schema_files' do; end
142
+ it 'should call postgres with schema_files' do
143
+ end
138
144
  end
139
145
 
140
146
  context 'when ruby schema_files configured' do
@@ -145,7 +151,8 @@ describe Masamune::Actions::Postgres do
145
151
  expect(instance).to receive(:postgres).with(file: 'catalog.psql', retries: 0).once
146
152
  after_initialize_invoke
147
153
  end
148
- it 'should call postgres with schema_files' do; end
154
+ it 'should call postgres with schema_files' do
155
+ end
149
156
  end
150
157
  end
151
158
  end
@@ -26,18 +26,23 @@ describe Masamune::AfterInitializeCallbacks do
26
26
  include Masamune::AfterInitializeCallbacks
27
27
 
28
28
  def first_callback; end
29
+
29
30
  def early_callback; end
31
+
30
32
  def default_callback; end
33
+
31
34
  def unknown_callback; end
35
+
32
36
  def later_callback; end
37
+
33
38
  def final_callback; end
34
39
 
35
- after_initialize(:first) { |o| o.first_callback }
36
- after_initialize(:early) { |o| o.early_callback }
37
- after_initialize(:default) { |o| o.default_callback }
38
- after_initialize(:unknown) { |o| o.unknown_callback }
39
- after_initialize(:later) { |o| o.later_callback }
40
- after_initialize(:final) { |o| o.final_callback}
40
+ after_initialize(:first, &:first_callback)
41
+ after_initialize(:early, &:early_callback)
42
+ after_initialize(:default, &:default_callback)
43
+ after_initialize(:unknown, &:unknown_callback)
44
+ after_initialize(:later, &:later_callback)
45
+ after_initialize(:final, &:final_callback)
41
46
  end
42
47
  end
43
48
 
@@ -54,6 +59,7 @@ describe Masamune::AfterInitializeCallbacks do
54
59
  instance.after_initialize_invoke
55
60
  end
56
61
 
57
- it 'should call callbacks in priority order' do; end
62
+ it 'should call callbacks in priority order' do
63
+ end
58
64
  end
59
65
  end
@@ -37,43 +37,43 @@ describe Masamune::Commands::AwsEmr do
37
37
  it { is_expected.to be_empty }
38
38
 
39
39
  context 'with config file' do
40
- let(:configuration) { {config_file: '/etc/aws/config'} }
41
- it { is_expected.to eq({'AWS_CONFIG_FILE' => '/etc/aws/config'}) }
40
+ let(:configuration) { { config_file: '/etc/aws/config' } }
41
+ it { is_expected.to eq('AWS_CONFIG_FILE' => '/etc/aws/config') }
42
42
  end
43
43
  end
44
44
 
45
45
  describe '#command_args' do
46
46
  subject { instance.command_args }
47
47
 
48
- it { is_expected.to eq(['aws', 'emr', 'ssh']) }
48
+ it { is_expected.to eq(%w(aws emr ssh)) }
49
49
 
50
50
  context 'with --cluster-id j-XYZ' do
51
51
  let(:delegate) { double(command_args: ['hive', '-e', "'show tables;'"]) }
52
52
  let(:attrs) { { config_file: '/etc/aws_config', cluster_id: 'j-XYZ' } }
53
53
 
54
54
  before do
55
- expect(instance).to receive(:execute).with('aws', 'emr', 'ssh', '--cluster-id', 'j-XYZ', '--command', 'exit', {env: {"AWS_CONFIG_FILE"=>"/etc/aws_config"}, fail_fast: true, safe: true}).
56
- and_yield('ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -i /etc/ssh/aws.key hadoop@ec2-10.0.0.1.compute-1.amazonaws.com exit').
57
- and_yield("Warning: Permanently added 'ec2-10.0.0.1.compute-1.amazonaws.com,10.0.0.1' (ECDSA) to the list of known hosts.")
55
+ expect(instance).to receive(:execute).with('aws', 'emr', 'ssh', '--cluster-id', 'j-XYZ', '--command', 'exit', env: { 'AWS_CONFIG_FILE' => '/etc/aws_config' }, fail_fast: true, safe: true)
56
+ .and_yield('ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=10 -i /etc/ssh/aws.key hadoop@ec2-10.0.0.1.compute-1.amazonaws.com exit')
57
+ .and_yield("Warning: Permanently added 'ec2-10.0.0.1.compute-1.amazonaws.com,10.0.0.1' (ECDSA) to the list of known hosts.")
58
58
  end
59
59
 
60
- it { is_expected.to eq(['ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-i', '/etc/ssh/aws.key', 'hadoop@ec2-10.0.0.1.compute-1.amazonaws.com', 'hive' , '-e', "'show tables;'"]) }
60
+ it { is_expected.to eq(['ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ServerAliveInterval=10', '-i', '/etc/ssh/aws.key', 'hadoop@ec2-10.0.0.1.compute-1.amazonaws.com', 'hive', '-e', "'show tables;'"]) }
61
61
  end
62
62
 
63
63
  context 'with action' do
64
- let(:configuration) { { create_cluster: { options: {'--ami-version' => '3.5.0'} } } }
64
+ let(:configuration) { { create_cluster: { options: { '--ami-version' => '3.5.0' } } } }
65
65
  let(:attrs) { { action: 'create-cluster', extra: ['--instance-type', 'm1.large'] } }
66
66
  it { is_expected.to eq(['aws', 'emr', 'create-cluster', '--ami-version', '3.5.0', '--instance-type', 'm1.large']) }
67
67
  end
68
68
 
69
69
  context 'with action and option override (symbolized)' do
70
- let(:configuration) { { create_cluster: { options: {:'--ami-version' => '3.5.0'} } } }
70
+ let(:configuration) { { create_cluster: { options: { :'--ami-version' => '3.5.0' } } } }
71
71
  let(:attrs) { { action: 'create-cluster', extra: ['--ami-version', '4.0.0', '--instance-type', 'm1.large'] } }
72
72
  it { is_expected.to eq(['aws', 'emr', 'create-cluster', '--ami-version', '4.0.0', '--instance-type', 'm1.large']) }
73
73
  end
74
74
 
75
75
  context 'with action and option override (stringified)' do
76
- let(:configuration) { { 'create_cluster' => { 'options' => {'--ami-version' => '3.5.0'} } } }
76
+ let(:configuration) { { 'create_cluster' => { 'options' => { '--ami-version' => '3.5.0' } } } }
77
77
  let(:attrs) { { action: 'create-cluster', extra: ['--ami-version', '4.0.0', '--instance-type', 'm1.large'] } }
78
78
  it { is_expected.to eq(['aws', 'emr', 'create-cluster', '--ami-version', '4.0.0', '--instance-type', 'm1.large']) }
79
79
  end