groonga-client 0.0.8 → 0.0.9
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.
- checksums.yaml +4 -4
- data/Rakefile +3 -1
- data/doc/text/news.md +7 -0
- data/groonga-client.gemspec +2 -1
- data/lib/groonga/client.rb +1 -1
- data/lib/groonga/client/protocol/http.rb +8 -1
- data/lib/groonga/client/protocol/http/coolio.rb +16 -1
- data/lib/groonga/client/protocol/http/synchronous.rb +116 -0
- data/lib/groonga/client/protocol/http/thread.rb +4 -63
- data/lib/groonga/client/version.rb +1 -1
- data/test/test-client.rb +23 -0
- metadata +12 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d4c4dbd708fca63ebcf3ca296f548dae1c8cf64b
|
|
4
|
+
data.tar.gz: a604c62095eacbba073e65812b99b2c922ff2951
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78e4d42b4fa59e6517052ca7413562d4392abacf86cea0328121047728d3d1ed41cd08405a07db21616e986cb78a772bce6bd844c1c9ae2ceccac0cd30d7af04
|
|
7
|
+
data.tar.gz: df04f9b4ba7dd62a8e1c1cac658a4b60c10745e81169a5dbed56d89afd5679ad16a6ed1e7a53c13146e23f8e08fe126d2a00e1825f473a0ea3f34db41b911aad
|
data/Rakefile
CHANGED
data/doc/text/news.md
CHANGED
data/groonga-client.gemspec
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# -*- mode: ruby; coding: utf-8 -*-
|
|
2
2
|
#
|
|
3
3
|
# Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
|
|
4
|
+
# Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
|
|
4
5
|
#
|
|
5
6
|
# This library is free software; you can redistribute it and/or
|
|
6
7
|
# modify it under the terms of the GNU Lesser General Public
|
|
@@ -47,7 +48,7 @@ Gem::Specification.new do |spec|
|
|
|
47
48
|
# end
|
|
48
49
|
|
|
49
50
|
spec.add_runtime_dependency("gqtp", ">= 1.0.4")
|
|
50
|
-
spec.add_runtime_dependency("groonga-command", ">= 1.0.
|
|
51
|
+
spec.add_runtime_dependency("groonga-command", ">= 1.0.8")
|
|
51
52
|
|
|
52
53
|
spec.add_development_dependency("bundler")
|
|
53
54
|
spec.add_development_dependency("rake")
|
data/lib/groonga/client.rb
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
# License along with this library; if not, write to the Free Software
|
|
18
18
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19
19
|
|
|
20
|
+
require "groonga/client/version"
|
|
20
21
|
require "groonga/client/protocol/error"
|
|
21
22
|
|
|
22
23
|
module Groonga
|
|
@@ -34,7 +35,7 @@ module Groonga
|
|
|
34
35
|
def initialize(options)
|
|
35
36
|
@host = options[:host] || "127.0.0.1"
|
|
36
37
|
@port = options[:port] || 10041
|
|
37
|
-
@options = options
|
|
38
|
+
@options = default_options.merge(options)
|
|
38
39
|
@backend = create_backend
|
|
39
40
|
end
|
|
40
41
|
|
|
@@ -51,6 +52,12 @@ module Groonga
|
|
|
51
52
|
end
|
|
52
53
|
|
|
53
54
|
private
|
|
55
|
+
def default_options
|
|
56
|
+
{
|
|
57
|
+
:user_agent => "groonga-client/#{VERSION}",
|
|
58
|
+
}
|
|
59
|
+
end
|
|
60
|
+
|
|
54
61
|
def create_backend
|
|
55
62
|
backend = @options[:backend] || :thread
|
|
56
63
|
|
|
@@ -73,7 +73,22 @@ module Groonga
|
|
|
73
73
|
def send(command, &block)
|
|
74
74
|
client = GroongaHTTPClient.connect(@host, @port, block)
|
|
75
75
|
client.attach(@loop)
|
|
76
|
-
|
|
76
|
+
if command.name == "load"
|
|
77
|
+
raw_values = command[:values]
|
|
78
|
+
command[:values] = nil
|
|
79
|
+
path = command.to_uri_format
|
|
80
|
+
command[:values] = raw_values
|
|
81
|
+
options = {
|
|
82
|
+
:head => {
|
|
83
|
+
"content-type" => "application/json",
|
|
84
|
+
"user-agent" => @options[:user_agent],
|
|
85
|
+
},
|
|
86
|
+
:body => raw_values,
|
|
87
|
+
}
|
|
88
|
+
client.request("POST", path, options)
|
|
89
|
+
else
|
|
90
|
+
client.request("GET", command.to_uri_format)
|
|
91
|
+
end
|
|
77
92
|
Request.new(client, @loop)
|
|
78
93
|
end
|
|
79
94
|
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
|
|
2
|
+
# Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
|
|
3
|
+
#
|
|
4
|
+
# This library is free software; you can redistribute it and/or
|
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
|
6
|
+
# License as published by the Free Software Foundation; either
|
|
7
|
+
# version 2.1 of the License, or (at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+
# Lesser General Public License for more details.
|
|
13
|
+
#
|
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
|
15
|
+
# License along with this library; if not, write to the Free Software
|
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
+
|
|
18
|
+
require "net/http"
|
|
19
|
+
|
|
20
|
+
require "groonga/client/version"
|
|
21
|
+
require "groonga/client/empty-request"
|
|
22
|
+
require "groonga/client/protocol/error"
|
|
23
|
+
|
|
24
|
+
module Groonga
|
|
25
|
+
class Client
|
|
26
|
+
module Protocol
|
|
27
|
+
class HTTP
|
|
28
|
+
class Synchronous
|
|
29
|
+
def initialize(host, port, options)
|
|
30
|
+
@host = host
|
|
31
|
+
@port = port
|
|
32
|
+
@options = options
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def send(command)
|
|
36
|
+
begin
|
|
37
|
+
Net::HTTP.start(@host, @port) do |http|
|
|
38
|
+
response = send_request(http, command)
|
|
39
|
+
case response
|
|
40
|
+
when Net::HTTPSuccess, Net::HTTPBadRequest
|
|
41
|
+
yield(response.body)
|
|
42
|
+
else
|
|
43
|
+
if response.body.start_with?("[[")
|
|
44
|
+
yield(response.body)
|
|
45
|
+
else
|
|
46
|
+
message =
|
|
47
|
+
"#{response.code} #{response.message}: #{response.body}"
|
|
48
|
+
raise Error.new(message)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
rescue SystemCallError, Timeout::Error
|
|
53
|
+
raise WrappedError.new($!)
|
|
54
|
+
end
|
|
55
|
+
EmptyRequest.new
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# @return [false] Always returns false because the current
|
|
59
|
+
# implementation doesn't support keep-alive.
|
|
60
|
+
def connected?
|
|
61
|
+
false
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Does nothing because the current implementation doesn't
|
|
65
|
+
# support keep-alive. If the implementation supports
|
|
66
|
+
# keep-alive, it close the opend connection.
|
|
67
|
+
#
|
|
68
|
+
# @overload close
|
|
69
|
+
# Closes synchronously.
|
|
70
|
+
#
|
|
71
|
+
# @return [false] It always returns false because there is always
|
|
72
|
+
# no connection.
|
|
73
|
+
#
|
|
74
|
+
# @overload close {}
|
|
75
|
+
# Closes asynchronously.
|
|
76
|
+
#
|
|
77
|
+
# @yield [] Calls the block when the opened connection is closed.
|
|
78
|
+
# @return [#wait] The request object. If you want to wait until
|
|
79
|
+
# the request is processed. You can send #wait message to the
|
|
80
|
+
# request.
|
|
81
|
+
def close(&block)
|
|
82
|
+
sync = !block_given?
|
|
83
|
+
if sync
|
|
84
|
+
false
|
|
85
|
+
else
|
|
86
|
+
yield
|
|
87
|
+
EmptyRequest.new
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
private
|
|
92
|
+
def send_request(http, command)
|
|
93
|
+
if command.name == "load"
|
|
94
|
+
raw_values = command[:values]
|
|
95
|
+
command[:values] = nil
|
|
96
|
+
path = command.to_uri_format
|
|
97
|
+
command[:values] = raw_values
|
|
98
|
+
request = Net::HTTP::Post.new(path, headers)
|
|
99
|
+
request.content_type = "application/json"
|
|
100
|
+
request.body = raw_values
|
|
101
|
+
http.request(request)
|
|
102
|
+
else
|
|
103
|
+
http.get(command.to_uri_format, headers)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def headers
|
|
108
|
+
{
|
|
109
|
+
"user-agent" => @options[:user_agent],
|
|
110
|
+
}
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
@@ -15,16 +15,15 @@
|
|
|
15
15
|
# License along with this library; if not, write to the Free Software
|
|
16
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
17
|
|
|
18
|
-
require "
|
|
18
|
+
require "thread"
|
|
19
19
|
|
|
20
|
-
require "groonga/client/
|
|
21
|
-
require "groonga/client/protocol/error"
|
|
20
|
+
require "groonga/client/protocol/http/synchronous"
|
|
22
21
|
|
|
23
22
|
module Groonga
|
|
24
23
|
class Client
|
|
25
24
|
module Protocol
|
|
26
25
|
class HTTP
|
|
27
|
-
class Thread
|
|
26
|
+
class Thread < Synchronous
|
|
28
27
|
class Request
|
|
29
28
|
def initialize(thread)
|
|
30
29
|
@thread = thread
|
|
@@ -35,70 +34,12 @@ module Groonga
|
|
|
35
34
|
end
|
|
36
35
|
end
|
|
37
36
|
|
|
38
|
-
def initialize(host, port, options)
|
|
39
|
-
@host = host
|
|
40
|
-
@port = port
|
|
41
|
-
@options = options
|
|
42
|
-
end
|
|
43
|
-
|
|
44
37
|
def send(command)
|
|
45
|
-
url = "http://#{@host}:#{@port}#{command.to_uri_format}"
|
|
46
38
|
thread = ::Thread.new do
|
|
47
|
-
|
|
48
|
-
Net::HTTP.start(@host, @port) do |http|
|
|
49
|
-
response = http.get(command.to_uri_format)
|
|
50
|
-
case response
|
|
51
|
-
when Net::HTTPSuccess, Net::HTTPBadRequest
|
|
52
|
-
yield(response.body)
|
|
53
|
-
else
|
|
54
|
-
if response.body.start_with?("[[")
|
|
55
|
-
yield(response.body)
|
|
56
|
-
else
|
|
57
|
-
message =
|
|
58
|
-
"#{response.code} #{response.message}: #{response.body}"
|
|
59
|
-
raise Error.new(message)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
rescue SystemCallError, Timeout::Error
|
|
64
|
-
raise WrappedError.new($!)
|
|
65
|
-
end
|
|
39
|
+
super
|
|
66
40
|
end
|
|
67
41
|
Request.new(thread)
|
|
68
42
|
end
|
|
69
|
-
|
|
70
|
-
# @return [false] Always returns false because the current
|
|
71
|
-
# implementation doesn't support keep-alive.
|
|
72
|
-
def connected?
|
|
73
|
-
false
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# Does nothing because the current implementation doesn't
|
|
77
|
-
# support keep-alive. If the implementation supports
|
|
78
|
-
# keep-alive, it close the opend connection.
|
|
79
|
-
#
|
|
80
|
-
# @overload close
|
|
81
|
-
# Closes synchronously.
|
|
82
|
-
#
|
|
83
|
-
# @return [false] It always returns false because there is always
|
|
84
|
-
# no connection.
|
|
85
|
-
#
|
|
86
|
-
# @overload close {}
|
|
87
|
-
# Closes asynchronously.
|
|
88
|
-
#
|
|
89
|
-
# @yield [] Calls the block when the opened connection is closed.
|
|
90
|
-
# @return [#wait] The request object. If you want to wait until
|
|
91
|
-
# the request is processed. You can send #wait message to the
|
|
92
|
-
# request.
|
|
93
|
-
def close(&block)
|
|
94
|
-
sync = !block_given?
|
|
95
|
-
if sync
|
|
96
|
-
false
|
|
97
|
-
else
|
|
98
|
-
yield
|
|
99
|
-
EmptyRequest.new
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
43
|
end
|
|
103
44
|
end
|
|
104
45
|
end
|
data/test/test-client.rb
CHANGED
|
@@ -223,6 +223,20 @@ JSON
|
|
|
223
223
|
end
|
|
224
224
|
end
|
|
225
225
|
|
|
226
|
+
module LoadTests
|
|
227
|
+
def test_load
|
|
228
|
+
values = [
|
|
229
|
+
{"content" => "1st content"},
|
|
230
|
+
{"content" => "2nd content"},
|
|
231
|
+
{"content" => "3rd content"},
|
|
232
|
+
]
|
|
233
|
+
stub_response("[#{values.size}]")
|
|
234
|
+
response = client.load(:table => "Memos",
|
|
235
|
+
:values => JSON.generate(values))
|
|
236
|
+
assert_equal([values.size], response.body)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
226
240
|
module Tests
|
|
227
241
|
include Utils
|
|
228
242
|
include Assertions
|
|
@@ -231,6 +245,7 @@ JSON
|
|
|
231
245
|
include ColumnsTests
|
|
232
246
|
include ParametersTests
|
|
233
247
|
include OpenTests
|
|
248
|
+
include LoadTests
|
|
234
249
|
end
|
|
235
250
|
|
|
236
251
|
class TestGQTP < self
|
|
@@ -281,9 +296,17 @@ JSON
|
|
|
281
296
|
@port = @server.addr[1]
|
|
282
297
|
@protocol = :http
|
|
283
298
|
|
|
299
|
+
@actual_method = nil
|
|
300
|
+
@actual_path = nil
|
|
301
|
+
|
|
284
302
|
@response_body = nil
|
|
285
303
|
@thread = Thread.new do
|
|
286
304
|
client = @server.accept
|
|
305
|
+
first_line = client.gets
|
|
306
|
+
if /\A([\w]+) ([^ ]+) HTTP/ =~ first_line
|
|
307
|
+
@actual_method = $1
|
|
308
|
+
@actual_path = $2
|
|
309
|
+
end
|
|
287
310
|
@server.close
|
|
288
311
|
status = 0
|
|
289
312
|
start = Time.now.to_f
|
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.
|
|
4
|
+
version: 0.0.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Haruka Yoshihara
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2014-
|
|
13
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: gqtp
|
|
@@ -32,14 +32,14 @@ dependencies:
|
|
|
32
32
|
requirements:
|
|
33
33
|
- - ">="
|
|
34
34
|
- !ruby/object:Gem::Version
|
|
35
|
-
version: 1.0.
|
|
35
|
+
version: 1.0.8
|
|
36
36
|
type: :runtime
|
|
37
37
|
prerelease: false
|
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
39
39
|
requirements:
|
|
40
40
|
- - ">="
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: 1.0.
|
|
42
|
+
version: 1.0.8
|
|
43
43
|
- !ruby/object:Gem::Dependency
|
|
44
44
|
name: bundler
|
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -165,6 +165,7 @@ files:
|
|
|
165
165
|
- lib/groonga/client/protocol/gqtp.rb
|
|
166
166
|
- lib/groonga/client/protocol/http.rb
|
|
167
167
|
- lib/groonga/client/protocol/http/coolio.rb
|
|
168
|
+
- lib/groonga/client/protocol/http/synchronous.rb
|
|
168
169
|
- lib/groonga/client/protocol/http/thread.rb
|
|
169
170
|
- lib/groonga/client/response.rb
|
|
170
171
|
- lib/groonga/client/response/base.rb
|
|
@@ -229,17 +230,17 @@ specification_version: 4
|
|
|
229
230
|
summary: Groonga-client is a client for groonga (http://groonga.org/) implemented
|
|
230
231
|
with pure ruby.
|
|
231
232
|
test_files:
|
|
232
|
-
- test/
|
|
233
|
-
- test/test-
|
|
234
|
-
- test/response/helper.rb
|
|
233
|
+
- test/protocol/test-http.rb
|
|
234
|
+
- test/protocol/test-gqtp.rb
|
|
235
235
|
- test/response/test-error.rb
|
|
236
|
-
- test/response/test-status.rb
|
|
237
236
|
- test/response/test-select.rb
|
|
238
237
|
- test/response/test-table-list.rb
|
|
239
238
|
- test/response/test-column-list.rb
|
|
240
|
-
- test/
|
|
239
|
+
- test/response/helper.rb
|
|
240
|
+
- test/response/test-status.rb
|
|
241
241
|
- test/results/test-table-list.rb
|
|
242
242
|
- test/results/test-column-list.rb
|
|
243
|
-
- test/
|
|
244
|
-
- test/
|
|
243
|
+
- test/test-command.rb
|
|
244
|
+
- test/run-test.rb
|
|
245
|
+
- test/test-client.rb
|
|
245
246
|
has_rdoc:
|