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
|
use lib 't/lib';
use Test::More;
use Test::Riak;
# JS source map reduce
test_riak {
my ($client, $bucket_name) = @_;
my $bucket = $client->bucket($bucket_name);
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';
};
# JS source map reduce
test_riak {
my ($client, $bucket_name) = @_;
my $bucket = $client->bucket($bucket_name);
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";
};
# JS named map reduce
test_riak {
my ($client, $bucket_name) = @_;
my $bucket = $client->bucket($bucket_name);
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];
};
# JS bucket map reduce
test_riak {
my ($client, $bucket_name) = @_;
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];
};
# JS map reduce from object
test_riak {
my ($client, $bucket_name) = @_;
my $bucket = $client->bucket($bucket_name);
$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';
};
|