Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
57 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,54 +1,86 @@ | |||
use strict; | use strict; | ||
use warnings; | use warnings; | ||
|
|||
use Test::More; | use Test::More; | ||
use JSON::XS; | use JSON::XS; | ||
use Test::Exception; | use Test::Exception; | ||
use AnyEvent::Riak; | use AnyEvent::Riak; | ||
|
|
||
my ($host, $path); | plan tests => 12; | ||
|
|||
my ( $host, $path ); | |||
|
|||
BEGIN { | BEGIN { | ||
my $riak_test = $ENV{RIAK_TEST_SERVER}; | my $riak_test = $ENV{RIAK_TEST_SERVER}; | ||
( $host, $path ) = split ";", $riak_test if $riak_test; | ( $host, $path ) = split ";", $riak_test if $riak_test; | ||
plan skip_all => | plan skip_all => | ||
'set $ENV{RIAK_TEST_SERVER} like this http://127.0.0.1:8098;jiak if you want to run the tests' | 'set $ENV{RIAK_TEST_SERVER} if you want to run the tests' | ||
unless ( $host && $path ); | unless ( $host && $path ); | ||
} | } | ||
|
|
||
my $jiak = AnyEvent::Riak->new( host => $host, path => $path ); | ok my $riak = AnyEvent::Riak->new( host => $host, path => $path ), | ||
'create riak object'; | |||
|
|||
# ping | |||
ok my $ping_one = $riak->is_alive( | |||
sub { | |||
pass "is alive"; | |||
return $_[0]; | |||
} | |||
), 'ping with callback'; | |||
|
|||
ok my $ping_two = $riak->is_alive()->recv, 'ping without callback'; | |||
is $ping_two, 'OK', 'valid response from ping without callback'; | |||
|
|
||
ok my $buckets = $jiak->list_bucket('bar')->recv, "... fetch bucket list"; | ok my $s = $ping_one->recv, 'response from ping without callback'; | ||
is scalar @{ $buckets->{keys} }, '0', '... no keys'; | is $s, 'OK', 'valid response from ping'; | ||
|
|
||
# list bucket | |||
ok my $bucket_cb = $riak->list_bucket( | |||
'bar', | |||
sub { | |||
my $res = JSON::decode_json(shift); | |||
is scalar $res->{keys}, '0', 'no keys'; | |||
} | |||
), | |||
'fetch bucket list'; | |||
|
|||
ok my $buckets = $riak->list_bucket('bar')->recv, "fetch bucket list"; | |||
is scalar @{ $buckets->{keys} }, '0', 'no keys'; | |||
|
|||
$bucket_cb->recv; | |||
|
|||
# set bucket | |||
ok my $new_bucket | ok my $new_bucket | ||
= $jiak->set_bucket( 'foo', { allowed_fields => '*' } )->recv, | = $riak->set_bucket( 'foo', { props => { n_val => 2 } } )->recv, | ||
'... set a new bucket'; | 'set a new bucket'; | ||
|
|
||
my $value = { | my $value = { | ||
bucket => 'foo', | bucket => 'foo', | ||
key => 'bar', | key => 'bar3', | ||
object => { foo => "bar", baz => 1 }, | object => { foo => "bar", baz => 1 }, | ||
links => [] | links => [] | ||
}; | }; | ||
|
|
||
ok my $res = $jiak->store($value)->recv, '... set a new key'; | ok my $res = $riak->store($value)->recv, '... set a new key'; | ||
|
|
||
ok $res = $jiak->fetch( 'foo', 'bar' )->recv, '... fetch our new key'; | ok $res = $riak->fetch( 'foo', 'bar' )->recv, '... fetch our new key'; | ||
ok $res = $jiak->delete( 'foo', 'bar' )->recv, '... delete our key'; | # #ok $res = $riak->delete( 'foo', 'bar' )->recv, '... delete our key'; | ||
|
|
||
dies_ok { $jiak->fetch( 'foo', 'foo' )->recv } '... dies when error'; | # #dies_ok { $riak->fetch( 'foo', 'foo' )->recv } '... dies when error'; | ||
like $@, qr/404/, '... 404 response'; | # #like $@, qr/404/, '... 404 response'; | ||
|
|
||
ok $res = $jiak->store($value)->recv, '... set a new key'; | # #ok $res = $riak->store($value)->recv, '... set a new key'; | ||
my $second_value = { | # #my $second_value = { | ||
bucket => 'foo', | # #bucket => 'foo', | ||
key => 'baz', | # #key => 'baz', | ||
object => { foo => "bar", baz => 2 }, | # #object => { foo => "bar", baz => 2 }, | ||
links => [ [ 'foo', 'bar', 'tagged' ] ], | # #links => [ [ 'foo', 'bar', 'tagged' ] ], | ||
}; | # #}; | ||
ok $res = $jiak->store($second_value)->recv, '... set another new key'; | # #ok $res = $riak->store($second_value)->recv, '... set another new key'; | ||
|
|
||
ok $res = $jiak->walk( 'foo', 'baz', [ { bucket => 'foo', } ] )->recv, | # #ok $res = $riak->walk( 'foo', 'baz', [ { bucket => 'foo', } ] )->recv, | ||
'... walk'; | # #'... walk'; | ||
is $res->{results}->[0]->[0]->{key}, "bar", "... walked to bar"; | # #is $res->{results}->[0]->[0]->{key}, "bar", "... walked to bar"; | ||
|
|
||
done_testing(); | # done_testing(); |