gremlin_client 0.0.4 → 0.1.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.
- checksums.yaml +4 -4
- data/.travis.yml +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -2
- data/example/test.rb +1 -5
- data/lib/gremlin_client.rb +1 -0
- data/lib/gremlin_client/connection.rb +22 -18
- data/lib/gremlin_client/connection_timeout_error.rb +13 -0
- data/lib/gremlin_client/version.rb +1 -1
- data/spec/connection_spec.rb +288 -0
- data/spec/exceptions_spec.rb +25 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/status_codes_spec.rb +28 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d93c96d3bd662c361f27897fa4d1f893df713a6
|
4
|
+
data.tar.gz: 9401ccd8d090760cc6007f9ccf654164f21f7a95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adbfeb75273dcf99e6b67e008ba1633220a1c1365b7f5300d2ca9458a211225a85b2c6de76f357990199f283ee6116d76fdd8b06f616e408e767e59f83637217
|
7
|
+
data.tar.gz: 313bfb016083761bec62ccdadf7452bb977523f46e19feed9e57329486a52f53c8b36b869c4198b811086c217203801ad8cf11135c492096be34901ec0e26380
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
# Ruby Gremlin Client
|
2
|
+
|
3
|
+
|
4
|
+
[](https://travis-ci.org/marcelocf/gremlin_clien)
|
5
|
+
[](https://badge.fury.io/rb/gremlin_client)
|
6
|
+

|
7
|
+
[](https://coveralls.io/github/marcelocf/gremlin_client?branch=master)
|
8
|
+
|
9
|
+
|
10
|
+
|
2
11
|
Gremlin client in ruby for the WebSocketChannelizer.
|
3
12
|
|
4
13
|
This client is not thread safe by itself! If you want to make it safer for your app, please make sure
|
@@ -18,7 +27,7 @@ resp = conn.send("g.V().has('myVar', myValue)", {myValue: 'this_is_processed_by_
|
|
18
27
|
Alternativelly, you can use groovy files instead:
|
19
28
|
|
20
29
|
```ruby
|
21
|
-
resp = conn.file_send("
|
30
|
+
resp = conn.file_send("query.groovy", {var1: 12})
|
22
31
|
```
|
23
32
|
|
24
33
|
```groovy
|
@@ -28,7 +37,7 @@ g.V().has("something", var1)
|
|
28
37
|
You can even specify the folder where to load those files in the constructor:
|
29
38
|
|
30
39
|
```ruby
|
31
|
-
conn = GremlinClient.Connection.new(
|
40
|
+
conn = GremlinClient.Connection.new(gremlin_script_path: 'scripts/gremlin')
|
32
41
|
```
|
33
42
|
|
34
43
|
|
data/example/test.rb
CHANGED
@@ -6,14 +6,10 @@ require 'gremlin_client'
|
|
6
6
|
|
7
7
|
conn = GremlinClient::Connection.new(groovy_script_path: 'example/scripts')
|
8
8
|
|
9
|
-
|
10
|
-
pp conn.send_file('concierge_scores.groovy', {fincUserId: 260607, contentTypeFilter: ['Try::Beauty']})
|
11
|
-
|
12
9
|
pp conn.send('1+what', {what: 10})
|
13
10
|
|
14
|
-
pp conn.send('g.V().
|
11
|
+
pp conn.send('g.V().count()')
|
15
12
|
|
16
13
|
pp conn.send_file('test.groovy', {what: Time.now.to_i})
|
17
14
|
|
18
|
-
|
19
15
|
conn.close
|
data/lib/gremlin_client.rb
CHANGED
@@ -3,7 +3,7 @@ module GremlinClient
|
|
3
3
|
# represents the connection to our gremlin server
|
4
4
|
class Connection
|
5
5
|
|
6
|
-
attr_reader :timeout, :
|
6
|
+
attr_reader :connection_timeout, :timeout, :gremlin_script_path
|
7
7
|
|
8
8
|
STATUS = {
|
9
9
|
success: 200,
|
@@ -13,7 +13,7 @@ module GremlinClient
|
|
13
13
|
unauthorized: 401,
|
14
14
|
authenticate: 407,
|
15
15
|
malformed_request: 498,
|
16
|
-
|
16
|
+
invalid_request_arguments: 499,
|
17
17
|
server_error: 500,
|
18
18
|
script_evaluation_error: 597,
|
19
19
|
server_timeout: 598,
|
@@ -33,8 +33,9 @@ module GremlinClient
|
|
33
33
|
def initialize(
|
34
34
|
host: 'localhost',
|
35
35
|
port: 8182,
|
36
|
+
connection_timeout: 1,
|
36
37
|
timeout: 10,
|
37
|
-
|
38
|
+
gremlin_script_path: '.'
|
38
39
|
)
|
39
40
|
url = "ws://#{host}:#{port}"
|
40
41
|
|
@@ -44,7 +45,6 @@ module GremlinClient
|
|
44
45
|
|
45
46
|
@ws.on :message do |msg|
|
46
47
|
gremlin.receive_message(msg)
|
47
|
-
@response=msg
|
48
48
|
end
|
49
49
|
|
50
50
|
@ws.on :error do |e|
|
@@ -53,22 +53,22 @@ module GremlinClient
|
|
53
53
|
end
|
54
54
|
|
55
55
|
|
56
|
+
@connection_timeout = connection_timeout
|
56
57
|
@timeout = timeout
|
57
|
-
@
|
58
|
-
@
|
58
|
+
@gremlin_script_path = gremlin_script_path
|
59
|
+
@gremlin_script_path = Pathname.new(@gremlin_script_path) unless @gremlin_script_path.is_a?(Pathname)
|
59
60
|
end
|
60
61
|
|
61
|
-
|
62
|
-
def send(command, bindings={})
|
62
|
+
def send_query(command, bindings={})
|
63
63
|
wait_connection
|
64
|
-
|
64
|
+
reset_request
|
65
65
|
@ws.send(build_message(command, bindings), { type: 'text' })
|
66
66
|
wait_response
|
67
|
-
return
|
67
|
+
return treat_response
|
68
68
|
end
|
69
69
|
|
70
70
|
def send_file(filename, bindings={})
|
71
|
-
|
71
|
+
send_query(IO.read(resolve_path(filename)), bindings)
|
72
72
|
end
|
73
73
|
|
74
74
|
def open?
|
@@ -82,7 +82,9 @@ module GremlinClient
|
|
82
82
|
|
83
83
|
# this has to be public so the websocket client thread sees it
|
84
84
|
def receive_message(msg)
|
85
|
-
|
85
|
+
response = JSON.parse(msg.data)
|
86
|
+
# this check is important in case a request timeout and we make new ones after
|
87
|
+
@response = response if response['requestId'] == @request_id
|
86
88
|
end
|
87
89
|
|
88
90
|
def receive_error(e)
|
@@ -91,14 +93,16 @@ module GremlinClient
|
|
91
93
|
|
92
94
|
protected
|
93
95
|
|
94
|
-
def wait_connection
|
96
|
+
def wait_connection
|
95
97
|
w_from = Time.now.to_i
|
96
|
-
while !open? && Time.now.to_i -
|
98
|
+
while !open? && Time.now.to_i - @connection_timeout < w_from
|
97
99
|
sleep 0.001
|
98
100
|
end
|
101
|
+
fail ::GremlinClient::ConnectionTimeoutError.new(@connection_timeout) unless open?
|
99
102
|
end
|
100
103
|
|
101
|
-
def
|
104
|
+
def reset_request
|
105
|
+
@request_id= SecureRandom.uuid
|
102
106
|
@started_at = Time.now.to_i
|
103
107
|
@error = nil
|
104
108
|
@response = nil
|
@@ -115,7 +119,7 @@ module GremlinClient
|
|
115
119
|
|
116
120
|
# we validate our response here to make sure it is going to be
|
117
121
|
# raising exceptions in the right thread
|
118
|
-
def
|
122
|
+
def treat_response
|
119
123
|
# note that the partial_content status should be processed differently.
|
120
124
|
# look at http://tinkerpop.apache.org/docs/3.0.1-incubating/ for more info
|
121
125
|
ok_status = [:success, :no_content, :partial_content].map { |st| STATUS[st] }
|
@@ -127,7 +131,7 @@ module GremlinClient
|
|
127
131
|
|
128
132
|
def build_message(command, bindings)
|
129
133
|
message = {
|
130
|
-
requestId:
|
134
|
+
requestId: @request_id,
|
131
135
|
op: 'eval',
|
132
136
|
processor: '',
|
133
137
|
args: {
|
@@ -141,7 +145,7 @@ module GremlinClient
|
|
141
145
|
|
142
146
|
def resolve_path(filename)
|
143
147
|
return filename if filename.is_a?(String) && filename[0,1] == '/'
|
144
|
-
@
|
148
|
+
@gremlin_script_path.join(filename).to_s
|
145
149
|
end
|
146
150
|
end
|
147
151
|
end
|
@@ -0,0 +1,288 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
# Tests on the freetext feature
|
7
|
+
RSpec.describe :connection do
|
8
|
+
class MockedSocket
|
9
|
+
end
|
10
|
+
|
11
|
+
module Message
|
12
|
+
def self.status=(name)
|
13
|
+
@status_code = GremlinClient::Connection::STATUS[name]
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.request_id=(requestId)
|
17
|
+
@request_id = requestId
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.called=(c)
|
21
|
+
@called = c
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.data
|
25
|
+
@called ||= 0
|
26
|
+
@called += 1
|
27
|
+
rid = ", \"requestId\" : \"#{@request_id}\"" unless @request_id.nil?
|
28
|
+
stt = ", \"status\" : { \"code\" : #{@status_code} }" unless @status_code.nil?
|
29
|
+
"{\"example\" : \"data #{@called}\"#{rid}#{stt}}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
before do
|
34
|
+
sock = MockedSocket.new
|
35
|
+
allow(sock).to receive(:on).and_yield(Message)
|
36
|
+
allow(WebSocket::Client::Simple).to receive(:connect).and_yield(sock)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe :initialize do
|
40
|
+
it :websocket do
|
41
|
+
expect(WebSocket::Client::Simple).to receive(:connect).with('ws://localhost:8182/')
|
42
|
+
conn = GremlinClient::Connection.new
|
43
|
+
end
|
44
|
+
|
45
|
+
it :websocket do
|
46
|
+
expect(WebSocket::Client::Simple).to receive(:connect).with('ws://SERVER_A:123/')
|
47
|
+
conn = GremlinClient::Connection.new(host: :SERVER_A, port: 123)
|
48
|
+
end
|
49
|
+
|
50
|
+
it :gremlin_script_path do
|
51
|
+
conn = GremlinClient::Connection.new
|
52
|
+
expect(conn.gremlin_script_path).to eq(Pathname.new('.'))
|
53
|
+
conn = GremlinClient::Connection.new(gremlin_script_path: '/etc/groovy')
|
54
|
+
expect(conn.gremlin_script_path).to eq(Pathname.new('/etc/groovy'))
|
55
|
+
end
|
56
|
+
|
57
|
+
it :connection_timeout do
|
58
|
+
conn = GremlinClient::Connection.new
|
59
|
+
expect(conn.connection_timeout).to eq(1)
|
60
|
+
conn = GremlinClient::Connection.new(connection_timeout: 11)
|
61
|
+
expect(conn.connection_timeout).to eq(11)
|
62
|
+
end
|
63
|
+
|
64
|
+
it :timeout do
|
65
|
+
conn = GremlinClient::Connection.new
|
66
|
+
expect(conn.timeout).to eq(10)
|
67
|
+
conn = GremlinClient::Connection.new(timeout: 1)
|
68
|
+
expect(conn.timeout).to eq(1)
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
it :socket_listeners do
|
73
|
+
Message.called = 0
|
74
|
+
conn = GremlinClient::Connection.new
|
75
|
+
expect(conn.instance_variable_get('@response')).to eq({'example' => 'data 1'})
|
76
|
+
expect(conn.instance_variable_get('@error').data).to eq("{\"example\" : \"data 2\"}")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
describe :send do
|
82
|
+
it :string do
|
83
|
+
conn = GremlinClient::Connection.new
|
84
|
+
sock = conn.instance_variable_get('@ws')
|
85
|
+
expect(conn).to receive(:wait_connection)
|
86
|
+
expect(conn).to receive(:reset_request)
|
87
|
+
expect(conn).to receive(:build_message).with(:query, :bindings).and_return(:my_message)
|
88
|
+
expect(sock).to receive(:send).with(:my_message, { type: 'text' })
|
89
|
+
expect(conn).to receive(:wait_response)
|
90
|
+
expect(conn).to receive(:treat_response)
|
91
|
+
|
92
|
+
conn.send_query(:query, :bindings)
|
93
|
+
end
|
94
|
+
|
95
|
+
it :file do
|
96
|
+
conn = GremlinClient::Connection.new
|
97
|
+
expect(IO).to receive(:read).with('filename').and_return(:file_contents)
|
98
|
+
expect(conn).to receive(:send_query).with(:file_contents, :bindings)
|
99
|
+
conn.send_file('filename', :bindings)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
it :open? do
|
105
|
+
conn = GremlinClient::Connection.new
|
106
|
+
expect(conn.instance_variable_get('@ws')).to receive(:open?).and_return(:from_websocket)
|
107
|
+
expect(conn.open?).to eq(:from_websocket)
|
108
|
+
end
|
109
|
+
|
110
|
+
it :close do
|
111
|
+
conn = GremlinClient::Connection.new
|
112
|
+
expect(conn.instance_variable_get('@ws')).to receive(:close).and_return(:from_websocket)
|
113
|
+
expect(conn.close).to eq(:from_websocket)
|
114
|
+
end
|
115
|
+
|
116
|
+
describe :receive_message do
|
117
|
+
it :no_request_id do
|
118
|
+
Message.called = 0
|
119
|
+
Message.request_id = nil
|
120
|
+
conn = GremlinClient::Connection.new
|
121
|
+
conn.send(:reset_request)
|
122
|
+
conn.receive_message(Message)
|
123
|
+
expect(conn.instance_variable_get('@response')).to be_nil
|
124
|
+
end
|
125
|
+
|
126
|
+
it :different_request_id do
|
127
|
+
Message.called = 0
|
128
|
+
Message.request_id = '123'
|
129
|
+
conn = GremlinClient::Connection.new
|
130
|
+
conn.send(:reset_request)
|
131
|
+
conn.instance_variable_set('@request_id', '123')
|
132
|
+
conn.receive_message(Message)
|
133
|
+
expect(conn.instance_variable_get('@response')).to eq({'example' => 'data 2', 'requestId' => '123'})
|
134
|
+
# exit this block reseting this value
|
135
|
+
Message.request_id = nil
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
it :receive_error do
|
140
|
+
conn = GremlinClient::Connection.new
|
141
|
+
conn.receive_error(:this_is_a_bad_error)
|
142
|
+
expect(conn.instance_variable_get('@error')).to eq(:this_is_a_bad_error)
|
143
|
+
end
|
144
|
+
|
145
|
+
describe :wait_connection do
|
146
|
+
it :timeouts do
|
147
|
+
conn = GremlinClient::Connection.new
|
148
|
+
expect(conn).to receive(:open?).and_return(false).at_least(:once)
|
149
|
+
expect{conn.send(:wait_connection)}.to raise_exception(::GremlinClient::ConnectionTimeoutError)
|
150
|
+
end
|
151
|
+
|
152
|
+
it :success do
|
153
|
+
conn = GremlinClient::Connection.new
|
154
|
+
expect(conn).to receive(:open?).and_return(true).twice
|
155
|
+
conn.send(:wait_connection)
|
156
|
+
end
|
157
|
+
|
158
|
+
it :fails_with_longer_timeout do
|
159
|
+
conn = GremlinClient::Connection.new(connection_timeout: 3)
|
160
|
+
started_at = Time.now.to_i
|
161
|
+
expect(conn).to receive(:open?).and_return(false).at_least(:once)
|
162
|
+
expect{conn.send(:wait_connection)}.to raise_exception(::GremlinClient::ConnectionTimeoutError)
|
163
|
+
expect(Time.now.to_i - started_at).to be_within(1).of(3)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
|
168
|
+
it :reset_request do
|
169
|
+
conn = GremlinClient::Connection.new
|
170
|
+
conn.instance_variable_set('@request_id', :old_id)
|
171
|
+
conn.instance_variable_set('@started_at', :old_started_at)
|
172
|
+
conn.instance_variable_set('@error', :old_error)
|
173
|
+
conn.instance_variable_set('@response', :old_response)
|
174
|
+
|
175
|
+
conn.send(:reset_request)
|
176
|
+
|
177
|
+
expect(conn.instance_variable_get('@request_id')).not_to eq(:old_id)
|
178
|
+
expect(conn.instance_variable_get('@request_id').length).to be(36) # uuid is 36 chars long
|
179
|
+
expect(conn.instance_variable_get('@started_at')).to be_within(1).of(Time.now.to_i)
|
180
|
+
expect(conn.instance_variable_get('@error')).to be_nil
|
181
|
+
expect(conn.instance_variable_get('@response')).to be_nil
|
182
|
+
end
|
183
|
+
|
184
|
+
|
185
|
+
describe :wait_response do
|
186
|
+
it :no_message do
|
187
|
+
conn = GremlinClient::Connection.new(timeout: 1)
|
188
|
+
conn.send(:reset_request)
|
189
|
+
expect{conn.send(:wait_response)}.to raise_exception(::GremlinClient::ExecutionTimeoutError)
|
190
|
+
end
|
191
|
+
|
192
|
+
it :wrong_id_message do
|
193
|
+
conn = GremlinClient::Connection.new(timeout: 1)
|
194
|
+
conn.send(:reset_request)
|
195
|
+
Message.request_id = :invalid_id
|
196
|
+
conn.receive_message(Message)
|
197
|
+
expect{conn.send(:wait_response)}.to raise_exception(::GremlinClient::ExecutionTimeoutError)
|
198
|
+
end
|
199
|
+
|
200
|
+
it :with_message do
|
201
|
+
conn = GremlinClient::Connection.new(timeout: 1)
|
202
|
+
conn.send(:reset_request)
|
203
|
+
Message.called = 0
|
204
|
+
Message.request_id = conn.instance_variable_get('@request_id')
|
205
|
+
conn.receive_message(Message)
|
206
|
+
conn.send(:wait_response)
|
207
|
+
expect(conn.instance_variable_get('@response')).to eq({
|
208
|
+
'example' =>'data 1',
|
209
|
+
'requestId' => conn.instance_variable_get('@request_id')
|
210
|
+
})
|
211
|
+
end
|
212
|
+
|
213
|
+
it :with_error do
|
214
|
+
conn = GremlinClient::Connection.new(timeout: 1)
|
215
|
+
conn.send(:reset_request)
|
216
|
+
Message.called = 0
|
217
|
+
Message.request_id = conn.instance_variable_get('@request_id')
|
218
|
+
conn.receive_error(Message)
|
219
|
+
expect{conn.send(:wait_response)}.to raise_exception(::GremlinClient::ServerError)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe :treat_response do
|
224
|
+
it :success_statuses do
|
225
|
+
def test_status(name)
|
226
|
+
conn = GremlinClient::Connection.new
|
227
|
+
conn.send(:reset_request)
|
228
|
+
Message.request_id = conn.instance_variable_get('@request_id')
|
229
|
+
Message.status = name
|
230
|
+
conn.receive_message(Message)
|
231
|
+
conn.send(:treat_response)
|
232
|
+
end
|
233
|
+
test_status(:success)
|
234
|
+
test_status(:no_content)
|
235
|
+
test_status(:partial_content)
|
236
|
+
end
|
237
|
+
|
238
|
+
it :error_statuses do
|
239
|
+
def test_status(name)
|
240
|
+
conn = GremlinClient::Connection.new
|
241
|
+
conn.send(:reset_request)
|
242
|
+
Message.request_id = conn.instance_variable_get('@request_id')
|
243
|
+
Message.status = name
|
244
|
+
conn.receive_message(Message)
|
245
|
+
expect{conn.send(:treat_response)}.to raise_exception(::GremlinClient::ServerError)
|
246
|
+
end
|
247
|
+
|
248
|
+
[
|
249
|
+
:unauthorized,
|
250
|
+
:authenticate,
|
251
|
+
:malformed_request,
|
252
|
+
:invalid_request_arguments,
|
253
|
+
:server_error,
|
254
|
+
:script_evaluation_error,
|
255
|
+
:server_timeout,
|
256
|
+
:server_serialization_error
|
257
|
+
].each { |name| test_status(name) }
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
it :build_message do
|
262
|
+
conn = GremlinClient::Connection.new
|
263
|
+
conn.send(:reset_request)
|
264
|
+
expect(JSON.parse(conn.send(:build_message, :query, :bindings))).to eq({
|
265
|
+
'requestId' => conn.instance_variable_get('@request_id'),
|
266
|
+
'op' => 'eval',
|
267
|
+
'processor' => '',
|
268
|
+
'args' => {
|
269
|
+
'gremlin' => 'query',
|
270
|
+
'bindings' => 'bindings',
|
271
|
+
'language' => 'gremlin-groovy'
|
272
|
+
}
|
273
|
+
})
|
274
|
+
end
|
275
|
+
|
276
|
+
|
277
|
+
it :resolve_path do
|
278
|
+
conn = GremlinClient::Connection.new
|
279
|
+
expect(conn.send(:resolve_path, 'test')).to eq('test')
|
280
|
+
|
281
|
+
conn = GremlinClient::Connection.new(gremlin_script_path: '/test/path')
|
282
|
+
expect(conn.send(:resolve_path, 'test')).to eq('/test/path/test')
|
283
|
+
|
284
|
+
|
285
|
+
conn = GremlinClient::Connection.new(gremlin_script_path: 'test/path')
|
286
|
+
expect(conn.send(:resolve_path, 'test')).to eq('test/path/test')
|
287
|
+
end
|
288
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
# test on formating messages from exceptions
|
7
|
+
RSpec.describe :exceptions do
|
8
|
+
it :connection_timeout_error do
|
9
|
+
expect(::GremlinClient::ConnectionTimeoutError.new(10).to_s).to eq('10s')
|
10
|
+
expect(::GremlinClient::ConnectionTimeoutError.new(1).to_s).to eq('1s')
|
11
|
+
expect(::GremlinClient::ConnectionTimeoutError.new(1123).to_s).to eq('1123s')
|
12
|
+
end
|
13
|
+
|
14
|
+
it :execution_timeout_error do
|
15
|
+
expect(::GremlinClient::ExecutionTimeoutError.new(10).to_s).to eq('10s')
|
16
|
+
expect(::GremlinClient::ExecutionTimeoutError.new(1).to_s).to eq('1s')
|
17
|
+
expect(::GremlinClient::ExecutionTimeoutError.new(1123).to_s).to eq('1123s')
|
18
|
+
end
|
19
|
+
|
20
|
+
it :server_error do
|
21
|
+
expect(::GremlinClient::ServerError.new(:code, :message).to_s).to eq('message (code code)');
|
22
|
+
expect(::GremlinClient::ServerError.new(312, 'this exploded here').to_s).to eq('this exploded here (code 312)');
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# Tests on the freetext feature
|
6
|
+
RSpec.describe :status_codes do
|
7
|
+
it :declared_every_code do
|
8
|
+
{
|
9
|
+
success: 200,
|
10
|
+
no_content: 204,
|
11
|
+
partial_content: 206,
|
12
|
+
unauthorized: 401,
|
13
|
+
authenticate: 407,
|
14
|
+
malformed_request: 498,
|
15
|
+
invalid_request_arguments: 499,
|
16
|
+
server_error: 500,
|
17
|
+
script_evaluation_error: 597,
|
18
|
+
server_timeout: 598,
|
19
|
+
server_serialization_error: 599
|
20
|
+
}.each_pair do |key, code|
|
21
|
+
expect(GremlinClient::Connection::STATUS[key]).to eq(code)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it :doesnt_have_extra_codes do
|
26
|
+
expect(GremlinClient::Connection::STATUS.count).to be(11)
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gremlin_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Coraça de Freitas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-client-simple
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- ".gitignore"
|
119
119
|
- ".ruby-gemset"
|
120
120
|
- ".ruby-version"
|
121
|
+
- ".travis.yml"
|
121
122
|
- Gemfile
|
122
123
|
- Gemfile.lock
|
123
124
|
- LICENSE
|
@@ -128,9 +129,14 @@ files:
|
|
128
129
|
- gremlin_client.gemspec
|
129
130
|
- lib/gremlin_client.rb
|
130
131
|
- lib/gremlin_client/connection.rb
|
132
|
+
- lib/gremlin_client/connection_timeout_error.rb
|
131
133
|
- lib/gremlin_client/execution_timeout_error.rb
|
132
134
|
- lib/gremlin_client/server_error.rb
|
133
135
|
- lib/gremlin_client/version.rb
|
136
|
+
- spec/connection_spec.rb
|
137
|
+
- spec/exceptions_spec.rb
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
- spec/status_codes_spec.rb
|
134
140
|
homepage: https://github.com/marcelocf/gremlin_client
|
135
141
|
licenses:
|
136
142
|
- Apache-2.0
|
@@ -156,4 +162,8 @@ rubygems_version: 2.5.1
|
|
156
162
|
signing_key:
|
157
163
|
specification_version: 4
|
158
164
|
summary: Simple Gremlin server client for the WebSocketChannelizer
|
159
|
-
test_files:
|
165
|
+
test_files:
|
166
|
+
- spec/connection_spec.rb
|
167
|
+
- spec/exceptions_spec.rb
|
168
|
+
- spec/spec_helper.rb
|
169
|
+
- spec/status_codes_spec.rb
|