groonga-client 0.0.2 → 0.0.3

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.
@@ -1,5 +1,3 @@
1
- require "test/unit/rr"
2
-
3
1
  require "response/helper"
4
2
 
5
3
  class TestResponseTableList < Test::Unit::TestCase
@@ -9,16 +7,9 @@ class TestResponseTableList < Test::Unit::TestCase
9
7
  header = [0,1372430096.70991,0.000522851943969727]
10
8
  body = [[["id","UInt32"],["name","ShortText"],["path","ShortText"],["flags","ShortText"],["domain","ShortText"],["range","ShortText"],["default_tokenizer","ShortText"],["normalizer","ShortText"]],
11
9
  [256,"Test","/tmp/test.db.0000100","TABLE_HASH_KEY|PERSISTENT",nil,nil,nil,nil]]
10
+ raw_response = [header, body].to_json
12
11
 
13
- connection = Object.new
14
- stub(connection).send.with_any_args.yields([header, body].to_json) do
15
- request = Object.new
16
- stub(request).wait do
17
- true
18
- end
19
- end
20
-
21
- response = make_command("table_list").execute(connection)
12
+ response = parse_raw_response("table_list", raw_response)
22
13
  assert_equal(Groonga::Client::Response::TableList, response.class)
23
14
  end
24
15
  end
@@ -3,12 +3,13 @@ require "test/unit/rr"
3
3
  class TestResultsColumnList < Test::Unit::TestCase
4
4
  class TestResults < self
5
5
  def setup
6
+ command = nil
6
7
  header = [0,1372430096.70991,0.000522851943969727]
7
8
  body = [[["id","UInt32"],["name","ShortText"],["path","ShortText"],["type","ShortText"],["flags","ShortText"],["domain","ShortText"],["range","ShortText"],["source","ShortText"]],
8
9
  [259,"_key","","","COLUMN_SCALAR","Bigram","ShortText",[]],
9
10
  [278,"comment_index","/tmp/db.db.0000116","index","COLUMN_INDEX|WITH_POSITION|PERSISTENT","Bigram","Comments",["Comments.comment"]],
10
11
  [277,"users_index","/tmp/db.db.0000115","index","COLUMN_INDEX|WITH_SECTION|WITH_POSITION|PERSISTENT","Bigram","Users",["Users.name","Users.location_str","Users.description"]]]
11
- @column_list = Groonga::Client::Response::ColumnList.new(header, body)
12
+ @column_list = Groonga::Client::Response::ColumnList.new(command, header, body)
12
13
  end
13
14
 
14
15
  def test_column_list
@@ -2,12 +2,13 @@ require "test/unit/rr"
2
2
 
3
3
  class TestResultsTableList < Test::Unit::TestCase
4
4
  def setup
5
+ command = nil
5
6
  header = [0,1372430096.70991,0.000522851943969727]
6
7
  body = [[["id","UInt32"],["name","ShortText"],["path","ShortText"],["flags","ShortText"],["domain","ShortText"],["range","ShortText"],["default_tokenizer","ShortText"],["normalizer","ShortText"]],
7
8
  [257,"Ages","/tmp/test.db.0000101","TABLE_DAT_KEY|PERSISTENT","UInt32",nil,nil,nil],
8
9
  [256,"Lexicon","/tmp/test.db.0000100","TABLE_PAT_KEY|PERSISTENT","ShortText",nil,"TokenBigram","NormalizerAuto"],
9
10
  [258,"Logs","/tmp/test.db.0000102","TABLE_NO_KEY|PERSISTENT",nil,nil,nil,nil]]
10
- @table_list = Groonga::Client::Response::TableList.new(header, body)
11
+ @table_list = Groonga::Client::Response::TableList.new(command, header, body)
11
12
  end
12
13
 
13
14
  def test_table_list
data/test/test-client.rb CHANGED
@@ -152,30 +152,29 @@ class TestClient < Test::Unit::TestCase
152
152
  XML
153
153
  response = client.table_list(:output_type => :xml)
154
154
  expected_body = [
155
- table(256,
156
- "Users",
157
- "/tmp/db/db.0000100",
158
- "TABLE_HASH_KEY|PERSISTENT",
159
- nil,
160
- nil,
161
- nil,
162
- nil),
155
+ [
156
+ ["id", "UInt32"],
157
+ ["name", "ShortText"],
158
+ ["path", "ShortText"],
159
+ ["flags", "ShortText"],
160
+ ["domain", "ShortText"],
161
+ ["range", "ShortText"],
162
+ ["default_tokenizer", "ShortText"],
163
+ ["normalizer", "ShortText"],
164
+ ],
165
+ [
166
+ 256,
167
+ "Users",
168
+ "/tmp/db/db.0000100",
169
+ "TABLE_HASH_KEY|PERSISTENT",
170
+ nil,
171
+ nil,
172
+ nil,
173
+ nil,
174
+ ],
163
175
  ]
164
176
  assert_response(expected_body, response)
165
177
  end
166
-
167
- private
168
- def table(id, name, path, flags, domain, range, default_tokenizer,
169
- normalizer)
170
- Groonga::Client::Response::TableList::Table.new(id,
171
- name,
172
- path,
173
- flags,
174
- domain,
175
- range,
176
- default_tokenizer,
177
- normalizer)
178
- end
179
178
  end
180
179
 
181
180
  module ColumnsTests
@@ -213,6 +212,16 @@ JSON
213
212
  end
214
213
  end
215
214
 
215
+ module OpenTests
216
+ def test_return_value
217
+ stub_response("['not-used']")
218
+ response = open_client do |client|
219
+ "response"
220
+ end
221
+ assert_equal("response", response)
222
+ end
223
+ end
224
+
216
225
  module Tests
217
226
  include Utils
218
227
  include Assertions
@@ -220,6 +229,7 @@ JSON
220
229
  include OutputTypeTests
221
230
  include ColumnsTests
222
231
  include ParametersTests
232
+ include OpenTests
223
233
  end
224
234
 
225
235
  class TestGQTP < self
@@ -237,14 +247,20 @@ JSON
237
247
  client = @server.accept
238
248
  @server.close
239
249
 
240
- header = GQTP::Header.parse(client.read(GQTP::Header.size))
241
- client.read(header.size)
250
+ loop do
251
+ raw_header = client.read(GQTP::Header.size)
252
+ break if raw_header.nil?
253
+
254
+ header = GQTP::Header.parse(raw_header)
255
+ client.read(header.size)
242
256
 
243
- response_header = GQTP::Header.new
244
- response_header.size = @response_body.bytesize
257
+ response_header = GQTP::Header.new
258
+ response_header.size = @response_body.bytesize
259
+
260
+ client.write(response_header.pack)
261
+ client.write(@response_body)
262
+ end
245
263
 
246
- client.write(response_header.pack)
247
- client.write(@response_body)
248
264
  client.close
249
265
  end
250
266
  end
data/test/test-command.rb CHANGED
@@ -3,23 +3,56 @@ class TestCommand < Test::Unit::TestCase
3
3
  @client = Groonga::Client.open(:protocol => :http)
4
4
  end
5
5
 
6
+ def test_column_create
7
+ response = Object.new
8
+ mock(@client).execute_command("column_create", :table => :Test, :name => :Body, :type => :ShortText) do
9
+ response
10
+ end
11
+ @client.column_create(:table => :Test, :name => :Body, :type => :ShortText)
12
+ end
13
+
6
14
  def test_column_list
15
+ response = Object.new
7
16
  mock(@client).execute_command("column_list", :table => :Test) do
8
- Object.new
17
+ response
9
18
  end
10
19
  @client.column_list(:table => :Test)
11
20
  end
12
21
 
22
+ def test_load
23
+ values = [
24
+ {
25
+ :_key => "Groonga",
26
+ :body => "It's very fast!!"
27
+ }
28
+ ]
29
+ response = Object.new
30
+ mock(@client).execute_command("load", :table => :Test, :values => values.to_json) do
31
+ response
32
+ end
33
+ @client.load(:table => :Test, :values => values.to_json)
34
+ end
35
+
13
36
  def test_select
37
+ response = Object.new
14
38
  mock(@client).execute_command("select", :table => :Test) do
15
- Object.new
39
+ response
16
40
  end
17
41
  @client.select(:table => :Test)
18
42
  end
19
43
 
44
+ def test_table_create
45
+ response = Object.new
46
+ mock(@client).execute_command("table_create", :name => :Test) do
47
+ response
48
+ end
49
+ @client.table_create(:name => :Test)
50
+ end
51
+
20
52
  def test_table_list
53
+ response = Object.new
21
54
  mock(@client).execute_command("table_list", {}) do
22
- Object.new
55
+ response
23
56
  end
24
57
  @client.table_list
25
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-client
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:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-07-08 00:00:00.000000000 Z
14
+ date: 2013-09-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: gqtp
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ! '>='
38
38
  - !ruby/object:Gem::Version
39
- version: 1.0.2
39
+ version: 1.0.4
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
@@ -44,7 +44,7 @@ dependencies:
44
44
  requirements:
45
45
  - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.0.2
47
+ version: 1.0.4
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bundler
50
50
  requirement: !ruby/object:Gem::Requirement
@@ -179,43 +179,47 @@ files:
179
179
  - Gemfile
180
180
  - groonga-client.gemspec
181
181
  - .yardopts
182
- - lib/groonga/client/protocol/gqtp.rb
183
- - lib/groonga/client/protocol/http.rb
184
- - lib/groonga/client/version.rb
185
- - lib/groonga/client/response/cache_limit.rb
186
- - lib/groonga/client/response/register.rb
187
- - lib/groonga/client/response/column_list.rb
188
- - lib/groonga/client/response/status.rb
182
+ - lib/groonga/client/response.rb
183
+ - lib/groonga/client/response/clearlock.rb
189
184
  - lib/groonga/client/response/column_remove.rb
190
185
  - lib/groonga/client/response/quit.rb
186
+ - lib/groonga/client/response/log_put.rb
191
187
  - lib/groonga/client/response/load.rb
192
188
  - lib/groonga/client/response/delete.rb
189
+ - lib/groonga/client/response/base.rb
190
+ - lib/groonga/client/response/status.rb
191
+ - lib/groonga/client/response/table_create.rb
192
+ - lib/groonga/client/response/register.rb
193
193
  - lib/groonga/client/response/column_create.rb
194
- - lib/groonga/client/response/log_reopen.rb
194
+ - lib/groonga/client/response/check.rb
195
+ - lib/groonga/client/response/cache_limit.rb
195
196
  - lib/groonga/client/response/column_rename.rb
196
- - lib/groonga/client/response/log_level.rb
197
197
  - lib/groonga/client/response/defrag.rb
198
- - lib/groonga/client/response/base.rb
199
- - lib/groonga/client/response/dump.rb
200
198
  - lib/groonga/client/response/table_list.rb
199
+ - lib/groonga/client/response/log_level.rb
200
+ - lib/groonga/client/response/log_reopen.rb
201
+ - lib/groonga/client/response/dump.rb
201
202
  - lib/groonga/client/response/select.rb
202
- - lib/groonga/client/response/log_put.rb
203
- - lib/groonga/client/response/clearlock.rb
204
- - lib/groonga/client/response/check.rb
203
+ - lib/groonga/client/response/column_list.rb
204
+ - lib/groonga/client/version.rb
205
205
  - lib/groonga/client/command.rb
206
- - lib/groonga/client/response.rb
206
+ - lib/groonga/client/connection/request.rb
207
+ - lib/groonga/client/connection/error.rb
208
+ - lib/groonga/client/connection/gqtp.rb
209
+ - lib/groonga/client/connection/http.rb
207
210
  - lib/groonga/client.rb
208
211
  - doc/text/news.md
209
- - test/response/test-table-list.rb
210
- - test/response/test-column-list.rb
212
+ - test/run-test.rb
213
+ - test/test-client.rb
211
214
  - test/response/helper.rb
212
215
  - test/response/test-select.rb
213
- - test/run-test.rb
216
+ - test/response/test-table-list.rb
217
+ - test/response/test-column-list.rb
218
+ - test/test-command.rb
214
219
  - test/results/test-table-list.rb
215
220
  - test/results/test-column-list.rb
216
- - test/results/test-select.rb
217
- - test/test-command.rb
218
- - test/test-client.rb
221
+ - test/connection/test-gqtp.rb
222
+ - test/connection/test-http.rb
219
223
  homepage: https://github.com/ranguba/groonga-client
220
224
  licenses:
221
225
  - LGPLv2.1 or later
@@ -243,14 +247,15 @@ specification_version: 3
243
247
  summary: Groonga-client is a client for groonga (http://groonga.org/) implemented
244
248
  with pure ruby.
245
249
  test_files:
246
- - test/response/test-table-list.rb
247
- - test/response/test-column-list.rb
250
+ - test/run-test.rb
251
+ - test/test-client.rb
248
252
  - test/response/helper.rb
249
253
  - test/response/test-select.rb
250
- - test/run-test.rb
254
+ - test/response/test-table-list.rb
255
+ - test/response/test-column-list.rb
256
+ - test/test-command.rb
251
257
  - test/results/test-table-list.rb
252
258
  - test/results/test-column-list.rb
253
- - test/results/test-select.rb
254
- - test/test-command.rb
255
- - test/test-client.rb
259
+ - test/connection/test-gqtp.rb
260
+ - test/connection/test-http.rb
256
261
  has_rdoc:
@@ -1,63 +0,0 @@
1
- require "test/unit/rr"
2
-
3
- class TestResultsSelect < Test::Unit::TestCase
4
- class TestResults < self
5
- def setup
6
- header = [0,1372430096.70991,0.000522851943969727]
7
- body = [[[6],[["_id","UInt32"],["country","Country"],["domain","Domain"]],[1,"japan",".com"],[2,"brazil",".com"],[3,"japan",".org"],[4,"usa",".com"],[5,"japan",".org"],[6,"usa",".com"]],
8
- [[3],[["_key","ShortText"],["_nsubrecs","Int32"]],["japan",3],["brazil",1],["usa",2]],
9
- [[2],[["_key","ShortText"],["_nsubrecs","Int32"]],[".com",4],[".org",2]]]
10
- @select = Groonga::Client::Response::Select.new(header, body)
11
- end
12
-
13
- def test_n_records
14
- assert_equal(6, @select.n_records)
15
- end
16
-
17
- def test_records
18
- expected_records = [
19
- {"_id"=>1, "country"=>"japan", "domain"=>".com"},
20
- {"_id"=>2, "country"=>"brazil", "domain"=>".com"},
21
- {"_id"=>3, "country"=>"japan", "domain"=>".org"},
22
- {"_id"=>4, "country"=>"usa", "domain"=>".com"},
23
- {"_id"=>5, "country"=>"japan", "domain"=>".org"},
24
- {"_id"=>6, "country"=>"usa", "domain"=>".com"},
25
- ]
26
- assert_equal(expected_records, @select.records)
27
- end
28
-
29
- def test_drilldowns
30
- expected_drilldowns = [
31
- Drilldown.new(3, [
32
- {"_key"=>"japan", "_nsubrecs"=>3},
33
- {"_key"=>"brazil", "_nsubrecs"=>1},
34
- {"_key"=>"usa", "_nsubrecs"=>2},]),
35
- Drilldown.new(2, [
36
- {"_key"=>".com", "_nsubrecs"=>4},
37
- {"_key"=>".org", "_nsubrecs"=>2}]),
38
- ]
39
- assert_equal(expected_drilldowns, @select.drilldowns.collect{|drilldown|
40
- Drilldown.new(drilldown.n_hits, drilldown.items)
41
- })
42
- end
43
- end
44
-
45
- class TestNoRecordsBody < self
46
- def setup
47
- header = [0,1372430096.70991,0.000522851943969727]
48
- body = [[[6],[["_id","UInt32"],["country","Country"]]]]
49
- @select = Groonga::Client::Response::Select.new(header, body)
50
- end
51
-
52
- def test_n_records
53
- assert_equal(6, @select.n_records)
54
- end
55
-
56
- def test_records
57
- assert_equal([], @select.records)
58
- end
59
- end
60
-
61
- Drilldown = Struct.new(:n_hits, :items)
62
- end
63
-