mosql 0.2.0 → 0.3.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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mosql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
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-12 00:00:00.000000000 Z
12
+ date: 2013-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel
@@ -192,15 +192,16 @@ files:
192
192
  - lib/mosql/log.rb
193
193
  - lib/mosql/schema.rb
194
194
  - lib/mosql/sql.rb
195
+ - lib/mosql/streamer.rb
195
196
  - lib/mosql/tailer.rb
196
197
  - lib/mosql/version.rb
197
198
  - mosql.gemspec
198
199
  - test/_lib.rb
199
200
  - test/functional/_lib.rb
200
- - test/functional/cli.rb
201
201
  - test/functional/functional.rb
202
202
  - test/functional/schema.rb
203
203
  - test/functional/sql.rb
204
+ - test/functional/streamer.rb
204
205
  - test/unit/lib/mosql/schema.rb
205
206
  homepage: https://github.com/stripe/mosql
206
207
  licenses: []
@@ -229,9 +230,9 @@ summary: MongoDB -> SQL streaming bridge
229
230
  test_files:
230
231
  - test/_lib.rb
231
232
  - test/functional/_lib.rb
232
- - test/functional/cli.rb
233
233
  - test/functional/functional.rb
234
234
  - test/functional/schema.rb
235
235
  - test/functional/sql.rb
236
+ - test/functional/streamer.rb
236
237
  - test/unit/lib/mosql/schema.rb
237
238
  has_rdoc:
@@ -1,153 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '_lib.rb')
2
- require 'mosql/cli'
3
-
4
- class MoSQL::Test::Functional::CLITest < MoSQL::Test::Functional
5
- TEST_MAP = <<EOF
6
- ---
7
- mosql_test:
8
- collection:
9
- :meta:
10
- :table: sqltable
11
- :columns:
12
- - _id: TEXT
13
- - var: INTEGER
14
- renameid:
15
- :meta:
16
- :table: sqltable2
17
- :columns:
18
- - id:
19
- :source: _id
20
- :type: TEXT
21
- - goats: INTEGER
22
- EOF
23
-
24
- def fake_cli
25
- # This is a hack. We should refactor cli.rb to be more testable.
26
- MoSQL::CLI.any_instance.expects(:setup_signal_handlers)
27
- cli = MoSQL::CLI.new([])
28
- cli.instance_variable_set(:@mongo, mongo)
29
- cli.instance_variable_set(:@schemamap, @map)
30
- cli.instance_variable_set(:@sql, @adapter)
31
- cli.instance_variable_set(:@options, {})
32
- cli
33
- end
34
-
35
- before do
36
- @map = MoSQL::Schema.new(YAML.load(TEST_MAP))
37
- @adapter = MoSQL::SQLAdapter.new(@map, sql_test_uri)
38
-
39
- @sequel.drop_table?(:sqltable)
40
- @sequel.drop_table?(:sqltable2)
41
- @map.create_schema(@sequel)
42
-
43
- @cli = fake_cli
44
- end
45
-
46
- it 'handle "u" ops without _id' do
47
- o = { '_id' => BSON::ObjectId.new, 'var' => 17 }
48
- @adapter.upsert_ns('mosql_test.collection', o)
49
-
50
- @cli.handle_op({ 'ns' => 'mosql_test.collection',
51
- 'op' => 'u',
52
- 'o2' => { '_id' => o['_id'] },
53
- 'o' => { 'var' => 27 }
54
- })
55
- assert_equal(27, sequel[:sqltable].where(:_id => o['_id'].to_s).select.first[:var])
56
- end
57
-
58
- it 'handle "d" ops with BSON::ObjectIds' do
59
- o = { '_id' => BSON::ObjectId.new, 'var' => 17 }
60
- @adapter.upsert_ns('mosql_test.collection', o)
61
-
62
- @cli.handle_op({ 'ns' => 'mosql_test.collection',
63
- 'op' => 'd',
64
- 'o' => { '_id' => o['_id'] },
65
- })
66
- assert_equal(0, sequel[:sqltable].where(:_id => o['_id'].to_s).count)
67
- end
68
-
69
- it 'handle "u" ops with $set and BSON::ObjectIDs' do
70
- o = { '_id' => BSON::ObjectId.new, 'var' => 17 }
71
- @adapter.upsert_ns('mosql_test.collection', o)
72
-
73
- # $set's are currently a bit of a hack where we read the object
74
- # from the db, so make sure the new object exists in mongo
75
- connect_mongo['mosql_test']['collection'].insert(o.merge('var' => 100),
76
- :w => 1)
77
-
78
- @cli.handle_op({ 'ns' => 'mosql_test.collection',
79
- 'op' => 'u',
80
- 'o2' => { '_id' => o['_id'] },
81
- 'o' => { '$set' => { 'var' => 100 } },
82
- })
83
- assert_equal(100, sequel[:sqltable].where(:_id => o['_id'].to_s).select.first[:var])
84
- end
85
-
86
- it 'handle "u" ops with $set and a renamed _id' do
87
- o = { '_id' => BSON::ObjectId.new, 'goats' => 96 }
88
- @adapter.upsert_ns('mosql_test.renameid', o)
89
-
90
- # $set's are currently a bit of a hack where we read the object
91
- # from the db, so make sure the new object exists in mongo
92
- connect_mongo['mosql_test']['renameid'].insert(o.merge('goats' => 0),
93
- :w => 1)
94
-
95
- @cli.handle_op({ 'ns' => 'mosql_test.renameid',
96
- 'op' => 'u',
97
- 'o2' => { '_id' => o['_id'] },
98
- 'o' => { '$set' => { 'goats' => 0 } },
99
- })
100
- assert_equal(0, sequel[:sqltable2].where(:id => o['_id'].to_s).select.first[:goats])
101
- end
102
-
103
- it 'handles "d" ops with a renamed id' do
104
- o = { '_id' => BSON::ObjectId.new, 'goats' => 1 }
105
- @adapter.upsert_ns('mosql_test.renameid', o)
106
-
107
- @cli.handle_op({ 'ns' => 'mosql_test.renameid',
108
- 'op' => 'd',
109
- 'o' => { '_id' => o['_id'] },
110
- })
111
- assert_equal(0, sequel[:sqltable2].where(:id => o['_id'].to_s).count)
112
- end
113
-
114
- describe '.bulk_upsert' do
115
- it 'inserts multiple rows' do
116
- objs = [
117
- { '_id' => BSON::ObjectId.new, 'var' => 0 },
118
- { '_id' => BSON::ObjectId.new, 'var' => 1 },
119
- { '_id' => BSON::ObjectId.new, 'var' => 3 },
120
- ].map { |o| @map.transform('mosql_test.collection', o) }
121
-
122
- @cli.bulk_upsert(sequel[:sqltable], 'mosql_test.collection',
123
- objs)
124
-
125
- assert(sequel[:sqltable].where(:_id => objs[0].first, :var => 0).count)
126
- assert(sequel[:sqltable].where(:_id => objs[1].first, :var => 1).count)
127
- assert(sequel[:sqltable].where(:_id => objs[2].first, :var => 3).count)
128
- end
129
-
130
- it 'upserts' do
131
- _id = BSON::ObjectId.new
132
- objs = [
133
- { '_id' => _id, 'var' => 0 },
134
- { '_id' => BSON::ObjectId.new, 'var' => 1 },
135
- { '_id' => BSON::ObjectId.new, 'var' => 3 },
136
- ].map { |o| @map.transform('mosql_test.collection', o) }
137
-
138
- @cli.bulk_upsert(sequel[:sqltable], 'mosql_test.collection',
139
- objs)
140
-
141
- newobjs = [
142
- { '_id' => _id, 'var' => 117 },
143
- { '_id' => BSON::ObjectId.new, 'var' => 32 },
144
- ].map { |o| @map.transform('mosql_test.collection', o) }
145
- @cli.bulk_upsert(sequel[:sqltable], 'mosql_test.collection',
146
- newobjs)
147
-
148
-
149
- assert(sequel[:sqltable].where(:_id => newobjs[0].first, :var => 117).count)
150
- assert(sequel[:sqltable].where(:_id => newobjs[1].first, :var => 32).count)
151
- end
152
- end
153
- end