File: 11.t

package info (click to toggle)
libcache-fastmmap-perl 1.58-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 356 kB
  • sloc: ansic: 1,399; perl: 628; makefile: 7
file content (46 lines) | stat: -rw-r--r-- 870 bytes parent folder | download | duplicates (4)
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

#########################

use Test::More tests => 7;
BEGIN { use_ok('Cache::FastMmap') };
use strict;

#########################

# Test recursive cache use

sub get_fc {
my $FC;
$FC = Cache::FastMmap->new(
  cache_not_found => 1,
  serializer => '',
  init_file => 1,
  num_pages => 89,
  page_size => 1024,
  read_cb => sub { $FC->get($_[1] . "1"); },
  write_cb => sub { $FC->set($_[1] . "1", $_[2]); },
  delete_cb => sub { $FC->delete($_[1]); },
  write_action => 'write_back',
  @_
);
return $FC;
}

my $FC = get_fc();
ok( defined $FC );

$FC->set("foo1", "bar");
my $V = eval { $FC->get("foo"); };
ok(!$V, "no return");
like($@, qr/already locked/, "recurse fail");

$FC = undef;

$FC = get_fc(allow_recursive => 1);
ok( defined $FC );

$FC->set("foo1", "bar");
$V = eval { $FC->get("foo"); };
ok(!$@, "recurse success 1");
is($V, "bar", "recurse success 2");