use DBIx::Class::Exception;
__PACKAGE__->mk_group_accessors(inherited => '_skip_namespace_frames');
-__PACKAGE__->_skip_namespace_frames('^DBIx::Class|^SQL::Abstract|^Try::Tiny|^Class::Accessor::Grouped|^Context::Preserve');
+__PACKAGE__->_skip_namespace_frames('^DBIx::Class|^SQL::Abstract|^Try::Tiny|^Class::Accessor::Grouped|^Context::Preserve|^Moose::Meta::');
# FIXME - this is not really necessary, and is in
# fact going to slow things down a bit
export DBI_DSN="dbi:ODBC:server=NonexistentServerAddress"
export DBI_DRIVER="ADO"
+ # if we have Moose - try to run everything under replicated
+ # FIXME - when switching to Moo kill this
+ if [[ "$CLEANTEST" != "true" ]] && perl -M5.008003 -e 1 &>/dev/null ; then
+ export DBICTEST_VIA_REPLICATED=1
+ fi
+
# some people do in fact set this - boggle!!!
# it of course won't work before 5.8.4
if perl -M5.008004 -e 1 &>/dev/null ; then
my $has_dt;
# Skip the heavy-duty leak tracing when just doing an install
-unless (DBICTest::RunMode->is_plain) {
+# or when having Moose crap all over everything
+if ( !$ENV{DBICTEST_VIA_REPLICATED} and !DBICTest::RunMode->is_plain ) {
# redefine the bless override so that we can catch each and every object created
no warnings qw/redefine once/;
use strict;
use warnings;
+BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }
+
use Test::More;
use Test::Warn;
use Test::Exception;
my $storage = $schema->storage;
- is(
- ref $storage, 'DBIx::Class::Storage::DBI',
- 'Starting with generic storage'
- );
+ if ($ENV{DBICTEST_VIA_REPLICATED}) {
+ $storage = $storage->master;
+ }
+ else {
+ is(
+ ref $storage, 'DBIx::Class::Storage::DBI',
+ 'Starting with generic storage'
+ );
+ }
# Calling date_time_parser should cause the storage to be reblessed,
# so that we can pick up datetime_parser_type from subclasses
# set a *DBI* disconnect callback, to make sure the physical SQLite
# file is still there (i.e. the test does not attempt to delete
# an open database, which fails on Win32)
- if (my $guard_cb = __mk_disconnect_guard($db_file)) {
+ if (! $storage->{master} and my $guard_cb = __mk_disconnect_guard($db_file)) {
$dbh->{Callbacks} = {
connect => sub { $guard_cb->('connect') },
disconnect => sub { $guard_cb->('disconnect') },
my $schema;
+ if (
+ $ENV{DBICTEST_VIA_REPLICATED} &&=
+ ( !$args{storage_type} && !defined $args{sqlite_use_file} )
+ ) {
+ $args{storage_type} = ['::DBI::Replicated', { balancer_type => '::Random' }];
+ $args{sqlite_use_file} = 1;
+ }
+
my @dsn = $self->_database(%args);
if ($args{compose_connection}) {
if ( !$args{no_connect} ) {
$schema->connection(@dsn);
+
+ $schema->storage->connect_replicants(\@dsn)
+ if $ENV{DBICTEST_VIA_REPLICATED};
}
if ( !$args{no_deploy} ) {
use base 'DBIx::Class::Storage::Statistics';
-sub query_start { push @{$_[0]{sqlbinds}}, [ ($_[1] =~ /^\s*(\S+)/)[0], [ $_[1], @{ $_[2]||[] } ] ] }
+sub query_start {
+ my ($self, $sql, $bind) = @_;
+
+ my $op = ($sql =~ /^\s*(\S+)/)[0];
+
+ $sql =~ s/^ \s* \Q$op\E \s+ \[ .+? \]/$op/x
+ if $ENV{DBICTEST_VIA_REPLICATED};
+
+ push @{$self->{sqlbinds}}, [ $op, [ $sql, @{ $bind || [] } ] ];
+}
# who the hell came up with this API >:(
for my $txn (qw(begin rollback commit)) {
my $schema = DBICTest->init_schema( sqlite_use_file => 1 );
-is( ref($schema->storage), 'DBIx::Class::Storage::DBI::SQLite',
- 'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite' );
-
my $storage = $schema->storage;
-$storage->ensure_connected;
+
+is(
+ ref($storage),
+ 'DBIx::Class::Storage::DBI::SQLite',
+ 'Storage reblessed correctly into DBIx::Class::Storage::DBI::SQLite'
+) unless $ENV{DBICTEST_VIA_REPLICATED};
throws_ok {
$schema->storage->throw_exception('test_exception_42');
my $schema = DBICTest->init_schema();
my $storage = $schema->storage;
+$storage = $storage->master
+ if $ENV{DBICTEST_VIA_REPLICATED};
+
+
# test (re)connection
for my $disconnect (0, 1) {
$schema->storage->_dbh->disconnect if $disconnect;
use warnings;
no warnings 'once';
+BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }
+
use Test::More;
use Test::Exception;
use Try::Tiny;
use strict;
use warnings;
+BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }
+
use Test::More;
use lib qw(t/lib);
use DBICTest;
use strict;
use warnings;
+BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }
+
# !!! do not replace this with done_testing - tests reside in the callbacks
# !!! number of calls is important
use Test::More tests => 13;
use Test::More;
use Test::Exception;
+use DBIx::Class::_Util qw(modver_gt_or_eq sigwarn_silencer);
use lib qw(t/lib);
use DBICTest;
is_deeply( $schema->storage->savepoints, [], 'All savepoints forgotten' );
+SKIP: {
+ skip "Reading inexplicably fails on very old replicated DBD::SQLite<1.33", 1 if (
+ $ENV{DBICTEST_VIA_REPLICATED}
+ and
+ $prefix eq 'SQLite Internal DB'
+ and
+ ! modver_gt_or_eq('DBD::SQLite', '1.33')
+ );
+
ok($ars->search({ name => 'in_outer_transaction' })->first,
'commit from outer transaction');
ok($ars->search({ name => 'in_outer_transaction2' })->first,
is $ars->search({ name => 'in_inner_transaction_rolling_back' })->first,
undef,
'rollback from inner transaction';
+}
### cleanupz
$schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") });
done_testing;
END {
+ local $SIG{__WARN__} = sigwarn_silencer( qr/Internal transaction state of handle/ )
+ unless modver_gt_or_eq('DBD::SQLite', '1.33');
eval { $schema->storage->dbh_do(sub { $_[1]->do("DROP TABLE artist") }) } if defined $schema;
undef $schema;
}
}
}
+BEGIN { $ENV{DBICTEST_VIA_REPLICATED} = 0 }
+
#######
### This is where the test starts
#######