orientdb_client 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34b02fe8fb6024627b8f8b7da8b29740018eef44
4
- data.tar.gz: 293559a446780800aa63e846cad714eef7e24d31
3
+ metadata.gz: 1f790f7d0f994bd626bff6f95c180024a2fbcd7c
4
+ data.tar.gz: 46f3386fef71ef7736be02b7b92e59254f1d62b2
5
5
  SHA512:
6
- metadata.gz: 8b2d8dcbdd22d90bd872b182694d410bba586205cb99216f0e89d50cdcd7925d6e963986b1f9d904fd023c894784c941b70ed3080faf2acadd3b759a801e21f1
7
- data.tar.gz: 88e1a49b4dd43aef5caee889180f3cd8f1ab6ceec199ea47dfdac42e3fee82c887dbe7ba4ff5457316b011bc176cf5e2cc5f2c624266b950f5a8538beffba931
6
+ metadata.gz: 7765f03411f6491a02751d05bf2bb0d3c5fa7c744a4c7290775e0fc376c709103d9c2bc4c4cc01a04cd45e766394d02cf3171ebcdff62d44f21ef82c09afa0fd
7
+ data.tar.gz: 9e42dc627c9e01792cbce92a16e9259efaac17f4ccae3d82220d48783eecf66b593f9bb0ed2f02e869f09fbbae244d7a3995d9c42c43f1af0d0fdfda404fe26c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Master
4
4
 
5
+ * Added support for timeouts.
6
+
5
7
  ## 0.0.3
6
8
 
7
9
  * Added `CHANGELOG.md`
data/README.md CHANGED
@@ -48,6 +48,9 @@ my_client.create_database('new_db', 'plocal', 'graph')
48
48
  require 'orientdb_client'
49
49
  require 'orientdb_client/http_adapters/curb_adapter'
50
50
  client = OrientdbClient.client(adapter: 'CurbAdapter')
51
+
52
+ # initialize client with an HTTP request timeout of 30s
53
+ client = OrientdbClient.client(host: 'localhost', timeout: 30)
51
54
  ```
52
55
 
53
56
  ## Logging/instrumentation
@@ -55,7 +58,13 @@ client = OrientdbClient.client(adapter: 'CurbAdapter')
55
58
  OrientdbClient does no logging by default, but will use ActiveSupport::Notifications
56
59
  if you `require 'orientdb_client/instrumentation/log_subscriber'`.
57
60
 
58
- If you are using Rails, this should *just work*.
61
+ If you are using Rails, this should *just work*. You will have to initialize your client instance
62
+ with the option `instrumenter: ActiveSupport::Notifications`, e.g.:
63
+
64
+
65
+ ```ruby
66
+ my_client = OrientdbClient.client(host: 'localhost', instrumenter: ActiveSupport::Notifications)
67
+ ```
59
68
 
60
69
  If you aren't, you'll need to manually specify the logger, like so:
61
70
 
@@ -105,10 +114,26 @@ curb 0.060000 0.010000 0.070000 ( 0.331764)
105
114
 
106
115
  Launch pry session with the gem: `rake console`, in pry use `reload!` to reload all gem files.
107
116
 
108
- Run tests: `rake db:test:create` (consult `test.rb` for information on customizing auth credentials via env variables).
109
-
110
117
  Turn on/off rudimentary debug mode with `client.debug = true/false`.
111
118
 
119
+ ### Running the tests
120
+
121
+ Currently, we don't run integration tests in CI due to the hackyness of setting running orientdb on Travis, and also because
122
+ some of the integration tests fail non-deterministically (especially the ones involving multiple threads).
123
+
124
+ To run all the tests:
125
+
126
+ 1. install orientdb locally
127
+ 2. if you used a different username or password than `root`, then you'll have to specify those values via environment variables, e.g.:
128
+
129
+ ```
130
+ export ORIENTDB_TEST_USERNAME=your_username
131
+ export ORIENTDB_TEST_PASSWORD=your_password
132
+ ```
133
+
134
+ 3. run `bundle exec rake db:test:create` to create the test database
135
+ 4. run `bundle exec rspec` to run the tests
136
+
112
137
  ## Contributing
113
138
 
114
139
  1. Fork it ( https://github.com/[my-github-username]/orientdb_client/fork )
@@ -36,7 +36,7 @@ module OrientdbClient
36
36
  HttpAdapters::TyphoeusAdapter
37
37
  end
38
38
  @instrumenter = options[:instrumenter] || Instrumenters::Noop
39
- @http_client = adapter_klass.new
39
+ @http_client = adapter_klass.new(timeout: options[:timeout])
40
40
  @node = Node.new(host: @host, port: @port, http_client: @http_client, client: self)
41
41
  @connected = false
42
42
  self
@@ -20,6 +20,7 @@ module OrientdbClient
20
20
  class DistributedRecordLockedException < TransactionException; end
21
21
  # Generic DistributedException, generally a more specific error is preferable.
22
22
  class DistributedException < ServerError; end
23
+ class Timeout < ServerError; end
23
24
 
24
25
  # ClientError: you did something wrong
25
26
  class ClientError < OrientdbError; end
@@ -5,10 +5,12 @@ module OrientdbClient
5
5
  class Base
6
6
  attr_accessor :username, :password
7
7
 
8
- def initialize
8
+ def initialize(timeout: nil)
9
9
  @username = nil
10
10
  @password = nil
11
11
  @session_id = nil
12
+ @timeout = timeout
13
+ after_initialize
12
14
  end
13
15
 
14
16
  def reset_credentials
@@ -20,6 +22,16 @@ module OrientdbClient
20
22
  def request
21
23
  raise NotImplementedError
22
24
  end
25
+
26
+ private
27
+
28
+ def timed_out!(method, url)
29
+ raise OrientdbClient::Timeout, "#{method}: #{url}"
30
+ end
31
+
32
+ def after_initialize
33
+ # noop, override me as necessary
34
+ end
23
35
  end
24
36
  end
25
37
  end
@@ -4,18 +4,19 @@ module OrientdbClient
4
4
  module HttpAdapters
5
5
  class CurbAdapter < Base
6
6
 
7
- def initialize
8
- super
9
- @curl = Curl::Easy.new
10
- end
11
-
12
7
  def request(method, url, options = {})
13
8
  req = prepare_request(method, url, options)
14
9
  run_request(req, method)
15
10
  req
11
+ rescue Curl::Err::TimeoutError
12
+ timed_out!(method, url)
16
13
  end
17
14
 
18
15
  private
16
+
17
+ def after_initialize
18
+ @curl = Curl::Easy.new
19
+ end
19
20
 
20
21
  def prepare_request(method, url, options)
21
22
  username = options[:username] || @username
@@ -24,6 +25,9 @@ module OrientdbClient
24
25
  @curl.http_auth_types = :basic
25
26
  @curl.username = username
26
27
  @curl.password = password
28
+ if timeout = @timeout || options[:timeout]
29
+ @curl.timeout = timeout
30
+ end
27
31
  @curl
28
32
  end
29
33
 
@@ -6,7 +6,12 @@ module OrientdbClient
6
6
 
7
7
  def request(method, url, options = {})
8
8
  req = prepare_request(method, url, options)
9
- run_request(req)
9
+ response = run_request(req)
10
+ if response.timed_out?
11
+ timed_out!(method, url)
12
+ else
13
+ return response
14
+ end
10
15
  end
11
16
 
12
17
  private
@@ -16,6 +21,9 @@ module OrientdbClient
16
21
  userpwd: authentication_string(options),
17
22
  method: method
18
23
  }.merge(options)
24
+ if timeout = @timeout || options[:timeout]
25
+ options[:timeout] = timeout
26
+ end
19
27
  Typhoeus::Request.new(url, options)
20
28
  end
21
29
 
@@ -1,8 +1,8 @@
1
1
  module OrientdbClient
2
2
  module Test
3
3
  OrientdbClient::Test::DatabaseName = ENV['ORIENTDB_TEST_DATABASENAME'] || 'orientdb_client_rb_test'
4
- OrientdbClient::Test::Username = ENV['ORIENTDB_TEST_USERNAME'] || 'test'
5
- OrientdbClient::Test::Password = ENV['ORIENTDB_TEST_PASSWORD'] || 'test'
4
+ OrientdbClient::Test::Username = ENV['ORIENTDB_TEST_USERNAME'] || 'root'
5
+ OrientdbClient::Test::Password = ENV['ORIENTDB_TEST_PASSWORD'] || 'root'
6
6
  end
7
7
  end
8
8
 
@@ -1,3 +1,3 @@
1
1
  module OrientdbClient
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -20,6 +20,15 @@ RSpec.shared_examples 'http adapter' do
20
20
  end
21
21
  end
22
22
 
23
+ describe 'timeout handling' do
24
+ let(:url) { 'http://localhost:2480/listDatabases' }
25
+
26
+ it 'raises a Timeout exception' do
27
+ stub_request(:get, url).to_timeout
28
+ expect { adapter.request(:get, url) }.to raise_exception(OrientdbClient::Timeout)
29
+ end
30
+ end
31
+
23
32
  describe '#request' do
24
33
  describe 'GET' do
25
34
  let(:url) { 'http://localhost:2480/listDatabases' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orientdb_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Rodgers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-21 00:00:00.000000000 Z
11
+ date: 2016-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus