monetdb 0.1.3 → 0.2.0
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 +5 -13
- data/.travis.yml +5 -0
- data/CHANGELOG.rdoc +4 -0
- data/Gemfile +0 -15
- data/README.rdoc +2 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/monetdb.rb +6 -255
- data/lib/monetdb/connection.rb +94 -412
- data/lib/monetdb/connection/messages.rb +16 -0
- data/lib/monetdb/connection/query.rb +136 -0
- data/lib/monetdb/connection/setup.rb +125 -0
- data/lib/monetdb/error.rb +6 -12
- data/lib/monetdb/version.rb +3 -3
- data/monetdb.gemspec +6 -3
- data/script/console +16 -1
- data/test/test_helper.rb +3 -0
- data/test/test_helper/minitest.rb +7 -0
- data/test/test_helper/simple_connection.rb +13 -0
- data/test/unit/connection/test_messages.rb +48 -0
- data/test/unit/connection/test_query.rb +276 -0
- data/test/unit/connection/test_setup.rb +364 -0
- data/test/unit/test_connection.rb +178 -0
- data/test/unit/test_monetdb.rb +77 -1
- metadata +62 -24
- data/lib/monetdb/core_ext.rb +0 -1
- data/lib/monetdb/core_ext/string.rb +0 -67
- data/lib/monetdb/data.rb +0 -300
- data/lib/monetdb/hasher.rb +0 -40
- data/lib/monetdb/transaction.rb +0 -36
@@ -0,0 +1,178 @@
|
|
1
|
+
require_relative "../test_helper"
|
2
|
+
|
3
|
+
module Unit
|
4
|
+
class TestConnection < MiniTest::Test
|
5
|
+
|
6
|
+
describe MonetDB::Connection do
|
7
|
+
before do
|
8
|
+
@connection = MonetDB::Connection.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#initialize" do
|
12
|
+
describe "when not passing a configuration" do
|
13
|
+
it "uses a default configuration" do
|
14
|
+
assert_equal({
|
15
|
+
:host => "localhost",
|
16
|
+
:port => 50000,
|
17
|
+
:username => "monetdb",
|
18
|
+
:password => "monetdb"
|
19
|
+
}, @connection.instance_variable_get(:@config))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "when passing a configuration" do
|
24
|
+
it "overrides the default configuration" do
|
25
|
+
connection = MonetDB::Connection.new "host" => "127.0.0.1"
|
26
|
+
assert_equal({
|
27
|
+
:host => "127.0.0.1",
|
28
|
+
:port => 50000,
|
29
|
+
:username => "monetdb",
|
30
|
+
:password => "monetdb"
|
31
|
+
}, connection.instance_variable_get(:@config))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#connect" do
|
37
|
+
it "defines an active socket" do
|
38
|
+
TCPSocket.expects(:new).returns(socket = mock)
|
39
|
+
|
40
|
+
assert_nil @connection.instance_variable_get(:@socket)
|
41
|
+
|
42
|
+
@connection.expects(:setup)
|
43
|
+
@connection.connect
|
44
|
+
assert_equal socket, @connection.instance_variable_get(:@socket)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#connected?" do
|
49
|
+
it "returns whether it has an active socket" do
|
50
|
+
assert_equal false, @connection.connected?
|
51
|
+
@connection.instance_variable_set :@socket, mock
|
52
|
+
assert_equal true, @connection.connected?
|
53
|
+
@connection.instance_variable_set :@socket, nil
|
54
|
+
assert_equal false, @connection.connected?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#disconnect" do
|
59
|
+
describe "when disconnected" do
|
60
|
+
it "does nothing" do
|
61
|
+
assert_equal false, @connection.connected?
|
62
|
+
@connection.disconnect
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "when connected" do
|
67
|
+
it "disconnects the socket and releases @socket" do
|
68
|
+
socket = mock
|
69
|
+
@connection.instance_variable_set(:@socket, socket)
|
70
|
+
|
71
|
+
assert_equal true, @connection.connected?
|
72
|
+
socket.expects(:disconnect)
|
73
|
+
|
74
|
+
@connection.disconnect
|
75
|
+
|
76
|
+
assert_equal nil, @connection.instance_variable_get(:@socket)
|
77
|
+
assert_equal false, @connection.connected?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#socket" do
|
83
|
+
it "returns its instance variable :@socket" do
|
84
|
+
@connection.instance_variable_set :@socket, (socket = mock)
|
85
|
+
assert_equal socket, @connection.send(:socket)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "#log" do
|
90
|
+
describe "without defined MonetDB.logger" do
|
91
|
+
it "does nothing" do
|
92
|
+
@connection.send(:log, :info, "This is a log line!")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "with defined MonetDB.logger" do
|
97
|
+
it "delegates to MonetDB.logger" do
|
98
|
+
logger = mock
|
99
|
+
MonetDB.instance_variable_set :@logger, logger
|
100
|
+
|
101
|
+
logger.expects(:info).with("Testing!")
|
102
|
+
@connection.send(:log, :info, "Testing!")
|
103
|
+
|
104
|
+
logger.expects(:error).with("Boom!")
|
105
|
+
@connection.send(:log, :error, "Boom!")
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "#read" do
|
111
|
+
describe "when disconnected" do
|
112
|
+
it "raises a connection error" do
|
113
|
+
assert_raises MonetDB::ConnectionError do
|
114
|
+
@connection.send(:read)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "when connected" do
|
120
|
+
it "obtains the block size and reads the server response" do
|
121
|
+
socket = mock
|
122
|
+
@connection.instance_variable_set(:@socket, socket)
|
123
|
+
|
124
|
+
first_chunk = " " * 44
|
125
|
+
last_chunk = " " * 22
|
126
|
+
|
127
|
+
socket.expects(:recv).with(2).returns("\x85\x00")
|
128
|
+
socket.expects(:recv).with(66).returns(first_chunk)
|
129
|
+
socket.expects(:recv).with(22).returns(last_chunk)
|
130
|
+
|
131
|
+
assert_equal first_chunk + last_chunk, @connection.send(:read)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#write" do
|
137
|
+
describe "when disconnected" do
|
138
|
+
it "raises a connection error" do
|
139
|
+
assert_raises MonetDB::ConnectionError do
|
140
|
+
@connection.send(:write, "")
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "when connected" do
|
146
|
+
it "writes chunks to the active socket provided with the length header" do
|
147
|
+
socket = mock
|
148
|
+
socket.expects(:write).with("\f\x00Hello")
|
149
|
+
socket.expects(:write).with("\t\x00World!")
|
150
|
+
|
151
|
+
@connection.instance_variable_set(:@socket, socket)
|
152
|
+
@connection.expects(:pack).with("foo bar").returns(["\f\x00Hello", "\t\x00World!"])
|
153
|
+
|
154
|
+
assert_equal true, @connection.send(:write, "foo bar")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "#pack" do
|
160
|
+
it "returns chunks provided with a length header" do
|
161
|
+
message = "BIG:monetdb:{MD5}6432e841c9943d524b9b922ee1e5924a:sql:test_drive:"
|
162
|
+
assert_equal ["#{[131].pack("v")}#{message}"], @connection.send(:pack, message)
|
163
|
+
|
164
|
+
message = "hKszBZEmQ1uOPYrpVFEc:merovingian:9:RIPEMD160,SHA256,SHA1,MD5:LIT:SHA512:"
|
165
|
+
assert_equal ["#{[145].pack("v")}#{message}"], @connection.send(:pack, message)
|
166
|
+
|
167
|
+
message.expects(:scan).with(/.{1,#{MonetDB::Connection::MAX_MSG_SIZE}}/m).returns(%w(foobar bazqux paul))
|
168
|
+
assert_equal [
|
169
|
+
"#{[12].pack("v")}foobar",
|
170
|
+
"#{[12].pack("v")}bazqux",
|
171
|
+
"#{[9].pack("v")}paul"
|
172
|
+
], @connection.send(:pack, message)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|
178
|
+
end
|
data/test/unit/test_monetdb.rb
CHANGED
@@ -9,7 +9,83 @@ module Unit
|
|
9
9
|
assert_equal version, MonetDB::VERSION
|
10
10
|
assert File.read(path "CHANGELOG.rdoc").include?("Version #{version}")
|
11
11
|
end
|
12
|
+
|
13
|
+
describe ".logger" do
|
14
|
+
it "returns its instance variable :@logger" do
|
15
|
+
MonetDB.instance_variable_set :@logger, (logger = mock)
|
16
|
+
assert_equal logger, MonetDB.logger
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".logger=" do
|
21
|
+
it "stores the passed value as the instance variable :@logger" do
|
22
|
+
MonetDB.logger = (logger = mock)
|
23
|
+
assert_equal logger, MonetDB.instance_variable_get(:@logger)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe ".configurations" do
|
28
|
+
it "returns its instance variable :@configurations" do
|
29
|
+
MonetDB.instance_variable_set :@configurations, (configurations = mock)
|
30
|
+
assert_equal configurations, MonetDB.configurations
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe ".configurations=" do
|
35
|
+
it "stores the passed hash as the instance variable :@configurations" do
|
36
|
+
MonetDB.configurations = (configurations = {})
|
37
|
+
assert_equal configurations, MonetDB.instance_variable_get(:@configurations)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "stringifies the passed hash" do
|
41
|
+
MonetDB.configurations = (configurations = {:a => "b"})
|
42
|
+
assert_equal({"a" => "b"}, MonetDB.instance_variable_get(:@configurations))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe ".establish_connection" do
|
47
|
+
describe "valid" do
|
48
|
+
before do
|
49
|
+
@connection = mock
|
50
|
+
@connection.expects(:connect)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "accepts configuration hashes" do
|
54
|
+
config = {"host" => "localhost"}
|
55
|
+
MonetDB::Connection.expects(:new).with(config).returns(@connection)
|
56
|
+
MonetDB.establish_connection config
|
57
|
+
end
|
58
|
+
|
59
|
+
it "accepts configuration names" do
|
60
|
+
config = {"host" => "localhost"}
|
61
|
+
MonetDB.instance_variable_set(:@configurations, {"foo" => config})
|
62
|
+
MonetDB::Connection.expects(:new).with(config).returns(@connection)
|
63
|
+
MonetDB.establish_connection "foo"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "invalid" do
|
68
|
+
it "denies non-configuration arguments" do
|
69
|
+
assert_raises MonetDB::ConnectionError do
|
70
|
+
MonetDB.establish_connection 123
|
71
|
+
end
|
72
|
+
assert_raises MonetDB::ConnectionError do
|
73
|
+
MonetDB.establish_connection true
|
74
|
+
end
|
75
|
+
assert_raises MonetDB::ConnectionError do
|
76
|
+
MonetDB.establish_connection "foo"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe ".connection" do
|
83
|
+
it "returns its instance variable :@connection" do
|
84
|
+
MonetDB.instance_variable_set :@connection, (connection = mock)
|
85
|
+
assert_equal connection, MonetDB.connection
|
86
|
+
end
|
87
|
+
end
|
12
88
|
end
|
13
89
|
|
14
90
|
end
|
15
|
-
end
|
91
|
+
end
|
metadata
CHANGED
@@ -1,113 +1,145 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monetdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Engel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- -
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
18
46
|
- !ruby/object:Gem::Version
|
19
47
|
version: '0'
|
20
48
|
type: :development
|
21
49
|
prerelease: false
|
22
50
|
version_requirements: !ruby/object:Gem::Requirement
|
23
51
|
requirements:
|
24
|
-
- -
|
52
|
+
- - ">="
|
25
53
|
- !ruby/object:Gem::Version
|
26
54
|
version: '0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: pry
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
|
-
- -
|
59
|
+
- - ">="
|
32
60
|
- !ruby/object:Gem::Version
|
33
61
|
version: '0'
|
34
62
|
type: :development
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
|
-
- -
|
66
|
+
- - ">="
|
39
67
|
- !ruby/object:Gem::Version
|
40
68
|
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: simplecov
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
|
-
- -
|
73
|
+
- - ">="
|
46
74
|
- !ruby/object:Gem::Version
|
47
75
|
version: '0'
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- -
|
80
|
+
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: minitest
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
|
-
- -
|
87
|
+
- - ">="
|
60
88
|
- !ruby/object:Gem::Version
|
61
89
|
version: '0'
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
|
-
- -
|
94
|
+
- - ">="
|
67
95
|
- !ruby/object:Gem::Version
|
68
96
|
version: '0'
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: mocha
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
|
-
- -
|
101
|
+
- - ">="
|
74
102
|
- !ruby/object:Gem::Version
|
75
103
|
version: '0'
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
|
-
- -
|
108
|
+
- - ">="
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '0'
|
83
|
-
description: A pure Ruby database driver for MonetDB
|
111
|
+
description: A pure Ruby database driver for MonetDB (monetdb5-sql)
|
84
112
|
email:
|
85
113
|
- pm_engel@icloud.com
|
86
114
|
executables: []
|
87
115
|
extensions: []
|
88
116
|
extra_rdoc_files: []
|
89
117
|
files:
|
90
|
-
- .gitignore
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
91
120
|
- CHANGELOG.rdoc
|
92
121
|
- Gemfile
|
93
|
-
- Gemfile.lock
|
94
122
|
- LICENSE
|
95
123
|
- README.rdoc
|
96
124
|
- Rakefile
|
97
125
|
- VERSION
|
98
126
|
- lib/monetdb.rb
|
99
127
|
- lib/monetdb/connection.rb
|
100
|
-
- lib/monetdb/
|
101
|
-
- lib/monetdb/
|
102
|
-
- lib/monetdb/
|
128
|
+
- lib/monetdb/connection/messages.rb
|
129
|
+
- lib/monetdb/connection/query.rb
|
130
|
+
- lib/monetdb/connection/setup.rb
|
103
131
|
- lib/monetdb/error.rb
|
104
|
-
- lib/monetdb/hasher.rb
|
105
|
-
- lib/monetdb/transaction.rb
|
106
132
|
- lib/monetdb/version.rb
|
107
133
|
- monetdb.gemspec
|
108
134
|
- script/console
|
109
135
|
- test/test_helper.rb
|
110
136
|
- test/test_helper/coverage.rb
|
137
|
+
- test/test_helper/minitest.rb
|
138
|
+
- test/test_helper/simple_connection.rb
|
139
|
+
- test/unit/connection/test_messages.rb
|
140
|
+
- test/unit/connection/test_query.rb
|
141
|
+
- test/unit/connection/test_setup.rb
|
142
|
+
- test/unit/test_connection.rb
|
111
143
|
- test/unit/test_monetdb.rb
|
112
144
|
homepage: https://github.com/archan937/monetdb
|
113
145
|
licenses: []
|
@@ -118,22 +150,28 @@ require_paths:
|
|
118
150
|
- lib
|
119
151
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
152
|
requirements:
|
121
|
-
- -
|
153
|
+
- - ">="
|
122
154
|
- !ruby/object:Gem::Version
|
123
155
|
version: '0'
|
124
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
157
|
requirements:
|
126
|
-
- -
|
158
|
+
- - ">="
|
127
159
|
- !ruby/object:Gem::Version
|
128
160
|
version: '0'
|
129
161
|
requirements: []
|
130
162
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
163
|
+
rubygems_version: 2.2.2
|
132
164
|
signing_key:
|
133
165
|
specification_version: 4
|
134
|
-
summary: A pure Ruby database driver for MonetDB
|
166
|
+
summary: A pure Ruby database driver for MonetDB (monetdb5-sql)
|
135
167
|
test_files:
|
136
168
|
- test/test_helper.rb
|
137
169
|
- test/test_helper/coverage.rb
|
170
|
+
- test/test_helper/minitest.rb
|
171
|
+
- test/test_helper/simple_connection.rb
|
172
|
+
- test/unit/connection/test_messages.rb
|
173
|
+
- test/unit/connection/test_query.rb
|
174
|
+
- test/unit/connection/test_setup.rb
|
175
|
+
- test/unit/test_connection.rb
|
138
176
|
- test/unit/test_monetdb.rb
|
139
177
|
has_rdoc:
|