- 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; |
|
removed EXPERIMENTAL DBIx::C...
|
35 |
my $dbi1; |
- removed EXPERIMENTAL statu...
|
36 |
my $dbi2; |
removed EXPERIMENTAL DBIx::C...
|
37 |
my $dbi3; |
38 |
my @dbis; |
|
39 |
my @results; |
|
- removed EXPERIMENTAL statu...
|
40 | |
41 |
test 'connect'; |
|
42 |
eval { |
|
43 |
$dbi = DBIx::Custom->connect( |
|
removed EXPERIMENTAL DBIx::C...
|
44 |
dsn => "dbi:mysql:database=$database;", |
- removed EXPERIMENTAL statu...
|
45 |
user => $user, |
46 |
password => $password |
|
47 |
); |
|
48 |
}; |
|
49 |
ok(!$@); |
|
50 | ||
51 |
eval { $dbi->do('drop table table1') }; |
|
52 |
$dbi->do('create table table1 (key1 varchar(255), key2 varchar(255)) engine=InnoDB'); |
|
53 |
$dbi->insert({key1 => 1, key2 => 2}, table => 'table1'); |
|
54 | ||
55 |
test 'async test'; |
|
56 | ||
removed EXPERIMENTAL DBIx::C...
|
57 |
require AnyEvent; |
- removed EXPERIMENTAL statu...
|
58 |
my $cond = AnyEvent->condvar; |
59 |
$result = $dbi->execute('SELECT SLEEP(1), 3', undef, |
|
60 |
prepare_attr => {async => 1}, statement => 'select'); |
|
61 | ||
62 |
$dbi2 = DBIx::Custom->connect( |
|
63 |
dsn => "dbi:mysql:database=$database;host=localhost;port=10000", |
|
64 |
user => $user, |
|
65 |
password => $password |
|
66 |
); |
|
67 |
$result2 = $dbi2->select('key1', table => 'table1', prepare_attr => {async => 1}); |
|
68 | ||
69 |
my $timer = AnyEvent->timer( |
|
70 |
interval => 1, |
|
71 |
cb => sub { |
|
72 |
1; |
|
73 |
} |
|
74 |
); |
|
75 | ||
76 |
my $count = 0; |
|
77 | ||
added async asccess and stat...
|
78 |
my $mysql_watcher; |
79 |
$mysql_watcher = AnyEvent->io( |
|
- removed EXPERIMENTAL statu...
|
80 |
fh => $dbi->dbh->mysql_fd, |
81 |
poll => 'r', |
|
82 |
cb => sub { |
|
83 |
my $row = $result->fetch_one; |
|
84 |
is($row->[1], 3, 'before'); |
|
85 |
$cond->send if ++$count == 2; |
|
86 |
undef $result; |
|
added async asccess and stat...
|
87 |
undef $mysql_watcher; |
- removed EXPERIMENTAL statu...
|
88 |
} |
89 |
); |
|
90 | ||
91 |
my $mysql_watcher2= AnyEvent->io( |
|
92 |
fh => $dbi2->dbh->mysql_fd, |
|
93 |
poll => 'r', |
|
94 |
cb => sub { |
|
95 |
my $row = $result2->fetch_one; |
|
96 |
is($row->[0], 1, 'after'); |
|
97 |
$cond->send if ++$count == 2; |
|
98 |
undef $result2; |
|
99 |
} |
|
100 |
); |
|
101 |
$cond->recv; |