idregistry 0.1.0

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.
@@ -0,0 +1,78 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Thread safety tests
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2012 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'test/unit'
38
+ require 'idregistry'
39
+ require 'set'
40
+
41
+
42
+ module IDRegistry
43
+ module Tests # :nodoc:
44
+
45
+ class TestThreads < ::Test::Unit::TestCase # :nodoc:
46
+
47
+
48
+ Class1 = ::Struct.new(:value)
49
+
50
+
51
+ def test_simultaneous_lookup
52
+ counter_ = 0
53
+ objects_ = []
54
+ registry_ = IDRegistry.create do
55
+ add_pattern([:hello, ::Integer]) do |tuple_|
56
+ sleep(0.1)
57
+ counter_ += 1
58
+ Class1.new(tuple_[1])
59
+ end
60
+ end
61
+ ::Array.new(2) do |i_|
62
+ ::Thread.new do
63
+ objects_ << registry_.lookup(:hello, 1)
64
+ end
65
+ end.each do |t_|
66
+ t_.join
67
+ end
68
+ assert_equal(2, counter_)
69
+ assert_equal(2, objects_.size)
70
+ assert_equal(1, registry_.size)
71
+ assert_equal(objects_[0].object_id, objects_[1].object_id)
72
+ end
73
+
74
+
75
+ end
76
+
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: idregistry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Azuma
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-02 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: IDRegistry is a generic object generator and identity map for Ruby.
15
+ email: dazuma@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files:
19
+ - History.rdoc
20
+ - IDRegistry.rdoc
21
+ - README.rdoc
22
+ files:
23
+ - lib/idregistry/configuration.rb
24
+ - lib/idregistry/errors.rb
25
+ - lib/idregistry/middleware.rb
26
+ - lib/idregistry/railtie.rb
27
+ - lib/idregistry/registry.rb
28
+ - lib/idregistry/utils.rb
29
+ - lib/idregistry/version.rb
30
+ - lib/idregistry.rb
31
+ - test/tc_categories.rb
32
+ - test/tc_configuration.rb
33
+ - test/tc_middleware.rb
34
+ - test/tc_misc.rb
35
+ - test/tc_simple_patterns.rb
36
+ - test/tc_threads.rb
37
+ - History.rdoc
38
+ - IDRegistry.rdoc
39
+ - README.rdoc
40
+ - Version
41
+ homepage: http://github.com/dazuma/idregistry
42
+ licenses: []
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 1.8.7
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>'
57
+ - !ruby/object:Gem::Version
58
+ version: 1.3.1
59
+ requirements: []
60
+ rubyforge_project: virtuoso
61
+ rubygems_version: 1.8.24
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: IDRegistry is a generic object generator and identity map for Ruby.
65
+ test_files:
66
+ - test/tc_categories.rb
67
+ - test/tc_configuration.rb
68
+ - test/tc_middleware.rb
69
+ - test/tc_misc.rb
70
+ - test/tc_simple_patterns.rb
71
+ - test/tc_threads.rb