-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
170 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Takuya Tsuchida <tsucchi@cpan.org> <takuya.tsuchida@gmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
requires 'perl', '5.008001'; | ||
requires 'Otogiri', '0.12'; | ||
requires 'Otogiri::Plugin', '0.03'; | ||
|
||
on configure => sub { | ||
requires 'Module::Build::Tiny', '0.035'; | ||
}; | ||
|
||
on test => sub { | ||
requires 'Otogiri'; | ||
requires 'File::Temp'; | ||
requires 'DBD::SQLite'; | ||
requires 'Test::More', '0.98'; | ||
requires 'Test::Requires'; | ||
requires 'Mock::Quick'; | ||
}; | ||
|
||
on develop => sub { | ||
requires 'Test::mysqld'; | ||
requires 'Test::PostgreSQL'; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Mock::Quick; | ||
use Otogiri; | ||
use Otogiri::Plugin; | ||
#use DBIx::QueryLog; | ||
|
||
use Test::Requires 'Test::mysqld'; | ||
|
||
my $mysqld = Test::mysqld->new( | ||
my_cnf => { | ||
'skip-networking' => '', | ||
} | ||
) or plan skip_all => $Test::mysqld::errstr; | ||
|
||
my $db = Otogiri->new( connect_info => [$mysqld->dsn(dbname => 'test'), '', ''] ); | ||
$db->load_plugin('AutoReconnect'); | ||
|
||
|
||
my $sql = " | ||
CREATE TABLE person ( | ||
id INTEGER PRIMARY KEY AUTO_INCREMENT, | ||
name TEXT NOT NULL, | ||
age INTEGER NOT NULL DEFAULT 20 | ||
);"; | ||
|
||
$db->do($sql); | ||
|
||
$db->fast_insert('person', { | ||
name => 'Sherlock Shellingford', | ||
age => 15, | ||
}); | ||
my $person_id = $db->last_insert_id(); | ||
|
||
|
||
subtest 'reconnect', sub { | ||
$db->dbh->disconnect(); | ||
$db->reconnect(); | ||
my $row = $db->single('person', { id => $person_id }); | ||
ok( defined $row ); | ||
}; | ||
|
||
subtest 'auto reconnect', sub { | ||
$db->dbh->disconnect(); | ||
#$db->reconnect(); | ||
my $row = $db->single('person', { id => $person_id }); | ||
ok( defined $row ); | ||
}; | ||
|
||
subtest 'in transaction', sub { | ||
|
||
my $txn = $db->txn_scope(); | ||
my $row = $db->single('person', { id => $person_id }); | ||
|
||
my $guard = qclass( | ||
-takeover => 'DBIx::Sunny::db', | ||
ping => sub { 0 }, | ||
); | ||
|
||
eval { | ||
$db->insert('person', { | ||
name => 'Nero Yuzurizaki', | ||
age => 15, | ||
}); | ||
}; | ||
like( $@, qr/^Detected transaction/ ); | ||
|
||
$txn->rollback(); | ||
}; | ||
|
||
|
||
|
||
done_testing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Mock::Quick; | ||
use Otogiri; | ||
use Otogiri::Plugin; | ||
#use DBIx::QueryLog; | ||
|
||
use Test::Requires 'Test::PostgreSQL'; | ||
|
||
my $pg = Test::PostgreSQL->new( | ||
my_cnf => { | ||
'skip-networking' => '', | ||
} | ||
) or plan skip_all => $Test::PostgreSQL::errstr; | ||
|
||
my $db = Otogiri->new( connect_info => [$pg->dsn(dbname => 'test'), '', '']); | ||
$db->load_plugin('AutoReconnect'); | ||
|
||
|
||
my $sql = " | ||
CREATE TABLE person ( | ||
id SERIAL PRIMARY KEY, | ||
name TEXT NOT NULL, | ||
age INTEGER NOT NULL DEFAULT 20 | ||
);"; | ||
|
||
$db->do($sql); | ||
|
||
$db->fast_insert('person', { | ||
name => 'Sherlock Shellingford', | ||
age => 15, | ||
}); | ||
my $person_id = $db->last_insert_id(); | ||
|
||
|
||
subtest 'reconnect', sub { | ||
$db->dbh->disconnect(); | ||
$db->reconnect(); | ||
my $row = $db->single('person', { id => $person_id }); | ||
ok( defined $row ); | ||
}; | ||
|
||
subtest 'auto reconnect', sub { | ||
$db->dbh->disconnect(); | ||
#$db->reconnect(); | ||
my $row = $db->single('person', { id => $person_id }); | ||
ok( defined $row ); | ||
}; | ||
|
||
subtest 'in transaction', sub { | ||
|
||
my $txn = $db->txn_scope(); | ||
my $row = $db->single('person', { id => $person_id }); | ||
|
||
my $guard = qclass( | ||
-takeover => 'DBIx::Sunny::db', | ||
ping => sub { 0 }, | ||
); | ||
|
||
eval { | ||
$db->insert('person', { | ||
name => 'Nero Yuzurizaki', | ||
age => 15, | ||
}); | ||
}; | ||
like( $@, qr/^Detected transaction/ ); | ||
$txn->rollback(); | ||
}; | ||
|
||
|
||
|
||
done_testing; |