masamune 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +15 -0
- data/bin/masamune-elastic-mapreduce +4 -0
- data/bin/masamune-hive +4 -0
- data/bin/masamune-psql +4 -0
- data/bin/masamune-shell +4 -0
- data/lib/masamune.rb +56 -0
- data/lib/masamune/accumulate.rb +60 -0
- data/lib/masamune/actions.rb +38 -0
- data/lib/masamune/actions/data_flow.rb +131 -0
- data/lib/masamune/actions/date_parse.rb +75 -0
- data/lib/masamune/actions/elastic_mapreduce.rb +68 -0
- data/lib/masamune/actions/execute.rb +52 -0
- data/lib/masamune/actions/filesystem.rb +37 -0
- data/lib/masamune/actions/hadoop_filesystem.rb +40 -0
- data/lib/masamune/actions/hadoop_streaming.rb +41 -0
- data/lib/masamune/actions/hive.rb +74 -0
- data/lib/masamune/actions/postgres.rb +76 -0
- data/lib/masamune/actions/postgres_admin.rb +34 -0
- data/lib/masamune/actions/s3cmd.rb +44 -0
- data/lib/masamune/actions/transform.rb +89 -0
- data/lib/masamune/after_initialize_callbacks.rb +55 -0
- data/lib/masamune/cached_filesystem.rb +110 -0
- data/lib/masamune/commands.rb +37 -0
- data/lib/masamune/commands/elastic_mapreduce.rb +119 -0
- data/lib/masamune/commands/hadoop_filesystem.rb +57 -0
- data/lib/masamune/commands/hadoop_streaming.rb +116 -0
- data/lib/masamune/commands/hive.rb +178 -0
- data/lib/masamune/commands/interactive.rb +37 -0
- data/lib/masamune/commands/postgres.rb +128 -0
- data/lib/masamune/commands/postgres_admin.rb +72 -0
- data/lib/masamune/commands/postgres_common.rb +33 -0
- data/lib/masamune/commands/retry_with_backoff.rb +60 -0
- data/lib/masamune/commands/s3cmd.rb +70 -0
- data/lib/masamune/commands/shell.rb +202 -0
- data/lib/masamune/configuration.rb +195 -0
- data/lib/masamune/data_plan.rb +31 -0
- data/lib/masamune/data_plan/builder.rb +66 -0
- data/lib/masamune/data_plan/elem.rb +190 -0
- data/lib/masamune/data_plan/engine.rb +162 -0
- data/lib/masamune/data_plan/rule.rb +292 -0
- data/lib/masamune/data_plan/set.rb +176 -0
- data/lib/masamune/environment.rb +164 -0
- data/lib/masamune/filesystem.rb +567 -0
- data/lib/masamune/has_environment.rb +40 -0
- data/lib/masamune/helpers.rb +27 -0
- data/lib/masamune/helpers/postgres.rb +84 -0
- data/lib/masamune/io.rb +33 -0
- data/lib/masamune/last_element.rb +53 -0
- data/lib/masamune/method_logger.rb +41 -0
- data/lib/masamune/multi_io.rb +39 -0
- data/lib/masamune/schema.rb +36 -0
- data/lib/masamune/schema/catalog.rb +233 -0
- data/lib/masamune/schema/column.rb +527 -0
- data/lib/masamune/schema/dimension.rb +133 -0
- data/lib/masamune/schema/event.rb +121 -0
- data/lib/masamune/schema/fact.rb +133 -0
- data/lib/masamune/schema/map.rb +265 -0
- data/lib/masamune/schema/row.rb +133 -0
- data/lib/masamune/schema/store.rb +115 -0
- data/lib/masamune/schema/table.rb +308 -0
- data/lib/masamune/schema/table_reference.rb +76 -0
- data/lib/masamune/spec_helper.rb +23 -0
- data/lib/masamune/string_format.rb +34 -0
- data/lib/masamune/tasks/elastic_mapreduce_thor.rb +60 -0
- data/lib/masamune/tasks/hive_thor.rb +55 -0
- data/lib/masamune/tasks/postgres_thor.rb +47 -0
- data/lib/masamune/tasks/shell_thor.rb +63 -0
- data/lib/masamune/template.rb +77 -0
- data/lib/masamune/thor.rb +186 -0
- data/lib/masamune/thor_loader.rb +38 -0
- data/lib/masamune/topological_hash.rb +34 -0
- data/lib/masamune/transform.rb +47 -0
- data/lib/masamune/transform/bulk_upsert.psql.erb +64 -0
- data/lib/masamune/transform/bulk_upsert.rb +52 -0
- data/lib/masamune/transform/consolidate_dimension.rb +54 -0
- data/lib/masamune/transform/deduplicate_dimension.psql.erb +52 -0
- data/lib/masamune/transform/deduplicate_dimension.rb +53 -0
- data/lib/masamune/transform/define_event_view.hql.erb +51 -0
- data/lib/masamune/transform/define_event_view.rb +60 -0
- data/lib/masamune/transform/define_index.psql.erb +34 -0
- data/lib/masamune/transform/define_schema.hql.erb +23 -0
- data/lib/masamune/transform/define_schema.psql.erb +79 -0
- data/lib/masamune/transform/define_schema.rb +56 -0
- data/lib/masamune/transform/define_table.hql.erb +34 -0
- data/lib/masamune/transform/define_table.psql.erb +95 -0
- data/lib/masamune/transform/define_table.rb +40 -0
- data/lib/masamune/transform/define_unique.psql.erb +30 -0
- data/lib/masamune/transform/insert_reference_values.psql.erb +43 -0
- data/lib/masamune/transform/insert_reference_values.rb +64 -0
- data/lib/masamune/transform/load_dimension.rb +47 -0
- data/lib/masamune/transform/load_fact.rb +45 -0
- data/lib/masamune/transform/operator.rb +96 -0
- data/lib/masamune/transform/relabel_dimension.psql.erb +76 -0
- data/lib/masamune/transform/relabel_dimension.rb +39 -0
- data/lib/masamune/transform/rollup_fact.psql.erb +79 -0
- data/lib/masamune/transform/rollup_fact.rb +149 -0
- data/lib/masamune/transform/snapshot_dimension.psql.erb +75 -0
- data/lib/masamune/transform/snapshot_dimension.rb +74 -0
- data/lib/masamune/transform/stage_dimension.psql.erb +39 -0
- data/lib/masamune/transform/stage_dimension.rb +83 -0
- data/lib/masamune/transform/stage_fact.psql.erb +80 -0
- data/lib/masamune/transform/stage_fact.rb +111 -0
- data/lib/masamune/version.rb +25 -0
- data/spec/fixtures/aggregate.sql.erb +25 -0
- data/spec/fixtures/comment.sql.erb +27 -0
- data/spec/fixtures/invalid.sql.erb +23 -0
- data/spec/fixtures/relative.sql.erb +23 -0
- data/spec/fixtures/simple.sql.erb +28 -0
- data/spec/fixtures/whitespace.sql.erb +30 -0
- data/spec/masamune/actions/elastic_mapreduce_spec.rb +108 -0
- data/spec/masamune/actions/execute_spec.rb +50 -0
- data/spec/masamune/actions/hadoop_filesystem_spec.rb +44 -0
- data/spec/masamune/actions/hadoop_streaming_spec.rb +74 -0
- data/spec/masamune/actions/hive_spec.rb +117 -0
- data/spec/masamune/actions/postgres_admin_spec.rb +58 -0
- data/spec/masamune/actions/postgres_spec.rb +134 -0
- data/spec/masamune/actions/s3cmd_spec.rb +44 -0
- data/spec/masamune/actions/transform_spec.rb +144 -0
- data/spec/masamune/after_initialization_callbacks_spec.rb +61 -0
- data/spec/masamune/cached_filesystem_spec.rb +167 -0
- data/spec/masamune/commands/hadoop_filesystem_spec.rb +50 -0
- data/spec/masamune/commands/hadoop_streaming_spec.rb +106 -0
- data/spec/masamune/commands/hive_spec.rb +117 -0
- data/spec/masamune/commands/postgres_admin_spec.rb +69 -0
- data/spec/masamune/commands/postgres_spec.rb +100 -0
- data/spec/masamune/commands/retry_with_backoff_spec.rb +116 -0
- data/spec/masamune/commands/s3cmd_spec.rb +50 -0
- data/spec/masamune/commands/shell_spec.rb +101 -0
- data/spec/masamune/configuration_spec.rb +102 -0
- data/spec/masamune/data_plan/builder_spec.rb +91 -0
- data/spec/masamune/data_plan/elem_spec.rb +102 -0
- data/spec/masamune/data_plan/engine_spec.rb +356 -0
- data/spec/masamune/data_plan/rule_spec.rb +407 -0
- data/spec/masamune/data_plan/set_spec.rb +517 -0
- data/spec/masamune/environment_spec.rb +65 -0
- data/spec/masamune/filesystem_spec.rb +1421 -0
- data/spec/masamune/helpers/postgres_spec.rb +95 -0
- data/spec/masamune/schema/catalog_spec.rb +613 -0
- data/spec/masamune/schema/column_spec.rb +696 -0
- data/spec/masamune/schema/dimension_spec.rb +137 -0
- data/spec/masamune/schema/event_spec.rb +75 -0
- data/spec/masamune/schema/fact_spec.rb +117 -0
- data/spec/masamune/schema/map_spec.rb +593 -0
- data/spec/masamune/schema/row_spec.rb +28 -0
- data/spec/masamune/schema/store_spec.rb +49 -0
- data/spec/masamune/schema/table_spec.rb +395 -0
- data/spec/masamune/string_format_spec.rb +60 -0
- data/spec/masamune/tasks/elastic_mapreduce_thor_spec.rb +57 -0
- data/spec/masamune/tasks/hive_thor_spec.rb +75 -0
- data/spec/masamune/tasks/postgres_thor_spec.rb +42 -0
- data/spec/masamune/tasks/shell_thor_spec.rb +51 -0
- data/spec/masamune/template_spec.rb +77 -0
- data/spec/masamune/thor_spec.rb +238 -0
- data/spec/masamune/transform/bulk_upsert.dimension_spec.rb +200 -0
- data/spec/masamune/transform/consolidate_dimension_spec.rb +62 -0
- data/spec/masamune/transform/deduplicate_dimension_spec.rb +84 -0
- data/spec/masamune/transform/define_event_view_spec.rb +84 -0
- data/spec/masamune/transform/define_schema_spec.rb +83 -0
- data/spec/masamune/transform/define_table.dimension_spec.rb +306 -0
- data/spec/masamune/transform/define_table.fact_spec.rb +291 -0
- data/spec/masamune/transform/define_table.table_spec.rb +525 -0
- data/spec/masamune/transform/insert_reference_values.dimension_spec.rb +111 -0
- data/spec/masamune/transform/insert_reference_values.fact_spec.rb +149 -0
- data/spec/masamune/transform/load_dimension_spec.rb +76 -0
- data/spec/masamune/transform/load_fact_spec.rb +89 -0
- data/spec/masamune/transform/relabel_dimension_spec.rb +102 -0
- data/spec/masamune/transform/rollup_fact_spec.rb +333 -0
- data/spec/masamune/transform/snapshot_dimension_spec.rb +103 -0
- data/spec/masamune/transform/stage_dimension_spec.rb +115 -0
- data/spec/masamune/transform/stage_fact_spec.rb +204 -0
- data/spec/masamune_spec.rb +32 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/support/masamune/example_group.rb +36 -0
- data/spec/support/masamune/mock_command.rb +99 -0
- data/spec/support/masamune/mock_delegate.rb +51 -0
- data/spec/support/masamune/mock_filesystem.rb +96 -0
- data/spec/support/masamune/thor_mute.rb +35 -0
- data/spec/support/rspec/example/action_example_group.rb +34 -0
- data/spec/support/rspec/example/task_example_group.rb +80 -0
- data/spec/support/rspec/example/transform_example_group.rb +36 -0
- data/spec/support/shared_examples/postgres_common_examples.rb +53 -0
- metadata +462 -0
@@ -0,0 +1,517 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
#
|
3
|
+
# Copyright (c) 2014-2015, VMware, Inc. All Rights Reserved.
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'spec_helper'
|
24
|
+
|
25
|
+
describe Masamune::DataPlan::Set do
|
26
|
+
let(:fs) { Masamune::MockFilesystem.new }
|
27
|
+
let!(:engine) { Masamune::DataPlan::Engine.new }
|
28
|
+
|
29
|
+
let!(:source_rule) { engine.add_source_rule('primary', path: '/log/%Y%m%d.*.log') }
|
30
|
+
let!(:target_rule) { engine.add_target_rule('primary', path: '/table/y=%Y/m=%m/d=%d') }
|
31
|
+
|
32
|
+
before do
|
33
|
+
engine.filesystem = fs
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#missing' do
|
37
|
+
let(:paths) { ['/table/y=2013/m=01/d=01', '/table/y=2013/m=01/d=02', '/table/y=2013/m=01/d=03'] }
|
38
|
+
|
39
|
+
let(:instance) { Masamune::DataPlan::Set.new(target_rule, paths) }
|
40
|
+
|
41
|
+
subject(:missing) do
|
42
|
+
instance.missing
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when all missing' do
|
46
|
+
it { expect(missing.size).to eq(3) }
|
47
|
+
it { expect(missing).to include '/table/y=2013/m=01/d=01' }
|
48
|
+
it { expect(missing).to include '/table/y=2013/m=01/d=02' }
|
49
|
+
it { expect(missing).to include '/table/y=2013/m=01/d=03' }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when files missing' do
|
53
|
+
before do
|
54
|
+
fs.touch!('/table/y=2013/m=01/d=01', '/table/y=2013/m=01/d=02')
|
55
|
+
end
|
56
|
+
it { expect(missing.size).to eq(3) }
|
57
|
+
it { expect(missing).to include '/table/y=2013/m=01/d=01' }
|
58
|
+
it { expect(missing).to include '/table/y=2013/m=01/d=02' }
|
59
|
+
it { expect(missing).to include '/table/y=2013/m=01/d=03' }
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when some missing' do
|
63
|
+
before do
|
64
|
+
fs.touch!('/table/y=2013/m=01/d=01/0000', '/table/y=2013/m=01/d=02/0000')
|
65
|
+
end
|
66
|
+
it { expect(missing.size).to eq(1) }
|
67
|
+
it { expect(missing).to include '/table/y=2013/m=01/d=03' }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when none missing' do
|
71
|
+
before do
|
72
|
+
fs.touch!('/table/y=2013/m=01/d=01/0000', '/table/y=2013/m=01/d=02/0000', '/table/y=2013/m=01/d=03/0000')
|
73
|
+
end
|
74
|
+
it { expect(missing).to be_empty }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#existing' do
|
79
|
+
let(:instance) { Masamune::DataPlan::Set.new(source_rule, paths) }
|
80
|
+
|
81
|
+
subject(:existing) do
|
82
|
+
instance.existing
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'with basic paths' do
|
86
|
+
let(:paths) { ['/log/20130101.random_1.log', '/log/20130102.random_1.log'] }
|
87
|
+
|
88
|
+
context 'when none existing' do
|
89
|
+
it { expect(existing).to be_empty }
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when some existing' do
|
93
|
+
before do
|
94
|
+
fs.touch!('/log/20130101.random_1.log', '/log/20130101.random_2.log')
|
95
|
+
end
|
96
|
+
it { expect(existing.size).to eq(1) }
|
97
|
+
it { expect(existing).to include '/log/20130101.random_1.log' }
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'when all existing' do
|
101
|
+
before do
|
102
|
+
fs.touch!('/log/20130101.random_1.log', '/log/20130101.random_2.log')
|
103
|
+
fs.touch!('/log/20130102.random_1.log', '/log/20130102.random_2.log')
|
104
|
+
end
|
105
|
+
it { expect(existing.size).to eq(2) }
|
106
|
+
it { expect(existing).to include '/log/20130101.random_1.log' }
|
107
|
+
it { expect(existing).to include '/log/20130102.random_1.log' }
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'with wildcard paths' do
|
112
|
+
let(:paths) { ['/log/20130101.*.log', '/log/20130102.*.log'] }
|
113
|
+
|
114
|
+
context 'when none existing' do
|
115
|
+
it { expect(existing).to be_empty }
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'when some existing' do
|
119
|
+
before do
|
120
|
+
fs.touch!('/log/20130101.random_1.log', '/log/20130101.random_2.log')
|
121
|
+
end
|
122
|
+
it { expect(existing.size).to eq(2) }
|
123
|
+
it { expect(existing).to include '/log/20130101.random_1.log' }
|
124
|
+
it { expect(existing).to include '/log/20130101.random_2.log' }
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'when all existing' do
|
128
|
+
before do
|
129
|
+
fs.touch!('/log/20130101.random_1.log', '/log/20130101.random_2.log')
|
130
|
+
fs.touch!('/log/20130102.random_1.log', '/log/20130102.random_2.log')
|
131
|
+
end
|
132
|
+
it { expect(existing.size).to eq(4) }
|
133
|
+
it { expect(existing).to include '/log/20130101.random_1.log' }
|
134
|
+
it { expect(existing).to include '/log/20130101.random_2.log' }
|
135
|
+
it { expect(existing).to include '/log/20130102.random_1.log' }
|
136
|
+
it { expect(existing).to include '/log/20130102.random_2.log' }
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#adjacent' do
|
142
|
+
let(:instance) { Masamune::DataPlan::Set.new(source_rule, paths) }
|
143
|
+
|
144
|
+
subject(:sources) do
|
145
|
+
instance.adjacent
|
146
|
+
end
|
147
|
+
|
148
|
+
subject(:existing) do
|
149
|
+
instance.adjacent.existing
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'with window of 1 time_step' do
|
153
|
+
let(:paths) { ['/log/20130101.*.log'] }
|
154
|
+
|
155
|
+
before do
|
156
|
+
allow(instance.rule).to receive(:window) { 1 }
|
157
|
+
end
|
158
|
+
|
159
|
+
it { expect(sources.size).to eq(3) }
|
160
|
+
it { expect(sources).to include '/log/20121231.*.log' }
|
161
|
+
it { expect(sources).to include '/log/20130101.*.log' }
|
162
|
+
it { expect(sources).to include '/log/20130102.*.log' }
|
163
|
+
|
164
|
+
context 'when none existing' do
|
165
|
+
it { expect(existing).to be_empty }
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'when some existing' do
|
169
|
+
before do
|
170
|
+
fs.touch!('/log/20130101.random_1.log', '/log/20130101.random_2.log')
|
171
|
+
end
|
172
|
+
it { expect(existing.size).to eq(2) }
|
173
|
+
it { expect(existing).to include '/log/20130101.random_1.log' }
|
174
|
+
it { expect(existing).to include '/log/20130101.random_2.log' }
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'when all existing' do
|
178
|
+
before do
|
179
|
+
fs.touch!('/log/20121231.random_1.log', '/log/20121231.random_2.log')
|
180
|
+
fs.touch!('/log/20130101.random_1.log', '/log/20130101.random_2.log')
|
181
|
+
fs.touch!('/log/20130102.random_1.log', '/log/20130102.random_2.log')
|
182
|
+
fs.touch!('/log/20130103.random_1.log', '/log/20130103.random_2.log')
|
183
|
+
end
|
184
|
+
it { expect(existing.size).to eq(6) }
|
185
|
+
it { expect(existing).to include '/log/20121231.random_1.log' }
|
186
|
+
it { expect(existing).to include '/log/20121231.random_2.log' }
|
187
|
+
it { expect(existing).to include '/log/20130101.random_1.log' }
|
188
|
+
it { expect(existing).to include '/log/20130101.random_2.log' }
|
189
|
+
it { expect(existing).to include '/log/20130102.random_1.log' }
|
190
|
+
it { expect(existing).to include '/log/20130102.random_2.log' }
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe '#stale' do
|
196
|
+
context 'when source rule' do
|
197
|
+
let(:paths) { ['/log/20130101.random_1.log', '/log/20130102.random_1.log'] }
|
198
|
+
let(:instance) { Masamune::DataPlan::Set.new(source_rule, paths) }
|
199
|
+
|
200
|
+
subject(:stale_sources) do
|
201
|
+
instance.stale
|
202
|
+
end
|
203
|
+
|
204
|
+
it { expect(stale_sources).to be_empty }
|
205
|
+
end
|
206
|
+
|
207
|
+
let(:paths) { ['/table/y=2013/m=01/d=01', '/table/y=2013/m=01/d=02', '/table/y=2013/m=01/d=03'] }
|
208
|
+
let(:instance) { Masamune::DataPlan::Set.new(target_rule, paths) }
|
209
|
+
let(:past_time) { Time.parse('2013-01-01 09:00:00 +0000') }
|
210
|
+
let(:present_time) { Time.parse('2013-01-01 09:30:00 +0000') }
|
211
|
+
let(:future_time) { Time.parse('2013-01-01 10:00:00 +0000') }
|
212
|
+
|
213
|
+
before do
|
214
|
+
fs.touch!('/log/20130101.random_1.log', '/log/20130101.random_2.log', mtime: past_time)
|
215
|
+
fs.touch!('/log/20130102.random_1.log', '/log/20130102.random_2.log', mtime: past_time)
|
216
|
+
fs.touch!('/log/20130103.random_1.log', '/log/20130103.random_2.log', mtime: past_time)
|
217
|
+
fs.touch!('/table/y=2013/m=01/d=01', '/table/y=2013/m=01/d=02', '/table/y=2013/m=01/d=03', mtime: present_time)
|
218
|
+
end
|
219
|
+
|
220
|
+
subject(:stale_targets) do
|
221
|
+
instance.stale
|
222
|
+
end
|
223
|
+
|
224
|
+
context 'when none stale targets' do
|
225
|
+
it { expect(stale_targets).to be_empty }
|
226
|
+
end
|
227
|
+
|
228
|
+
context 'when some stale targets (first source)' do
|
229
|
+
before do
|
230
|
+
fs.touch!('/log/20130101.random_1.log', mtime: future_time)
|
231
|
+
end
|
232
|
+
|
233
|
+
it { expect(stale_targets.size).to eq(1) }
|
234
|
+
it { expect(stale_targets).to include '/table/y=2013/m=01/d=01' }
|
235
|
+
end
|
236
|
+
|
237
|
+
context 'when some stale targets (second source)' do
|
238
|
+
before do
|
239
|
+
fs.touch!('/log/20130101.random_2.log', mtime: future_time)
|
240
|
+
end
|
241
|
+
|
242
|
+
it { expect(stale_targets.size).to eq(1) }
|
243
|
+
it { expect(stale_targets).to include '/table/y=2013/m=01/d=01' }
|
244
|
+
end
|
245
|
+
|
246
|
+
context 'when some stale targets (tie breaker)' do
|
247
|
+
before do
|
248
|
+
fs.touch!('/log/20130101.random_1.log', mtime: present_time)
|
249
|
+
end
|
250
|
+
|
251
|
+
it { expect(stale_targets.size).to eq(1) }
|
252
|
+
it { expect(stale_targets).to include '/table/y=2013/m=01/d=01' }
|
253
|
+
end
|
254
|
+
|
255
|
+
context 'when all stale targets' do
|
256
|
+
before do
|
257
|
+
fs.touch!('/log/20130101.random_1.log', mtime: future_time)
|
258
|
+
fs.touch!('/log/20130102.random_2.log', mtime: future_time)
|
259
|
+
fs.touch!('/log/20130103.random_1.log', mtime: future_time)
|
260
|
+
fs.touch!('/log/20130103.random_2.log', mtime: future_time)
|
261
|
+
end
|
262
|
+
|
263
|
+
it { expect(stale_targets.size).to eq(3) }
|
264
|
+
it { expect(stale_targets).to include '/table/y=2013/m=01/d=01' }
|
265
|
+
it { expect(stale_targets).to include '/table/y=2013/m=01/d=02' }
|
266
|
+
it { expect(stale_targets).to include '/table/y=2013/m=01/d=03' }
|
267
|
+
end
|
268
|
+
|
269
|
+
context 'when missing source last_modified_at' do
|
270
|
+
before do
|
271
|
+
fs.touch!('/log/20130101.random_1.log', mtime: Masamune::DataPlan::Elem::MISSING_MODIFIED_AT)
|
272
|
+
end
|
273
|
+
|
274
|
+
it { expect(stale_targets).to be_empty }
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
describe '#with_grain' do
|
279
|
+
let(:paths) { ['/table/y=2012/m=12/d=29', '/table/y=2012/m=12/d=30', '/table/y=2012/m=12/d=31',
|
280
|
+
'/table/y=2013/m=01/d=01', '/table/y=2013/m=01/d=02', '/table/y=2013/m=02/d=01', ] }
|
281
|
+
|
282
|
+
let(:instance) { Masamune::DataPlan::Set.new(target_rule, paths) }
|
283
|
+
|
284
|
+
subject(:granular_targets) do
|
285
|
+
instance.with_grain(grain)
|
286
|
+
end
|
287
|
+
|
288
|
+
context 'when :day' do
|
289
|
+
let(:grain) { :day }
|
290
|
+
it 'has 6 items' do
|
291
|
+
expect(subject.size).to eq(6)
|
292
|
+
end
|
293
|
+
it { is_expected.to include '/table/y=2012/m=12/d=29' }
|
294
|
+
it { is_expected.to include '/table/y=2012/m=12/d=30' }
|
295
|
+
it { is_expected.to include '/table/y=2012/m=12/d=31' }
|
296
|
+
it { is_expected.to include '/table/y=2013/m=01/d=01' }
|
297
|
+
it { is_expected.to include '/table/y=2013/m=01/d=02' }
|
298
|
+
it { is_expected.to include '/table/y=2013/m=02/d=01' }
|
299
|
+
end
|
300
|
+
|
301
|
+
context 'when :month' do
|
302
|
+
let(:grain) { :month }
|
303
|
+
it 'has 3 items' do
|
304
|
+
expect(subject.size).to eq(3)
|
305
|
+
end
|
306
|
+
it { is_expected.to include '/table/y=2012/m=12' }
|
307
|
+
it { is_expected.to include '/table/y=2013/m=01' }
|
308
|
+
it { is_expected.to include '/table/y=2013/m=02' }
|
309
|
+
end
|
310
|
+
|
311
|
+
context 'when :year' do
|
312
|
+
let(:grain) { :year }
|
313
|
+
it 'has 2 items' do
|
314
|
+
expect(subject.size).to eq(2)
|
315
|
+
end
|
316
|
+
it { is_expected.to include '/table/y=2012' }
|
317
|
+
it { is_expected.to include '/table/y=2013' }
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
describe '#include?' do
|
322
|
+
let(:instance) { Masamune::DataPlan::Set.new(source_rule, enum) }
|
323
|
+
subject do
|
324
|
+
instance.include?(elem)
|
325
|
+
end
|
326
|
+
|
327
|
+
context 'with basic enum and basic elem' do
|
328
|
+
let(:enum) { ['/log/20130101.random_1.log', '/log/20130102.random_2.log'] }
|
329
|
+
let(:elem) { '/log/20130101.random_1.log' }
|
330
|
+
|
331
|
+
it { is_expected.to eq(true) }
|
332
|
+
end
|
333
|
+
|
334
|
+
context 'with basic enum and wildcard elem' do
|
335
|
+
let(:enum) { ['/log/20130101.random_1.log', '/log/20130102.random_2.log'] }
|
336
|
+
let(:elem) { '/log/20130101.*.log' }
|
337
|
+
|
338
|
+
it { is_expected.to eq(false) }
|
339
|
+
end
|
340
|
+
|
341
|
+
context 'with wildcard enum and wildcard elem' do
|
342
|
+
let(:enum) { ['/log/20130101.*.log', '/log/20130102.*.log'] }
|
343
|
+
let(:elem) { '/log/20130101.*.log' }
|
344
|
+
|
345
|
+
it { is_expected.to eq(true) }
|
346
|
+
end
|
347
|
+
|
348
|
+
context 'with wildcard enum and basic elem' do
|
349
|
+
let(:enum) { ['/log/20130101.*.log', '/log/20130102.*.log'] }
|
350
|
+
let(:elem) { '/log/20130101.random_1.log' }
|
351
|
+
|
352
|
+
it { is_expected.to eq(false) }
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
describe '#incomplete' do
|
357
|
+
let!(:source_rule) { engine.add_source_rule('primary', path: '/log/%Y%m%d.*.log') }
|
358
|
+
let!(:target_rule) { engine.add_target_rule('primary', path: '/table/y=%Y/m=%m') }
|
359
|
+
|
360
|
+
let(:paths) { ['/log/20140101.random_1.log', '/log/20140102.random_1.log', '/log/20140201.random_1.log', '/log/20140202.random_1.log'] }
|
361
|
+
|
362
|
+
let(:instance) { Masamune::DataPlan::Set.new(source_rule, paths) }
|
363
|
+
|
364
|
+
subject(:incomplete) do
|
365
|
+
instance.targets.incomplete
|
366
|
+
end
|
367
|
+
|
368
|
+
context 'when all incomplete' do
|
369
|
+
it { expect(incomplete.size).to eq(2) }
|
370
|
+
it { expect(incomplete).to include '/table/y=2014/m=01' }
|
371
|
+
it { expect(incomplete).to include '/table/y=2014/m=02' }
|
372
|
+
end
|
373
|
+
|
374
|
+
context 'when some incomplete' do
|
375
|
+
before do
|
376
|
+
(1..31).each do |day|
|
377
|
+
fs.touch!('/log/201401%02d.random_1.log' % day)
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
it { expect(incomplete.size).to eq(1) }
|
382
|
+
it { expect(incomplete).to include '/table/y=2014/m=02' }
|
383
|
+
end
|
384
|
+
|
385
|
+
context 'when none incomplete' do
|
386
|
+
before do
|
387
|
+
(1..31).each do |day|
|
388
|
+
fs.touch!('/log/201401%02d.random_1.log' % day)
|
389
|
+
fs.touch!('/log/201402%02d.random_1.log' % day)
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
it { expect(incomplete.size).to eq(0) }
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
describe '#updatable' do
|
398
|
+
let(:paths) { ['/table/y=2013/m=01/d=01', '/table/y=2013/m=01/d=02', '/table/y=2013/m=01/d=03'] }
|
399
|
+
|
400
|
+
let(:instance) { Masamune::DataPlan::Set.new(target_rule, paths) }
|
401
|
+
|
402
|
+
let(:past_time) { Time.parse('2013-01-01 09:00:00 +0000') }
|
403
|
+
let(:present_time) { Time.parse('2013-01-01 09:30:00 +0000') }
|
404
|
+
let(:future_time) { Time.parse('2013-01-01 10:00:00 +0000') }
|
405
|
+
|
406
|
+
subject(:actionable) do
|
407
|
+
instance.actionable
|
408
|
+
end
|
409
|
+
|
410
|
+
subject(:updateable) do
|
411
|
+
instance.updateable
|
412
|
+
end
|
413
|
+
|
414
|
+
context 'when targets are existing' do
|
415
|
+
before do
|
416
|
+
fs.touch!('/table/y=2013/m=01/d=01/0000', '/table/y=2013/m=01/d=02/0000', '/table/y=2013/m=01/d=03/0000', mtime: present_time)
|
417
|
+
end
|
418
|
+
|
419
|
+
context 'when all sources missing' do
|
420
|
+
it 'actionable is equivalent to incomplete' do
|
421
|
+
expect(actionable).to eq(instance.incomplete)
|
422
|
+
end
|
423
|
+
it { expect(updateable).to be_empty }
|
424
|
+
end
|
425
|
+
|
426
|
+
context 'when all sources existing (stale)' do
|
427
|
+
before do
|
428
|
+
fs.touch!('/log/20130101.random_1.log', '/log/20130101.random_2.log', mtime: future_time)
|
429
|
+
fs.touch!('/log/20130102.random_1.log', '/log/20130102.random_2.log', mtime: future_time)
|
430
|
+
fs.touch!('/log/20130103.random_1.log', '/log/20130103.random_2.log', mtime: future_time)
|
431
|
+
end
|
432
|
+
it 'actionable is equivalent to stale' do
|
433
|
+
expect(actionable).to eq(instance.stale)
|
434
|
+
end
|
435
|
+
it { expect(updateable.size).to eq(3) }
|
436
|
+
it { expect(updateable).to include '/table/y=2013/m=01/d=01' }
|
437
|
+
it { expect(updateable).to include '/table/y=2013/m=01/d=02' }
|
438
|
+
it { expect(updateable).to include '/table/y=2013/m=01/d=03' }
|
439
|
+
end
|
440
|
+
|
441
|
+
context 'when all sources existing (fresh)' do
|
442
|
+
before do
|
443
|
+
fs.touch!('/log/20130101.random_1.log', '/log/20130101.random_2.log', mtime: past_time)
|
444
|
+
fs.touch!('/log/20130102.random_1.log', '/log/20130102.random_2.log', mtime: past_time)
|
445
|
+
fs.touch!('/log/20130103.random_1.log', '/log/20130103.random_2.log', mtime: past_time)
|
446
|
+
end
|
447
|
+
it { expect(actionable).to be_empty }
|
448
|
+
it { expect(updateable).to be_empty }
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
context 'when targets are missing' do
|
453
|
+
context 'when all sources missing' do
|
454
|
+
it 'actionable is equivalent to incomplete' do
|
455
|
+
expect(actionable).to eq(instance.incomplete)
|
456
|
+
end
|
457
|
+
it { expect(updateable).to be_empty }
|
458
|
+
end
|
459
|
+
|
460
|
+
context 'when some sources missing' do
|
461
|
+
before do
|
462
|
+
fs.touch!('/log/20130101.random_1.log', '/log/20130101.random_2.log')
|
463
|
+
end
|
464
|
+
it 'actionable is equivalent to missing' do
|
465
|
+
expect(actionable).to eq(instance.missing)
|
466
|
+
end
|
467
|
+
it { expect(updateable.size).to eq(1) }
|
468
|
+
it { expect(updateable).to include '/table/y=2013/m=01/d=01' }
|
469
|
+
end
|
470
|
+
|
471
|
+
context 'when all sources existing' do
|
472
|
+
before do
|
473
|
+
fs.touch!('/log/20130101.random_1.log', '/log/20130101.random_2.log')
|
474
|
+
fs.touch!('/log/20130102.random_1.log', '/log/20130102.random_2.log')
|
475
|
+
fs.touch!('/log/20130103.random_1.log', '/log/20130103.random_2.log')
|
476
|
+
end
|
477
|
+
it 'actionable is equivalent to missing' do
|
478
|
+
expect(actionable).to eq(instance.missing)
|
479
|
+
end
|
480
|
+
it { expect(updateable.size).to eq(3) }
|
481
|
+
it { expect(updateable).to include '/table/y=2013/m=01/d=01' }
|
482
|
+
it { expect(updateable).to include '/table/y=2013/m=01/d=02' }
|
483
|
+
it { expect(updateable).to include '/table/y=2013/m=01/d=03' }
|
484
|
+
end
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
context 'when sets are chained together' do
|
489
|
+
let!(:source_rule) { engine.add_source_rule('primary', path: '/log/%Y%m%d.*.log') }
|
490
|
+
let!(:target_rule) { engine.add_target_rule('primary', path: '/table/y=%Y/m=%m') }
|
491
|
+
|
492
|
+
let(:paths) { ['/log/20140101.random_1.log', '/log/20140102.random_1.log', '/log/20140201.random_1.log', '/log/20140202.random_1.log'] }
|
493
|
+
|
494
|
+
let(:instance) { Masamune::DataPlan::Set.new(source_rule, paths) }
|
495
|
+
|
496
|
+
context 'when sources are missing' do
|
497
|
+
it 'should chain expectedly' do
|
498
|
+
expect(instance.targets.size).to eq(2)
|
499
|
+
expect(instance.targets.sources.existing.size).to eq(0)
|
500
|
+
expect(instance.targets.sources.existing.targets.size).to eq(0)
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
context 'when sources are present' do
|
505
|
+
before do
|
506
|
+
fs.touch!(*paths)
|
507
|
+
end
|
508
|
+
|
509
|
+
it 'should chain expectedly' do
|
510
|
+
expect(instance.targets.size).to eq(2)
|
511
|
+
expect(instance.targets.sources.existing.size).to eq(4)
|
512
|
+
expect(instance.targets.sources.existing.targets.size).to eq(2)
|
513
|
+
expect(instance.targets.sources.existing.targets.sources.existing.size).to eq(4)
|
514
|
+
end
|
515
|
+
end
|
516
|
+
end
|
517
|
+
end
|