From abda6d784eb0940b352cd28c28a3f3e87757a489 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 5 Jul 2017 18:57:45 +0200 Subject: [PATCH] Basic MirrorSite Still need to convert it to threading --- README.md | 2 +- lib/active_vault/site/mirror_site.rb | 9 ++++++--- test/site/mirror_site_test.rb | 30 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 test/site/mirror_site_test.rb diff --git a/README.md b/README.md index bb6e9c1e34..97101c6099 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/active_vault/site/mirror_site.rb b/lib/active_vault/site/mirror_site.rb index 67d79a2607..62b2f20586 100644 --- a/lib/active_vault/site/mirror_site.rb +++ b/lib/active_vault/site/mirror_site.rb @@ -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 diff --git a/test/site/mirror_site_test.rb b/test/site/mirror_site_test.rb new file mode 100644 index 0000000000..326edb2f9c --- /dev/null +++ b/test/site/mirror_site_test.rb @@ -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