Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wattsworth
/
lumen-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
19ef9cb1
authored
Jun 27, 2016
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
more specs for db_update
parent
299e1659
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
29 deletions
.rspec
app/adapters/db_adapter.rb
app/services/db/update_db.rb
spec/services/db/update_db_spec.rb
.rspec
View file @
19ef9cb1
--color
--require spec_helper
#--format documentation
app/adapters/db_adapter.rb
View file @
19ef9cb1
...
...
@@ -11,14 +11,18 @@ class DbAdapter
def
schema
# rubocop:disable Metrics/MethodLength
dump
=
self
.
class
.
get
(
"
#{
@url
}
/stream/list?extended=1"
)
dump
.
parsed_response
.
map
do
|
entry
|
# TODO: implement global metadata dump, because this is sloooow
dump
=
self
.
class
.
get
(
"
#{
@url
}
/stream/get_metadata?path=
#{
entry
[
0
]
}
"
)
metadata
=
dump
.
parsed_response
[
'config_key__'
]
{
path:
entry
[
0
],
attributes:
{
data_type:
entry
[
1
],
start_time:
entry
[
2
]
||
0
,
end_time:
entry
[
3
]
||
0
,
total_rows:
entry
[
4
],
total_time:
entry
[
5
]
},
metadata:
{}
}
total_time:
entry
[
5
]
}.
merge
(
metadata
)
}
end
end
end
app/services/db/update_db.rb
View file @
19ef9cb1
...
...
@@ -150,11 +150,15 @@ class UpdateDb # rubocop:disable Metrics/ClassLength
def
__build_file
(
folder
:,
entry_group
:,
default_name
:)
base
=
__base_entry
(
entry_group
)
return
unless
base
# corrupt file, don't process
unless
base
# corrupt file, don't process
@warnings
<<
"
#{
entry_group
.
count
}
orphan decimations in
#{
folder
.
name
}
"
return
end
# find or create the file
file
=
folder
.
db_files
.
find_by_path
(
base
[
:path
])
file
||=
DbFile
.
new
(
db_folder:
folder
,
path:
base
[
:path
])
info
=
{
name:
default_name
}.
merge
(
base
[
:metadata
])
# automatically updates the streams for this file
file
.
update_attributes
(
info
)
file
.
save!
__build_decimations
(
file:
file
,
...
...
@@ -168,10 +172,7 @@ class UpdateDb # rubocop:disable Metrics/ClassLength
base_entry
=
entry_group
.
select
{
|
entry
|
entry
[
:path
].
match
(
decimation_tag
).
nil?
}.
first
unless
base_entry
warnings
<<
"Missing base stream for
#{
default_name
}
in
#{
folder
.
name
}
"
return
nil
end
return
nil
unless
base_entry
base_entry
end
...
...
spec/services/db/update_db_spec.rb
View file @
19ef9cb1
...
...
@@ -6,19 +6,21 @@ helper = DbSchemaHelper.new
# a simple schema that could be returned
# from DbAdapater.schema
# folder1
# `- file1_1
# - file1_2
# `- file1_1
: 4 streams
# - file1_2
: 5 streams
# folder2
# '- file2_1
# `- file2_2
# '- file2_1
: 1 stream
# `- file2_2
: 3 streams
simple_db
=
[
helper
.
entry
(
'/folder1/f1_1'
,
metadata:
{
name:
'file1_1'
},
stream_count:
4
),
metadata:
{
name:
'file1_1'
},
stream_count:
3
),
helper
.
entry
(
'/folder1/f1_2'
,
metadata:
{
name:
'file1_2'
},
stream_count:
5
),
helper
.
entry
(
'/folder2/f2_1'
,
metadata:
{
name:
'file2_1'
}),
helper
.
entry
(
'/folder2/f2_2'
,
metadata:
{
name:
'file2_2'
})
helper
.
entry
(
'/folder2/f2_1'
,
metadata:
{
name:
'file2_1'
},
stream_count:
1
),
helper
.
entry
(
'/folder2/f2_2'
,
metadata:
{
name:
'file2_2'
},
stream_count:
3
)
]
describe
'UpdateDb'
do
...
...
@@ -33,6 +35,7 @@ describe 'UpdateDb' do
@service
.
run
(
db_adapter:
adapter
)
@root
=
@db
.
root_folder
end
# simple schema parsing
describe
'given the simple_db schema'
do
it
'builds a root folder'
do
update_with_schema
(
simple_db
)
...
...
@@ -56,7 +59,6 @@ describe 'UpdateDb' do
expect
(
file1
.
db_streams
.
count
).
to
eq
(
4
)
expect
(
file2
.
db_streams
.
count
).
to
eq
(
5
)
end
it
'builds sub-folder2'
do
update_with_schema
(
simple_db
)
folder2
=
@root
.
subfolders
[
1
]
...
...
@@ -67,22 +69,41 @@ describe 'UpdateDb' do
end
end
it
'uses folder info streams if available'
do
schema
=
Array
.
new
(
simple_db
)
schema
<<
helper
.
entry
(
'/folder1/info'
,
metadata:
{
name:
'first'
})
update_with_schema
(
schema
)
folder1
=
@root
.
subfolders
[
0
]
expect
(
folder1
.
name
).
to
eq
(
'first'
)
# decimation handling
describe
'given decimations'
do
it
'adds decimations to files'
do
schema
=
Array
.
new
(
simple_db
)
schema
<<
helper
.
entry
(
'/folder1/f1_1~decim4'
)
schema
<<
helper
.
entry
(
'/folder1/f1_1~decim16'
)
update_with_schema
(
schema
)
folder1
=
@root
.
subfolders
[
0
]
file1
=
folder1
.
db_files
[
0
]
expect
(
file1
.
db_decimations
.
count
).
to
eq
(
2
)
end
it
'ignores orphaned decimations'
do
schema
=
Array
.
new
(
simple_db
)
# no /folder1/f1_3 so this is an orphan decimation
schema
<<
helper
.
entry
(
'/folder1/f1_3~decim4'
)
update_with_schema
(
schema
)
folder1
=
@root
.
subfolders
[
0
]
# expect just 2 files in this folder
expect
(
folder1
.
db_files
.
count
).
to
eq
(
2
)
# and a warning about orphaned decimations
expect
(
@service
.
warnings
.
count
).
to
eq
(
1
)
end
end
it
'adds decimations to files'
do
schema
=
Array
.
new
(
simple_db
)
schema
<<
helper
.
entry
(
'/folder1/f1_1~decim4'
)
schema
<<
helper
.
entry
(
'/folder1/f1_1~decim16'
)
update_with_schema
(
schema
)
folder1
=
@root
.
subfolders
[
0
]
file1
=
folder1
.
db_files
[
0
]
expect
(
file1
.
db_decimations
.
count
).
to
eq
(
2
)
# info streams and metadata
describe
'given info streams'
do
it
'uses info stream to set folder data'
do
schema
=
Array
.
new
(
simple_db
)
schema
<<
helper
.
entry
(
'/folder1/info'
,
metadata:
{
name:
'first'
})
update_with_schema
(
schema
)
folder1
=
@root
.
subfolders
[
0
]
expect
(
folder1
.
name
).
to
eq
(
'first'
)
end
it
'reads metadata from base file'
it
'reads metadata from decimations'
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment