torquebox-cache 2.0.3-java → 2.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,31 @@
1
+ #
2
+ # Copyright 2012 Red Hat, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require File.dirname(__FILE__) + '/spec_helper'
18
+ require 'gem_hook'
19
+
20
+ describe 'torquebox-cache gem_hook.rb with ' do
21
+ it "should not load torque_box_store.rb if ActiveSupport is unavailable" do
22
+ lambda { ActiveSupport::Cache::TorqueBoxStore.should raise_error(NameError) }
23
+ end
24
+
25
+ it "should load torque_box_store.rb if ActiveSupport is available" do
26
+ module ActiveSupport ; end
27
+ load 'gem_hook.rb'
28
+ lambda { ActiveSupport::Cache::TorqueBoxStore.should_not raise_error(NameError) }
29
+ end
30
+ end
31
+
data/spec/spec_helper.rb CHANGED
@@ -14,15 +14,8 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
- require 'dm-core/spec/shared/adapter_spec'
18
- require 'dm-core/spec/lib/pending_helpers'
19
- require 'datamapper/dm-infinispan-adapter'
20
17
  require 'cache'
21
18
 
22
- RSpec::Runner.configure do |config|
23
- config.include(DataMapper::Spec::PendingHelpers)
24
- end
25
-
26
19
  def random_string( length = 20 )
27
20
  chars = ('a'..'z').to_a + ('A'..'Z').to_a
28
21
  dir_string = (0...length).collect { chars[Kernel.rand(chars.length)] }.join
@@ -9,6 +9,10 @@ TORQUEBOX_APP_NAME = 'active-support-unit-test'
9
9
  describe ActiveSupport::Cache::TorqueBoxStore do
10
10
 
11
11
  before(:each) do
12
+ manager = org.infinispan.manager.DefaultCacheManager.new
13
+ service = org.projectodd.polyglot.cache.as.CacheService.new
14
+ service.stub!(:cache_container).and_return( manager )
15
+ TorqueBox::ServiceRegistry.stub!(:[]).with(org.projectodd.polyglot.cache.as.CacheService::CACHE).and_return( service )
12
16
  TorqueBox::ServiceRegistry.service_registry = nil
13
17
  @cache = ActiveSupport::Cache::TorqueBoxStore.new()
14
18
  end
@@ -169,6 +173,10 @@ describe ActiveSupport::Cache::TorqueBoxStore do
169
173
  @cache.read_multi("john", "paul").should == {"john" => "guitar", "paul" => "bass"}
170
174
  end
171
175
 
176
+ it "should default to local mode" do
177
+ @cache.clustering_mode.should == CacheMode::LOCAL
178
+ end
179
+
172
180
  end
173
181
 
174
182
  describe "advanced" do
@@ -189,32 +197,14 @@ describe ActiveSupport::Cache::TorqueBoxStore do
189
197
 
190
198
  end
191
199
 
192
- describe "clustering" do
193
-
194
- it "should default to invalidation mode" do
195
- @cache.clustering_mode.should == CacheMode::INVALIDATION_SYNC
196
- TorqueBoxStore.new(:mode => :unknown).clustering_mode.should == CacheMode::INVALIDATION_SYNC
197
- end
198
-
199
- [:repl, :dist, :invalidation].each do |mode|
200
- it "should be configurable in #{mode} mode" do
201
- TorqueBoxStore.new(:mode => mode).clustering_mode.to_s.should == "#{mode.to_s.upcase}_SYNC"
202
- TorqueBoxStore.new(:name => 'async', :mode => mode, :sync => false).clustering_mode.to_s.should == "#{mode.to_s.upcase}_ASYNC"
203
- end
200
+ describe "options when not clustered" do
201
+ it "should default to :local mode" do
202
+ TorqueBoxStore.new.clustering_mode.to_s.should == "LOCAL"
204
203
  end
205
-
206
- it "should support replicated mode" do
207
- [:r, :repl, :replicated, :replication].each do |mode|
208
- TorqueBoxStore.new(:mode => mode).clustering_mode.should be_replicated
209
- end
210
- end
211
-
212
- it "should support distributed mode" do
213
- [:d, :dist, :distributed, :distribution].each do |mode|
214
- TorqueBoxStore.new(:mode => mode).clustering_mode.should be_distributed
215
- end
204
+
205
+ it "should not fail if set to a clustered mode" do
206
+ TorqueBoxStore.new( :mode => :repl ).clustering_mode.to_s.should == "LOCAL"
216
207
  end
217
-
218
208
  end
219
209
 
220
210
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: torquebox-cache
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.0.3
5
+ version: 2.1.0
6
6
  platform: java
7
7
  authors:
8
8
  - The TorqueBox Team
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-04 00:00:00 Z
13
+ date: 2012-07-26 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - "="
44
44
  - !ruby/object:Gem::Version
45
- version: 2.0.3
45
+ version: 2.1.0
46
46
  type: :runtime
47
47
  version_requirements: *id003
48
48
  - !ruby/object:Gem::Dependency
@@ -53,53 +53,31 @@ dependencies:
53
53
  requirements:
54
54
  - - "="
55
55
  - !ruby/object:Gem::Version
56
- version: 2.0.3
56
+ version: 2.1.0
57
57
  type: :runtime
58
58
  version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: dm-serializer
61
- prerelease: false
62
- requirement: &id005 !ruby/object:Gem::Requirement
63
- none: false
64
- requirements:
65
- - - "="
66
- - !ruby/object:Gem::Version
67
- version: 1.1.0
68
- type: :development
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
71
- name: dm-core
72
- prerelease: false
73
- requirement: &id006 !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - "="
77
- - !ruby/object:Gem::Version
78
- version: 1.1.0
79
- type: :development
80
- version_requirements: *id006
81
59
  - !ruby/object:Gem::Dependency
82
60
  name: json
83
61
  prerelease: false
84
- requirement: &id007 !ruby/object:Gem::Requirement
62
+ requirement: &id005 !ruby/object:Gem::Requirement
85
63
  none: false
86
64
  requirements:
87
65
  - - "="
88
66
  - !ruby/object:Gem::Version
89
67
  version: 1.4.6
90
68
  type: :development
91
- version_requirements: *id007
69
+ version_requirements: *id005
92
70
  - !ruby/object:Gem::Dependency
93
71
  name: rspec
94
72
  prerelease: false
95
- requirement: &id008 !ruby/object:Gem::Requirement
73
+ requirement: &id006 !ruby/object:Gem::Requirement
96
74
  none: false
97
75
  requirements:
98
76
  - - "="
99
77
  - !ruby/object:Gem::Version
100
78
  version: 2.7.0
101
79
  type: :development
102
- version_requirements: *id008
80
+ version_requirements: *id006
103
81
  description: ""
104
82
  email:
105
83
  - torquebox-dev@torquebox.org
@@ -113,20 +91,19 @@ files:
113
91
  - licenses/lgpl-2.1.txt
114
92
  - lib/torquebox-cache.jar
115
93
  - lib/torquebox-cache.rb
116
- - lib/cache.rb
94
+ - lib/polyglot-cache-1.7.1.jar
95
+ - lib/polyglot-core-1.7.1.jar
117
96
  - lib/gem_hook.rb
118
- - lib/dm-infinispan-adapter.rb
97
+ - lib/cache.rb
119
98
  - lib/cache_listener.rb
120
- - lib/datamapper/model.rb
121
- - lib/datamapper/dm-infinispan-adapter.rb
122
- - lib/datamapper/search.rb
99
+ - lib/sequence.rb
123
100
  - lib/active_support/cache/torque_box_store.rb
101
+ - spec/cache_listener_spec.rb
124
102
  - spec/spec_helper.rb
103
+ - spec/cache_spec.rb
104
+ - spec/gem_hook_spec.rb
125
105
  - spec/spec.opts
126
- - spec/cache_listener_spec.rb
127
106
  - spec/torque_box_store_spec.rb
128
- - spec/dm-infinispan-adapter_spec.rb
129
- - spec/cache_spec.rb
130
107
  homepage: http://torquebox.org/
131
108
  licenses:
132
109
  - lgpl
@@ -156,6 +133,6 @@ specification_version: 3
156
133
  summary: TorqueBox Cache Gem
157
134
  test_files:
158
135
  - spec/cache_listener_spec.rb
159
- - spec/torque_box_store_spec.rb
160
- - spec/dm-infinispan-adapter_spec.rb
161
136
  - spec/cache_spec.rb
137
+ - spec/gem_hook_spec.rb
138
+ - spec/torque_box_store_spec.rb
@@ -1,129 +0,0 @@
1
- # Copyright 2008-2012 Red Hat, Inc, and individual contributors.
2
- #
3
- # This is free software; you can redistribute it and/or modify it
4
- # under the terms of the GNU Lesser General Public License as
5
- # published by the Free Software Foundation; either version 2.1 of
6
- # the License, or (at your option) any later version.
7
- #
8
- # This software is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
- # Lesser General Public License for more details.
12
- #
13
- # You should have received a copy of the GNU Lesser General Public
14
- # License along with this software; if not, write to the Free
15
- # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
- # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
-
18
- require "digest/sha1"
19
- require 'dm-core'
20
- require 'cache'
21
- require 'json'
22
- require 'torquebox-cache' # is this needed?
23
- require 'datamapper/model'
24
- require 'datamapper/search'
25
-
26
-
27
- module DataMapper::Adapters
28
-
29
- class InfinispanAdapter < AbstractAdapter
30
-
31
- include TorqueBox::Infinispan
32
-
33
- DataMapper::Model.append_inclusions( Infinispan::Model )
34
-
35
- def initialize( name, options )
36
- super
37
- @options = options.dup
38
- @metadata = @options.dup
39
- @options[:name] = name.to_s
40
- @options[:index] = true
41
- @metadata[:name] = name.to_s + "/metadata"
42
- @cache = Cache.new( @options )
43
- @metadata_cache = Cache.new( @metadata )
44
- @search = Infinispan::Search.new(cache, lambda{ |v| self.deserialize(v) })
45
- end
46
-
47
-
48
- def create( resources )
49
- cache.transaction do
50
- resources.each do |resource|
51
- initialize_serial( resource, @metadata_cache.increment( index_for( resource ) ) )
52
- cache.put( key( resource ), serialize( resource ) )
53
- end
54
- end
55
- end
56
-
57
- def read( query )
58
- query.filter_records(@search.search( query ))
59
- end
60
-
61
- def update( attributes, collection )
62
- attributes = attributes_as_fields(attributes)
63
- cache.transaction do
64
- collection.each do |resource|
65
- resource.attributes(:field).merge(attributes)
66
- cache.put( key(resource), serialize(resource) )
67
- end
68
- end
69
- end
70
-
71
- def delete( collection )
72
- cache.transaction do
73
- collection.each do |resource|
74
- cache.remove( key(resource) )
75
- end
76
- end
77
- end
78
-
79
- def stop
80
- cache.stop
81
- end
82
-
83
- def serialize(resource)
84
- resource.is_a?(DataMapper::Resource) ? resource : resource.to_json
85
- end
86
-
87
- def deserialize(value)
88
- value.is_a?(String) ? JSON.parse(value) : value
89
- end
90
-
91
- def search_manager
92
- @search.search_manager
93
- end
94
-
95
- private
96
- def cache
97
- @cache
98
- end
99
-
100
- def metadata_cache
101
- @metadata_cache
102
- end
103
-
104
- def next_id(resource)
105
- Digest::SHA1.hexdigest(Time.now.to_i + rand(1000000000).to_s)[1..length].to_i
106
- end
107
-
108
- def key( resource )
109
- model = resource.model
110
- key = resource.key.nil? ? '' : resource.key.join('/')
111
- "#{model}/#{key}/#{resource.id}"
112
- end
113
-
114
- def index_for( resource )
115
- resource.model.name + ".index"
116
- end
117
-
118
- def all_records
119
- records = []
120
- cache.keys.each do |key|
121
- value = cache.get(key)
122
- records << deserialize(value) if value
123
- end
124
- records
125
- end
126
-
127
- end
128
- end
129
-
@@ -1,187 +0,0 @@
1
- # Copyright 2008-2012 Red Hat, Inc, and individual contributors.
2
- #
3
- # This is free software; you can redistribute it and/or modify it
4
- # under the terms of the GNU Lesser General Public License as
5
- # published by the Free Software Foundation; either version 2.1 of
6
- # the License, or (at your option) any later version.
7
- #
8
- # This software is distributed in the hope that it will be useful,
9
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
- # Lesser General Public License for more details.
12
- #
13
- # You should have received a copy of the GNU Lesser General Public
14
- # License along with this software; if not, write to the Free
15
- # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
16
- # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
17
-
18
- require 'dm-serializer'
19
- require 'jruby/core_ext'
20
- require 'json'
21
-
22
-
23
- module Infinispan
24
- JVoid = java.lang.Void::TYPE
25
-
26
- module Model
27
-
28
- # TODO enhance TYPEs list
29
- TYPES = {
30
- ::String => java.lang.String,
31
- ::Integer => java.lang.Integer,
32
- ::Float => java.lang.Double,
33
- ::BigDecimal => java.math.BigDecimal,
34
- ::Date => java.util.Date,
35
- ::DateTime => java.util.Date,
36
- ::Time => java.util.Date,
37
- ::TrueClass => java.lang.Boolean
38
- }
39
-
40
- def self.included(model)
41
- model.extend(ClassMethods)
42
- include java.io.Serializable
43
-
44
- unless model.mapped? model.name
45
- [:auto_migrate!, :auto_upgrade!, :create, :all, :copy, :first, :first_or_create, :first_or_new, :get, :last, :load].each do |method|
46
- model.before_class_method(method, :configure_index)
47
- end
48
-
49
- [:save, :update, :destroy, :update_attributes].each do |method|
50
- model.before(method) { model.configure_index }
51
- end
52
- end
53
- end
54
-
55
- def deserialize_to
56
- self.class.name
57
- end
58
-
59
- def is_a_with_hack?( thing )
60
- thing == java.lang.Object || is_a_without_hack?( thing )
61
- end
62
-
63
- alias_method :is_a_without_hack?, :is_a?
64
- alias_method :is_a?, :is_a_with_hack?
65
-
66
- module ClassMethods
67
-
68
- @@mapped = {}
69
-
70
- def auto_upgrade!
71
- configure_index
72
- end
73
-
74
- def auto_migrate!
75
- destroy
76
- configure_index
77
- end
78
-
79
- def to_java_type(type)
80
- TYPES[type] || self.to_java_type(type.primitive)
81
- end
82
-
83
- def mapped?( type )
84
- @@mapped[type]
85
- end
86
-
87
- def configure_index
88
- unless mapped?( name )
89
- configure_index!
90
- end
91
- end
92
-
93
- def configure_index!
94
- TorqueBox::Infinispan::Cache.log( "Configuring dm-infinispan-adapter model #{name}" )
95
- properties().each do |prop|
96
- TorqueBox::Infinispan::Cache.log( "Adding property #{prop.inspect}" )
97
- add_java_property(prop)
98
- TorqueBox::Infinispan::Cache.log( "Added property #{prop.inspect}" )
99
- end
100
-
101
- annotation = {
102
- org.hibernate.search.annotations.Indexed => {},
103
- org.hibernate.search.annotations.ProvidedId => {},
104
- org.infinispan.marshall.SerializeWith => { "value" => org.torquebox.cache.marshalling.JsonExternalizer.java_class }
105
- }
106
-
107
- add_class_annotation( annotation )
108
-
109
- # Wonder twin powers... ACTIVATE!
110
- java_class = become_java!(false)
111
-
112
- @@mapped[name] = true
113
- end
114
-
115
- def add_java_property(prop)
116
- name = prop.name
117
- type = prop.class
118
-
119
- column_name = prop.field
120
- annotation = {}
121
-
122
- annotation[org.hibernate.search.annotations.Field] = {}
123
-
124
- get_name = "get#{name.to_s.capitalize}"
125
- set_name = "set#{name.to_s.capitalize}"
126
-
127
- # TODO Time, Discriminator, EmbededValue
128
- # to consider: in mu opinion those methods should set from/get to java objects...
129
- if (type == DataMapper::Property::Date)
130
- class_eval <<-EOT
131
- def #{set_name.intern} (d)
132
- attribute_set(:#{name} , d.nil? ? nil : Date.civil(d.year + 1900, d.month + 1, d.date))
133
- end
134
- EOT
135
- class_eval <<-EOT
136
- def #{get_name.intern}
137
- d = attribute_get(:#{name} )
138
- java.util.Date.new( (Time.mktime(d.year, d.month, d.day).to_i * 1000) ) if d
139
- end
140
- EOT
141
- elsif (type == DataMapper::Property::DateTime)
142
- class_eval <<-EOT
143
- def #{set_name.intern} (d)
144
- attribute_set(:#{name} , d.nil? ? nil : DateTime.civil(d.year + 1900, d.month + 1, d.date, d.hours, d.minutes, d.seconds))
145
- end
146
- EOT
147
- class_eval <<-EOT
148
- def #{get_name.intern}
149
- d = attribute_get(:#{name} )
150
- java.util.Date.new( (Time.mktime(d.year, d.month, d.day, d.hour, d.min, d.sec, 0).to_i * 1000) ) if d
151
- end
152
- EOT
153
- elsif (type.to_s == BigDecimal || type == DataMapper::Property::Decimal)
154
- class_eval <<-EOT
155
- def #{set_name.intern} (d)
156
- attribute_set(:#{name} , d.nil? ? nil :#{type}.new(d.to_s))
157
- end
158
- EOT
159
- class_eval <<-EOT
160
- def #{get_name.intern}
161
- d = attribute_get(:#{name} )
162
- java.math.BigDecimal.new(d.to_i) if d
163
- end
164
- EOT
165
- else
166
- class_eval <<-EOT
167
- def #{set_name.intern} (d)
168
- attribute_set(:#{name} , d)
169
- end
170
- EOT
171
- class_eval <<-EOT
172
- def #{get_name.intern}
173
- d = attribute_get(:#{name} )
174
- d
175
- end
176
- EOT
177
- end
178
-
179
- mapped_type = to_java_type(type)
180
- add_method_signature get_name, [mapped_type]
181
- add_method_annotation get_name, annotation
182
- add_method_signature set_name, [JVoid, mapped_type]
183
- end
184
- end
185
-
186
- end
187
- end