Data-Riak
view release on metacpan or search on metacpan
t/buckets/001-simple.t view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use Try::Tiny;
use Test::Fatal;
use Test::More;
use Test::Data::Riak;
use Data::Riak;
use Data::Riak::Bucket;
skip_unless_riak;
my $riak = riak_transport;
my $bucket_name = create_test_bucket_name;
my $bucket = Data::Riak::Bucket->new({
name => $bucket_name,
riak => $riak
});
is($bucket->count, 0, 'No keys in the bucket');
my $props = $bucket->props;
is(ref $props, 'HASH', '... got back a HASH ref');
$bucket->add('foo', 'bar');
my $obj = $bucket->get('foo');
is($obj->value, 'bar', 'Check the value immediately after insertion');
is($obj->key, 'foo', "Name property is inflated correctly");
is($obj->bucket_name, $bucket_name, "Bucket name property is inflated correctly");
my $e = exception { $bucket->get('foo' => { accept => 'application/json' }) };
ok $e, 'asking for an incompatible content type fails';
isa_ok $e, 'Data::Riak::Exception::ClientError';
is $e->transport_response->code, 406,
'asking for an incompatible content type fails with a 406';
is_deeply(
$bucket->list_keys,
['foo'],
'... got the keys we expected'
);
is($bucket->count, 1, 'One key in the bucket');
$bucket->remove('foo');
try {
$bucket->get('foo')
} catch {
isa_ok $_, 'Data::Riak::Exception::ObjectNotFound';
like $_, qr/Object not found/;
isa_ok $_->request, 'Data::Riak::Request::GetObject';
is $_->request->bucket_name, $bucket_name;
is $_->request->key, 'foo';
is $_->transport_response->code, "404",
"Calling for a value that doesn't exist returns 404";
};
{
sleep 5;
my $res;
is exception { $res = $bucket->remove('foo') }, undef,
( run in 1.929 second using v1.01-cache-2.11-cpan-54e63673c56 )