Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3910b4f4
Commit
3910b4f4
authored
Apr 05, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Normalize default object types to file in the file download service
parent
84fee50e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
4 deletions
+57
-4
app/services/geo/file_download_service.rb
app/services/geo/file_download_service.rb
+19
-2
spec/services/geo/file_download_service_spec.rb
spec/services/geo/file_download_service_spec.rb
+38
-2
No files found.
app/services/geo/file_download_service.rb
View file @
3910b4f4
...
...
@@ -3,6 +3,7 @@ module Geo
attr_reader
:object_type
,
:object_db_id
LEASE_TIMEOUT
=
8
.
hours
.
freeze
DEFAULT_OBJECT_TYPES
=
[
:attachment
,
:avatar
,
:file
].
freeze
def
initialize
(
object_type
,
object_db_id
)
@object_type
=
object_type
...
...
@@ -20,10 +21,22 @@ module Geo
private
def
downloader
klass
=
"Gitlab::Geo::
#{
object_type
.
to_s
.
camelize
}
Downloader"
.
constantize
klass
=
downloader_klass_name
.
constantize
klass
.
new
(
object_type
,
object_db_id
)
rescue
NameError
Gitlab
::
Geo
::
FileDownloader
.
new
(
object_type
,
object_db_id
)
log
(
"Unknown file type:
#{
object_type
}
"
)
raise
end
def
downloader_klass_name
klass_name
=
if
DEFAULT_OBJECT_TYPES
.
include?
(
object_type
.
to_sym
)
:file
else
object_type
end
"Gitlab::Geo::
#{
klass_name
.
to_s
.
camelize
}
Downloader"
end
def
try_obtain_lease
...
...
@@ -51,5 +64,9 @@ module Geo
def
lease_key
"file_download_service:
#{
object_type
}
:
#{
object_db_id
}
"
end
def
log
(
message
)
Rails
.
logger
.
info
"
#{
self
.
class
.
name
}
:
#{
message
}
"
end
end
end
spec/services/geo/file_download_service_spec.rb
View file @
3910b4f4
...
...
@@ -57,6 +57,42 @@ describe Geo::FileDownloadService, services: true do
end
end
context
'with an attachment'
do
let
(
:note
)
{
create
(
:note
,
:with_attachment
)
}
let
(
:upload
)
{
Upload
.
find_by
(
model:
note
,
uploader:
'AttachmentUploader'
)
}
subject
{
described_class
.
new
(
:attachment
,
upload
.
id
)
}
it
'downloads the attachment'
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
)
.
to
receive
(
:try_obtain
).
and_return
(
true
)
allow_any_instance_of
(
Gitlab
::
Geo
::
FileTransfer
)
.
to
receive
(
:download_from_primary
).
and_return
(
100
)
expect
{
subject
.
execute
}.
to
change
{
Geo
::
FileRegistry
.
count
}.
by
(
1
)
end
end
context
'with file upload'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:upload
)
{
Upload
.
find_by
(
model:
project
,
uploader:
'FileUploader'
)
}
subject
{
described_class
.
new
(
:file
,
upload
.
id
)
}
before
do
FileUploader
.
new
(
project
).
store!
(
fixture_file_upload
(
Rails
.
root
+
'spec/fixtures/dk.png'
,
'image/png'
))
end
it
'downloads the file'
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
)
.
to
receive
(
:try_obtain
).
and_return
(
true
)
allow_any_instance_of
(
Gitlab
::
Geo
::
FileTransfer
)
.
to
receive
(
:download_from_primary
).
and_return
(
100
)
expect
{
subject
.
execute
}.
to
change
{
Geo
::
FileRegistry
.
count
}.
by
(
1
)
end
end
context
'LFS object'
do
let
(
:lfs_object
)
{
create
(
:lfs_object
)
}
...
...
@@ -73,8 +109,8 @@ describe Geo::FileDownloadService, services: true do
end
context
'bad object type'
do
it
'
does not track transfe
r'
do
expect
{
described_class
.
new
(
:bad
,
1
).
execute
}.
not_to
change
(
Geo
::
FileRegistry
,
:count
)
it
'
raises an erro
r'
do
expect
{
described_class
.
new
(
:bad
,
1
).
execute
}.
to
raise_error
(
NameError
)
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