gremlin_client 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d93c96d3bd662c361f27897fa4d1f893df713a6
4
- data.tar.gz: 9401ccd8d090760cc6007f9ccf654164f21f7a95
3
+ metadata.gz: fc716e4dee2bd4e4e566ed3d136702832de0c480
4
+ data.tar.gz: ef08136b65687b30af6ce277115d5d25352fb9a7
5
5
  SHA512:
6
- metadata.gz: adbfeb75273dcf99e6b67e008ba1633220a1c1365b7f5300d2ca9458a211225a85b2c6de76f357990199f283ee6116d76fdd8b06f616e408e767e59f83637217
7
- data.tar.gz: 313bfb016083761bec62ccdadf7452bb977523f46e19feed9e57329486a52f53c8b36b869c4198b811086c217203801ad8cf11135c492096be34901ec0e26380
6
+ metadata.gz: 95beb8ca2da1f158cd3645d3e2de793561f6e623e6d4a60fabeaaab448d39fe1dae2e30e64a8586637fc3b66c9b660793b74d3d7563ca01c17a9ae6410c9eb10
7
+ data.tar.gz: 9830edf26890fa8057cb5d8b1c05b83aafea82e1dc7d07e5cdb2ca878714ebca88d97901a815d78a9505e09ea28d738538fa52b99ab9a8692ce7a381cce7e809
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gremlin_client (0.1.0)
4
+ gremlin_client (0.1.1)
5
5
  websocket-client-simple (~> 0.3)
6
6
 
7
7
  GEM
@@ -4,11 +4,11 @@ require 'pp'
4
4
  require 'gremlin_client'
5
5
 
6
6
 
7
- conn = GremlinClient::Connection.new(groovy_script_path: 'example/scripts')
7
+ conn = GremlinClient::Connection.new(gremlin_script_path: 'example/scripts')
8
8
 
9
- pp conn.send('1+what', {what: 10})
9
+ pp conn.send_query('1+what', {what: 10})
10
10
 
11
- pp conn.send('g.V().count()')
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
- url = "ws://#{host}:#{port}"
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
- @connection_timeout = connection_timeout
57
- @timeout = timeout
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
- fail ::GremlinClient::ConnectionTimeoutError.new(@connection_timeout) unless open?
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
@@ -1,3 +1,3 @@
1
1
  module GremliClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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.0
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-01 00:00:00.000000000 Z
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