green-em-pg 0.1.0 → 0.1.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.
- data/Gemfile.lock +1 -1
- data/green-em-pg.gemspec +2 -2
- data/lib/green-em/pg.rb +1 -1
- data/lib/green-em/pg/sequel.rb +6 -0
- data/spec/green-em/pg/sequel_spec.rb +42 -36
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/green-em-pg.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
2
2
|
s.name = 'green-em-pg'
|
3
|
-
s.version = '0.1.
|
4
|
-
s.date = '2013-01-
|
3
|
+
s.version = '0.1.1'
|
4
|
+
s.date = '2013-01-30'
|
5
5
|
s.summary = 'Async PostgreSQL client API for Ruby/EventMachine'
|
6
6
|
s.email = "ceo@prepor.ru"
|
7
7
|
s.homepage = "http://github.com/prepor/em-postgres"
|
data/lib/green-em/pg.rb
CHANGED
data/lib/green-em/pg/sequel.rb
CHANGED
@@ -38,6 +38,8 @@ class Green
|
|
38
38
|
|
39
39
|
def_delegators :@pg, :status, :escape_string, :escape_bytea
|
40
40
|
|
41
|
+
CONNECTION_OK = ::PG::CONNECTION_OK
|
42
|
+
|
41
43
|
class << self
|
42
44
|
alias :connect :new
|
43
45
|
end
|
@@ -55,6 +57,10 @@ class Green
|
|
55
57
|
# alias :exec_prepared :send_query_prepared
|
56
58
|
# alias :finish :close
|
57
59
|
|
60
|
+
def block
|
61
|
+
true
|
62
|
+
end
|
63
|
+
|
58
64
|
[:get_copy_data, :put_copy_data, :put_copy_end, :get_result, :wait_for_notify].each do |m|
|
59
65
|
define_method(m) do |*args|
|
60
66
|
raise "Unimplemented method #{m} in green postgres adapter"
|
@@ -12,53 +12,59 @@ describe Green::EM::PG do
|
|
12
12
|
let(:db) { Sequel.connect(url, max_connection: size, pool_class: Green::EM::PG::Sequel::ConnectionPool, db_logger: Logger.new(nil)) }
|
13
13
|
let(:test) { db[:test] }
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
integer :value, index: true
|
15
|
+
describe "unexist table" do
|
16
|
+
it "should raise exception" do
|
17
|
+
proc { test.all }.must_raise Sequel::DatabaseError
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
describe "exist table" do
|
22
|
+
before do
|
23
|
+
db.create_table!(:test) do
|
24
|
+
text :name
|
25
|
+
integer :value, index: true
|
26
|
+
end
|
27
|
+
end
|
25
28
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
29
|
+
after do
|
30
|
+
db.drop_table?(:test)
|
31
|
+
end
|
30
32
|
|
33
|
+
it "should connect and execute query" do
|
34
|
+
test.insert name: "andrew", value: 42
|
35
|
+
test.where(name: "andrew").first[:value].must_equal 42
|
36
|
+
end
|
31
37
|
|
32
|
-
describe "pool size is exceeded" do
|
33
|
-
let(:size) { 1 }
|
34
|
-
it "should queue requests" do
|
35
|
-
start = Time.now.to_f
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
describe "pool size is exceeded" do
|
40
|
+
let(:size) { 1 }
|
41
|
+
it "should queue requests" do
|
42
|
+
start = Time.now.to_f
|
43
|
+
|
44
|
+
g = Green::Group.new
|
45
|
+
res = []
|
46
|
+
g.spawn { res << db[QUERY].all }
|
47
|
+
g.spawn { res << db[QUERY].all }
|
48
|
+
g.join
|
49
|
+
(Time.now.to_f - start.to_f).must_be_within_delta DELAY * 2, DELAY * 2 * 0.15
|
50
|
+
res.size.must_equal 2
|
51
|
+
end
|
44
52
|
end
|
45
|
-
end
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
54
|
+
describe "pool size is enough" do
|
55
|
+
let(:size) { 2 }
|
56
|
+
it "should parallel requests" do
|
57
|
+
start = Time.now.to_f
|
51
58
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
59
|
+
g = Green::Group.new
|
60
|
+
res = []
|
61
|
+
g.spawn { res << db[QUERY].all }
|
62
|
+
g.spawn { res << db[QUERY].all }
|
63
|
+
g.join
|
57
64
|
|
58
|
-
|
59
|
-
|
65
|
+
(Time.now.to_f - start.to_f).must_be_within_delta DELAY, DELAY * 0.30
|
66
|
+
res.size.must_equal 2
|
67
|
+
end
|
60
68
|
end
|
61
69
|
end
|
62
|
-
|
63
|
-
|
64
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: green-em-pg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|