nginx: additional version check for uwsgi and scgi
[MogileFS-Server.git] / t / fid-stat.t
blob89ee7617ed2f990e99fedf1c6719c734de69fd72
1 # -*-perl-*-
3 use strict;
4 use warnings;
5 use Test::More;
6 use FindBin qw($Bin);
8 use Mogstored::FIDStatter;
9 use File::Temp qw(tempdir);
11 my $td = tempdir(CLEANUP => 1);
12 ok($td, "got tempdir");
13 ok(-d $td, "tempdir is writable");
15 my $n_stats;
16 my $on_fid;
18 my $fs = Mogstored::FIDStatter->new(
19                                     dir  => $td,
20                                     from => 500,
21                                     to   => 1499,
22                                     t_stat => sub { $n_stats++ },
23                                     on_fid => sub { $on_fid->(@_); },
24                                     );
25 ok($fs, "made statter");
27 # empty directory, no stats
29     $n_stats = 0;
30     my @list;
31     $on_fid = sub {
32         push @list, [@_],
33     };
34     $fs->run;
35     is($n_stats, 0, "no stats on empty directory");
36     is(scalar @list, 0, "no contents on empty directory");
39 # make a normal (packed) directory structure
41     for (my $n = 500; $n < 1500; $n += 2) {
42         make_file($n, ($n%50) + 1);
43     }
45     $n_stats = 0;
46     my @list;
47     $on_fid = sub {
48         push @list, [@_],
49     };
50     $fs->run;
51     is($n_stats, 500, "500 stats");
52     is(scalar @list, 500, "500 fids found");
55 # make a sparse directory structure, with huge (64-bit numbers)
57     $n_stats = 0;
58     my @list;
59     make_file("52048709162819278", 50);
60     make_file("52048709163819278", 50);
61     make_file("52048809163819278", 50);
62     make_file("52048819163819278", 50);
63     $fs = Mogstored::FIDStatter->new(
64                                      dir  => $td,
65                                      from => "52048709162819278",
66                                      to   => "52048819163819278",
67                                      t_stat => sub { $n_stats++ },
68                                      on_fid => sub {
69                                          push @list, [@_];
70                                      },
71                                      );
72     $fs->run;
73     is(scalar @list, 4, "found 4 files");
74     is($n_stats, 4, "and statted 4 files");
77 # trick jonathan...
79     $n_stats = 0;
80     my @list;
81     make_file("3001002456", 50);
82     make_file("3001002457", 50);
83     make_file("30010023383333458", 50);
84     make_file("3001002459", 50);
85     $fs = Mogstored::FIDStatter->new(
86                                      dir  => $td,
87                                      from => "3001002456",
88                                      to   => "3001002459",
89                                      t_stat => sub { $n_stats++ },
90                                      on_fid => sub {
91                                          push @list, [@_];
92                                      },
93                                      );
94     $fs->run();
95     is(scalar @list, 3, "found 3 files");
96     is($n_stats, 3, "and statted 3 files");
99 sub make_file {
100     my ($fid, $len) = @_;
101     my $pad = $fid;
102     if (length($pad) < 10) {
103         $pad = "0"x(10-length($pad)) . $pad;
104     }
105     my ($b, $mmm, $ttt, $hto) = ($pad =~ m{(\d)(\d{3})(\d{3})(\d{3})});
106     my $fh;
107     unless (open($fh, ">$td/$b/$mmm/$ttt/$pad.fid")) {
108         if ($!{ENOENT}) {
109             mkdir "$td/$b";
110             mkdir "$td/$b/$mmm";
111             mkdir "$td/$b/$mmm/$ttt";
112         }
113         open($fh, ">$td/$b/$mmm/$ttt/$pad.fid") or die
114             "Error writing file: $td/$b/$mmm/$ttt/$pad.fid: $!\n";
115     }
116     print $fh "x" x (($len % 50) + 1);
117     close($fh) or die;
120 done_testing();