Class: TestIngresTransactionSavePoints
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- TestIngresTransactionSavePoints
- Defined in:
- ext/tests/tc_transactions_savepoint.rb
Constant Summary collapse
- @@data =
Data set used for inserting
[[1, "one"], [2, "two"], [3, "three"], [4, "four"], [5, "five"], [6, "six"], [7, "seven"], [8, "eight"], [9, "nine"], [10, "ten"]]
- @@rollback_points =
Some savepoint => rollback values in the form of at savepoint x rollback to (=>) y
{ 5 => 3, 7 => 6 }
Instance Method Summary collapse
- #setup ⇒ Object
- #teardown ⇒ Object
-
#test_savepoint_multiple ⇒ Object
Generate a savepoint for each insert into the table and rollback them all at the end.
-
#test_savepoint_named_rollback ⇒ Object
Generate a savepoint for each insert then rollback to specified savepoints verifying we have actually rolled back.
-
#test_savepoint_nested_transactions ⇒ Object
Test the ability to carry on working after a rollback has been issued against a named savepoint.
-
#test_savepoint_no_transaction ⇒ Object
Ingres requires that a transaction has been started using “start transaction” before a savepoint can be created.
-
#test_savepoint_rollback_non_existent ⇒ Object
Verify the driver raises a RuntimeError exception when rolling back to a non-existant savepoint.
-
#test_savepoint_single ⇒ Object
A simple test to create a savepoint, if this fails then the rest of this unit test has no chance.
Instance Method Details
#setup ⇒ Object
12 13 14 15 16 |
# File 'ext/tests/tc_transactions_savepoint.rb', line 12 def setup @@ing = Ingres.new() #@@ing.set_debug_flag("GLOBAL_DEBUG","TRUE") assert_kind_of(Ingres, @@ing.connect(@@database, @@username, @@password), "conn is not an Ingres object") end |
#teardown ⇒ Object
18 19 20 21 22 23 24 |
# File 'ext/tests/tc_transactions_savepoint.rb', line 18 def teardown # drop the savepoint_tests table if it happens to be around still if @@ing.tables.include? "savepoint_tests" @@ing.execute "drop table savepoint_tests" end @@ing.disconnect end |
#test_savepoint_multiple ⇒ Object
Generate a savepoint for each insert into the table and rollback them all at the end
37 38 39 40 41 42 43 44 45 |
# File 'ext/tests/tc_transactions_savepoint.rb', line 37 def test_savepoint_multiple @@ing.execute "start transaction" @@ing.execute "create table savepoint_tests (id integer not null, txt varchar(100))" @@data.each { |element| @@ing.execute("insert into savepoint_tests values (#{element[0]}, '#{element[1]}')") @@ing.savepoint "savepoint_#{element[0]}" } @@ing.rollback end |
#test_savepoint_named_rollback ⇒ Object
Generate a savepoint for each insert then rollback to specified savepoints verifying we have actually rolled back
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'ext/tests/tc_transactions_savepoint.rb', line 49 def test_savepoint_named_rollback @@ing.execute "start transaction" @@ing.execute "create table savepoint_tests (id integer not null, txt varchar(100))" @@data.each { |element| @@ing.execute("insert into savepoint_tests values (#{element[0]}, '#{element[1]}')") @@ing.savepoint "savepoint_#{element[0]}" } @@ing.rollback "savepoint_8" assert_equal 8, @@ing.execute("select max(id) from savepoint_tests").flatten[0] @@ing.rollback "savepoint_5" assert_equal 5, @@ing.execute("select max(id) from savepoint_tests").flatten[0] @@ing.rollback "savepoint_3" assert_equal 3, @@ing.execute("select max(id) from savepoint_tests").flatten[0] @@ing.rollback end |
#test_savepoint_nested_transactions ⇒ Object
Test the ability to carry on working after a rollback has been issued against a named savepoint. Then carry on inserting then rollback again.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'ext/tests/tc_transactions_savepoint.rb', line 67 def test_savepoint_nested_transactions @@ing.execute "start transaction" @@ing.execute "create table savepoint_tests (id integer not null, txt varchar(100))" @@data.each { |data_set| @@ing.execute("insert into savepoint_tests values (#{data_set[0]}, '#{data_set[1]}')") @@ing.savepoint "savepoint_#{data_set[0]}" if @@rollback_points.has_key?(data_set[0]) @savepoint_no = @@rollback_points.values_at(data_set[0]) @@ing.rollback "savepoint_#{@savepoint_no}" assert_equal @savepoint_no, @@ing.execute("select max(id) from savepoint_tests").flatten end } @@ing.rollback end |
#test_savepoint_no_transaction ⇒ Object
Ingres requires that a transaction has been started using “start transaction” before a savepoint can be created
102 103 104 105 106 107 |
# File 'ext/tests/tc_transactions_savepoint.rb', line 102 def test_savepoint_no_transaction # Cannot start a savepoint with no active transaction assert_raise RuntimeError do @@ing.savepoint "savepoint_1" end end |
#test_savepoint_rollback_non_existent ⇒ Object
Verify the driver raises a RuntimeError exception when rolling back to a non-existant savepoint
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'ext/tests/tc_transactions_savepoint.rb', line 84 def test_savepoint_rollback_non_existent @@ing.execute "start transaction" @@ing.execute "create table savepoint_tests (id integer not null, txt varchar(100))" @@data.each { |data_set| @@ing.execute("insert into savepoint_tests values (#{data_set[0]}, '#{data_set[1]}')") @@ing.savepoint "savepoint_#{data_set[0]}" if (data_set[0]) == 5 @@ing.rollback "savepoint_3" assert_equal 3, @@ing.execute("select max(id) from savepoint_tests").flatten[0] end } assert_raise RuntimeError do @@ing.rollback "savepoint_5" end end |
#test_savepoint_single ⇒ Object
A simple test to create a savepoint, if this fails then the rest of this unit test has no chance
28 29 30 31 32 33 34 |
# File 'ext/tests/tc_transactions_savepoint.rb', line 28 def test_savepoint_single @@ing.execute "start transaction" @@ing.execute "create table savepoint_tests (id integer not null, txt varchar(100))" @@ing.savepoint "savepoint_1" @@ing.execute "insert into savepoint_tests values (1, 'one')" @@ing.rollback end |