Permalink
Browse files

Merge pull request #72 from nihen/remove_mode_fixup

stop mode:fixup support since v0.14_05
  • Loading branch information...
2 parents 6087a46 + 942791a commit 8256154f82597539c5d92c2fe6cd73f68547c702 @nekokak committed Jul 21, 2012
Showing with 4 additions and 207 deletions.
  1. +4 −45 lib/Teng.pm
  2. +0 −162 t/001_basic/031_reconnect_fixup.t
View
49 lib/Teng.pm
@@ -228,19 +228,7 @@ sub _execute {
eval { $sth = $self->__execute($sql, $binds) };
if ($@) {
- if ( $self->mode eq 'fixup' ) {
- if ( $self->connected ) {
- $self->handle_error($sql, $binds, $@);
- }
- $self->reconnect;
- eval { $sth = $self->__execute($sql, $binds) };
- if ($@) {
- $self->handle_error($sql, $binds, $@);
- }
- }
- else {
- $self->handle_error($sql, $binds, $@);
- }
+ $self->handle_error($sql, $binds, $@);
}
return $sth;
@@ -439,38 +427,13 @@ sub txn_scope {
my $self = shift;
my @caller = caller();
- my $scope;
- if ( $self->mode eq 'fixup' ) {
- eval { $scope = $self->txn_manager->txn_scope(caller => \@caller) };
- if ( $@ ) {
- if ( $self->connected ) {
- die $@;
- }
- $self->reconnect;
- $scope = $self->txn_manager->txn_scope(caller => \@caller);
- }
- }
- else {
- $scope = $self->txn_manager->txn_scope(caller => \@caller);
- }
- return $scope;
+ $self->txn_manager->txn_scope(caller => \@caller);
}
sub txn_begin {
my $self = shift;
- if ( $self->mode eq 'fixup' ) {
- eval { $self->txn_manager->txn_begin };
- if ( $@ ) {
- if ( $self->connected ) {
- die $@;
- }
- $self->reconnect;
- $self->txn_manager->txn_begin;
- }
- }
- else {
- $self->txn_manager->txn_begin;
- }
+
+ $self->txn_manager->txn_begin;
}
sub txn_rollback { $_[0]->txn_manager->txn_rollback }
sub txn_commit { $_[0]->txn_manager->txn_commit }
@@ -760,10 +723,6 @@ Specifies the database handle to use.
reconnect at dbh->ping fail each execute.
-=item * C<fixup>
-
-reconnect at fail execute.
-
=item * C<no_ping>
no auto reconnect.
View
162 t/001_basic/031_reconnect_fixup.t
@@ -1,162 +0,0 @@
-use t::Utils;
-use Test::More;
-use Mock::Basic;
-use Test::Mock::Guard qw/mock_guard/;
-
-unlink 'test.db';
-my $dbh = t::Utils->setup_dbh('test.db');
-my $db = Mock::Basic->new({dbh => $dbh, mode => 'fixup'});
-$db->setup_test_db;
-
-subtest 'fixup_reconnect' => sub {
- $db->reconnect;
- my $row;
- my $old_dbh = $db->dbh;
- eval {
- my $guard; $guard = mock_guard('DBI::db' => +{ping => sub { undef $guard; return 0 } });
- my $guard_execute; $guard_execute = mock_guard('DBI::st' => +{execute => sub {
- undef $guard_execute;
- die('disconnected');
- } });
-
- $row = $db->insert('mock_basic',{
- name => 'perl',
- });
- };
- ok(!$@);
-
- isnt($old_dbh, $db->dbh);
- is_deeply($db->single('mock_basic', { id => $row->id })->get_columns, $row->get_columns);
-};
-
-subtest 'fixup_reconnect_at_txn_begin' => sub {
- $db->reconnect;
- my $old_dbh = $db->dbh;
- eval {
- my $guard; $guard = mock_guard('DBI::db' => +{ping => sub { undef $guard; return 0 } });
- my $guard_begin; $guard_begin = mock_guard('DBI::db' => +{begin_work => sub {
- undef $guard_begin;
- die('disconnected');
- } });
- $db->txn_begin;
- };
- ok(!$@);
- isnt($old_dbh, $db->dbh);
-
- my $row = $db->insert('mock_basic',{
- name => 'python',
- });
- $db->txn_commit;
-
- is_deeply($db->single('mock_basic', { id => $row->id })->get_columns, $row->get_columns);
-};
-
-subtest 'fixup_reconnect_at_txn_scope' => sub {
- $db->reconnect;
- my $old_dbh = $db->dbh;
- my $scope;
- eval {
- my $guard; $guard = mock_guard('DBI::db' => +{ping => sub { undef $guard; return 0 } });
- my $guard_begin; $guard_begin = mock_guard('DBI::db' => +{begin_work => sub {
- undef $guard_begin;
- die('disconnected');
- } });
- $scope = $db->txn_scope;
- };
- ok(!$@);
- isnt($old_dbh, $db->dbh);
-
- my $row = $db->insert('mock_basic',{
- name => 'ruby',
- });
- $scope->commit;
-
- is_deeply($db->single('mock_basic', { id => $row->id })->get_columns, $row->get_columns);
-};
-
-subtest 'fixup_reconnect_at_after_txn_begin' => sub {
- $db->reconnect;
- $db->txn_begin;
-
- my $row;
- eval {
- my $guard; $guard = mock_guard('DBI::db' => +{ping => sub { undef $guard; return 0 } });
- my $guard_execute; $guard_execute = mock_guard('DBI::st' => +{execute => sub {
- undef $guard_execute;
- die('disconnected');
- } });
- $row = $db->insert('mock_basic',{
- name => 'c++',
- });
- };
- like $@, qr/Detected transaction during a connect operation \(last known transaction at/;
- ok(!$row);
-
- $db->txn_rollback;
-};
-
-subtest 'fixup_reconnect_at_after_txn_scope' => sub {
- my $scope = $db->txn_scope;
-
- my $row;
- eval {
- my $guard; $guard = mock_guard('DBI::db' => +{ping => sub { undef $guard; return 0 } });
- my $guard_execute; $guard_execute = mock_guard('DBI::st' => +{execute => sub {
- undef $guard_execute;
- die('disconnected');
- } });
- $row = $db->insert('mock_basic',{
- name => 'golang',
- });
- };
- like $@, qr/Detected transaction during a connect operation \(last known transaction at/;
- ok(!$row);
- $scope->rollback;
-};
-
-subtest 'fixup_reconnect_at_txn_commit' => sub {
- $db->reconnect;
- $db->txn_begin;
-
- my $row = $db->insert('mock_basic',{
- name => 'basic',
- });
-
- eval {
- my $guard; $guard = mock_guard('DBI::db' => +{ping => sub { undef $guard; return 0 } });
- my $guard_commit; $guard_commit = mock_guard('DBI::db' => +{commit => sub {
- undef $guard_commit;
- die('disconnected');
- } });
- $db->txn_commit;
- };
- like $@, qr/disconnected/;
- $db->txn_rollback;
-};
-
-subtest 'fixup_reconnect_at_txn_scope_commit' => sub {
- $db->reconnect;
- my $row;
- {
- my $scope = $db->txn_scope;
-
- $row = $db->insert('mock_basic',{
- name => 'cobol',
- });
-
- eval {
- my $guard; $guard = mock_guard('DBI::db' => +{ping => sub { undef $guard; return 0 } });
- my $guard_commit; $guard_commit = mock_guard('DBIx::TransactionManager::ScopeGuard' => +{commit => sub {
- undef $guard_commit;
- die('disconnected');
- }});
- $scope->commit;
- };
- like $@, qr/disconnected/;
- $scope->rollback;
- }
-};
-
-
-unlink 'test.db';
-done_testing;

0 comments on commit 8256154

Please sign in to comment.