# # Author:: Jamie Winsor () # Copyright:: 2011, En Masse Entertainment, Inc # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'spec_helper' describe EnMasse::Dragonfly::MogileFS::DataStore do before(:each) do options = { :domain => 'dragonfly-test', :hosts => ['127.0.0.1:7001'] } begin mog = MogileFS::MogileFS.new(options) mog.list_keys('/') rescue MogileFS::UnreachableBackendError pending "You need to start a MogileFS tracker on 127.0.0.1:7001 to test the MogileFS DataStore" rescue MogileFS::Backend::UnregDomainError pending "You need to create a MogileFS domain called 'dragonfly-test' to test the MogileFS DataStore" end @data_store = EnMasse::Dragonfly::MogileFS::DataStore.new(options) @temp_object = Dragonfly::TempObject.new('gollum') end describe "store" do it "should return a unique identifier for each storage" do temp_object2 = Dragonfly::TempObject.new('gollum') @data_store.store(@temp_object).should_not == @data_store.store(temp_object2) end it "should return a unique identifier for each storage even when the first is deleted" do uid1 = @data_store.store(@temp_object) @data_store.destroy(uid1) uid2 = @data_store.store(@temp_object) uid1.should_not == uid2 end it "should allow for passing in options as a second argument" do @data_store.store(@temp_object, :some => :option) end end describe "retrieve" do describe "without meta" do before(:each) do uid = @data_store.store(@temp_object) @obj, @meta = @data_store.retrieve(uid) end it "should retrieve the stored data" do Dragonfly::TempObject.new(@obj).data.should == @temp_object.data end it "should return a meta hash (probably empty)" do @meta.should be_a(Hash) end end describe "when meta is given" do before(:each) do temp_object = Dragonfly::TempObject.new('gollum') @uid = @data_store.store(temp_object, :meta => {:bitrate => '35', :name => 'danny.boy'}) @obj, @meta = @data_store.retrieve(@uid) end it "should return the stored meta" do @meta[:bitrate].should == '35' @meta[:name].should == 'danny.boy' end end it "should raise an exception if the data doesn't exist" do lambda{ @data_store.retrieve('gooble/gubbub') }.should raise_error(Dragonfly::DataStorage::DataNotFound) end end describe "destroy" do it "should destroy the stored data" do uid = @data_store.store(@temp_object) @data_store.destroy(uid) lambda{ @data_store.retrieve(uid) }.should raise_error(Dragonfly::DataStorage::DataNotFound) end end end