crate_ruby 0.2.0 → 0.2.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/CHANGES.rst +64 -0
- data/LICENSE +0 -16
- data/NOTICE +20 -7
- data/README.rst +58 -46
- data/lib/crate_ruby/client.rb +7 -5
- data/lib/crate_ruby/error.rb +3 -0
- data/lib/crate_ruby/result_set.rb +2 -0
- data/lib/crate_ruby/version.rb +3 -1
- data/lib/crate_ruby.rb +8 -8
- metadata +90 -43
- data/.gitignore +0 -24
- data/.travis.yml +0 -15
- data/CONTRIBUTING.rst +0 -10
- data/DEVELOP.rst +0 -46
- data/Gemfile +0 -4
- data/Rakefile +0 -7
- data/crate_ruby.gemspec +0 -44
- data/devtools/create_tag.sh +0 -77
- data/history.txt +0 -32
- data/log/.keep +0 -0
- data/spec/bootstrap.rb +0 -74
- data/spec/crate_ruby/client_spec.rb +0 -252
- data/spec/crate_ruby/result_set_spec.rb +0 -93
- data/spec/spec_helper.rb +0 -43
- data/spec/support/test_cluster.rb +0 -107
- data/spec/uploads/get_logo-crate.png +0 -0
- data/spec/uploads/logo-crate.png +0 -0
- data/spec/uploads/text.txt +0 -1
data/DEVELOP.rst
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
===============
|
|
2
|
-
Developer Guide
|
|
3
|
-
===============
|
|
4
|
-
|
|
5
|
-
Tests
|
|
6
|
-
=====
|
|
7
|
-
|
|
8
|
-
First, download and install CrateDB locally::
|
|
9
|
-
|
|
10
|
-
$ ruby spec/bootstrap.rb
|
|
11
|
-
|
|
12
|
-
Then, run tests like so::
|
|
13
|
-
|
|
14
|
-
$ bundle exec rspec spec
|
|
15
|
-
|
|
16
|
-
Preparing a Release
|
|
17
|
-
===================
|
|
18
|
-
|
|
19
|
-
To create a new release, you must:
|
|
20
|
-
|
|
21
|
-
- Update ``CrateRuby.version`` in ``lib/crate_ruby/version.rb``
|
|
22
|
-
|
|
23
|
-
- Add a section for the new version in the ``history.txt`` file
|
|
24
|
-
|
|
25
|
-
- Commit your changes with a message like "prepare release x.y.z"
|
|
26
|
-
|
|
27
|
-
- Push to ``origin/master``
|
|
28
|
-
|
|
29
|
-
- Create a tag by running ``./devtools/create_tag.sh``
|
|
30
|
-
|
|
31
|
-
RubyGems Deployment
|
|
32
|
-
===================
|
|
33
|
-
|
|
34
|
-
Update your package manager::
|
|
35
|
-
|
|
36
|
-
$ gem update --system
|
|
37
|
-
|
|
38
|
-
Build the new gem::
|
|
39
|
-
|
|
40
|
-
$ gem build crate_ruby.gemspec
|
|
41
|
-
|
|
42
|
-
Publish the new gem::
|
|
43
|
-
|
|
44
|
-
$ gem push crate_ruby-<VERISON>.gem
|
|
45
|
-
|
|
46
|
-
Here, ``<VERISON>`` is the version you are releasing.
|
data/Gemfile
DELETED
data/Rakefile
DELETED
data/crate_ruby.gemspec
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
#
|
|
3
|
-
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
|
4
|
-
# license agreements. See the NOTICE file distributed with this work for
|
|
5
|
-
# additional information regarding copyright ownership. Crate licenses
|
|
6
|
-
# this file to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License. You may
|
|
8
|
-
# obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
14
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
15
|
-
# License for the specific language governing permissions and limitations
|
|
16
|
-
# under the License.
|
|
17
|
-
#
|
|
18
|
-
# However, if you have executed another commercial license agreement
|
|
19
|
-
# with Crate these terms will supersede the license and you may use the
|
|
20
|
-
# software solely pursuant to the terms of the relevant commercial agreement.
|
|
21
|
-
|
|
22
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
23
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
24
|
-
require 'crate_ruby/version'
|
|
25
|
-
|
|
26
|
-
Gem::Specification.new do |spec|
|
|
27
|
-
spec.name = "crate_ruby"
|
|
28
|
-
spec.version = CrateRuby::VERSION
|
|
29
|
-
spec.authors = ["Christoph Klocker", "CRATE Technology GmbH"]
|
|
30
|
-
spec.email = ["office@crate.io"]
|
|
31
|
-
spec.summary = "A simple interface for the Crate.IO database."
|
|
32
|
-
spec.description = "A Ruby interface for Crate.IO. Put your data to work. Simply."
|
|
33
|
-
spec.homepage = "http://crate.io"
|
|
34
|
-
spec.license = "Apache-2.0"
|
|
35
|
-
spec.required_ruby_version = '>= 2.0'
|
|
36
|
-
|
|
37
|
-
spec.files = `git ls-files -z`.split("\x0")
|
|
38
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
39
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
40
|
-
spec.require_paths = ["lib"]
|
|
41
|
-
|
|
42
|
-
spec.add_development_dependency "rake"
|
|
43
|
-
spec.add_development_dependency "rspec", "~> 2.99"
|
|
44
|
-
end
|
data/devtools/create_tag.sh
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
#
|
|
3
|
-
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
|
4
|
-
# license agreements. See the NOTICE file distributed with this work for
|
|
5
|
-
# additional information regarding copyright ownership. Crate licenses
|
|
6
|
-
# this file to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License. You may
|
|
8
|
-
# obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
14
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
15
|
-
# License for the specific language governing permissions and limitations
|
|
16
|
-
# under the License.
|
|
17
|
-
#
|
|
18
|
-
# However, if you have executed another commercial license agreement
|
|
19
|
-
# with Crate these terms will supersede the license and you may use the
|
|
20
|
-
# software solely pursuant to the terms of the relevant commercial agreement.
|
|
21
|
-
|
|
22
|
-
# check if everything is committed
|
|
23
|
-
CLEAN=`git status -s`
|
|
24
|
-
if [ ! -z "$CLEAN" ]
|
|
25
|
-
then
|
|
26
|
-
echo "Working directory not clean. Please commit all changes before tagging"
|
|
27
|
-
echo "Aborting."
|
|
28
|
-
exit -1
|
|
29
|
-
fi
|
|
30
|
-
|
|
31
|
-
echo "Fetching origin..."
|
|
32
|
-
git fetch origin > /dev/null
|
|
33
|
-
|
|
34
|
-
# get current branch
|
|
35
|
-
BRANCH=`git branch | grep "^*" | cut -d " " -f 2`
|
|
36
|
-
echo "Current branch is $BRANCH."
|
|
37
|
-
|
|
38
|
-
# check if master == origin/master
|
|
39
|
-
LOCAL_COMMIT=`git show --format="%H" $BRANCH`
|
|
40
|
-
ORIGIN_COMMIT=`git show --format="%H" origin/$BRANCH`
|
|
41
|
-
|
|
42
|
-
if [ "$LOCAL_COMMIT" != "$ORIGIN_COMMIT" ]
|
|
43
|
-
then
|
|
44
|
-
echo "Local $BRANCH is not up to date. "
|
|
45
|
-
echo "Aborting."
|
|
46
|
-
exit -1
|
|
47
|
-
fi
|
|
48
|
-
|
|
49
|
-
# get version from version.rb
|
|
50
|
-
VERSION=$(grep "VERSION =" lib/crate_ruby/version.rb | \
|
|
51
|
-
cut -d' ' -f5 | tr -d "\'" | sed -e "s/.freeze//")
|
|
52
|
-
echo "Version: $VERSION"
|
|
53
|
-
|
|
54
|
-
# check if tag to create has already been created
|
|
55
|
-
EXISTS=`git tag | grep $VERSION`
|
|
56
|
-
|
|
57
|
-
if [ "$VERSION" == "$EXISTS" ]
|
|
58
|
-
then
|
|
59
|
-
echo "Revision $VERSION already tagged."
|
|
60
|
-
echo "Aborting."
|
|
61
|
-
exit -1
|
|
62
|
-
fi
|
|
63
|
-
|
|
64
|
-
# check if VERSION is in head of CHANGES.txt
|
|
65
|
-
REV_NOTE=`grep "=== $VERSION" history.txt`
|
|
66
|
-
if [ -z "$REV_NOTE" ]
|
|
67
|
-
then
|
|
68
|
-
echo "No notes for revision $VERSION found in history.txt"
|
|
69
|
-
echo "Aborting."
|
|
70
|
-
exit -1
|
|
71
|
-
fi
|
|
72
|
-
|
|
73
|
-
echo "Creating tag $VERSION..."
|
|
74
|
-
git tag -a "$VERSION" -m "Tag release for revision $VERSION"
|
|
75
|
-
git push --tags
|
|
76
|
-
echo "Done."
|
|
77
|
-
|
data/history.txt
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# coding: UTF-8
|
|
2
|
-
=== 0.2.0
|
|
3
|
-
* Added SSL support.
|
|
4
|
-
|
|
5
|
-
=== 0.1.0
|
|
6
|
-
* HTTP Basic Authentication support that comes with 2.3.0
|
|
7
|
-
|
|
8
|
-
=== 0.0.9
|
|
9
|
-
|
|
10
|
-
* fixed breaking changes that kept driver from working with crate > v2.0
|
|
11
|
-
* removed ruby 1.9.3 from travis.yml
|
|
12
|
-
* client now supports HTTP options
|
|
13
|
-
* update travis.yml and fix broken test
|
|
14
|
-
|
|
15
|
-
=== 0.0.8
|
|
16
|
-
|
|
17
|
-
* undocumented gem release
|
|
18
|
-
|
|
19
|
-
=== 0.0.7
|
|
20
|
-
|
|
21
|
-
* use prepared statements for insert
|
|
22
|
-
|
|
23
|
-
=== 0.0.6
|
|
24
|
-
|
|
25
|
-
* now officially supported by Crate Data and available under the
|
|
26
|
-
Apache 2.0 License
|
|
27
|
-
|
|
28
|
-
=== 0.0.5
|
|
29
|
-
|
|
30
|
-
Enhancements:
|
|
31
|
-
|
|
32
|
-
* #execute now supports parameter substitution
|
data/log/.keep
DELETED
|
File without changes
|
data/spec/bootstrap.rb
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
#
|
|
3
|
-
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
|
4
|
-
# license agreements. See the NOTICE file distributed with this work for
|
|
5
|
-
# additional information regarding copyright ownership. Crate licenses
|
|
6
|
-
# this file to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License. You may
|
|
8
|
-
# obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
14
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
15
|
-
# License for the specific language governing permissions and limitations
|
|
16
|
-
# under the License.
|
|
17
|
-
#
|
|
18
|
-
# However, if you have executed another commercial license agreement
|
|
19
|
-
# with Crate these terms will supersede the license and you may use the
|
|
20
|
-
# software solely pursuant to the terms of the relevant commercial agreement.
|
|
21
|
-
|
|
22
|
-
require 'rubygems/package'
|
|
23
|
-
require 'net/http'
|
|
24
|
-
require 'zlib'
|
|
25
|
-
|
|
26
|
-
class Bootstrap
|
|
27
|
-
VERSION = '2.3.0'.freeze
|
|
28
|
-
|
|
29
|
-
def initialize
|
|
30
|
-
@fname = "crate-#{VERSION}.tar.gz"
|
|
31
|
-
@crate_bin = File.join('parts', 'crate' 'bin', 'crate')
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def run
|
|
35
|
-
unless File.file?(@crate_bin)
|
|
36
|
-
download unless File.file?(@fname)
|
|
37
|
-
extract
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def download
|
|
42
|
-
uri = URI("https://cdn.crate.io/downloads/releases/#{@fname}")
|
|
43
|
-
puts "Downloading Crate from #{uri} ..."
|
|
44
|
-
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
|
45
|
-
request = Net::HTTP::Get.new uri
|
|
46
|
-
resp = http.request request
|
|
47
|
-
open(@fname, 'wb') do |file|
|
|
48
|
-
file.write(resp.body)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def extract
|
|
54
|
-
tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(@fname))
|
|
55
|
-
tar_extract.rewind # The extract has to be rewinded after every iteration
|
|
56
|
-
tar_extract.each do |entry|
|
|
57
|
-
dest_file = File.join 'parts', entry.full_name.gsub(/^(crate)(\-\d+\.\d+\.\d+)(.*)/, '\1\3')
|
|
58
|
-
puts dest_file
|
|
59
|
-
if entry.directory?
|
|
60
|
-
FileUtils.mkdir_p dest_file
|
|
61
|
-
else
|
|
62
|
-
dest_dir = File.dirname(dest_file)
|
|
63
|
-
FileUtils.mkdir_p dest_dir unless File.directory?(dest_dir)
|
|
64
|
-
File.open dest_file, 'wb' do |f|
|
|
65
|
-
f.print entry.read
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
tar_extract.close
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
bootstrap = Bootstrap.new(*ARGV)
|
|
74
|
-
bootstrap.run
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
|
3
|
-
# license agreements. See the NOTICE file distributed with this work for
|
|
4
|
-
# additional information regarding copyright ownership. Crate licenses
|
|
5
|
-
# this file to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
# you may not use this file except in compliance with the License. You may
|
|
7
|
-
# obtain a copy of the License at
|
|
8
|
-
#
|
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
#
|
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
13
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
14
|
-
# License for the specific language governing permissions and limitations
|
|
15
|
-
# under the License.
|
|
16
|
-
#
|
|
17
|
-
# However, if you have executed another commercial license agreement
|
|
18
|
-
# with Crate these terms will supersede the license and you may use the
|
|
19
|
-
# software solely pursuant to the terms of the relevant commercial agreement.
|
|
20
|
-
|
|
21
|
-
require_relative '../spec_helper'
|
|
22
|
-
require 'securerandom'
|
|
23
|
-
|
|
24
|
-
describe CrateRuby::Client do
|
|
25
|
-
let(:client) { CrateRuby::Client.new(['localhost:44200']) }
|
|
26
|
-
let(:client_w_schema) { CrateRuby::Client.new(['localhost:44200'], schema: 'custom') }
|
|
27
|
-
|
|
28
|
-
describe '#create_table' do
|
|
29
|
-
describe 'blob management' do
|
|
30
|
-
let(:file) { 'logo-crate.png' }
|
|
31
|
-
let(:path) { File.join(File.dirname(__FILE__), '../uploads/') }
|
|
32
|
-
let(:file_path) { File.join(path, file) }
|
|
33
|
-
let(:digest) { Digest::SHA1.file(file_path).hexdigest }
|
|
34
|
-
let(:store_location) { File.join(path, "get_#{file}") }
|
|
35
|
-
|
|
36
|
-
before do
|
|
37
|
-
@blob_table = 'my_blobs'
|
|
38
|
-
client.execute("create blob table #{@blob_table} clustered into 1 shards with (number_of_replicas=0)")
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
after do
|
|
42
|
-
client.execute("drop blob table #{@blob_table}")
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
describe '#blob_put' do
|
|
46
|
-
context 'file' do
|
|
47
|
-
it 'should upload a file to the blob table' do
|
|
48
|
-
f = File.read(file_path)
|
|
49
|
-
client.blob_put(@blob_table, digest, f).should be_truthy
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
context '#string' do
|
|
53
|
-
let(:string) { 'my crazy' }
|
|
54
|
-
let(:digest) { Digest::SHA1.hexdigest(string) }
|
|
55
|
-
it 'should upload a string to the blob table' do
|
|
56
|
-
client.blob_put(@blob_table, digest, string).should be_truthy
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
describe '#blob_get' do
|
|
62
|
-
before do
|
|
63
|
-
f = File.read(file_path)
|
|
64
|
-
client.blob_put(@blob_table, digest, f)
|
|
65
|
-
end
|
|
66
|
-
it 'should download a blob' do
|
|
67
|
-
data = client.blob_get(@blob_table, digest)
|
|
68
|
-
data.should_not be_falsey
|
|
69
|
-
open(store_location, 'wb') do |file|
|
|
70
|
-
file.write(data)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
describe '#blob_delete' do
|
|
76
|
-
before do
|
|
77
|
-
f = File.read(file_path)
|
|
78
|
-
client.blob_put(@blob_table, digest, f)
|
|
79
|
-
end
|
|
80
|
-
it 'should delete a blob' do
|
|
81
|
-
client.blob_delete(@blob_table, digest)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
describe '#execute' do
|
|
87
|
-
let(:table_name) { 't_test' }
|
|
88
|
-
|
|
89
|
-
before do
|
|
90
|
-
client.execute("create table #{table_name} " \
|
|
91
|
-
'(id integer primary key, name string, address object, tags array(string)) ')
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
after do
|
|
95
|
-
client.execute("drop table #{table_name}")
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it 'should allow parameters' do
|
|
99
|
-
client.execute("insert into #{table_name} (id, name, address, tags) VALUES (?, ?, ?, ?)",
|
|
100
|
-
[1, 'Post 1', { street: '1010 W 2nd Ave', city: 'Vancouver' },
|
|
101
|
-
%w[awesome freaky]]).should be_truthy
|
|
102
|
-
client.refresh_table table_name
|
|
103
|
-
client.execute("select * from #{table_name}").rowcount.should eq(1)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it 'should allow bulk parameters' do
|
|
107
|
-
bulk_args = [
|
|
108
|
-
[1, 'Post 1', { street: '1010 W 2nd Ave', city: 'New York' }, %w[foo bar]],
|
|
109
|
-
[2, 'Post 2', { street: '1010 W 2nd Ave', city: 'San Fran' }, []]
|
|
110
|
-
]
|
|
111
|
-
client.execute("insert into #{table_name} (id, name, address, tags) VALUES (?, ?, ?, ?)",
|
|
112
|
-
nil, bulk_args).should be_truthy
|
|
113
|
-
client.refresh_table table_name
|
|
114
|
-
client.execute("select * from #{table_name}").rowcount.should eq(2)
|
|
115
|
-
client.execute("select count(*) from #{table_name}")[0][0].should eq(2)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
it 'should accept http options' do
|
|
119
|
-
expect do
|
|
120
|
-
client.execute("select * from #{table_name}", nil, nil,
|
|
121
|
-
'read_timeout' => 0)
|
|
122
|
-
end.to raise_error Net::ReadTimeout
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
context 'with schema' do
|
|
126
|
-
before do
|
|
127
|
-
client_w_schema.execute("create table #{table_name} \n
|
|
128
|
-
(id integer primary key, name string, address object, tags array(string)) ")
|
|
129
|
-
end
|
|
130
|
-
after { client_w_schema.execute("drop table #{table_name}") }
|
|
131
|
-
|
|
132
|
-
it 'should allow parameters' do
|
|
133
|
-
client_w_schema.execute("insert into #{table_name} (id, name, address, tags) VALUES (?, ?, ?, ?)",
|
|
134
|
-
[1, 'Post 1', { street: '1010 W 2nd Ave', city: 'Vancouver' },
|
|
135
|
-
%w[awesome freaky]]).should be_truthy
|
|
136
|
-
client_w_schema.refresh_table table_name
|
|
137
|
-
client.execute("select * from #{table_name}").rowcount.should_not eq(1)
|
|
138
|
-
client_w_schema.execute("select * from #{table_name}").rowcount.should eq(1)
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
describe '#initialize' do
|
|
144
|
-
it 'should use host and ports parameters' do
|
|
145
|
-
logger = double
|
|
146
|
-
client = CrateRuby::Client.new ['10.0.0.1:4200'], logger: logger
|
|
147
|
-
client.instance_variable_get(:@servers).should eq(['10.0.0.1:4200'])
|
|
148
|
-
end
|
|
149
|
-
it 'should use default request parameters' do
|
|
150
|
-
client = CrateRuby::Client.new
|
|
151
|
-
client.instance_variable_get(:@http_options).should eq(read_timeout: 3600)
|
|
152
|
-
end
|
|
153
|
-
it 'should use request parameters' do
|
|
154
|
-
client = CrateRuby::Client.new ['10.0.0.1:4200'],
|
|
155
|
-
http_options: { read_timeout: 60 }
|
|
156
|
-
client.instance_variable_get(:@http_options).should eq(read_timeout: 60)
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
describe '#tables' do
|
|
161
|
-
before do
|
|
162
|
-
client.create_table 'posts', id: :integer
|
|
163
|
-
client.create_table 'comments', id: :integer
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
after do
|
|
167
|
-
client.tables.each do |table|
|
|
168
|
-
client.drop_table table
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
it 'should return all user tables as an array of string values' do
|
|
173
|
-
client.tables.should eq %w[comments posts]
|
|
174
|
-
end
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
describe '#blob_tables' do
|
|
178
|
-
before do
|
|
179
|
-
client.create_blob_table 'pix'
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
after do
|
|
183
|
-
client.drop_table 'pix', true
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
it 'should return all user tables as an array of string values' do
|
|
187
|
-
client.blob_tables.should eq %w(pix)
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
describe '#insert' do
|
|
192
|
-
before do
|
|
193
|
-
client.create_table('posts', id: [:string, 'primary key'],
|
|
194
|
-
title: :string, views: :integer)
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
after do
|
|
198
|
-
client.drop_table 'posts'
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
it 'should insert the record' do
|
|
202
|
-
expect do
|
|
203
|
-
id = SecureRandom.uuid
|
|
204
|
-
client.insert('posts', id: id, title: 'Test')
|
|
205
|
-
client.refresh_table('posts')
|
|
206
|
-
result_set = client.execute("Select * from posts where id = '#{id}'")
|
|
207
|
-
result_set.rowcount.should eq 1
|
|
208
|
-
end.not_to raise_exception
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
describe '#refresh table' do
|
|
213
|
-
it 'should issue the proper refresh statment' do
|
|
214
|
-
client.should_receive(:execute).with('refresh table posts')
|
|
215
|
-
client.refresh_table('posts')
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
describe 'authentication' do
|
|
221
|
-
let(:username) { 'matz' }
|
|
222
|
-
let(:password) { 'ruby' }
|
|
223
|
-
let(:encrypted_credentials) { Base64.encode64 "#{username}:#{password}" }
|
|
224
|
-
|
|
225
|
-
describe 'with password' do
|
|
226
|
-
let(:auth_client) { CrateRuby::Client.new(['localhost:44200'], username: username, password: password) }
|
|
227
|
-
it 'sets the basic auth header' do
|
|
228
|
-
headers = auth_client.send(:headers)
|
|
229
|
-
expect(headers['Authorization']).to eq "Basic #{encrypted_credentials}"
|
|
230
|
-
end
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
describe 'without password' do
|
|
234
|
-
let(:auth_client) { CrateRuby::Client.new(['localhost:44200'], username: username) }
|
|
235
|
-
let(:enc_creds_wo_pwd) { Base64.encode64 "#{username}:" }
|
|
236
|
-
|
|
237
|
-
it 'sets and encodes auth header even without password' do
|
|
238
|
-
headers = auth_client.send(:headers)
|
|
239
|
-
expect(headers['Authorization']).to eq "Basic #{enc_creds_wo_pwd}"
|
|
240
|
-
end
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
describe 'X-User header' do
|
|
244
|
-
let(:auth_client) { CrateRuby::Client.new(['localhost:44200'], username: username) }
|
|
245
|
-
|
|
246
|
-
it 'sets the X-User header' do
|
|
247
|
-
headers = auth_client.send(:headers)
|
|
248
|
-
expect(headers['X-User']).to eq username
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
end
|
|
252
|
-
end
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
|
3
|
-
# license agreements. See the NOTICE file distributed with this work for
|
|
4
|
-
# additional information regarding copyright ownership. Crate licenses
|
|
5
|
-
# this file to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
# you may not use this file except in compliance with the License. You may
|
|
7
|
-
# obtain a copy of the License at
|
|
8
|
-
#
|
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
#
|
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
13
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
14
|
-
# License for the specific language governing permissions and limitations
|
|
15
|
-
# under the License.
|
|
16
|
-
#
|
|
17
|
-
# However, if you have executed another commercial license agreement
|
|
18
|
-
# with Crate these terms will supersede the license and you may use the
|
|
19
|
-
# software solely pursuant to the terms of the relevant commercial agreement.
|
|
20
|
-
|
|
21
|
-
require_relative '../spec_helper'
|
|
22
|
-
|
|
23
|
-
describe ResultSet do
|
|
24
|
-
let(:crate_result) { '{"cols":["my_column","my_integer_col"],"rows":[["Foo",5],["Bar",5]],"rowcount":1,"duration":4}' }
|
|
25
|
-
let(:result_with_array_col) { %({"cols":["id","tags","title"],"rows":[[1,["awesome","freaky"],"My life with crate"]],"rowcount":1,"duration":2}) }
|
|
26
|
-
let(:result_with_object) { %({"cols":["address","id","name"],"rows":[[{"street":"1010 W 2nd Ave","city":"Vancouver"},"fb7183ac-d049-462c-85a9-732aca59a1c1","Mad Max"]],"rowcount":1,"duration":3}) }
|
|
27
|
-
|
|
28
|
-
let(:result_set) { ResultSet.new(crate_result) }
|
|
29
|
-
|
|
30
|
-
let(:json_result) { JSON.parse crate_result }
|
|
31
|
-
|
|
32
|
-
describe '#initialize' do
|
|
33
|
-
it 'should set rowcount' do
|
|
34
|
-
result_set.rowcount.should eq 1
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it 'should set duration' do
|
|
38
|
-
result_set.duration.should eq 4
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'should set cols' do
|
|
42
|
-
result_set.cols.should eq json_result['cols']
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it 'should parse an array column result into an Array' do
|
|
46
|
-
res = ResultSet.new(result_with_array_col)
|
|
47
|
-
res[0][1].should be_a(Array)
|
|
48
|
-
res[0][1].should eq(%w[awesome freaky])
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'should parse an object column result into an Object' do
|
|
52
|
-
res = ResultSet.new(result_with_object)
|
|
53
|
-
res[0][0].should be_a(Hash)
|
|
54
|
-
res[0][0].should eq('street' => '1010 W 2nd Ave', 'city' => 'Vancouver')
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
describe '#each' do
|
|
59
|
-
it 'should loop over the result rows' do
|
|
60
|
-
result_set.each_with_index do |r, i|
|
|
61
|
-
r.should eq json_result['rows'][i]
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
describe '#[]' do
|
|
67
|
-
it 'should return the row at index' do
|
|
68
|
-
result_set[1][0].should eq('Bar')
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
describe '#values_at' do
|
|
73
|
-
it 'should only return the columns specified' do
|
|
74
|
-
a = []
|
|
75
|
-
result_set.select_columns(['my_column']) do |res|
|
|
76
|
-
a << res
|
|
77
|
-
end
|
|
78
|
-
a.should eq [['Foo'], ['Bar']]
|
|
79
|
-
end
|
|
80
|
-
it 'should not raise error on invalid column name' do
|
|
81
|
-
expect do
|
|
82
|
-
result_set.select_columns(%w[my_column invalid]) do |row|
|
|
83
|
-
end
|
|
84
|
-
end.to_not raise_error
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
describe '#values' do
|
|
89
|
-
it 'should return all rows as an array of arrays' do
|
|
90
|
-
result_set.values.should eq json_result['rows']
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
|
3
|
-
# license agreements. See the NOTICE file distributed with this work for
|
|
4
|
-
# additional information regarding copyright ownership. Crate licenses
|
|
5
|
-
# this file to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
# you may not use this file except in compliance with the License. You may
|
|
7
|
-
# obtain a copy of the License at
|
|
8
|
-
#
|
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
#
|
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
13
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
14
|
-
# License for the specific language governing permissions and limitations
|
|
15
|
-
# under the License.
|
|
16
|
-
#
|
|
17
|
-
# However, if you have executed another commercial license agreement
|
|
18
|
-
# with Crate these terms will supersede the license and you may use the
|
|
19
|
-
# software solely pursuant to the terms of the relevant commercial agreement.
|
|
20
|
-
|
|
21
|
-
require_relative '../lib/crate_ruby'
|
|
22
|
-
require 'net/http'
|
|
23
|
-
require_relative 'support/test_cluster'
|
|
24
|
-
|
|
25
|
-
HOST = '127.0.0.1'.freeze
|
|
26
|
-
PORT = 44_200
|
|
27
|
-
|
|
28
|
-
RSpec.configure do |config|
|
|
29
|
-
config.before(:each) do
|
|
30
|
-
end
|
|
31
|
-
config.after(:each) do
|
|
32
|
-
end
|
|
33
|
-
config.before(:suite) do
|
|
34
|
-
@cluster = TestCluster.new(1, PORT)
|
|
35
|
-
@cluster.start_nodes
|
|
36
|
-
end
|
|
37
|
-
config.after(:suite) do
|
|
38
|
-
pid_file = File.join(__dir__, 'support/testnode.pid')
|
|
39
|
-
pid = File.read(pid_file)
|
|
40
|
-
File.delete(pid_file)
|
|
41
|
-
Process.kill('HUP', pid.to_i)
|
|
42
|
-
end
|
|
43
|
-
end
|