crate_ruby 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.travis.yml +6 -8
- data/LICENSE +1 -1
- data/NOTICE +1 -1
- data/README.md +15 -9
- data/crate_ruby.gemspec +3 -2
- data/history.txt +8 -0
- data/lib/crate_ruby/client.rb +12 -5
- data/lib/crate_ruby/version.rb +1 -1
- data/spec/crate_ruby/client_spec.rb +18 -11
- data/spec/spec_helper.rb +1 -1
- data/spec/test_server.rb +27 -37
- metadata +16 -19
- data/spec/travis_test_server.rb +0 -75
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
Zjg3ZjYzMTgwNWI2OTBmZjFkYzhkMzhmYzE4YTBhZDk2Yzk5ZTc1NQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 72fb2668765dffdf58642563d96e75aa751e8c3c
|
4
|
+
data.tar.gz: f071d33f570d3108a9a34f4899a3f6ac63666f28
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MTVjMjU5OTFlMDFmMWM2OGU3NzI0ZTE3MDg1MWYyNGRhOTMyOWNhYzc3YjVj
|
11
|
-
YmQyMjc4YmE2MTRjMjYwZTZiMDRhMjhmYzc3YTdhNmI4MmUxMTM=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MDNiMDQ2ZDdlODYzNDAzMDc1YzNiZWZlMzQ1MzI5M2NkMTdjYjNjMTYxMWI5
|
14
|
-
NmU5ODEwZWVlMjczYzE1ZTFmZDY1MThiMWE2OTAxNGI2ODlmMzUxZjJjYmQw
|
15
|
-
NjAyMTczYTM1Y2MwNzdlNDJkMTU1MWYzNzg4ZTdlZmU2ODI4NmQ=
|
6
|
+
metadata.gz: 95523cb97d5db61f189a383330e0d42e4877a9fb893ee6e6ec1ad11a156fc89a1836de17cba8446f4c18523b94b4b20b5fca8bdb6f40aca2e44a9f0389832a9e
|
7
|
+
data.tar.gz: 759a5002f9498893ea8c888ee3bcf9974c8e53620b5e3ef78f78b076481505404bec3dc63fd750069cab7c7192856a9b974b27f4f8fb40a5769917b42448e574
|
data/.travis.yml
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- "1.9.3"
|
4
|
-
- "2.1.1"
|
5
3
|
- "2.0.0"
|
6
|
-
|
4
|
+
- "2.1.5"
|
5
|
+
- "2.2.0"
|
6
|
+
sudo:
|
7
|
+
false
|
7
8
|
|
8
9
|
before_script:
|
9
|
-
- wget https://cdn.crate.io/downloads/releases/crate-0.
|
10
|
+
- wget https://cdn.crate.io/downloads/releases/crate-0.48.2.tar.gz -O /tmp/crate.tar.gz
|
10
11
|
- tar -xvf /tmp/crate.tar.gz
|
11
|
-
-
|
12
|
-
- echo $PWD
|
13
|
-
- bundle exec ruby spec/travis_test_server.rb $PWD/crate-0.39.0/ 4209
|
12
|
+
- bundle exec ruby spec/test_server.rb $PWD/crate-0.48.2/ true
|
14
13
|
|
15
14
|
script: bundle exec rspec spec
|
16
|
-
|
data/LICENSE
CHANGED
data/NOTICE
CHANGED
data/README.md
CHANGED
@@ -9,6 +9,8 @@ Official Ruby library to access a [Crate](http://crate.io) database.
|
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
12
|
+
This gem requires Ruby 2.0 or greater.
|
13
|
+
|
12
14
|
Add this line to your application's Gemfile:
|
13
15
|
|
14
16
|
gem 'crate_ruby'
|
@@ -34,34 +36,39 @@ Or install it yourself as:
|
|
34
36
|
|
35
37
|
result.cols
|
36
38
|
=> ["id", "my_column", "my_integer_col"]
|
37
|
-
|
38
|
-
|
39
|
+
|
40
|
+
|
39
41
|
#### Using parameter substitution
|
40
|
-
|
42
|
+
|
41
43
|
client.execute("INSERT INTO posts (id, title, tags) VALUES (\$1, \$2, \$3)",
|
42
44
|
[1, "My life with crate", ['awesome', 'freaky']])
|
43
45
|
|
44
46
|
### Up/Downloading data
|
47
|
+
|
45
48
|
digest = Digest::SHA1.file(file_path).hexdigest
|
46
49
|
|
47
|
-
#upload
|
50
|
+
# upload
|
48
51
|
f = File.read(file_path)
|
49
52
|
client.blob_put(table_name, digest, f)
|
50
53
|
|
51
|
-
#download
|
54
|
+
# download
|
52
55
|
data = client.blob_get(table_name, digest)
|
53
56
|
open(file_path, "wb") do |file|
|
54
57
|
file.write(data)
|
55
58
|
end
|
56
59
|
|
57
|
-
#deletion
|
60
|
+
# deletion
|
58
61
|
client.blob_delete(table_name, digest)
|
59
62
|
|
60
63
|
## Tests
|
61
64
|
|
62
|
-
|
65
|
+
Start up the crate server before running the tests
|
66
|
+
|
67
|
+
ruby spec/test_server.rb /path/to/crate
|
63
68
|
|
64
|
-
|
69
|
+
Then run tests with
|
70
|
+
|
71
|
+
bundle exec rspec spec
|
65
72
|
|
66
73
|
## Contributing
|
67
74
|
|
@@ -76,4 +83,3 @@ Please refer to CONTRIBUTING.rst for further information.
|
|
76
83
|
|
77
84
|
##License & Copyright
|
78
85
|
See LICENSE for details.
|
79
|
-
|
data/crate_ruby.gemspec
CHANGED
@@ -28,10 +28,11 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.version = CrateRuby::VERSION
|
29
29
|
spec.authors = ["Christoph Klocker", "CRATE Technology GmbH"]
|
30
30
|
spec.email = ["office@crate.io"]
|
31
|
-
spec.summary = "A simple interface
|
32
|
-
spec.description = "A
|
31
|
+
spec.summary = "A simple interface for the Crate database"
|
32
|
+
spec.description = "A Ruby interface for Crate, the distributed database for Docker."
|
33
33
|
spec.homepage = "http://crate.io"
|
34
34
|
spec.license = "Apache License, v2.0"
|
35
|
+
spec.required_ruby_version = '>= 2.0'
|
35
36
|
|
36
37
|
spec.files = `git ls-files -z`.split("\x0")
|
37
38
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
data/history.txt
CHANGED
data/lib/crate_ruby/client.rb
CHANGED
@@ -32,11 +32,13 @@ module CrateRuby
|
|
32
32
|
# @param [Array] servers An Array of servers including ports [127.0.0.1:4200, 10.0.0.1:4201]
|
33
33
|
# @param [opts] Optional paramters
|
34
34
|
# * logger: Custom Logger
|
35
|
+
# * http_options [Hash]: Net::HTTP options (open_timeout, read_timeout)
|
35
36
|
# @return [CrateRuby::Client]
|
36
37
|
def initialize(servers = [], opts = {})
|
37
38
|
@servers = servers
|
38
39
|
@servers << "#{DEFAULT_HOST}:#{DEFAULT_PORT}" if servers.empty?
|
39
40
|
@logger = opts[:logger] || CrateRuby.logger
|
41
|
+
@http_options = opts[:http_options] || { read_timeout: 3600 }
|
40
42
|
end
|
41
43
|
|
42
44
|
def inspect
|
@@ -93,14 +95,15 @@ module CrateRuby
|
|
93
95
|
# Executes a SQL statement against the Crate HTTP REST endpoint.
|
94
96
|
# @param [String] sql statement to execute
|
95
97
|
# @param [Array] args Array of values used for parameter substitution
|
98
|
+
# @param [Hash] Net::HTTP options (open_timeout, read_timeout)
|
96
99
|
# @return [ResultSet]
|
97
|
-
def execute(sql, args = nil)
|
100
|
+
def execute(sql, args = nil, http_options = {})
|
98
101
|
@logger.debug sql
|
99
102
|
req = Net::HTTP::Post.new("/_sql", initheader = {'Content-Type' => 'application/json'})
|
100
103
|
body = {"stmt" => sql}
|
101
104
|
body.merge!({'args' => args}) if args
|
102
105
|
req.body = body.to_json
|
103
|
-
response = request(req)
|
106
|
+
response = request(req, http_options)
|
104
107
|
@logger.debug response.body
|
105
108
|
success = case response.code
|
106
109
|
when /^2\d{2}/
|
@@ -207,9 +210,13 @@ module CrateRuby
|
|
207
210
|
Net::HTTP.new(host, port)
|
208
211
|
end
|
209
212
|
|
210
|
-
def request(req)
|
211
|
-
|
213
|
+
def request(req, http_options = {})
|
214
|
+
options = @http_options.merge(http_options)
|
215
|
+
connection.start do |http|
|
216
|
+
options.each { |opt, value| http.send("#{opt}=", value) }
|
217
|
+
http.request(req)
|
218
|
+
end
|
212
219
|
end
|
213
220
|
|
214
221
|
end
|
215
|
-
end
|
222
|
+
end
|
data/lib/crate_ruby/version.rb
CHANGED
@@ -23,8 +23,10 @@ require_relative '../spec_helper'
|
|
23
23
|
|
24
24
|
describe CrateRuby::Client do
|
25
25
|
TABLE_NAME = 'blob_table'
|
26
|
+
CRATE_HOST = "localhost:44200"
|
27
|
+
|
26
28
|
describe '#create_table' do
|
27
|
-
let(:client) { CrateRuby::Client.new([
|
29
|
+
let(:client) { CrateRuby::Client.new([CRATE_HOST]) }
|
28
30
|
|
29
31
|
describe 'blob management' do
|
30
32
|
let(:file) { 'logo-crate.png' }
|
@@ -34,11 +36,11 @@ describe CrateRuby::Client do
|
|
34
36
|
let(:store_location) { File.join(path, "get_#{file}") }
|
35
37
|
|
36
38
|
before(:all) do
|
37
|
-
CrateRuby::Client.new([
|
39
|
+
CrateRuby::Client.new([CRATE_HOST]).execute("create blob TABLE #{TABLE_NAME}")
|
38
40
|
end
|
39
41
|
|
40
42
|
after(:all) do
|
41
|
-
CrateRuby::Client.new([
|
43
|
+
CrateRuby::Client.new([CRATE_HOST]).execute("drop blob TABLE #{TABLE_NAME}")
|
42
44
|
end
|
43
45
|
|
44
46
|
describe '#blob_put' do
|
@@ -51,7 +53,7 @@ describe CrateRuby::Client do
|
|
51
53
|
|
52
54
|
it 'should upload a file to the blob table' do
|
53
55
|
f = File.read(file_path)
|
54
|
-
client.blob_put(TABLE_NAME, digest, f).should
|
56
|
+
client.blob_put(TABLE_NAME, digest, f).should be_truthy
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
@@ -75,7 +77,7 @@ describe CrateRuby::Client do
|
|
75
77
|
|
76
78
|
it 'should download a blob' do
|
77
79
|
data = client.blob_get(TABLE_NAME, digest)
|
78
|
-
data.should_not
|
80
|
+
data.should_not be_falsey
|
79
81
|
open(store_location, "wb") { |file|
|
80
82
|
file.write(data)
|
81
83
|
}
|
@@ -102,27 +104,32 @@ describe CrateRuby::Client do
|
|
102
104
|
let(:table_name) { "post" }
|
103
105
|
|
104
106
|
after do
|
105
|
-
client.execute("drop TABLE #{table_name}").should
|
107
|
+
client.execute("drop TABLE #{table_name}").should be_truthy
|
106
108
|
end
|
107
109
|
|
108
110
|
it 'should create a new table' do
|
109
|
-
client.execute("CREATE TABLE #{table_name} (id int)").should
|
111
|
+
client.execute("CREATE TABLE #{table_name} (id int)").should be_truthy
|
110
112
|
end
|
111
113
|
|
112
114
|
it 'should allow parameter substitution' do
|
113
|
-
client.execute("CREATE TABLE #{table_name} (id int, title string, tags array(string) )").should
|
115
|
+
client.execute("CREATE TABLE #{table_name} (id int, title string, tags array(string) )").should be_truthy
|
114
116
|
client.execute("INSERT INTO #{table_name} (id, title, tags) VALUES (\$1, \$2, \$3)",
|
115
|
-
[1, "My life with crate", ['awesome', 'freaky']]).should
|
117
|
+
[1, "My life with crate", ['awesome', 'freaky']]).should be_truthy
|
116
118
|
end
|
117
119
|
|
118
120
|
it 'should create an object' do
|
119
121
|
client.execute("CREATE TABLE #{table_name} (id STRING PRIMARY KEY, name string, address object) ")
|
120
|
-
client.execute(%Q{INSERT INTO #{table_name} (address, id, name) VALUES ({
|
122
|
+
client.execute(%Q{INSERT INTO #{table_name} (address, id, name) VALUES ({street='1010 W 2nd Ave',city='Vancouver'}, 'fb7183ac-d049-462c-85a9-732aca59a1c1', 'Mad Max')})
|
121
123
|
client.refresh_table table_name
|
122
124
|
client.execute(%Q{select * from #{table_name}})
|
123
|
-
|
124
125
|
end
|
125
126
|
|
127
|
+
it 'should accept http options' do
|
128
|
+
client.execute("CREATE TABLE #{table_name} (id STRING PRIMARY KEY, name string, address object) ")
|
129
|
+
client.execute(%Q{INSERT INTO #{table_name} (address, id, name) VALUES ({street='1010 W 2nd Ave',city='Vancouver'}, 'fb7183ac-d049-462c-85a9-732aca59a1c1', 'Mad Max')})
|
130
|
+
client.refresh_table table_name
|
131
|
+
expect { client.execute("SELECT * FROM #{table_name}", nil, {read_timeout: 0}) }.to raise_error Net::ReadTimeout
|
132
|
+
end
|
126
133
|
end
|
127
134
|
|
128
135
|
|
data/spec/spec_helper.rb
CHANGED
data/spec/test_server.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
# -*- coding: utf-8; -*-
|
2
3
|
#
|
3
4
|
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
@@ -20,57 +21,53 @@
|
|
20
21
|
# software solely pursuant to the terms of the relevant commercial agreement.
|
21
22
|
|
22
23
|
require 'net/http'
|
24
|
+
|
23
25
|
class TestServer
|
24
|
-
CRATE_PATH = "~/crate"
|
25
|
-
TEST_PORT = 4209
|
26
26
|
NAME = "TestCluster"
|
27
|
+
HOST = "127.0.0.1"
|
28
|
+
PORT = 44200
|
29
|
+
TIMEOUT = 30
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
@
|
31
|
-
@port = port || TEST_PORT
|
32
|
-
@host = host
|
31
|
+
def initialize(crate_home = '~/crate', run_in_background = false)
|
32
|
+
@crate_home = crate_home
|
33
|
+
@run_in_background = run_in_background
|
33
34
|
end
|
34
35
|
|
35
36
|
def start
|
36
|
-
cmd = "sh #{
|
37
|
-
@pid = spawn(cmd, :
|
37
|
+
cmd = "sh #{File.join(@crate_home, 'bin', 'crate')} #{start_params}"
|
38
|
+
@pid = spawn(cmd, out: "/tmp/crate_test_server.out",
|
39
|
+
err: "/tmp/crate_test_server.err")
|
38
40
|
Process.detach(@pid)
|
39
|
-
puts '
|
41
|
+
puts 'Starting Crate... (this will take a few seconds)'
|
40
42
|
time_slept = 0
|
43
|
+
interval = 2
|
41
44
|
while true
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
+
if !alive? and time_slept > TIMEOUT
|
46
|
+
puts "Crate hasn't started for #{TIMEOUT} seconds. Giving up now..."
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
if alive? and @run_in_background
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
sleep(interval)
|
53
|
+
time_slept += interval
|
45
54
|
end
|
46
55
|
end
|
47
56
|
|
48
|
-
def stop
|
49
|
-
Process.kill("HUP", @pid)
|
50
|
-
end
|
51
|
-
|
52
57
|
private
|
53
58
|
|
54
|
-
|
55
|
-
def crate_exec
|
56
|
-
end
|
57
|
-
|
58
|
-
def crate_config
|
59
|
-
end
|
60
|
-
|
61
59
|
def start_params
|
62
60
|
"-Des.index.storage.type=memory " +
|
63
61
|
"-Des.node.name=#{NAME} " +
|
64
|
-
"-Des.cluster.name=Testing#{
|
65
|
-
"-Des.http.port=#{
|
62
|
+
"-Des.cluster.name=Testing#{PORT} " +
|
63
|
+
"-Des.http.port=#{PORT}-#{PORT} " +
|
66
64
|
"-Des.network.host=localhost " +
|
67
|
-
"-Des.discovery.type=zen " +
|
68
65
|
"-Des.discovery.zen.ping.multicast.enabled=false"
|
69
66
|
end
|
70
67
|
|
71
68
|
def alive?
|
72
69
|
req = Net::HTTP::Get.new('/')
|
73
|
-
resp = Net::HTTP.new(
|
70
|
+
resp = Net::HTTP.new(HOST, PORT)
|
74
71
|
begin
|
75
72
|
response = resp.start { |http| http.request(req) }
|
76
73
|
response.code == "200" ? true : false
|
@@ -78,14 +75,7 @@ class TestServer
|
|
78
75
|
false
|
79
76
|
end
|
80
77
|
end
|
81
|
-
|
82
78
|
end
|
83
79
|
|
84
|
-
server = TestServer.new
|
85
|
-
|
86
|
-
trap("INT") do
|
87
|
-
puts "Script terminated by user."
|
88
|
-
server.stop
|
89
|
-
puts "Server stopped"
|
90
|
-
exit
|
91
|
-
end
|
80
|
+
server = TestServer.new(*ARGV)
|
81
|
+
server.start
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crate_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Klocker
|
@@ -9,60 +9,59 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '1.5'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- - ~>
|
25
|
+
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '1.5'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rspec
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - ~>
|
46
|
+
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '2.14'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - ~>
|
53
|
+
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '2.14'
|
56
|
-
description: A
|
57
|
-
document-oriented cluster data store.
|
56
|
+
description: A Ruby interface for Crate, the distributed database for Docker.
|
58
57
|
email:
|
59
58
|
- office@crate.io
|
60
59
|
executables: []
|
61
60
|
extensions: []
|
62
61
|
extra_rdoc_files: []
|
63
62
|
files:
|
64
|
-
- .gitignore
|
65
|
-
- .travis.yml
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
66
65
|
- CONTRIBUTING.rst
|
67
66
|
- DEVELOP.md
|
68
67
|
- Gemfile
|
@@ -82,7 +81,6 @@ files:
|
|
82
81
|
- spec/crate_ruby/result_set_spec.rb
|
83
82
|
- spec/spec_helper.rb
|
84
83
|
- spec/test_server.rb
|
85
|
-
- spec/travis_test_server.rb
|
86
84
|
- spec/uploads/get_logo-crate.png
|
87
85
|
- spec/uploads/logo-crate.png
|
88
86
|
- spec/uploads/text.txt
|
@@ -96,26 +94,25 @@ require_paths:
|
|
96
94
|
- lib
|
97
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
98
96
|
requirements:
|
99
|
-
- -
|
97
|
+
- - ">="
|
100
98
|
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
99
|
+
version: '2.0'
|
102
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
101
|
requirements:
|
104
|
-
- -
|
102
|
+
- - ">="
|
105
103
|
- !ruby/object:Gem::Version
|
106
104
|
version: '0'
|
107
105
|
requirements: []
|
108
106
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.4.
|
107
|
+
rubygems_version: 2.4.6
|
110
108
|
signing_key:
|
111
109
|
specification_version: 4
|
112
|
-
summary: A simple interface
|
110
|
+
summary: A simple interface for the Crate database
|
113
111
|
test_files:
|
114
112
|
- spec/crate_ruby/client_spec.rb
|
115
113
|
- spec/crate_ruby/result_set_spec.rb
|
116
114
|
- spec/spec_helper.rb
|
117
115
|
- spec/test_server.rb
|
118
|
-
- spec/travis_test_server.rb
|
119
116
|
- spec/uploads/get_logo-crate.png
|
120
117
|
- spec/uploads/logo-crate.png
|
121
118
|
- spec/uploads/text.txt
|
data/spec/travis_test_server.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- coding: utf-8; -*-
|
3
|
-
#
|
4
|
-
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
5
|
-
# license agreements. See the NOTICE file distributed with this work for
|
6
|
-
# additional information regarding copyright ownership. Crate licenses
|
7
|
-
# this file to you under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License. You may
|
9
|
-
# obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
15
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
16
|
-
# License for the specific language governing permissions and limitations
|
17
|
-
# under the License.
|
18
|
-
#
|
19
|
-
# However, if you have executed another commercial license agreement
|
20
|
-
# with Crate these terms will supersede the license and you may use the
|
21
|
-
# software solely pursuant to the terms of the relevant commercial agreement.
|
22
|
-
|
23
|
-
require 'net/http'
|
24
|
-
class TestServer
|
25
|
-
CRATE_PATH = "~/crate"
|
26
|
-
TEST_PORT = 4209
|
27
|
-
NAME = "TestCluster"
|
28
|
-
|
29
|
-
|
30
|
-
def initialize(crate_home = nil, port = nil)
|
31
|
-
@crate_home = crate_home
|
32
|
-
@port = port
|
33
|
-
@host = "127.0.0.1"
|
34
|
-
end
|
35
|
-
|
36
|
-
def start
|
37
|
-
cmd = "sh #{File.join(@crate_home, 'bin/crate')} #{start_params}"
|
38
|
-
@pid = spawn(cmd, :out => "/tmp/crate_test_server.out", :err => "/tmp/crate_test_server.err")
|
39
|
-
Process.detach(@pid)
|
40
|
-
puts 'starting'
|
41
|
-
time_slept = 0
|
42
|
-
while !alive?
|
43
|
-
puts "Crate not yet fully available. Waiting since #{time_slept} seconds..."
|
44
|
-
sleep(2)
|
45
|
-
time_slept += 2
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def start_params
|
52
|
-
"-Des.index.storage.type=memory " +
|
53
|
-
"-Des.node.name=#{NAME} " +
|
54
|
-
"-Des.cluster.name=Testing#{@port} " +
|
55
|
-
"-Des.http.port=#{@port}-#{@port} " +
|
56
|
-
"-Des.network.host=localhost " +
|
57
|
-
"-Des.discovery.type=zen " +
|
58
|
-
"-Des.discovery.zen.ping.multicast.enabled=false"
|
59
|
-
end
|
60
|
-
|
61
|
-
def alive?
|
62
|
-
req = Net::HTTP::Get.new('/')
|
63
|
-
resp = Net::HTTP.new(@host, @port)
|
64
|
-
begin
|
65
|
-
response = resp.start { |http| http.request(req) }
|
66
|
-
response.code == "200" ? true : false
|
67
|
-
rescue Errno::ECONNREFUSED
|
68
|
-
false
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
server = TestServer.new *ARGV
|
75
|
-
server.start
|