mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Basic MirrorSite
Still need to convert it to threading
This commit is contained in:
parent
54886cb7b0
commit
abda6d784e
3 changed files with 37 additions and 4 deletions
|
@ -65,7 +65,7 @@ Add `require "active_vault"` to config/application.rb and create a `config/initi
|
|||
|
||||
- Strip Download of its resposibilities and delete class
|
||||
- Proper logging
|
||||
- MirrorSite
|
||||
- Convert MirrorSite to use threading
|
||||
- Read metadata via Marcel?
|
||||
- Copy over migration to app via rake task
|
||||
- Add Migrator to copy/move between sites
|
||||
|
|
|
@ -6,7 +6,10 @@ class ActiveVault::Site::MirrorSite < ActiveVault::Site
|
|||
end
|
||||
|
||||
def upload(key, io)
|
||||
perform_across_sites :upload, key, io
|
||||
sites.collect do |site|
|
||||
site.upload key, io
|
||||
io.rewind
|
||||
end
|
||||
end
|
||||
|
||||
def download(key)
|
||||
|
@ -35,10 +38,10 @@ class ActiveVault::Site::MirrorSite < ActiveVault::Site
|
|||
sites.first
|
||||
end
|
||||
|
||||
def perform_across_sites(method, **args)
|
||||
def perform_across_sites(method, *args)
|
||||
# FIXME: Convert to be threaded
|
||||
sites.collect do |site|
|
||||
site.send method, **args
|
||||
site.public_send method, *args
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
30
test/site/mirror_site_test.rb
Normal file
30
test/site/mirror_site_test.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require "tmpdir"
|
||||
require "site/shared_site_tests"
|
||||
|
||||
class ActiveVault::Site::MirrorSiteTest < ActiveSupport::TestCase
|
||||
PRIMARY_DISK_SITE = ActiveVault::Site.configure(:Disk, root: File.join(Dir.tmpdir, "active_vault"))
|
||||
SECONDARY_DISK_SITE = ActiveVault::Site.configure(:Disk, root: File.join(Dir.tmpdir, "active_vault_mirror"))
|
||||
|
||||
SITE = ActiveVault::Site.configure :Mirror, sites: [ PRIMARY_DISK_SITE, SECONDARY_DISK_SITE ]
|
||||
|
||||
include ActiveVault::Site::SharedSiteTests
|
||||
|
||||
test "uploading was done to all sites" do
|
||||
begin
|
||||
key = SecureRandom.base58(24)
|
||||
data = "Something else entirely!"
|
||||
io = StringIO.new(data)
|
||||
@site.upload(key, io)
|
||||
|
||||
assert_equal data, PRIMARY_DISK_SITE.download(key)
|
||||
assert_equal data, SECONDARY_DISK_SITE.download(key)
|
||||
ensure
|
||||
@site.delete key
|
||||
end
|
||||
end
|
||||
|
||||
test "existing in all sites" do
|
||||
assert PRIMARY_DISK_SITE.exist?(FIXTURE_KEY)
|
||||
assert SECONDARY_DISK_SITE.exist?(FIXTURE_KEY)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue