forked from appoxy/simple_record
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to store all clobs on an object as one chunk in s3.
- Loading branch information
Travis Reeder
committed
Dec 22, 2010
1 parent
3615af8
commit 1bb8ec6
Showing
5 changed files
with
169 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,94 @@ | ||
require 'test/unit' | ||
require File.join(File.dirname(__FILE__), "/../lib/simple_record") | ||
require File.join(File.dirname(__FILE__), "./test_helpers") | ||
require File.join(File.dirname(__FILE__), "./test_base") | ||
require_relative "../lib/simple_record" | ||
require_relative "test_helpers" | ||
require_relative "test_base" | ||
require "yaml" | ||
require 'aws' | ||
require 'my_model' | ||
require 'my_child_model' | ||
require 'model_with_enc' | ||
require 'active_support' | ||
require_relative 'my_model' | ||
require_relative 'my_child_model' | ||
require_relative 'model_with_enc' | ||
|
||
# Tests for SimpleRecord | ||
# | ||
|
||
class TestLobs < TestBase | ||
|
||
|
||
def test_blobs | ||
def test_clobs | ||
mm = MyModel.new | ||
|
||
puts mm.clob1.inspect | ||
assert mm.clob1.nil? | ||
mm.name = "whatever" | ||
mm.age = "1" | ||
|
||
mm.name = "whatever" | ||
mm.age = "1" | ||
mm.clob1 = "0" * 2000 | ||
assert SimpleRecord.stats.s3_puts == 0 | ||
puts mm.inspect | ||
mm.save | ||
|
||
assert SimpleRecord.stats.s3_puts == 1 | ||
sleep 2 | ||
|
||
mm.clob1 = "1" * 2000 | ||
mm.clob2 = "2" * 2000 | ||
mm.save | ||
assert SimpleRecord.stats.s3_puts == 3 | ||
|
||
mm2 = MyModel.find(mm.id) | ||
assert mm.id == mm2.id | ||
puts 'mm.clob1=' + mm.clob1.to_s | ||
puts 'mm2.clob1=' + mm2.clob1.to_s | ||
assert mm.clob1 == mm2.clob1 | ||
assert SimpleRecord.stats.s3_puts == 1, "puts is #{SimpleRecord.stats.s3_puts}" | ||
assert SimpleRecord.stats.s3_puts == 3, "puts is #{SimpleRecord.stats.s3_puts}" | ||
assert SimpleRecord.stats.s3_gets == 1, "gets is #{SimpleRecord.stats.s3_gets}" | ||
mm2.clob1 # make sure it doesn't do another get | ||
assert SimpleRecord.stats.s3_gets == 1 | ||
|
||
assert mm.clob2 == mm2.clob2 | ||
assert SimpleRecord.stats.s3_gets == 2 | ||
|
||
mm2.save | ||
|
||
# shouldn't save twice if not dirty | ||
assert SimpleRecord.stats.s3_puts == 1 | ||
assert SimpleRecord.stats.s3_puts == 3 | ||
|
||
end | ||
|
||
def test_single_clob | ||
mm = SingleClobClass.new | ||
|
||
puts mm.clob1.inspect | ||
assert mm.clob1.nil? | ||
|
||
mm.name = "whatever" | ||
mm.clob1 = "0" * 2000 | ||
mm.clob2 = "2" * 2000 | ||
assert SimpleRecord.stats.s3_puts == 0 | ||
puts mm.inspect | ||
mm.save | ||
|
||
assert SimpleRecord.stats.s3_puts == 1 | ||
|
||
sleep 2 | ||
|
||
mm2 = SingleClobClass.find(mm.id) | ||
assert mm.id == mm2.id | ||
puts 'mm.clob1=' + mm.clob1.to_s | ||
puts 'mm2.clob1=' + mm2.clob1.to_s | ||
assert_equal mm.clob1, mm2.clob1 | ||
assert SimpleRecord.stats.s3_puts == 1, "puts is #{SimpleRecord.stats.s3_puts}" | ||
assert SimpleRecord.stats.s3_gets == 1, "gets is #{SimpleRecord.stats.s3_gets}" | ||
mm2.clob1 # make sure it doesn't do another get | ||
assert SimpleRecord.stats.s3_gets == 1 | ||
|
||
assert mm.clob2 == mm2.clob2 | ||
assert SimpleRecord.stats.s3_gets == 1 | ||
|
||
mm2.save | ||
|
||
# shouldn't save twice if not dirty | ||
assert SimpleRecord.stats.s3_puts == 1 | ||
end | ||
|
||
end |