DBIx-Custom / t / mysql-async-opt.t /
Newer Older
101 lines | 1.936kb
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
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-opt.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 $dbi1;
36
my $dbi2;
37
my $dbi3;
38
my @dbis;
39
my @results;
40

            
41
test 'connect';
42
eval {
43
  $dbi = DBIx::Custom->connect(
44
    dsn => "dbi:mysql:database=$database;",
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

            
57
require AnyEvent;
58

            
59
my $cond = AnyEvent->condvar;
60

            
61
my $timer = AnyEvent->timer(
62
  interval => 1,
63
  cb => sub {
64
    1;
65
  }
66
);
67

            
68
my $count = 0;
69

            
added EXPERIMETNAL aysnc_con...
Yuki Kimoto authored on 2012-02-10
70
$dbi->async_conf({
71
  prepare_attr => {async => 1},
72
  fh => sub { shift->dbh->mysql_fd }
73
});
74

            
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
75
$dbi->execute('SELECT SLEEP(1), 3', undef,
added EXPERIMETNAL aysnc_con...
Yuki Kimoto authored on 2012-02-10
76
  select => 1,
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
77
  async => sub {
78
    my ($dbi, $result) = @_;
79
    my $row = $result->fetch_one;
80
    is($row->[1], 3, 'before');
81
    $cond->send if ++$count == 2;
82
  }
83
);
84

            
added EXPERIMETNAL aysnc_con...
Yuki Kimoto authored on 2012-02-10
85
$dbi->select('key1', table => 'table1',
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
86
  async => sub {
87
    my ($dbi, $result) = @_;
88
    my $row = $result->fetch_one;
89
    is($row->[0], 1, 'after1');
added EXPERIMETNAL aysnc_con...
Yuki Kimoto authored on 2012-02-10
90
    $dbi->select('key1', table => 'table1',
added async asccess and stat...
Yuki Kimoto authored on 2012-01-29
91
      async => sub {
92
        my ($dbi, $result) = @_;
93
        my $row = $result->fetch_one;
94
        is($row->[0], 1, 'after2');
95
        $cond->send if ++$count == 2;
96
      }
97
    )
98
  }
99
);
100

            
101
$cond->recv;