groonga-client 0.0.1

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.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +4 -0
  3. data/Gemfile +21 -0
  4. data/README.md +66 -0
  5. data/Rakefile +44 -0
  6. data/doc/text/news.md +5 -0
  7. data/groonga-client.gemspec +58 -0
  8. data/lib/groonga/client.rb +165 -0
  9. data/lib/groonga/client/command.rb +49 -0
  10. data/lib/groonga/client/protocol/gqtp.rb +93 -0
  11. data/lib/groonga/client/protocol/http.rb +54 -0
  12. data/lib/groonga/client/response.rb +36 -0
  13. data/lib/groonga/client/response/base.rb +114 -0
  14. data/lib/groonga/client/response/cache_limit.rb +30 -0
  15. data/lib/groonga/client/response/check.rb +29 -0
  16. data/lib/groonga/client/response/clearlock.rb +30 -0
  17. data/lib/groonga/client/response/column_create.rb +30 -0
  18. data/lib/groonga/client/response/column_list.rb +56 -0
  19. data/lib/groonga/client/response/column_remove.rb +30 -0
  20. data/lib/groonga/client/response/column_rename.rb +30 -0
  21. data/lib/groonga/client/response/defrag.rb +30 -0
  22. data/lib/groonga/client/response/delete.rb +30 -0
  23. data/lib/groonga/client/response/dump.rb +30 -0
  24. data/lib/groonga/client/response/load.rb +30 -0
  25. data/lib/groonga/client/response/log_level.rb +30 -0
  26. data/lib/groonga/client/response/log_put.rb +30 -0
  27. data/lib/groonga/client/response/log_reopen.rb +30 -0
  28. data/lib/groonga/client/response/quit.rb +30 -0
  29. data/lib/groonga/client/response/register.rb +30 -0
  30. data/lib/groonga/client/response/status.rb +29 -0
  31. data/lib/groonga/client/response/table_list.rb +57 -0
  32. data/lib/groonga/client/version.rb +5 -0
  33. data/test/run-test.rb +44 -0
  34. data/test/test-client.rb +300 -0
  35. metadata +201 -0
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "groonga/client/response/base"
20
+
21
+ module Groonga
22
+ class Client
23
+ module Response
24
+ class Defrag < Base
25
+ Response.register("defrag", self)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "groonga/client/response/base"
20
+
21
+ module Groonga
22
+ class Client
23
+ module Response
24
+ class Delete < Base
25
+ Response.register("delete", self)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "groonga/client/response/base"
20
+
21
+ module Groonga
22
+ class Client
23
+ module Response
24
+ class Dump < Base
25
+ Response.register("dump", self)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "groonga/client/response/base"
20
+
21
+ module Groonga
22
+ class Client
23
+ module Response
24
+ class Load < Base
25
+ Response.register("load", self)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "groonga/client/response/base"
20
+
21
+ module Groonga
22
+ class Client
23
+ module Response
24
+ class LogLevel < Base
25
+ Response.register("log_level", self)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "groonga/client/response/base"
20
+
21
+ module Groonga
22
+ class Client
23
+ module Response
24
+ class LogPut < Base
25
+ Response.register("log_put", self)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "groonga/client/response/base"
20
+
21
+ module Groonga
22
+ class Client
23
+ module Response
24
+ class LogReopen < Base
25
+ Response.register("log_reopen", self)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "groonga/client/response/base"
20
+
21
+ module Groonga
22
+ class Client
23
+ module Response
24
+ class Quit < Base
25
+ Response.register("quit", self)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "groonga/client/response/base"
20
+
21
+ module Groonga
22
+ class Client
23
+ module Response
24
+ class Register < Base
25
+ Response.register("register", self)
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,29 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "groonga/client/response/base"
20
+
21
+ module Groonga
22
+ class Client
23
+ module Response
24
+ class Status < Base
25
+ Response.register("status", self)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,57 @@
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/response/base"
21
+
22
+ module Groonga
23
+ class Client
24
+ module Response
25
+ class TableList < Base
26
+ Response.register("table_list", self)
27
+
28
+ def initialize(header, body)
29
+ super(header, parse_body(body))
30
+ end
31
+
32
+ private
33
+ def parse_body(body)
34
+ properties = body.first
35
+ infos = body[1..-1]
36
+ infos.collect do |info|
37
+ table = Table.new
38
+ properties.each_with_index do |(name, _), i|
39
+ table.send("#{name}=", info[i])
40
+ end
41
+ table
42
+ end
43
+ end
44
+
45
+ class Table < Struct.new(:id,
46
+ :name,
47
+ :path,
48
+ :flags,
49
+ :domain,
50
+ :range,
51
+ :default_tokenizer,
52
+ :normalizer)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,5 @@
1
+ module Groonga
2
+ class Client
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
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
+ $VERBOSE = true
21
+
22
+ require "pathname"
23
+
24
+ base_dir = Pathname.new(__FILE__).dirname.parent.expand_path
25
+
26
+ gqtp_base_dir = base_dir.parent + "gqtp"
27
+ gqtp_lib_dir = gqtp_base_dir + "lib"
28
+ $LOAD_PATH.unshift(gqtp_lib_dir.to_s)
29
+
30
+ groonga_command_base_dir = base_dir.parent + "groonga-command"
31
+ groonga_command_lib_dir = groonga_command_base_dir + "lib"
32
+ $LOAD_PATH.unshift(groonga_command_lib_dir.to_s)
33
+
34
+ lib_dir = base_dir + "lib"
35
+ test_dir = base_dir + "test"
36
+
37
+ $LOAD_PATH.unshift(lib_dir.to_s)
38
+
39
+ require "test-unit"
40
+ require "test/unit/notify"
41
+
42
+ Thread.abort_on_exception = true
43
+
44
+ exit Test::Unit::AutoRunner.run(true, test_dir.to_s)
@@ -0,0 +1,300 @@
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 "socket"
21
+ require "groonga/client"
22
+
23
+ class TestClient < Test::Unit::TestCase
24
+ module ClientFixture
25
+ class << self
26
+ def included(base)
27
+ super
28
+ base.class_eval do
29
+ setup :setup_client
30
+ teardown :teardown_client
31
+ end
32
+ end
33
+ end
34
+
35
+ def setup_client
36
+ @client = nil
37
+ end
38
+
39
+ def teardown_client
40
+ @client.close if @client
41
+ end
42
+ end
43
+
44
+ module Utils
45
+ def client
46
+ @client ||= open_client
47
+ end
48
+
49
+ def open_client(&block)
50
+ options = {:host => @address, :port => @port, :protocol => @protocol}
51
+ Groonga::Client.open(options, &block)
52
+ end
53
+
54
+ def stub_response(body, output_type=:json)
55
+ @response_body = body
56
+ @response_output_type = output_type
57
+ end
58
+ end
59
+
60
+ module Assertions
61
+ NORMALIZED_START_TIME = Time.parse("2013-05-23T16:43:39+09:00").to_i
62
+ NORMALIZED_ELAPSED_TIME = 29
63
+ def normalize_header(header)
64
+ normalized_header = header.dup
65
+ start_time = header[1]
66
+ if start_time.is_a?(Numeric)
67
+ normalized_header[1] = NORMALIZED_START_TIME
68
+ end
69
+ elapsed_time = header[2]
70
+ if elapsed_time.is_a?(Numeric)
71
+ normalized_header[2] = NORMALIZED_ELAPSED_TIME
72
+ end
73
+ normalized_header
74
+ end
75
+
76
+ def assert_header(response)
77
+ normalized_header = normalize_header(response.header)
78
+ assert_equal([0, NORMALIZED_START_TIME, NORMALIZED_ELAPSED_TIME],
79
+ normalized_header)
80
+ end
81
+
82
+ def assert_response(expected_body, response)
83
+ if @response_output_type == :none
84
+ expected_header = nil
85
+ actual_header = response.header
86
+ else
87
+ expected_header = [
88
+ 0,
89
+ NORMALIZED_START_TIME,
90
+ NORMALIZED_ELAPSED_TIME,
91
+ ]
92
+ actual_header = normalize_header(response.header)
93
+ end
94
+ actual_body = response.body
95
+ actual_body = yield(actual_body) if block_given?
96
+ assert_equal({
97
+ :header => expected_header,
98
+ :body => expected_body,
99
+ },
100
+ {
101
+ :header => actual_header,
102
+ :body => actual_body,
103
+ })
104
+ end
105
+ end
106
+
107
+ module OutputTypeTests
108
+ def test_dump
109
+ dumped_commands = "table_create TEST_TABLE TABLE_NO_KEY"
110
+ stub_response(dumped_commands, :none)
111
+ response = client.dump
112
+ assert_response(dumped_commands, response)
113
+ end
114
+
115
+ def test_xml
116
+ stub_response(<<-XML, :xml)
117
+ <TABLE_LIST>
118
+ <HEADER>
119
+ <PROPERTY>
120
+ <TEXT>id</TEXT>
121
+ <TEXT>UInt32</TEXT></PROPERTY>
122
+ <PROPERTY>
123
+ <TEXT>name</TEXT>
124
+ <TEXT>ShortText</TEXT></PROPERTY>
125
+ <PROPERTY>
126
+ <TEXT>path</TEXT>
127
+ <TEXT>ShortText</TEXT></PROPERTY>
128
+ <PROPERTY>
129
+ <TEXT>flags</TEXT>
130
+ <TEXT>ShortText</TEXT></PROPERTY>
131
+ <PROPERTY>
132
+ <TEXT>domain</TEXT>
133
+ <TEXT>ShortText</TEXT></PROPERTY>
134
+ <PROPERTY>
135
+ <TEXT>range</TEXT>
136
+ <TEXT>ShortText</TEXT></PROPERTY>
137
+ <PROPERTY>
138
+ <TEXT>default_tokenizer</TEXT>
139
+ <TEXT>ShortText</TEXT></PROPERTY>
140
+ <PROPERTY>
141
+ <TEXT>normalizer</TEXT>
142
+ <TEXT>ShortText</TEXT></PROPERTY></HEADER>
143
+ <TABLE>
144
+ <INT>256</INT>
145
+ <TEXT>Users</TEXT>
146
+ <TEXT>/tmp/db/db.0000100</TEXT>
147
+ <TEXT>TABLE_HASH_KEY|PERSISTENT</TEXT>
148
+ <NULL/>
149
+ <NULL/>
150
+ <NULL/>
151
+ <NULL/></TABLE></TABLE_LIST>
152
+ XML
153
+ response = client.table_list(:output_type => :xml)
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),
163
+ ]
164
+ assert_response(expected_body, response)
165
+ 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
+ end
180
+
181
+ module ColumnsTests
182
+ def test_not_exist
183
+ stub_response('{"key":"value"}')
184
+ response = client.status
185
+ assert_response({"key" => "value"}, response)
186
+ end
187
+
188
+ def disabled_test_exist
189
+ stub_response(<<-JSON)
190
+ [[["name","ShortText"],
191
+ ["age","UInt32"]],
192
+ ["Alice",32],
193
+ ["Bob",21]]
194
+ JSON
195
+ expected_table_infos = [
196
+ {:name => "Alice", :age => 32},
197
+ {:name => "Bob", :age => 21}
198
+ ]
199
+ response = client.table_list
200
+ assert_response(expected_table_infos, response) do |actual_body|
201
+ actual_body.collect do |value|
202
+ value.table_info
203
+ end
204
+ end
205
+ end
206
+ end
207
+
208
+ module ParametersTests
209
+ def test_integer
210
+ stub_response("100")
211
+ response = client.cache_limit(:max => 4)
212
+ assert_response(100, response)
213
+ end
214
+ end
215
+
216
+ module Tests
217
+ include Utils
218
+ include Assertions
219
+
220
+ include OutputTypeTests
221
+ include ColumnsTests
222
+ include ParametersTests
223
+ end
224
+
225
+ class TestGQTP < self
226
+ include Tests
227
+ include ClientFixture
228
+
229
+ def setup
230
+ @address = "127.0.0.1"
231
+ @server = TCPServer.new(@address, 0)
232
+ @port = @server.addr[1]
233
+ @protocol = :gqtp
234
+
235
+ @response_body = nil
236
+ @thread = Thread.new do
237
+ client = @server.accept
238
+ @server.close
239
+
240
+ header = GQTP::Header.parse(client.read(GQTP::Header.size))
241
+ client.read(header.size)
242
+
243
+ response_header = GQTP::Header.new
244
+ response_header.size = @response_body.bytesize
245
+
246
+ client.write(response_header.pack)
247
+ client.write(@response_body)
248
+ client.close
249
+ end
250
+ end
251
+
252
+ def teardown
253
+ @thread.kill
254
+ end
255
+ end
256
+
257
+ class TestHTTP < self
258
+ include Tests
259
+ include ClientFixture
260
+
261
+ def setup
262
+ @address = "127.0.0.1"
263
+ @server = TCPServer.new(@address, 0)
264
+ @port = @server.addr[1]
265
+ @protocol = :http
266
+
267
+ @response_body = nil
268
+ @thread = Thread.new do
269
+ client = @server.accept
270
+ @server.close
271
+ status = 0
272
+ start = Time.now.to_f
273
+ elapsed = rand
274
+ case @response_output_type
275
+ when :json
276
+ header = "[#{status},#{start},#{elapsed}]"
277
+ body = "[#{header},#{@response_body}]"
278
+ when :xml
279
+ body = <<-XML
280
+ <RESULT CODE="#{status}" UP="#{start}" ELAPSED="#{elapsed}">
281
+ #{@response_body}
282
+ </RESULT>
283
+ XML
284
+ else
285
+ body = @response_body
286
+ end
287
+ header = <<-EOH
288
+ HTTP/1.1 200 OK
289
+ Connection: close
290
+ Content-Type: application/json
291
+ Content-Length: #{body.bytesize}
292
+
293
+ EOH
294
+ client.write(header)
295
+ client.write(body)
296
+ client.close
297
+ end
298
+ end
299
+ end
300
+ end