|
6 | 6 | @result = @client.query "SELECT 1"
|
7 | 7 | end
|
8 | 8 |
|
9 |
| - it "should maintain a count while streaming" do |
10 |
| - result = @client.query('SELECT 1') |
11 |
| - |
12 |
| - result.count.should eql(1) |
13 |
| - result.each.to_a |
14 |
| - result.count.should eql(1) |
15 |
| - end |
16 |
| - |
17 |
| - it "should set the actual count of rows after streaming" do |
18 |
| - @client.query "USE test" |
19 |
| - result = @client.query("SELECT * FROM mysql2_test", :stream => true, :cache_rows => false) |
20 |
| - result.count.should eql(0) |
21 |
| - result.each {|r| } |
22 |
| - result.count.should eql(1) |
23 |
| - end |
24 |
| - |
25 |
| - it "should not yield nil at the end of streaming" do |
26 |
| - result = @client.query('SELECT * FROM mysql2_test', :stream => true) |
27 |
| - result.each { |r| r.should_not be_nil} |
28 |
| - end |
29 |
| - |
30 |
| - it "#count should be zero for rows after streaming when there were no results" do |
31 |
| - @client.query "USE test" |
32 |
| - result = @client.query("SELECT * FROM mysql2_test WHERE null_test IS NOT NULL", :stream => true, :cache_rows => false) |
33 |
| - result.count.should eql(0) |
34 |
| - result.each.to_a |
35 |
| - result.count.should eql(0) |
36 |
| - end |
37 |
| - |
38 |
| - it "should raise an exception if streaming ended due to a timeout" do |
39 |
| - # Create an extra client instance, since we're going to time it out |
40 |
| - client = Mysql2::Client.new DatabaseCredentials['root'] |
41 |
| - client.query "CREATE TEMPORARY TABLE streamingTest (val VARCHAR(10))" |
42 |
| - |
43 |
| - # Insert enough records to force the result set into multiple reads |
44 |
| - 10000.times do |i| |
45 |
| - client.query "INSERT INTO streamingTest (val) VALUES ('Foo #{i}')" |
46 |
| - end |
47 |
| - |
48 |
| - client.query "SET net_write_timeout = 1" |
49 |
| - res = client.query "SELECT * FROM streamingTest", :stream => true |
50 |
| - |
51 |
| - lambda { |
52 |
| - res.each_with_index do |row, i| |
53 |
| - # Exhaust the first result packet then trigger a timeout |
54 |
| - sleep 2 if i > 0 && i % 1000 == 0 |
55 |
| - end |
56 |
| - }.should raise_error(Mysql2::Error, /Lost connection/) |
57 |
| - end |
58 |
| - |
59 | 9 | it "should have included Enumerable" do
|
60 | 10 | Mysql2::Result.ancestors.include?(Enumerable).should be_true
|
61 | 11 | end
|
|
156 | 106 | end
|
157 | 107 | end
|
158 | 108 |
|
| 109 | + context "streaming" do |
| 110 | + it "should maintain a count while streaming" do |
| 111 | + result = @client.query('SELECT 1') |
| 112 | + |
| 113 | + result.count.should eql(1) |
| 114 | + result.each.to_a |
| 115 | + result.count.should eql(1) |
| 116 | + end |
| 117 | + |
| 118 | + it "should set the actual count of rows after streaming" do |
| 119 | + @client.query "USE test" |
| 120 | + result = @client.query("SELECT * FROM mysql2_test", :stream => true, :cache_rows => false) |
| 121 | + result.count.should eql(0) |
| 122 | + result.each {|r| } |
| 123 | + result.count.should eql(1) |
| 124 | + end |
| 125 | + |
| 126 | + it "should not yield nil at the end of streaming" do |
| 127 | + result = @client.query('SELECT * FROM mysql2_test', :stream => true) |
| 128 | + result.each { |r| r.should_not be_nil} |
| 129 | + end |
| 130 | + |
| 131 | + it "#count should be zero for rows after streaming when there were no results" do |
| 132 | + @client.query "USE test" |
| 133 | + result = @client.query("SELECT * FROM mysql2_test WHERE null_test IS NOT NULL", :stream => true, :cache_rows => false) |
| 134 | + result.count.should eql(0) |
| 135 | + result.each.to_a |
| 136 | + result.count.should eql(0) |
| 137 | + end |
| 138 | + |
| 139 | + it "should raise an exception if streaming ended due to a timeout" do |
| 140 | + # Create an extra client instance, since we're going to time it out |
| 141 | + client = Mysql2::Client.new DatabaseCredentials['root'] |
| 142 | + client.query "CREATE TEMPORARY TABLE streamingTest (val VARCHAR(10))" |
| 143 | + |
| 144 | + # Insert enough records to force the result set into multiple reads |
| 145 | + 10000.times do |i| |
| 146 | + client.query "INSERT INTO streamingTest (val) VALUES ('Foo #{i}')" |
| 147 | + end |
| 148 | + |
| 149 | + client.query "SET net_write_timeout = 1" |
| 150 | + res = client.query "SELECT * FROM streamingTest", :stream => true |
| 151 | + |
| 152 | + lambda { |
| 153 | + res.each_with_index do |row, i| |
| 154 | + # Exhaust the first result packet then trigger a timeout |
| 155 | + sleep 2 if i > 0 && i % 1000 == 0 |
| 156 | + end |
| 157 | + }.should raise_error(Mysql2::Error, /Lost connection/) |
| 158 | + end |
| 159 | + end |
| 160 | + |
159 | 161 | context "row data type mapping" do
|
160 | 162 | before(:each) do
|
161 | 163 | @client.query "USE test"
|
|
0 commit comments