summary refs log tree commit diff
path: root/t/10_async.t
blob: 06e1f1a56e6c4d772d3989bf6b78072fa6b49935 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use strict;
use warnings;

use Test::More;
use JSON::XS;
use Test::Exception;
use AnyEvent::Riak;
use YAML::Syck;

#plan tests => 15;

my ( $host, $path );

BEGIN {
    my $riak_test = $ENV{RIAK_TEST_SERVER};
    ($host, $path) = split ";", $riak_test if $riak_test;
    plan skip_all => 'set $ENV{RIAK_TEST_SERVER} if you want to run the tests'
      unless ($host && $path);
}



my $bucket = 'test';

ok my $riak = AnyEvent::Riak->new(
    host => $host,
    path => $path,
    w    => 1,
    dw   => 1
  ),
  'create riak object';

my $cv = AnyEvent->condvar;
$cv->begin(sub { $cv->send });
$cv->begin;

# ping
$riak->is_alive(
    callback => sub {
        my $res = shift;
        pass "is alive in cb" if $res;
    }
);

# list bucket
$riak->list_bucket(
    'bar',
    parameters => {props => 'true', keys => 'true'},
    callback   => sub {
        my $res = shift;
        ok $res->{props}, 'got props';
        is scalar @{$res->{keys}}, 0, '0 keys in cb';
    }
);

my $value = {foo => 'bar',};

# store object
$riak->store(
    'foo', 'bar3', $value,
    callback => sub {
        pass "store value ok";
        $riak->fetch(
            'foo', 'bar3',
            callback => sub {
                my $body = shift;
                is_deeply($body, $value, 'value is ok in cb');
                $cv->end;
            }
        );
    }
);

$cv->end;
$cv->recv;

done_testing();