- removed EXPERIMENTAL statu...
|
1 |
use Test::More; |
2 |
use strict; |
|
3 |
use warnings; |
|
4 |
use utf8; |
|
5 | ||
6 |
use FindBin; |
|
7 |
use DBIx::Custom; |
|
8 | ||
9 |
my $dbi; |
|
10 |
my $dsn; |
|
11 |
my $args; |
|
12 |
my $user = 'dbix_custom'; |
|
13 |
my $password = 'dbix_custom'; |
|
14 |
my $database = 'dbix_custom'; |
|
15 | ||
16 |
$dsn = "dbi:mysql:database=$database"; |
|
17 |
$args = {dsn => $dsn, user => $user, password => $password,}; |
|
18 | ||
19 |
plan skip_all => 'mysql private test' unless -f "$FindBin::Bin/run/mysql-async.run" |
|
20 |
&& eval { $dbi = DBIx::Custom->connect($args); 1 }; |
|
21 |
plan 'no_plan'; |
|
22 | ||
23 |
$SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /DEPRECATED/}; |
|
24 | ||
25 |
# Function for test name |
|
26 |
sub test { print "# $_[0]\n" } |
|
27 | ||
28 |
# Varialbes for tests |
|
29 |
my $dbname; |
|
30 |
my $row; |
|
31 |
my $rows; |
|
32 |
my $result; |
|
33 |
my $result2; |
|
34 |
my $model; |
|
35 |
my $dbi2; |
|
36 | ||
37 |
test 'connect'; |
|
38 |
eval { |
|
39 |
$dbi = DBIx::Custom->connect( |
|
40 |
dsn => "dbi:mysql:database=$database;host=localhost;port=10000", |
|
41 |
user => $user, |
|
42 |
password => $password |
|
43 |
); |
|
44 |
}; |
|
45 |
ok(!$@); |
|
46 | ||
47 |
eval { $dbi->do('drop table table1') }; |
|
48 |
$dbi->do('create table table1 (key1 varchar(255), key2 varchar(255)) engine=InnoDB'); |
|
49 |
$dbi->insert({key1 => 1, key2 => 2}, table => 'table1'); |
|
50 | ||
51 |
test 'async test'; |
|
52 | ||
53 |
use AnyEvent; |
|
54 |
use DBI; |
|
55 |
my $cond = AnyEvent->condvar; |
|
56 |
$result = $dbi->execute('SELECT SLEEP(1), 3', undef, |
|
57 |
prepare_attr => {async => 1}, statement => 'select'); |
|
58 | ||
59 |
$dbi2 = DBIx::Custom->connect( |
|
60 |
dsn => "dbi:mysql:database=$database;host=localhost;port=10000", |
|
61 |
user => $user, |
|
62 |
password => $password |
|
63 |
); |
|
64 |
$result2 = $dbi2->select('key1', table => 'table1', prepare_attr => {async => 1}); |
|
65 | ||
66 |
my $timer = AnyEvent->timer( |
|
67 |
interval => 1, |
|
68 |
cb => sub { |
|
69 |
1; |
|
70 |
} |
|
71 |
); |
|
72 | ||
73 |
my $count = 0; |
|
74 | ||
75 |
my $mysql_watcher = AnyEvent->io( |
|
76 |
fh => $dbi->dbh->mysql_fd, |
|
77 |
poll => 'r', |
|
78 |
cb => sub { |
|
79 |
my $row = $result->fetch_one; |
|
80 |
is($row->[1], 3, 'before'); |
|
81 |
$cond->send if ++$count == 2; |
|
82 |
undef $result; |
|
83 |
} |
|
84 |
); |
|
85 | ||
86 |
my $mysql_watcher2= AnyEvent->io( |
|
87 |
fh => $dbi2->dbh->mysql_fd, |
|
88 |
poll => 'r', |
|
89 |
cb => sub { |
|
90 |
my $row = $result2->fetch_one; |
|
91 |
is($row->[0], 1, 'after'); |
|
92 |
$cond->send if ++$count == 2; |
|
93 |
undef $result2; |
|
94 |
} |
|
95 |
); |
|
96 |
$cond->recv; |