monga 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +1 -0
  3. data/README.md +59 -3
  4. data/lib/monga/client.rb +51 -6
  5. data/lib/monga/clients/master_slave_client.rb +0 -5
  6. data/lib/monga/clients/replica_set_client.rb +32 -71
  7. data/lib/monga/clients/single_instance_client.rb +53 -0
  8. data/lib/monga/collection.rb +102 -41
  9. data/lib/monga/connection.rb +38 -13
  10. data/lib/monga/connection_pool.rb +6 -17
  11. data/lib/monga/connections/buffer.rb +33 -0
  12. data/lib/monga/connections/em_connection.rb +25 -56
  13. data/lib/monga/connections/em_proxy_connection.rb +80 -0
  14. data/lib/monga/connections/fibered_connection.rb +26 -0
  15. data/lib/monga/connections/fibered_proxy_connection.rb +23 -0
  16. data/lib/monga/connections/proxy_connection.rb +4 -0
  17. data/lib/monga/connections/tcp_connection.rb +57 -0
  18. data/lib/monga/cursor.rb +197 -95
  19. data/lib/monga/database.rb +175 -60
  20. data/lib/monga/{requests → protocol}/delete.rb +1 -2
  21. data/lib/monga/{requests → protocol}/get_more.rb +1 -1
  22. data/lib/monga/{requests → protocol}/insert.rb +1 -2
  23. data/lib/monga/{requests → protocol}/kill_cursors.rb +1 -1
  24. data/lib/monga/{requests → protocol}/query.rb +3 -3
  25. data/lib/monga/{requests → protocol}/update.rb +1 -1
  26. data/lib/monga/request.rb +27 -23
  27. data/lib/monga/utils/constants.rb +5 -0
  28. data/lib/monga/utils/exceptions.rb +11 -0
  29. data/lib/monga.rb +19 -11
  30. data/monga.gemspec +2 -2
  31. data/spec/helpers/mongodb.rb +115 -38
  32. data/spec/monga/block/collection_spec.rb +172 -0
  33. data/spec/monga/block/cursor_spec.rb +160 -0
  34. data/spec/monga/block/database_spec.rb +80 -0
  35. data/spec/monga/block/single_instance_client_spec.rb +31 -0
  36. data/spec/monga/em/collection_spec.rb +308 -0
  37. data/spec/monga/em/cursor_spec.rb +256 -0
  38. data/spec/monga/em/database_spec.rb +140 -0
  39. data/spec/monga/em/replica_set_client_spec.rb +86 -0
  40. data/spec/monga/em/single_instance_client_spec.rb +28 -0
  41. data/spec/monga/sync/collection_spec.rb +247 -0
  42. data/spec/monga/sync/cursor_spec.rb +211 -0
  43. data/spec/monga/sync/database_spec.rb +110 -0
  44. data/spec/monga/sync/replica_set_client_spec.rb +54 -0
  45. data/spec/monga/sync/single_instance_client_spec.rb +25 -0
  46. data/spec/spec_helper.rb +2 -20
  47. metadata +50 -38
  48. data/lib/monga/clients/client.rb +0 -24
  49. data/lib/monga/connections/primary.rb +0 -46
  50. data/lib/monga/connections/secondary.rb +0 -13
  51. data/lib/monga/exceptions.rb +0 -9
  52. data/lib/monga/miner.rb +0 -72
  53. data/lib/monga/response.rb +0 -11
  54. data/spec/helpers/truncate.rb +0 -15
  55. data/spec/monga/collection_spec.rb +0 -448
  56. data/spec/monga/connection_pool_spec.rb +0 -50
  57. data/spec/monga/connection_spec.rb +0 -64
  58. data/spec/monga/cursor_spec.rb +0 -186
  59. data/spec/monga/database_spec.rb +0 -67
  60. data/spec/monga/replica_set_client_spec.rb +0 -46
  61. data/spec/monga/requests/delete_spec.rb +0 -0
  62. data/spec/monga/requests/insert_spec.rb +0 -0
  63. data/spec/monga/requests/query_spec.rb +0 -28
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monga
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-03 00:00:00.000000000 Z
12
+ date: 2013-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  none: false
53
- type: :runtime
53
+ type: :development
54
54
  version_requirements: !ruby/object:Gem::Requirement
55
55
  requirements:
56
56
  - - ! '>='
@@ -58,7 +58,7 @@ dependencies:
58
58
  version: '0'
59
59
  none: false
60
60
  prerelease: false
61
- name: eventmachine
61
+ name: em-synchrony
62
62
  - !ruby/object:Gem::Dependency
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
@@ -99,45 +99,53 @@ extensions: []
99
99
  extra_rdoc_files: []
100
100
  files:
101
101
  - .gitignore
102
+ - .travis.yml
102
103
  - Gemfile
103
104
  - LICENSE.txt
104
105
  - README.md
105
106
  - Rakefile
106
107
  - lib/monga.rb
107
108
  - lib/monga/client.rb
108
- - lib/monga/clients/client.rb
109
109
  - lib/monga/clients/master_slave_client.rb
110
110
  - lib/monga/clients/replica_set_client.rb
111
+ - lib/monga/clients/single_instance_client.rb
111
112
  - lib/monga/collection.rb
112
113
  - lib/monga/connection.rb
113
114
  - lib/monga/connection_pool.rb
115
+ - lib/monga/connections/buffer.rb
114
116
  - lib/monga/connections/em_connection.rb
115
- - lib/monga/connections/primary.rb
116
- - lib/monga/connections/secondary.rb
117
+ - lib/monga/connections/em_proxy_connection.rb
118
+ - lib/monga/connections/fibered_connection.rb
119
+ - lib/monga/connections/fibered_proxy_connection.rb
120
+ - lib/monga/connections/proxy_connection.rb
121
+ - lib/monga/connections/tcp_connection.rb
117
122
  - lib/monga/cursor.rb
118
123
  - lib/monga/database.rb
119
- - lib/monga/exceptions.rb
120
- - lib/monga/miner.rb
124
+ - lib/monga/protocol/delete.rb
125
+ - lib/monga/protocol/get_more.rb
126
+ - lib/monga/protocol/insert.rb
127
+ - lib/monga/protocol/kill_cursors.rb
128
+ - lib/monga/protocol/query.rb
129
+ - lib/monga/protocol/update.rb
121
130
  - lib/monga/request.rb
122
- - lib/monga/requests/delete.rb
123
- - lib/monga/requests/get_more.rb
124
- - lib/monga/requests/insert.rb
125
- - lib/monga/requests/kill_cursors.rb
126
- - lib/monga/requests/query.rb
127
- - lib/monga/requests/update.rb
128
- - lib/monga/response.rb
131
+ - lib/monga/utils/constants.rb
132
+ - lib/monga/utils/exceptions.rb
129
133
  - monga.gemspec
130
134
  - spec/helpers/mongodb.rb
131
- - spec/helpers/truncate.rb
132
- - spec/monga/collection_spec.rb
133
- - spec/monga/connection_pool_spec.rb
134
- - spec/monga/connection_spec.rb
135
- - spec/monga/cursor_spec.rb
136
- - spec/monga/database_spec.rb
137
- - spec/monga/replica_set_client_spec.rb
138
- - spec/monga/requests/delete_spec.rb
139
- - spec/monga/requests/insert_spec.rb
140
- - spec/monga/requests/query_spec.rb
135
+ - spec/monga/block/collection_spec.rb
136
+ - spec/monga/block/cursor_spec.rb
137
+ - spec/monga/block/database_spec.rb
138
+ - spec/monga/block/single_instance_client_spec.rb
139
+ - spec/monga/em/collection_spec.rb
140
+ - spec/monga/em/cursor_spec.rb
141
+ - spec/monga/em/database_spec.rb
142
+ - spec/monga/em/replica_set_client_spec.rb
143
+ - spec/monga/em/single_instance_client_spec.rb
144
+ - spec/monga/sync/collection_spec.rb
145
+ - spec/monga/sync/cursor_spec.rb
146
+ - spec/monga/sync/database_spec.rb
147
+ - spec/monga/sync/replica_set_client_spec.rb
148
+ - spec/monga/sync/single_instance_client_spec.rb
141
149
  - spec/spec_helper.rb
142
150
  homepage: ''
143
151
  licenses:
@@ -150,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
158
  requirements:
151
159
  - - ! '>='
152
160
  - !ruby/object:Gem::Version
153
- hash: 1080619375756789325
161
+ hash: -1506820029322651348
154
162
  version: '0'
155
163
  segments:
156
164
  - 0
@@ -159,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
167
  requirements:
160
168
  - - ! '>='
161
169
  - !ruby/object:Gem::Version
162
- hash: 1080619375756789325
170
+ hash: -1506820029322651348
163
171
  version: '0'
164
172
  segments:
165
173
  - 0
@@ -172,14 +180,18 @@ specification_version: 3
172
180
  summary: MongoDB Ruby Evented Driver on EventMachine
173
181
  test_files:
174
182
  - spec/helpers/mongodb.rb
175
- - spec/helpers/truncate.rb
176
- - spec/monga/collection_spec.rb
177
- - spec/monga/connection_pool_spec.rb
178
- - spec/monga/connection_spec.rb
179
- - spec/monga/cursor_spec.rb
180
- - spec/monga/database_spec.rb
181
- - spec/monga/replica_set_client_spec.rb
182
- - spec/monga/requests/delete_spec.rb
183
- - spec/monga/requests/insert_spec.rb
184
- - spec/monga/requests/query_spec.rb
183
+ - spec/monga/block/collection_spec.rb
184
+ - spec/monga/block/cursor_spec.rb
185
+ - spec/monga/block/database_spec.rb
186
+ - spec/monga/block/single_instance_client_spec.rb
187
+ - spec/monga/em/collection_spec.rb
188
+ - spec/monga/em/cursor_spec.rb
189
+ - spec/monga/em/database_spec.rb
190
+ - spec/monga/em/replica_set_client_spec.rb
191
+ - spec/monga/em/single_instance_client_spec.rb
192
+ - spec/monga/sync/collection_spec.rb
193
+ - spec/monga/sync/cursor_spec.rb
194
+ - spec/monga/sync/database_spec.rb
195
+ - spec/monga/sync/replica_set_client_spec.rb
196
+ - spec/monga/sync/single_instance_client_spec.rb
185
197
  - spec/spec_helper.rb
@@ -1,24 +0,0 @@
1
- module Monga::Clients
2
- class Client
3
- extend Forwardable
4
-
5
- def_delegators :@connection_pool, :aquire_connection, :send_command, :primary?, :connected?
6
-
7
- attr_reader :connection_pool
8
-
9
- def initialize(opts={})
10
- opts[:pool_size] ||= 1
11
- @connection_pool = Monga::ConnectionPool.new(opts)
12
- end
13
-
14
- def [](db_name)
15
- Monga::Database.new(self, db_name)
16
- end
17
-
18
- def find_primary!
19
- @connection_pool.connections.each do |conn|
20
- conn.is_master?(self)
21
- end
22
- end
23
- end
24
- end
@@ -1,46 +0,0 @@
1
- module Monga::Connections
2
- class Primary < Monga::Connections::EMConnection
3
- def initialize(opts)
4
- @client = opts.delete :client
5
- @ser
6
- super
7
- end
8
-
9
- def connection_completed
10
- check_master do |master|
11
- if master
12
- super
13
- else
14
- reconnect
15
- end
16
- end
17
- end
18
-
19
- def check_master
20
- db = @client["admin"]
21
- request = Monga::Request.new(db, "$cmd", query: { "isMaster" => 1 })
22
- request_id = request.request_id
23
- @responses[request_id] = proc do |data|
24
- request.parse_response(data)
25
- if Exception === data
26
- Monga.logger.debug("Error on connecting Primary to #{@host}:#{@port}, #{data.class}, #{data.message}")
27
- @host, @port = @client.next_addr(@host, @port)
28
- yield false
29
- else
30
- doc = data.last.first
31
- if doc["ismaster"]
32
- Monga.logger.debug("Primary has connected to #{@host}:#{@port}")
33
- @client.inform(:primary, @host, @port)
34
- yield true
35
- else
36
- Monga.logger.debug("#{@host}:#{@port} is not a primary")
37
- @host, @port = @client.select_addr(doc)
38
- yield false
39
- end
40
- end
41
- end
42
- command = request.command
43
- send_data(command)
44
- end
45
- end
46
- end
@@ -1,13 +0,0 @@
1
- module Monga::Connections
2
- class Secondary < Monga::Connections::EMConnection
3
- def initialize(opts)
4
- @client = opts.delete :client
5
- super
6
- end
7
-
8
- def connection_completed
9
- @client.inform(:secondary, @host, @port)
10
- super()
11
- end
12
- end
13
- end
@@ -1,9 +0,0 @@
1
- module Monga::Exceptions
2
- class LostConnection < StandardError; end
3
- class CursorNotFound < StandardError; end
4
- class CursorIsClosed < StandardError; end
5
- class CursorLimit < StandardError; end
6
- class QueryFailure < StandardError; end
7
- class UndefinedIndexVersion < StandardError; end
8
- class NoAvailableServers < StandardError; end
9
- end
data/lib/monga/miner.rb DELETED
@@ -1,72 +0,0 @@
1
- # Miner is a "proxy" object to Cursor.
2
- # It dinamically stores Cursor options and at any moment can return cursor.
3
- # Also it hides Deferrable that could return all objects that cursor do.
4
- module Monga
5
- class Miner < EM::DefaultDeferrable
6
- attr_reader :options
7
-
8
- def initialize(db, collection_name, options={})
9
- @db = db
10
- @collection_name = collection_name
11
- @options = options
12
-
13
- # Defaults
14
- @options[:query] ||= {}
15
- @options[:limit] ||= 0
16
- @options[:skip] ||= 0
17
- end
18
-
19
- def cursor(flags = {})
20
- @cursor = Monga::Cursor.new(@db, @collection_name, @options, flags)
21
- end
22
-
23
- def explain
24
- @options[:explain] = true
25
- end
26
-
27
- def hint
28
- @options[:hint] = true
29
- end
30
-
31
- def sort(val)
32
- @options[:sort] = val
33
- end
34
-
35
- def limit(count)
36
- @options[:limit] = count and self
37
- end
38
-
39
- def skip(count)
40
- @options[:skip] = count and self
41
- end
42
-
43
- def batch_size(count)
44
- @options[:batch_size] = count and self
45
- end
46
-
47
- # Lazy operation execution
48
- [:callback, :errback, :timeout].each do |meth|
49
- class_eval <<-EOS
50
- def #{meth}(*args)
51
- mine! && @deferred = true unless @deferred
52
- super
53
- end
54
- EOS
55
- end
56
-
57
- private
58
-
59
- def mine!
60
- docs = []
61
- itrator = cursor.each_doc do |doc|
62
- docs << doc
63
- end
64
- itrator.callback do |resp|
65
- succeed docs
66
- end
67
- itrator.errback do |err|
68
- fail err
69
- end
70
- end
71
- end
72
- end
@@ -1,11 +0,0 @@
1
- module Monga
2
- class Response
3
- include EM::Deferrable
4
-
5
- def self.surround
6
- resp = new
7
- yield(resp)
8
- resp
9
- end
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- module Helpers
2
- module Truncate
3
- def teardown
4
- EM.run do
5
- RS_COLLECTION.safe_delete.callback do
6
- RS_COLLECTION.drop_indexes.callback do
7
- COLLECTION.safe_delete.callback do |res|
8
- COLLECTION.drop_indexes.callback{ EM.stop }
9
- end
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end