MemcacheDBI
view release on metacpan or search on metacpan
t/00-basic.t view on Meta::CPAN
my $password = $ENV{'dbi_pass'};
my $database = $ENV{'dbi_table'} // 'test';
my $table = $ENV{'dbi_table'} // 'test';
my $data_source = $ENV{'dbi_source'} // "dbi:CSV:f_dir=./t";
my $dbh_outside = DBI->connect($data_source, $user, $password, {
'AutoCommit' => 1,
'ChopBlanks' => 1,
'ShowErrorStatement' => 1,
'pg_enable_utf8' => 1,
'mysql_enable_utf8' => 1,
});
cmp_ok(ref $dbh_outside,'eq','DBI::db', 'DBH created successfully');
SKIP: {
skip 'Failed to connect to database', 20 unless ref $dbh_outside;
foreach my $AutoCommit ( 1, 0 ) {
SKIP: {
skip 'dbi:CSV does not support transactions', 10 if !$AutoCommit && $data_source =~ /^dbi:CSV:/;
my $testData = 'abc'.$AutoCommit;
my $dbh = MemcacheDBI->connect($data_source, $user, $password, {
'AutoCommit' => $AutoCommit,
'ChopBlanks' => 1,
'ShowErrorStatement' => 1,
'pg_enable_utf8' => 1,
'mysql_enable_utf8' => 1,
});
ok(ref $dbh, 'MemcacheDBH created successfully AutoCommit='.$AutoCommit);
my $sth = $dbh->prepare("update $table set district = '' where locationnum = 126");
$sth->execute;
$dbh->commit unless $dbh->{'AutoCommit'};
t/01-commit.t view on Meta::CPAN
SKIP: {
skip 'This test is designed for the DBI:Pg driver', 15 unless $data_source =~ /^DBI:Pg:/;
foreach my $autocommit ( 0, 1 ) {
local $SIG{__WARN__} = sub{}; # eat warnings about autocommit, it will fail with DBD:CSV
my $dbh = eval{MemcacheDBI->connect($data_source, $user, $password, {
'AutoCommit' => $autocommit,
'ChopBlanks' => 1,
'ShowErrorStatement' => 1,
'pg_enable_utf8' => 1,
'mysql_enable_utf8' => 1,
})};
#this is specifically to test that commit works without memcache being initialized
my $test = $dbh->commit;
ok($dbh->{'AutoCommit'} ? !$test : $test, 'commit');
}
SKIPMEMD: {
skip 'This test is requires the memd_server ENV varaiable', 13 unless defined $memd_server;
my $dbh = eval{MemcacheDBI->connect($data_source, $user, $password, {
'AutoCommit' => 1,
'ChopBlanks' => 1,
'ShowErrorStatement' => 1,
'pg_enable_utf8' => 1,
'mysql_enable_utf8' => 1,
})};
$dbh->memd_init({servers=>['localhost:11211']});
my $dbh2 = eval{MemcacheDBI->connect($data_source, $user, $password, {
'AutoCommit' => 1,
'ChopBlanks' => 1,
'ShowErrorStatement' => 1,
'pg_enable_utf8' => 1,
'mysql_enable_utf8' => 1,
})};
$dbh2->memd_init({servers=>['localhost:11211']});
$dbh->memd->set('test_me',1);
cmp_ok($dbh->memd->get('test_me'),'eq','1','test 1');
$dbh->{'AutoCommit'} = 0;
cmp_ok($dbh->memd->get('test_me'),'eq','1','test 1');
$dbh->memd->set('test_me',2);
cmp_ok($dbh->memd->get('test_me'),'eq','2','test 2 dbh1');
t/02-negative.t view on Meta::CPAN
my $database = $ENV{'dbi_table'} // 'test';
my $table = $ENV{'dbi_table'} // 'test';
my $data_source = $ENV{'dbi_source'} // "dbi:CSV:f_dir=./t";
my $dbh = eval{MemcacheDBI->connect('dbi:nodriverfailme:host=127.127.127.127', $user, $password, {
'AutoCommit' => 1,
'ChopBlanks' => 1,
'ShowErrorStatement' => 1,
'pg_enable_utf8' => 1,
'mysql_enable_utf8' => 1,
})};
ok(!defined $dbh,'dbh should not be defined yet');
ok(!eval{$dbh->commit},'trying to commit should fail');
$dbh = MemcacheDBI->connect($data_source, $user, $password, {
'AutoCommit' => 1,
'ChopBlanks' => 1,
'ShowErrorStatement' => 1,
'pg_enable_utf8' => 1,
'mysql_enable_utf8' => 1,
});
ok(defined $dbh,'dbh should be defined');
ok(!eval{$dbh->iamaninvalidcommand},'trying an invalid command should fail AUTOLOAD');
ok($@ =~ /02\-negative\.t/,'error message reported me');
ok(!eval{$dbh->iamaninvalidcommand},'trying an invalid command should fail SUB');
ok($@ =~ /02\-negative\.t/,'error message reported me');
1;
( run in 0.263 second using v1.01-cache-2.11-cpan-00829025b61 )