odba 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +5 -1
- data/lib/odba.rb +1 -1
- data/lib/odba/18_19_loading_compatibility.rb +11 -5
- data/lib/odba/cache.rb +9 -7
- data/lib/odba/persistable.rb +8 -2
- data/test/test_cache.rb +38 -8
- data/test/test_stub.rb +3 -0
- metadata +4 -4
    
        data/History.txt
    CHANGED
    
    | @@ -1,4 +1,8 @@ | |
| 1 | 
            -
            === 1.0. | 
| 1 | 
            +
            === 1.0.2 / 09.12.2011
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            * Updated cache.rb persitatble.rb 18_19_loading_compatibility.rb to be compatible for both Ruby 1.8 and 1.9
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            === 1.0.1 / 08.12.2011
         | 
| 2 6 |  | 
| 3 7 | 
             
            * Added file lock exclusive control to create a new odba_id between processes.
         | 
| 4 8 |  | 
    
        data/lib/odba.rb
    CHANGED
    
    
| @@ -1,4 +1,6 @@ | |
| 1 1 | 
             
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            # encoding: utf-8
         | 
| 3 | 
            +
            # 18_19_loading_compatibility -- odba -- 09.12.2011 -- mhatakeyama@ywesee.com
         | 
| 2 4 |  | 
| 3 5 | 
             
            require 'date'
         | 
| 4 6 | 
             
            require 'strscan'
         | 
| @@ -28,17 +30,21 @@ if RUBY_VERSION >= '1.9' | |
| 28 30 | 
             
                      a.push Marshal.load(dump)
         | 
| 29 31 | 
             
                    end
         | 
| 30 32 | 
             
                  end
         | 
| 31 | 
            -
             | 
| 32 33 | 
             
                  ajd = of = sg = 0
         | 
| 33 34 | 
             
                  if a.size == 3
         | 
| 34 35 | 
             
                    num, den, sg = a
         | 
| 35 | 
            -
                     | 
| 36 | 
            -
             | 
| 36 | 
            +
                    if den > 0
         | 
| 37 | 
            +
                      ajd = Rational(num,den)
         | 
| 38 | 
            +
                      ajd -= 1.to_r/2
         | 
| 39 | 
            +
                    end
         | 
| 37 40 | 
             
                  else
         | 
| 38 41 | 
             
                    num, den, of, sg = a
         | 
| 39 | 
            -
                     | 
| 42 | 
            +
                    if den > 0
         | 
| 43 | 
            +
                      ajd = Rational(num,den)
         | 
| 44 | 
            +
                    end
         | 
| 40 45 | 
             
                  end
         | 
| 41 | 
            -
                   | 
| 46 | 
            +
                  ajd += 1.to_r/2
         | 
| 47 | 
            +
                  jd(ajd)
         | 
| 42 48 | 
             
                end
         | 
| 43 49 | 
             
              end
         | 
| 44 50 | 
             
              class Encoding
         | 
    
        data/lib/odba/cache.rb
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            #!/usr/bin/env ruby
         | 
| 2 2 | 
             
            # encoding: utf-8
         | 
| 3 | 
            -
            # ODBA::Cache -- odba --  | 
| 3 | 
            +
            # ODBA::Cache -- odba -- 09.12.2011 -- mhatakeyama@ywesee.com
         | 
| 4 4 | 
             
            # ODBA::Cache -- odba -- 29.04.2004 -- hwyss@ywesee.com rwaltert@ywesee.com mwalder@ywesee.com
         | 
| 5 5 |  | 
| 6 6 | 
             
            require 'singleton'
         | 
| @@ -97,12 +97,14 @@ module ODBA | |
| 97 97 | 
             
                  end
         | 
| 98 98 | 
             
                  counter = 0
         | 
| 99 99 | 
             
                  cutoff = offset + @cleaner_step
         | 
| 100 | 
            -
                   | 
| 101 | 
            -
                     | 
| 102 | 
            -
             | 
| 103 | 
            -
                       | 
| 104 | 
            -
             | 
| 105 | 
            -
             | 
| 100 | 
            +
                  @cache_mutex.synchronize {
         | 
| 101 | 
            +
                    holder.each_value { |value|
         | 
| 102 | 
            +
                      counter += 1
         | 
| 103 | 
            +
                      if(counter > offset && value.odba_old?(retire_time))
         | 
| 104 | 
            +
                        value.odba_retire && @cleaned += 1
         | 
| 105 | 
            +
                      end
         | 
| 106 | 
            +
                      return cutoff if(counter > cutoff)
         | 
| 107 | 
            +
                    }
         | 
| 106 108 | 
             
                  }
         | 
| 107 109 | 
             
                  cutoff 
         | 
| 108 110 | 
             
                # every once in a while we'll get a 'hash modified during iteration'-Error.
         | 
    
        data/lib/odba/persistable.rb
    CHANGED
    
    | @@ -1,5 +1,7 @@ | |
| 1 1 | 
             
            #!/usr/bin/env ruby
         | 
| 2 | 
            -
             | 
| 2 | 
            +
            # encoding: utf-8
         | 
| 3 | 
            +
            # ODBA::Persistable -- odba -- 09.12.2011 -- mhatakeyama@ywesee.com
         | 
| 4 | 
            +
            # ODBA::Persistable -- odba -- 29.04.2004 -- hwyss@ywesee.com rwaltert@ywesee.com mwalder@ywesee.com
         | 
| 3 5 |  | 
| 4 6 | 
             
            class Object # :nodoc: all
         | 
| 5 7 | 
             
            	def odba_id
         | 
| @@ -325,7 +327,11 @@ module ODBA | |
| 325 327 | 
             
            			odba_serializables.each { |name|
         | 
| 326 328 | 
             
            				var = instance_variable_get(name)
         | 
| 327 329 | 
             
            				if(var.is_a?(ODBA::Stub))
         | 
| 328 | 
            -
             | 
| 330 | 
            +
                      if RUBY_VERSION > "1.9"
         | 
| 331 | 
            +
            					  instance_variable_set(name, var)
         | 
| 332 | 
            +
                      else
         | 
| 333 | 
            +
            					  instance_variable_set(name, var.odba_instance)
         | 
| 334 | 
            +
                      end
         | 
| 329 335 | 
             
            				end
         | 
| 330 336 | 
             
            			}
         | 
| 331 337 | 
             
            		end
         | 
    
        data/test/test_cache.rb
    CHANGED
    
    | @@ -1,4 +1,6 @@ | |
| 1 1 | 
             
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            # encoding: utf-8
         | 
| 3 | 
            +
            # ODBA::TestCache -- odba -- 08.12.2011 -- mhatakeyama@ywesee.com
         | 
| 2 4 |  | 
| 3 5 | 
             
            $: << File.dirname(__FILE__)
         | 
| 4 6 | 
             
            $: << File.expand_path('../lib/', File.dirname(__FILE__))
         | 
| @@ -597,32 +599,37 @@ module ODBA | |
| 597 599 | 
             
                  @storage.should_receive(:store).with(1,'dump1',nil,nil,Object)\
         | 
| 598 600 | 
             
                    .times(1).and_return { assert(true) }
         | 
| 599 601 | 
             
                  @storage.should_receive(:ensure_object_connections)\
         | 
| 600 | 
            -
                    .with( | 
| 602 | 
            +
                    .with(Integer,Array).times(1).and_return { assert(true) }
         | 
| 601 603 |  | 
| 602 604 | 
             
                  ## store o2
         | 
| 603 | 
            -
                  @storage.should_receive(:restore_collection).with( | 
| 605 | 
            +
                  @storage.should_receive(:restore_collection).with(Integer)\
         | 
| 604 606 | 
             
                    .times(1).and_return([])
         | 
| 605 607 | 
             
                  @storage.should_receive(:store)\
         | 
| 606 | 
            -
                    .with( | 
| 608 | 
            +
                    .with(Integer,String,'name2',nil,Object)\
         | 
| 607 609 | 
             
                    .times(1).and_return { assert(true) }
         | 
| 608 610 | 
             
                  @storage.should_receive(:ensure_object_connections)\
         | 
| 609 | 
            -
                    .with( | 
| 611 | 
            +
                    .with(Integer,Array).times(1).and_return { assert(true) }
         | 
| 610 612 |  | 
| 611 613 | 
             
                  ## store o3 and raise
         | 
| 612 | 
            -
                  @storage.should_receive(:restore_collection).with( | 
| 614 | 
            +
                  @storage.should_receive(:restore_collection).with(Integer)\
         | 
| 613 615 | 
             
                    .times(1).and_return([])
         | 
| 614 616 | 
             
                  ## at this stage 1 and 2 (and 'name2') are stored:
         | 
| 615 617 | 
             
                  @storage.should_receive(:store)\
         | 
| 616 | 
            -
                    .with( | 
| 618 | 
            +
                    .with(Integer,String,nil,nil,Object)\
         | 
| 617 619 | 
             
                    .times(1).and_return { raise "trigger rollback" }
         | 
| 618 620 |  | 
| 619 621 | 
             
                  ## rollback
         | 
| 620 | 
            -
                  @storage.should_receive(:restore).with( | 
| 622 | 
            +
                  @storage.should_receive(:restore).with(Integer)\
         | 
| 621 623 | 
             
                    .times(1).and_return(nil)
         | 
| 622 624 | 
             
                  @storage.should_receive(:restore).with(1)\
         | 
| 623 625 | 
             
                    .times(1).and_return('dump1')
         | 
| 624 | 
            -
                  @storage.should_receive(:restore_collection).with( | 
| 626 | 
            +
                  @storage.should_receive(:restore_collection).with(Integer)\
         | 
| 625 627 | 
             
                    .times(2).and_return([])
         | 
| 628 | 
            +
                  dbi = flexmock('dbi', :dbi_args => ['dbi_args'])
         | 
| 629 | 
            +
                  flexmock(@storage, 
         | 
| 630 | 
            +
                           :dbi => dbi,
         | 
| 631 | 
            +
                           :update_max_id => 123
         | 
| 632 | 
            +
                          )
         | 
| 626 633 | 
             
                  @marshal.should_receive(:load).with('dump1')\
         | 
| 627 634 | 
             
                    .times(1).and_return(o4)
         | 
| 628 635 | 
             
                  @cache.fetched.store(1, ODBA::CacheEntry.new(o1))
         | 
| @@ -720,6 +727,29 @@ module ODBA | |
| 720 727 | 
             
                  @cache.instance_variable_set('@deferred_indices', [df1, df2])
         | 
| 721 728 | 
             
                  @cache.setup
         | 
| 722 729 | 
             
            			@cache.instance_variable_set('@indices', {})
         | 
| 730 | 
            +
                end
         | 
| 731 | 
            +
                def test_lock
         | 
| 732 | 
            +
                  result = ""
         | 
| 733 | 
            +
                  th = Thread.new do
         | 
| 734 | 
            +
                    sleep 1
         | 
| 735 | 
            +
                    @cache.lock('testcase') do
         | 
| 736 | 
            +
                      result << '123'
         | 
| 737 | 
            +
                    end
         | 
| 738 | 
            +
                  end
         | 
| 739 | 
            +
                  @cache.lock('testcase') do
         | 
| 740 | 
            +
                    result << '456'
         | 
| 741 | 
            +
                  end
         | 
| 742 | 
            +
                  th.join
         | 
| 743 | 
            +
                  expected = '456123'
         | 
| 744 | 
            +
                  assert_equal(expected, result)
         | 
| 745 | 
            +
                end
         | 
| 746 | 
            +
                def test_new_id
         | 
| 747 | 
            +
                  flexmock(File, :exist? => false)
         | 
| 748 | 
            +
                  storage = flexmock('storage',
         | 
| 749 | 
            +
                                     :max_id => 123,
         | 
| 750 | 
            +
                                     :update_max_id => nil
         | 
| 751 | 
            +
                                    )
         | 
| 752 | 
            +
                  assert_equal(124, @cache.new_id('testcase', storage))
         | 
| 723 753 | 
             
                end
         | 
| 724 754 | 
             
            	end
         | 
| 725 755 | 
             
            end
         | 
    
        data/test/test_stub.rb
    CHANGED
    
    | @@ -1,4 +1,6 @@ | |
| 1 1 | 
             
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
            # encoding: utf-8
         | 
| 3 | 
            +
            # ODBA::TestStub -- odba -- 08.12.2011 -- mhatakeyama@ywesee.com
         | 
| 2 4 |  | 
| 3 5 | 
             
            $: << File.expand_path('../lib/', File.dirname(__FILE__))
         | 
| 4 6 | 
             
            $: << File.dirname(__FILE__)
         | 
| @@ -193,6 +195,7 @@ module ODBA | |
| 193 195 | 
             
            			assert_nil(hash[other])
         | 
| 194 196 | 
             
            		end
         | 
| 195 197 | 
             
            		def test_to_yaml
         | 
| 198 | 
            +
                  flexmock(@cache, :fetch => nil)
         | 
| 196 199 | 
             
            			yaml = ''
         | 
| 197 200 | 
             
            			assert_nothing_raised {
         | 
| 198 201 | 
             
            				yaml = @stub.odba_isolated_stub.to_yaml
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: odba
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 19
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 1
         | 
| 8 8 | 
             
              - 0
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 1.0. | 
| 9 | 
            +
              - 2
         | 
| 10 | 
            +
              version: 1.0.2
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Masaomi Hatakeyama, Zeno R.R. Davatz
         | 
| @@ -15,7 +15,7 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2011-12- | 
| 18 | 
            +
            date: 2011-12-09 00:00:00 +01:00
         | 
| 19 19 | 
             
            default_executable: 
         | 
| 20 20 | 
             
            dependencies: 
         | 
| 21 21 | 
             
            - !ruby/object:Gem::Dependency 
         |