groonga-client 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 421c54a9bc6c48ecfa2324010d0fd8e51d1bfb5d
4
+ data.tar.gz: 2588991abfffd393e18b43e5ebe8db807af463a5
5
+ SHA512:
6
+ metadata.gz: f7a4b01cee40b67dd1c8225c90ae22c2fc4e0b9403df4345c68f8fb641cdb4c5282fbcb4668b2c4646092a36fc275cb408ff7fb0a84b1a719d903cd97e0ef6cd
7
+ data.tar.gz: a846c1f591bb17d996a521b6c4d5b7e28f5f8d2c0b06d9ec09a4b8feda6967e3057073464fa3f5413058bb1e09f401c7db9415b181b9936a3d7f6cbe1a74c3b7
data/doc/text/news.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.0.5 - 2014-03-25
4
+
5
+ ### Improvements
6
+
7
+ * Wrapped internal connection errors by
8
+ `Groonga::Client::Connection::Error`.
9
+ * Supported asynchronous request by calling with block.
10
+ * Added Cool.io HTTP backend.
11
+
12
+ ### Changes
13
+
14
+ * Changed protocol implementation module/directory name to
15
+ `protocol` from `connection`.
16
+
17
+ ### Fixes
18
+
19
+ * Fixed a bug that options passed to `Groonga::Client.new` is
20
+ changed destructively.
21
+
3
22
  ## 0.0.4 - 2013-10-29
4
23
 
5
24
  ### Improvements
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
4
+ # Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
5
5
  #
6
6
  # This library is free software; you can redistribute it and/or
7
7
  # modify it under the terms of the GNU Lesser General Public
@@ -18,8 +18,9 @@
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
 
20
20
  require "groonga/client/command"
21
- require "groonga/client/connection/gqtp"
22
- require "groonga/client/connection/http"
21
+ require "groonga/client/empty-request"
22
+ require "groonga/client/protocol/gqtp"
23
+ require "groonga/client/protocol/http"
23
24
 
24
25
  module Groonga
25
26
  class Client
@@ -59,18 +60,16 @@ module Groonga
59
60
  end
60
61
  end
61
62
 
62
- attr_reader :protocol
63
- attr_reader :connection
64
-
65
63
  # @macro initialize_options
66
- def initialize(options)
67
- @protocol = options.delete(:protocol) || :gqtp
64
+ def initialize(options={})
65
+ options = options.dup
66
+ protocol = options.delete(:protocol) || :gqtp
68
67
 
69
68
  @connection = nil
70
- if @protocol == :gqtp
71
- @connection = Groonga::Client::Connection::GQTP.new(options)
69
+ if protocol == :gqtp
70
+ @connection = Groonga::Client::Protocol::GQTP.new(options)
72
71
  else
73
- @connection = Groonga::Client::Connection::HTTP.new(options)
72
+ @connection = Groonga::Client::Protocol::HTTP.new(options)
74
73
  end
75
74
  end
76
75
 
@@ -108,101 +107,101 @@ module Groonga
108
107
  if sync
109
108
  false
110
109
  else
111
- Connection::EmptryReqest.new
110
+ EmptryReqest.new
112
111
  end
113
112
  end
114
113
  end
115
114
 
116
- def cache_limit(parameters)
117
- execute_command("cache_limit", parameters)
115
+ def cache_limit(parameters, &block)
116
+ execute_command("cache_limit", parameters, &block)
118
117
  end
119
118
 
120
- def check(parameters)
121
- execute_command("check", parameters)
119
+ def check(parameters, &block)
120
+ execute_command("check", parameters, &block)
122
121
  end
123
122
 
124
- def clearlock(parameters={})
125
- execute_command("clearlock", parameters)
123
+ def clearlock(parameters={}, &block)
124
+ execute_command("clearlock", parameters, &block)
126
125
  end
127
126
 
128
- def column_create(parameters)
129
- execute_command("column_create", parameters)
127
+ def column_create(parameters, &block)
128
+ execute_command("column_create", parameters, &block)
130
129
  end
131
130
 
132
- def column_list(parameters)
133
- execute_command("column_list", parameters)
131
+ def column_list(parameters, &block)
132
+ execute_command("column_list", parameters, &block)
134
133
  end
135
134
 
136
- def column_remove(parameters)
137
- execute_command("column_remove", parameters)
135
+ def column_remove(parameters, &block)
136
+ execute_command("column_remove", parameters, &block)
138
137
  end
139
138
 
140
- def column_rename(parameters)
141
- execute_command("column_rename", parameters)
139
+ def column_rename(parameters, &block)
140
+ execute_command("column_rename", parameters, &block)
142
141
  end
143
142
 
144
- def defrag(parameters={})
145
- execute_command("defrag", parameters)
143
+ def defrag(parameters={}, &block)
144
+ execute_command("defrag", parameters, &block)
146
145
  end
147
146
 
148
- def delete(parameters)
149
- execute_command("delete", parameters)
147
+ def delete(parameters, &block)
148
+ execute_command("delete", parameters, &block)
150
149
  end
151
150
 
152
- def dump(parameters={})
153
- execute_command("dump", parameters)
151
+ def dump(parameters={}, &block)
152
+ execute_command("dump", parameters, &block)
154
153
  end
155
154
 
156
- def load(parameters)
157
- execute_command("load", parameters)
155
+ def load(parameters, &block)
156
+ execute_command("load", parameters, &block)
158
157
  end
159
158
 
160
- def log_level(parameters)
161
- execute_command("log_level", parameters)
159
+ def log_level(parameters, &block)
160
+ execute_command("log_level", parameters, &block)
162
161
  end
163
162
 
164
- def log_put(parameters)
165
- execute_command("log_put", parameters)
163
+ def log_put(parameters, &block)
164
+ execute_command("log_put", parameters, &block)
166
165
  end
167
166
 
168
- def log_reopen(parameters={})
169
- execute_command("log_reopen", parameters)
167
+ def log_reopen(parameters={}, &block)
168
+ execute_command("log_reopen", parameters, &block)
170
169
  end
171
170
 
172
- def quit(parameters={})
173
- execute_command("quit", parameters)
171
+ def quit(parameters={}, &block)
172
+ execute_command("quit", parameters, &block)
174
173
  end
175
174
 
176
- def register(parameters)
177
- execute_command("register", parameters)
175
+ def register(parameters, &block)
176
+ execute_command("register", parameters, &block)
178
177
  end
179
178
 
180
- def select(parameters)
181
- execute_command("select", parameters)
179
+ def select(parameters, &block)
180
+ execute_command("select", parameters, &block)
182
181
  end
183
182
 
184
- def shutdown(parameters={})
183
+ def shutdown(parameters={}, &block)
185
184
  end
186
185
 
187
- def status(parameters={})
188
- execute_command("status", parameters)
186
+ def status(parameters={}, &block)
187
+ execute_command("status", parameters, &block)
189
188
  end
190
189
 
191
- def table_create(parameters)
192
- execute_command("table_create", parameters)
190
+ def table_create(parameters, &block)
191
+ execute_command("table_create", parameters, &block)
193
192
  end
194
193
 
195
- def table_list(parameters={})
196
- execute_command("table_list", parameters)
194
+ def table_list(parameters={}, &block)
195
+ execute_command("table_list", parameters, &block)
197
196
  end
198
197
 
199
- def table_remove(parameters)
198
+ def table_remove(parameters, &block)
200
199
  end
201
200
 
202
- def table_rename(parameters)
201
+ def table_rename(parameters, &block)
203
202
  end
204
203
 
205
- def truncate(parameters)
204
+ def truncate(parameters, &block)
206
205
  end
207
206
 
208
207
  def execute(command, &block)
@@ -210,11 +209,11 @@ module Groonga
210
209
  end
211
210
 
212
211
  private
213
- def execute_command(command_name, parameters={})
212
+ def execute_command(command_name, parameters={}, &block)
214
213
  parameters = normalize_parameters(parameters)
215
214
  command_class = Groonga::Command.find(command_name)
216
215
  command = command_class.new(command_name, parameters)
217
- execute(command)
216
+ execute(command, &block)
218
217
  end
219
218
 
220
219
  def normalize_parameters(parameters)
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -18,23 +18,11 @@
18
18
 
19
19
  module Groonga
20
20
  class Client
21
- module Connection
22
- class ThreadRequest
23
- def initialize(thread)
24
- @thread = thread
25
- end
26
-
27
- def wait
28
- @thread.join
29
- end
21
+ class EmptyRequest
22
+ def initialize
30
23
  end
31
24
 
32
- class EmptyRequest
33
- def initialize
34
- end
35
-
36
- def wait
37
- end
25
+ def wait
38
26
  end
39
27
  end
40
28
  end
@@ -0,0 +1,22 @@
1
+ # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library 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 library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ module Groonga
18
+ class Client
19
+ class Error < StandardError
20
+ end
21
+ end
22
+ end
@@ -16,10 +16,15 @@
16
16
  # License along with this library; if not, write to the Free Software
17
17
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
 
19
+ require "groonga/client/error"
20
+
19
21
  module Groonga
20
22
  class Client
21
- module Connection
22
- class Error < StandardError
23
+ module Protocol
24
+ class Error < Client::Error
25
+ end
26
+
27
+ class WrappedError < Error
23
28
  attr_reader :raw_error
24
29
  def initialize(raw_error)
25
30
  @raw_error = raw_error
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
4
+ # Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
5
5
  #
6
6
  # This library is free software; you can redistribute it and/or
7
7
  # modify it under the terms of the GNU Lesser General Public
@@ -22,14 +22,19 @@ require "erb"
22
22
  require "gqtp"
23
23
  require "json"
24
24
 
25
- require "groonga/client/connection/request"
25
+ require "groonga/client/empty-request"
26
+ require "groonga/client/protocol/error"
26
27
 
27
28
  module Groonga
28
29
  class Client
29
- module Connection
30
+ module Protocol
30
31
  class GQTP
31
32
  def initialize(options)
32
- @client = ::GQTP::Client.new(options)
33
+ begin
34
+ @client = ::GQTP::Client.new(options)
35
+ rescue ::GQTP::ConnectionError
36
+ raise WrappedError.new($!)
37
+ end
33
38
  end
34
39
 
35
40
  def send(command)
@@ -0,0 +1,70 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+
20
+ require "groonga/client/protocol/error"
21
+
22
+ module Groonga
23
+ class Client
24
+ module Protocol
25
+ class HTTP
26
+ class UnknownBackendError < Error
27
+ attr_reader :backend
28
+ def initialize(backend, detail)
29
+ @backend = backend
30
+ super("Unknown HTTP backend: <#{backend}>: #{detail}")
31
+ end
32
+ end
33
+
34
+ def initialize(options)
35
+ @host = options[:host] || "127.0.0.1"
36
+ @port = options[:port] || 10041
37
+ @options = options
38
+ @backend = create_backend
39
+ end
40
+
41
+ def send(command, &block)
42
+ @backend.send(command, &block)
43
+ end
44
+
45
+ def connected?
46
+ @backend.connected?
47
+ end
48
+
49
+ def close(&block)
50
+ @backend.close(&block)
51
+ end
52
+
53
+ private
54
+ def create_backend
55
+ backend = @options[:backend] || :thread
56
+
57
+ begin
58
+ require "groonga/client/protocol/http/#{backend}"
59
+ rescue LoadError
60
+ raise UnknownBackendError.new(backend, $!.message)
61
+ end
62
+
63
+ backend_name = backend.to_s.capitalize
64
+ backend_class = self.class.const_get(backend_name)
65
+ backend_class.new(@host, @port, @options)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,92 @@
1
+ # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library 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 library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "coolio"
18
+
19
+ require "groonga/client/empty-request"
20
+ require "groonga/client/protocol/error"
21
+
22
+ module Groonga
23
+ class Client
24
+ module Protocol
25
+ class HTTP
26
+ class Coolio
27
+ class Request
28
+ def initialize(client, loop)
29
+ @client = client
30
+ @loop = loop
31
+ end
32
+
33
+ def wait
34
+ until @client.finished?
35
+ @loop.run_once
36
+ end
37
+ end
38
+ end
39
+
40
+ class GroongaHTTPClient < ::Coolio::HttpClient
41
+ def initialize(socket, callback)
42
+ super(socket)
43
+ @callback = callback
44
+ @finished = false
45
+ end
46
+
47
+ def finished?
48
+ @finished
49
+ end
50
+
51
+ def on_body_data(data)
52
+ @callback.call(data)
53
+ end
54
+
55
+ def on_close
56
+ super
57
+ @finished = true
58
+ end
59
+ end
60
+
61
+ def initialize(host, port, options)
62
+ @host = host
63
+ @port = port
64
+ @options = options
65
+ @loop = @options[:loop] || ::Coolio::Loop.default
66
+ end
67
+
68
+ def send(command, &block)
69
+ client = GroongaHTTPClient.connect(@host, @port, block)
70
+ client.attach(@loop)
71
+ client.request("GET", command.to_uri_format)
72
+ Request.new(client, @loop)
73
+ end
74
+
75
+ def connected?
76
+ false
77
+ end
78
+
79
+ def close(&block)
80
+ sync = !block_given?
81
+ if sync
82
+ false
83
+ else
84
+ yield
85
+ EmptyRequest.new
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,95 @@
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 "open-uri"
19
+
20
+ require "groonga/client/empty-request"
21
+ require "groonga/client/protocol/error"
22
+
23
+ module Groonga
24
+ class Client
25
+ module Protocol
26
+ class HTTP
27
+ class Thread
28
+ class Request
29
+ def initialize(thread)
30
+ @thread = thread
31
+ end
32
+
33
+ def wait
34
+ @thread.join
35
+ end
36
+ end
37
+
38
+ def initialize(host, port, options)
39
+ @host = host
40
+ @port = port
41
+ @options = options
42
+ end
43
+
44
+ def send(command)
45
+ url = "http://#{@host}:#{@port}#{command.to_uri_format}"
46
+ thread = ::Thread.new do
47
+ begin
48
+ open(url) do |response|
49
+ body = response.read
50
+ yield(body)
51
+ end
52
+ rescue OpenURI::HTTPError, Timeout::Error
53
+ raise WrappedError.new($!)
54
+ end
55
+ end
56
+ Request.new(thread)
57
+ end
58
+
59
+ # @return [false] Always returns false because the current
60
+ # implementation doesn't support keep-alive.
61
+ def connected?
62
+ false
63
+ end
64
+
65
+ # Does nothing because the current implementation doesn't
66
+ # support keep-alive. If the implementation supports
67
+ # keep-alive, it close the opend connection.
68
+ #
69
+ # @overload close
70
+ # Closes synchronously.
71
+ #
72
+ # @return [false] It always returns false because there is always
73
+ # no connection.
74
+ #
75
+ # @overload close {}
76
+ # Closes asynchronously.
77
+ #
78
+ # @yield [] Calls the block when the opened connection is closed.
79
+ # @return [#wait] The request object. If you want to wait until
80
+ # the request is processed. You can send #wait message to the
81
+ # request.
82
+ def close(&block)
83
+ sync = !block_given?
84
+ if sync
85
+ false
86
+ else
87
+ yield
88
+ EmptyRequest.new
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -18,6 +18,6 @@
18
18
 
19
19
  module Groonga
20
20
  class Client
21
- VERSION = "0.0.4"
21
+ VERSION = "0.0.5"
22
22
  end
23
23
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -18,16 +18,16 @@
18
18
 
19
19
  require "socket"
20
20
 
21
- require "groonga/client/connection/gqtp"
21
+ require "groonga/client/protocol/gqtp"
22
22
 
23
- class TestConnectionGQTP < Test::Unit::TestCase
23
+ class TestProtocolGQTP < Test::Unit::TestCase
24
24
  def setup
25
25
  setup_server
26
- setup_connection
26
+ setup_client
27
27
  end
28
28
 
29
29
  def teardown
30
- teardown_connection
30
+ teardown_client
31
31
  teardown_server
32
32
  end
33
33
 
@@ -35,7 +35,6 @@ class TestConnectionGQTP < Test::Unit::TestCase
35
35
  @address = "127.0.0.1"
36
36
  @server = TCPServer.new(@address, 0)
37
37
  @port = @server.addr[1]
38
- @protocol = :gqtp
39
38
 
40
39
  @thread = Thread.new do
41
40
  client = @server.accept
@@ -51,12 +50,12 @@ class TestConnectionGQTP < Test::Unit::TestCase
51
50
  @thread.kill
52
51
  end
53
52
 
54
- def setup_connection
55
- @connection = nil
53
+ def setup_client
54
+ @client = nil
56
55
  end
57
56
 
58
- def teardown_connection
59
- @connection.close {} if @connection
57
+ def teardown_client
58
+ @client.close {} if @client
60
59
  end
61
60
 
62
61
  private
@@ -65,41 +64,51 @@ class TestConnectionGQTP < Test::Unit::TestCase
65
64
  :host => @address,
66
65
  :port => @port,
67
66
  }
68
- Groonga::Client::Connection::GQTP.new(default_options.merge(options))
67
+ Groonga::Client::Protocol::GQTP.new(default_options.merge(options))
69
68
  end
70
69
 
71
70
  def process_client_close(client)
72
71
  response_body = [].to_json
73
- 2.times do
74
- header = GQTP::Header.parse(client.read(GQTP::Header.size))
75
- client.read(header.size)
72
+ header = GQTP::Header.parse(client.read(GQTP::Header.size))
73
+ client.read(header.size)
76
74
 
77
- response_header = GQTP::Header.new
78
- response_header.size = response_body.bytesize
75
+ response_header = GQTP::Header.new
76
+ response_header.size = response_body.bytesize
79
77
 
80
- client.write(response_header.pack)
81
- client.write(response_body)
78
+ client.write(response_header.pack)
79
+ client.write(response_body)
80
+ end
81
+
82
+ class TestConnect < self
83
+ def test_no_server
84
+ server = TCPServer.new("127.0.0.1", 0)
85
+ free_port = server.addr[1]
86
+ server.close
87
+ assert_raise(Groonga::Client::Protocol::WrappedError) do
88
+ Groonga::Client::Protocol::GQTP.new(:host => "127.0.0.1",
89
+ :port => free_port)
90
+ end
82
91
  end
83
92
  end
84
93
 
85
94
  class TestConnected < self
86
95
  def test_opened
87
- @connection = connect
88
- assert_true(@connection.connected?)
96
+ @client = connect
97
+ assert_true(@client.connected?)
89
98
  end
90
99
 
91
100
  def test_closed
92
- @connection = connect
93
- @connection.close
94
- assert_false(@connection.connected?)
101
+ @client = connect
102
+ @client.close
103
+ assert_false(@client.connected?)
95
104
  end
96
105
  end
97
106
 
98
107
  class TestClose < self
99
108
  def test_twice
100
- @connection = connect
101
- @connection.close
102
- assert_false(@connection.close)
109
+ @client = connect
110
+ @client.close
111
+ assert_false(@client.close)
103
112
  end
104
113
  end
105
114
  end
@@ -1,6 +1,6 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
4
4
  #
5
5
  # This library is free software; you can redistribute it and/or
6
6
  # modify it under the terms of the GNU Lesser General Public
@@ -18,16 +18,16 @@
18
18
 
19
19
  require "socket"
20
20
 
21
- require "groonga/client/connection/http"
21
+ require "groonga/client/protocol/http"
22
22
 
23
- class TestConnectionHTTP < Test::Unit::TestCase
23
+ class TestProtocolHTTP < Test::Unit::TestCase
24
24
  def setup
25
25
  setup_server
26
- setup_connection
26
+ setup_client
27
27
  end
28
28
 
29
29
  def teardown
30
- teardown_connection
30
+ teardown_client
31
31
  teardown_server
32
32
  end
33
33
 
@@ -35,7 +35,6 @@ class TestConnectionHTTP < Test::Unit::TestCase
35
35
  @address = "127.0.0.1"
36
36
  @server = TCPServer.new(@address, 0)
37
37
  @port = @server.addr[1]
38
- @protocol = :http
39
38
 
40
39
  @response_body = nil
41
40
  @thread = Thread.new do
@@ -66,12 +65,12 @@ EOH
66
65
  @thread.kill
67
66
  end
68
67
 
69
- def setup_connection
70
- @connection = nil
68
+ def setup_client
69
+ @client = nil
71
70
  end
72
71
 
73
- def teardown_connection
74
- @connection.close if @connection
72
+ def teardown_client
73
+ @client.close if @client
75
74
  end
76
75
 
77
76
  def connect(options={})
@@ -79,19 +78,19 @@ EOH
79
78
  :host => @address,
80
79
  :port => @port,
81
80
  }
82
- Groonga::Client::Connection::HTTP.new(default_options.merge(options))
81
+ Groonga::Client::Protocol::HTTP.new(default_options.merge(options))
83
82
  end
84
83
 
85
84
  def test_connected?
86
- @connection = connect
87
- assert_false(@connection.connected?)
85
+ @client = connect
86
+ assert_false(@client.connected?)
88
87
  end
89
88
 
90
89
  class TestClose < self
91
90
  def test_twice
92
- @connection = connect
93
- assert_false(@connection.close)
94
- assert_false(@connection.close)
91
+ @client = connect
92
+ assert_false(@client.close)
93
+ assert_false(@client.close)
95
94
  end
96
95
  end
97
96
  end
data/test/test-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 "time"
20
21
  require "socket"
21
22
  require "groonga/client"
22
23
 
metadata CHANGED
@@ -1,8 +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
5
- prerelease:
4
+ version: 0.0.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Haruka Yoshihara
@@ -11,161 +10,139 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2013-10-29 00:00:00.000000000 Z
13
+ date: 2014-03-25 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: gqtp
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
- - - ! '>='
19
+ - - '>='
22
20
  - !ruby/object:Gem::Version
23
21
  version: 1.0.4
24
22
  type: :runtime
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
25
  requirements:
29
- - - ! '>='
26
+ - - '>='
30
27
  - !ruby/object:Gem::Version
31
28
  version: 1.0.4
32
29
  - !ruby/object:Gem::Dependency
33
30
  name: groonga-command
34
31
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
32
  requirements:
37
- - - ! '>='
33
+ - - '>='
38
34
  - !ruby/object:Gem::Version
39
35
  version: 1.0.4
40
36
  type: :runtime
41
37
  prerelease: false
42
38
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
39
  requirements:
45
- - - ! '>='
40
+ - - '>='
46
41
  - !ruby/object:Gem::Version
47
42
  version: 1.0.4
48
43
  - !ruby/object:Gem::Dependency
49
44
  name: bundler
50
45
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
46
  requirements:
53
- - - ! '>='
47
+ - - '>='
54
48
  - !ruby/object:Gem::Version
55
49
  version: '0'
56
50
  type: :development
57
51
  prerelease: false
58
52
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
53
  requirements:
61
- - - ! '>='
54
+ - - '>='
62
55
  - !ruby/object:Gem::Version
63
56
  version: '0'
64
57
  - !ruby/object:Gem::Dependency
65
58
  name: rake
66
59
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
60
  requirements:
69
- - - ! '>='
61
+ - - '>='
70
62
  - !ruby/object:Gem::Version
71
63
  version: '0'
72
64
  type: :development
73
65
  prerelease: false
74
66
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
67
  requirements:
77
- - - ! '>='
68
+ - - '>='
78
69
  - !ruby/object:Gem::Version
79
70
  version: '0'
80
71
  - !ruby/object:Gem::Dependency
81
72
  name: test-unit
82
73
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
74
  requirements:
85
- - - ! '>='
75
+ - - '>='
86
76
  - !ruby/object:Gem::Version
87
77
  version: '0'
88
78
  type: :development
89
79
  prerelease: false
90
80
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
81
  requirements:
93
- - - ! '>='
82
+ - - '>='
94
83
  - !ruby/object:Gem::Version
95
84
  version: '0'
96
85
  - !ruby/object:Gem::Dependency
97
86
  name: test-unit-notify
98
87
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
88
  requirements:
101
- - - ! '>='
89
+ - - '>='
102
90
  - !ruby/object:Gem::Version
103
91
  version: '0'
104
92
  type: :development
105
93
  prerelease: false
106
94
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
95
  requirements:
109
- - - ! '>='
96
+ - - '>='
110
97
  - !ruby/object:Gem::Version
111
98
  version: '0'
112
99
  - !ruby/object:Gem::Dependency
113
100
  name: test-unit-rr
114
101
  requirement: !ruby/object:Gem::Requirement
115
- none: false
116
102
  requirements:
117
- - - ! '>='
103
+ - - '>='
118
104
  - !ruby/object:Gem::Version
119
105
  version: '0'
120
106
  type: :development
121
107
  prerelease: false
122
108
  version_requirements: !ruby/object:Gem::Requirement
123
- none: false
124
109
  requirements:
125
- - - ! '>='
110
+ - - '>='
126
111
  - !ruby/object:Gem::Version
127
112
  version: '0'
128
113
  - !ruby/object:Gem::Dependency
129
114
  name: packnga
130
115
  requirement: !ruby/object:Gem::Requirement
131
- none: false
132
116
  requirements:
133
- - - ! '>='
117
+ - - '>='
134
118
  - !ruby/object:Gem::Version
135
119
  version: '0'
136
120
  type: :development
137
121
  prerelease: false
138
122
  version_requirements: !ruby/object:Gem::Requirement
139
- none: false
140
123
  requirements:
141
- - - ! '>='
124
+ - - '>='
142
125
  - !ruby/object:Gem::Version
143
126
  version: '0'
144
127
  - !ruby/object:Gem::Dependency
145
128
  name: redcarpet
146
129
  requirement: !ruby/object:Gem::Requirement
147
- none: false
148
130
  requirements:
149
- - - ! '>='
131
+ - - '>='
150
132
  - !ruby/object:Gem::Version
151
133
  version: '0'
152
134
  type: :development
153
135
  prerelease: false
154
136
  version_requirements: !ruby/object:Gem::Requirement
155
- none: false
156
137
  requirements:
157
- - - ! '>='
138
+ - - '>='
158
139
  - !ruby/object:Gem::Version
159
140
  version: '0'
160
- description: ! 'Groonga-client gem supports HTTP or
161
-
141
+ description: |
142
+ Groonga-client gem supports HTTP or
162
143
  [GQTP (Groonga Query Transfer Protocol)](http://groonga.org/docs/spec/gqtp.html)
163
-
164
144
  as the protocol using a client. You can use it without groonga
165
-
166
145
  package.
167
-
168
- '
169
146
  email:
170
147
  - yshr04hrk@gmail.com
171
148
  - kou@clear-code.com
@@ -180,6 +157,7 @@ files:
180
157
  - groonga-client.gemspec
181
158
  - .yardopts
182
159
  - lib/groonga/client/response.rb
160
+ - lib/groonga/client/error.rb
183
161
  - lib/groonga/client/response/clearlock.rb
184
162
  - lib/groonga/client/response/column_remove.rb
185
163
  - lib/groonga/client/response/quit.rb
@@ -203,10 +181,12 @@ files:
203
181
  - lib/groonga/client/response/column_list.rb
204
182
  - lib/groonga/client/version.rb
205
183
  - lib/groonga/client/command.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
184
+ - lib/groonga/client/protocol/error.rb
185
+ - lib/groonga/client/protocol/http/coolio.rb
186
+ - lib/groonga/client/protocol/http/thread.rb
187
+ - lib/groonga/client/protocol/gqtp.rb
188
+ - lib/groonga/client/protocol/http.rb
189
+ - lib/groonga/client/empty-request.rb
210
190
  - lib/groonga/client.rb
211
191
  - doc/text/news.md
212
192
  - test/run-test.rb
@@ -219,32 +199,31 @@ files:
219
199
  - test/test-command.rb
220
200
  - test/results/test-table-list.rb
221
201
  - test/results/test-column-list.rb
222
- - test/connection/test-gqtp.rb
223
- - test/connection/test-http.rb
202
+ - test/protocol/test-gqtp.rb
203
+ - test/protocol/test-http.rb
224
204
  homepage: https://github.com/ranguba/groonga-client
225
205
  licenses:
226
206
  - LGPLv2.1 or later
207
+ metadata: {}
227
208
  post_install_message:
228
209
  rdoc_options: []
229
210
  require_paths:
230
211
  - lib
231
212
  required_ruby_version: !ruby/object:Gem::Requirement
232
- none: false
233
213
  requirements:
234
- - - ! '>='
214
+ - - '>='
235
215
  - !ruby/object:Gem::Version
236
216
  version: '0'
237
217
  required_rubygems_version: !ruby/object:Gem::Requirement
238
- none: false
239
218
  requirements:
240
- - - ! '>='
219
+ - - '>='
241
220
  - !ruby/object:Gem::Version
242
221
  version: '0'
243
222
  requirements: []
244
223
  rubyforge_project:
245
- rubygems_version: 1.8.23
224
+ rubygems_version: 2.0.14
246
225
  signing_key:
247
- specification_version: 3
226
+ specification_version: 4
248
227
  summary: Groonga-client is a client for groonga (http://groonga.org/) implemented
249
228
  with pure ruby.
250
229
  test_files:
@@ -258,6 +237,6 @@ test_files:
258
237
  - test/test-command.rb
259
238
  - test/results/test-table-list.rb
260
239
  - test/results/test-column-list.rb
261
- - test/connection/test-gqtp.rb
262
- - test/connection/test-http.rb
240
+ - test/protocol/test-gqtp.rb
241
+ - test/protocol/test-http.rb
263
242
  has_rdoc:
@@ -1,83 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
5
- #
6
- # This library is free software; you can redistribute it and/or
7
- # modify it under the terms of the GNU Lesser General Public
8
- # License as published by the Free Software Foundation; either
9
- # version 2.1 of the License, or (at your option) any later version.
10
- #
11
- # This library is distributed in the hope that it will be useful,
12
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- # Lesser General Public License for more details.
15
- #
16
- # You should have received a copy of the GNU Lesser General Public
17
- # License along with this library; if not, write to the Free Software
18
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
-
20
- require "open-uri"
21
-
22
- require "groonga/client/connection/request"
23
- require "groonga/client/connection/error"
24
-
25
- module Groonga
26
- class Client
27
- module Connection
28
- class HTTP
29
- def initialize(options)
30
- @host = options[:host] || "127.0.0.1"
31
- @port = options[:port] || 10041
32
- end
33
-
34
- def send(command)
35
- url = "http://#{@host}:#{@port}#{command.to_uri_format}"
36
- thread = Thread.new do
37
- begin
38
- open(url) do |response|
39
- body = response.read
40
- yield(body)
41
- end
42
- rescue OpenURI::HTTPError, Timeout::Error
43
- raise Error.new($!)
44
- end
45
- end
46
- ThreadRequest.new(thread)
47
- end
48
-
49
- # @return [false] Always returns false because the current
50
- # implementation doesn't support keep-alive.
51
- def connected?
52
- false
53
- end
54
-
55
- # Does nothing because the current implementation doesn't
56
- # support keep-alive. If the implementation supports
57
- # keep-alive, it close the opend connection.
58
- #
59
- # @overload close
60
- # Closes synchronously.
61
- #
62
- # @return [false] It always returns false because there is always
63
- # no connectin.
64
- #
65
- # @overload close {}
66
- # Closes asynchronously.
67
- #
68
- # @yield [] Calls the block when the opened connection is closed.
69
- # @return [#wait] The request object. If you want to wait until
70
- # the request is processed. You can send #wait message to the
71
- # request.
72
- def close(&block)
73
- sync = !block_given?
74
- if sync
75
- false
76
- else
77
- EmptyRequest.new
78
- end
79
- end
80
- end
81
- end
82
- end
83
- end