gremlin_client 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/example/test.rb +3 -3
- data/lib/gremlin_client/connection.rb +27 -10
- data/lib/gremlin_client/version.rb +1 -1
- data/spec/connection_spec.rb +13 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc716e4dee2bd4e4e566ed3d136702832de0c480
|
4
|
+
data.tar.gz: ef08136b65687b30af6ce277115d5d25352fb9a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95beb8ca2da1f158cd3645d3e2de793561f6e623e6d4a60fabeaaab448d39fe1dae2e30e64a8586637fc3b66c9b660793b74d3d7563ca01c17a9ae6410c9eb10
|
7
|
+
data.tar.gz: 9830edf26890fa8057cb5d8b1c05b83aafea82e1dc7d07e5cdb2ca878714ebca88d97901a815d78a9505e09ea28d738538fa52b99ab9a8692ce7a381cce7e809
|
data/Gemfile.lock
CHANGED
data/example/test.rb
CHANGED
@@ -4,11 +4,11 @@ require 'pp'
|
|
4
4
|
require 'gremlin_client'
|
5
5
|
|
6
6
|
|
7
|
-
conn = GremlinClient::Connection.new(
|
7
|
+
conn = GremlinClient::Connection.new(gremlin_script_path: 'example/scripts')
|
8
8
|
|
9
|
-
pp conn.
|
9
|
+
pp conn.send_query('1+what', {what: 10})
|
10
10
|
|
11
|
-
pp conn.
|
11
|
+
pp conn.send_query('0 && 1')
|
12
12
|
|
13
13
|
pp conn.send_file('test.groovy', {what: Time.now.to_i})
|
14
14
|
|
@@ -35,12 +35,23 @@ module GremlinClient
|
|
35
35
|
port: 8182,
|
36
36
|
connection_timeout: 1,
|
37
37
|
timeout: 10,
|
38
|
-
gremlin_script_path: '.'
|
38
|
+
gremlin_script_path: '.',
|
39
|
+
autoconnect: true
|
39
40
|
)
|
40
|
-
|
41
|
+
@host = host
|
42
|
+
@port = port
|
43
|
+
@connection_timeout = connection_timeout
|
44
|
+
@timeout = timeout
|
45
|
+
@gremlin_script_path = gremlin_script_path
|
46
|
+
@gremlin_script_path = Pathname.new(@gremlin_script_path) unless @gremlin_script_path.is_a?(Pathname)
|
47
|
+
@autoconnect = autoconnect
|
48
|
+
connect if @autoconnect
|
49
|
+
end
|
41
50
|
|
51
|
+
# creates a new connection object
|
52
|
+
def connect
|
42
53
|
gremlin = self
|
43
|
-
WebSocket::Client::Simple.connect("ws://#{host}:#{port}/") do |ws|
|
54
|
+
WebSocket::Client::Simple.connect("ws://#{@host}:#{@port}/") do |ws|
|
44
55
|
@ws = ws
|
45
56
|
|
46
57
|
@ws.on :message do |msg|
|
@@ -51,12 +62,11 @@ module GremlinClient
|
|
51
62
|
receive_error(e)
|
52
63
|
end
|
53
64
|
end
|
65
|
+
end
|
54
66
|
|
55
|
-
|
56
|
-
@
|
57
|
-
|
58
|
-
@gremlin_script_path = gremlin_script_path
|
59
|
-
@gremlin_script_path = Pathname.new(@gremlin_script_path) unless @gremlin_script_path.is_a?(Pathname)
|
67
|
+
def reconnect
|
68
|
+
@ws.close unless @ws.nil?
|
69
|
+
connect
|
60
70
|
end
|
61
71
|
|
62
72
|
def send_query(command, bindings={})
|
@@ -93,12 +103,19 @@ module GremlinClient
|
|
93
103
|
|
94
104
|
protected
|
95
105
|
|
96
|
-
def wait_connection
|
106
|
+
def wait_connection(skip_reconnect = false)
|
97
107
|
w_from = Time.now.to_i
|
98
108
|
while !open? && Time.now.to_i - @connection_timeout < w_from
|
99
109
|
sleep 0.001
|
100
110
|
end
|
101
|
-
|
111
|
+
unless open?
|
112
|
+
# reconnection code
|
113
|
+
if @autoconnect && !skip_reconnect
|
114
|
+
reconnect
|
115
|
+
return wait_connection(true)
|
116
|
+
end
|
117
|
+
fail ::GremlinClient::ConnectionTimeoutError.new(@connection_timeout)
|
118
|
+
end
|
102
119
|
end
|
103
120
|
|
104
121
|
def reset_request
|
data/spec/connection_spec.rb
CHANGED
@@ -6,6 +6,9 @@ require 'spec_helper'
|
|
6
6
|
# Tests on the freetext feature
|
7
7
|
RSpec.describe :connection do
|
8
8
|
class MockedSocket
|
9
|
+
def close
|
10
|
+
nil
|
11
|
+
end
|
9
12
|
end
|
10
13
|
|
11
14
|
module Message
|
@@ -156,12 +159,21 @@ RSpec.describe :connection do
|
|
156
159
|
end
|
157
160
|
|
158
161
|
it :fails_with_longer_timeout do
|
159
|
-
conn = GremlinClient::Connection.new(connection_timeout: 3)
|
162
|
+
conn = GremlinClient::Connection.new(connection_timeout: 3, autoconnect: false)
|
163
|
+
conn.connect
|
160
164
|
started_at = Time.now.to_i
|
161
165
|
expect(conn).to receive(:open?).and_return(false).at_least(:once)
|
162
166
|
expect{conn.send(:wait_connection)}.to raise_exception(::GremlinClient::ConnectionTimeoutError)
|
163
167
|
expect(Time.now.to_i - started_at).to be_within(1).of(3)
|
164
168
|
end
|
169
|
+
|
170
|
+
it :fails_with_autonnect do
|
171
|
+
conn = GremlinClient::Connection.new(connection_timeout: 2, autoconnect: true)
|
172
|
+
started_at = Time.now.to_i
|
173
|
+
expect(conn).to receive(:open?).and_return(false).at_least(:once)
|
174
|
+
expect{conn.send(:wait_connection)}.to raise_exception(::GremlinClient::ConnectionTimeoutError)
|
175
|
+
expect(Time.now.to_i - started_at).to be_within(1).of(4)
|
176
|
+
end
|
165
177
|
end
|
166
178
|
|
167
179
|
|
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.1.
|
4
|
+
version: 0.1.1
|
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-03-
|
11
|
+
date: 2017-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-client-simple
|