summaryrefslogtreecommitdiff
path: root/t/01_basic.t
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--t/01_basic.t171
1 files changed, 74 insertions, 97 deletions
diff --git a/t/01_basic.t b/t/01_basic.t
index f55a263..f3f3dda 100644
--- a/t/01_basic.t
+++ b/t/01_basic.t
@@ -4,9 +4,11 @@ use Test::More;
use Net::Riak;
use YAML::Syck;
+
+
my $host = 'http://localhost:8098';
my $bucket_name = 'test4';
-my $bucket_multi = 'multiBucket1';
+my $bucket_multi = 'multiBucket2';
# is alive
{
@@ -46,7 +48,7 @@ my $bucket_multi = 'multiBucket1';
ok $obj->exists, 'object exists';
$obj->delete;
$obj->load;
- ok !$obj->exists;
+ ok !$obj->exists, "object don't exists anymore";
}
# test set bucket properties
@@ -58,7 +60,7 @@ my $bucket_multi = 'multiBucket1';
$bucket->n_val(3);
is $bucket->n_val, 3, 'n_val is set to 3';
$bucket->set_properties({allow_mult => "False", "n_val" => 2});
- ok !$bucket->allow_multiples;
+ ok !$bucket->allow_multiples, "don't allow multiple anymore";
is $bucket->n_val, 2, 'n_val is set to 2';
}
@@ -73,61 +75,57 @@ my $bucket_multi = 'multiBucket1';
for(1..5) {
my $client = Net::Riak->new();
my $bucket = $client->bucket($bucket_multi);
- my $rand = int(rand(100));
- $obj = $bucket->new_object('foo', [$rand]);
+ $obj = $bucket->new_object('foo', [int(rand(100))]);
$obj->store;
}
- # my $siblings_count = $obj->get_siblings;
- # is $siblings_count, 5, 'got 5 siblings';
- # my $obj3 = $obj->sibling(3);
- # XXX FIXME
- # $obj3 = $obj3->sibling(3);
- # $obj3->store;
- # $obj->reload;
- # is_deeply $obj3->data, $obj->data;
- # $obj->delete;
+ # check we got 5 siblings
+ ok $obj->has_siblings, 'object has siblings';
+ $obj = $bucket->get('foo');
+ my $siblings_count = $obj->get_siblings;
+ is $siblings_count, 5, 'got 5 siblings';
+ # test set/get
+ my @siblings = $obj->siblings;
+ my $obj3 = $obj->sibling(3);
+ is_deeply $obj3->data, $obj->sibling(3)->data;
+ $obj3 = $obj->sibling(3);
+ $obj3->store;
+ $obj->load;
+ is_deeply $obj->data, $obj3->data;
+ $obj->delete;
}
# test js source map
{
my $client = Net::Riak->new();
my $bucket = $client->bucket($bucket_name);
- my $obj = $bucket->new_object('foo', [2]);
- $obj->store;
- my $map_reduce = $client->add($bucket_name, 'foo');
- $map_reduce->map("function (v) {return [JSON.parse(v.values[0].data)];}");
- my $result = $map_reduce->run();
+ my $obj = $bucket->new_object('foo', [2])->store;
+ my $result =
+ $client->add($bucket_name, 'foo')
+ ->map("function (v) {return [JSON.parse(v.values[0].data)];}")->run;
is_deeply $result, [[2]], 'got valid result';
}
-# javascript named map
-{
- my $client = Net::Riak->new();
- my $bucket = $client->bucket($bucket_name);
- my $obj = $bucket->new_object('foo', [2]);
- my $map_reduce = $client->add("bucket", "foo");
- $map_reduce->map("Riak.mapValuesJson");
- my $result = $map_reduce->run;
- use YAML::Syck;
- warn Dump $result;
-}
+# XXX javascript named map
+# {
+# my $client = Net::Riak->new();
+# my $bucket = $client->bucket($bucket_name);
+# my $obj = $bucket->new_object('foo', [2])->store;
+# my $result = $client->add("bucket", "foo")->map("Riak.mapValuesJson")->run;
+# use YAML; warn Dump $result;
+# is_deeply $result, [[2]], 'got valid result';
+# }
# javascript source map reduce
{
my $client = Net::Riak->new();
my $bucket = $client->bucket($bucket_name);
- my $obj = $bucket->new_object('foo', [2]);
- $obj->store;
- $obj = $bucket->new_object('bar', [3]);
- $obj->store;
- $bucket->new_object('baz', [4]);
- $obj->store;
- my $map_reduce = $client->add($bucket_name, "foo");
- $map_reduce->add($bucket_name, "bar");
- $map_reduce->add($bucket_name, "baz");
- $map_reduce->map("function (v) { return [1]; }");
- $map_reduce->reduce("function (v) { return [v.length]; }");
- my $result = $map_reduce->run;
+ my $obj = $bucket->new_object('foo', [2])->store;
+ $obj = $bucket->new_object('bar', [3])->store;
+ $bucket->new_object('baz', [4])->store;
+ my $result =
+ $client->add($bucket_name, "foo")->add($bucket_name, "bar")
+ ->add($bucket_name, "baz")->map("function (v) { return [1]; }")
+ ->reduce("function (v) { return [v.length]; }")->run;
is $result->[0], 3, "success map reduce";
}
@@ -135,49 +133,37 @@ my $bucket_multi = 'multiBucket1';
{
my $client = Net::Riak->new();
my $bucket = $client->bucket($bucket_name);
- my $obj = $bucket->new_object("foo", [2]);
- $obj->store;
- $obj = $bucket->new_object("bar", [3]);
- $obj->store;
- $obj = $bucket->new_object("baz", [4]);
- $obj->store;
- my $map_reduce = $client->add($bucket_name, "foo");
- $map_reduce->add($bucket_name, "bar");
- $map_reduce->add($bucket_name, "baz");
- $map_reduce->map("Riak.mapValuesJson");
- $map_reduce->reduce("Riak.reduceSum");
- my $result = $map_reduce->run();
-# is $result->[0], 243; # ????
+ my $obj = $bucket->new_object("foo", [2])->store;
+ $obj = $bucket->new_object("bar", [3])->store;
+ $obj = $bucket->new_object("baz", [4])->store;
+ my $result =
+ $client->add($bucket_name, "foo")->add($bucket_name, "bar")
+ ->add($bucket_name, "baz")->map("Riak.mapValuesJson")
+ ->reduce("Riak.reduceSum")->run();
+ ok $result->[0];
}
# javascript bucket map reduce
{
my $client = Net::Riak->new();
- my $bucket = $client->bucket($bucket_name);
- my $obj = $bucket->new_object("foo", [2]);
- $obj->store;
- $obj = $bucket->new_object("bar", [3]);
- $obj->store;
- $obj = $bucket->new_object("baz", [4]);
- $obj->store;
- my $map_reduce = $client->add($bucket->name);
- $map_reduce->map("Riak.mapValuesJson");
- $map_reduce->reduce("Riak.reduceSum");
- my $result = $map_reduce->run;
- ok 1, "ici";
-# is $result->[0], 243;
+ my $bucket = $client->bucket("bucket_".int(rand(10)));
+ $bucket->new_object("foo", [2])->store;
+ $bucket->new_object("bar", [3])->store;
+ $bucket->new_object("baz", [4])->store;
+ my $result =
+ $client->add($bucket->name)->map("Riak.mapValuesJson")
+ ->reduce("Riak.reduceSum")->run;
+ ok $result->[0];
}
# javascript map reduce from object
{
my $client = Net::Riak->new();
my $bucket = $client->bucket($bucket_name);
- my $obj = $bucket->new_object("foo", [2]);
- $obj->store;
- $obj = $bucket->get("foo");
- my $map_reduce = $obj->map("Riak.mapValuesJson");
- my $result = $map_reduce->run();
- is_deeply $result->[0], [2];
+ $bucket->new_object("foo", [2])->store;
+ my $obj = $bucket->get("foo");
+ my $result = $obj->map("Riak.mapValuesJson")->run;
+ is_deeply $result->[0], [2], 'valid content';
}
# store and get links
@@ -185,42 +171,33 @@ my $bucket_multi = 'multiBucket1';
my $client = Net::Riak->new();
my $bucket = $client->bucket($bucket_name);
my $obj = $bucket->new_object("foo", [2]);
- my $obj1 = $bucket->new_object("foo1", {test => 1});
- $obj1->store;
- my $obj2 = $bucket->new_object("foo2", {test => 2});
- $obj2->store;
- my $obj3 = $bucket->new_object("foo3", {test => 3});
- $obj3->store;
+ my $obj1 = $bucket->new_object("foo1", {test => 1})->store;
+ my $obj2 = $bucket->new_object("foo2", {test => 2})->store;
+ my $obj3 = $bucket->new_object("foo3", {test => 3})->store;
$obj->add_link($obj1);
$obj->add_link($obj2, "tag");
$obj->add_link($obj3, "tag2!@&");
$obj->store;
$obj = $bucket->get("foo");
- my $mr = $obj->link("bucket");
- my $results = $mr->run();
- # XXX fixme !!
- use YAML::Syck; warn Dump $results;
+ my $count = $obj->count_links;
+ is $count, 3, 'got 3 links';
}
# link walking
{
my $client = Net::Riak->new();
my $bucket = $client->bucket($bucket_name);
- my $obj = $bucket->new_object("foo", [2]);
- my $obj1 = $bucket->new_object("foo1", {test => 1});
- $obj1->store;
- my $obj2 = $bucket->new_object("foo2", {test => 2});
- $obj2->store;
- my $obj3 = $bucket->new_object("foo3", {test => 3});
- $obj3->store;
- $obj->add_link($obj1);
- $obj->add_link($obj2, "tag");
- $obj->add_link($obj3, "tag2!@&");
+ my $obj = $bucket->new_object("foo", [2]);
+ my $obj1 = $bucket->new_object("foo1", {test => 1})->store;
+ my $obj2 = $bucket->new_object("foo2", {test => 2})->store;
+ my $obj3 = $bucket->new_object("foo3", {test => 3})->store;
+ $obj->add_link($obj1)->add_link($obj2, "tag")->add_link($obj3, "tag2!@&");
$obj->store;
$obj = $bucket->get("foo");
- my $mr = $obj->link("bucket");
- my $results = $mr->run();
- use YAML::Syck; warn Dump $results;
+ my $results = $obj->link($bucket_name)->run();
+ is scalar @$results, 3, 'got 3 links via links walking';
+ $results = $obj->link($bucket_name, 'tag')->run;
+ is scalar @$results, 1, 'got one link via link walking';
}
done_testing;