Changeset 763

Show
Ignore:
Timestamp:
03/08/07 20:45:01 (2 years ago)
Author:
hachi
Message:

Testing most of the actions we can do so far.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/filepaths-20070306/server/t/20-filepaths.t

    r758 r763  
    2828my $sto = eval { temp_store(); }; 
    2929if ($sto) { 
    30     plan tests => 16
     30    plan tests => 18
    3131} else { 
    3232    plan skip_all => "Can't create temporary test database: $@"; 
     
    6464ok($tmptrack->mogadm("device", "add", "host", 1), "created dev1 on host"); 
    6565 
    66 ok($mogc->enable_filepaths, "Filepaths enabled successfully"); 
     66ok($mogc->filepaths_enable, "Filepaths enabled successfully"); 
    6767 
    6868# wait for monitor 
     
    7575} 
    7676 
    77 __END__ 
     77my $data = "My test file.\n" x 1024; 
    7878 
    7979# create one sample file 
    80 my $fh = $mogc->new_file("file1", "2copies"); 
    81 ok($fh, "got filehandle"); 
    82 unless ($fh) { 
    83     die "Error: " . $mogc->errstr; 
     80
     81    my $fh = $mogc->new_file("/bar/file1.txt", "test"); 
     82    ok($fh, "got filehandle"); 
     83    unless ($fh) { 
     84        die "Error: " . $mogc->errstr; 
     85    } 
     86 
     87    print $fh $data; 
     88    ok(close($fh), "closed file"); 
    8489} 
    8590 
    86 my $data = "My test file.\n" x 1024; 
    87 print $fh $data; 
    88 ok(close($fh), "closed file"); 
    89  
    90 # wait for it to replicate 
    91 my $tries = 1; 
    92 my @urls; 
    93 while ($tries++ < 30 && (@urls = $mogc->get_paths("file1")) < 2) { 
    94     sleep .25; 
    95 
    96 is(scalar @urls, 2, "replicated to 2 paths"); 
    97 my $to_repl_rows = $dbh->selectrow_array("SELECT COUNT(*) FROM file_to_replicate"); 
    98 is($to_repl_rows, 0, "no more files to replicate"); 
    99  
    100 my %stats; 
    101 for (1..100) { 
    102     @urls = $mogc->get_paths("file1"); 
    103     my ($devno) = $urls[0] =~ m!/dev(\d+)/!; 
    104     $stats{$devno}++; 
     91
     92    my $fh = $mogc->new_file("foo.txt", "test"); 
     93    is($fh, undef, "File without absolute path should fail to be created"); 
    10594} 
    10695 
    107 ok($stats{1} < 15, "Device 1 should get roughly 5% of traffic, got: $stats{1}"); 
    108 ok($stats{2} > 80, "Device 2 should get roughly 95% of traffic, got: $stats{2}"); 
     96
     97    my $dir = $mogc->list_directory('/'); 
     98    ok($dir, "Got a directory listing for/"); 
     99    ok(!$dir->{'foo.txt'}, "foo.txt didn't end up in the listing"); 
     100    my $bar = $dir->{'bar'}; 
     101    ok($bar, "/bar is in the listing"); 
     102    is($bar, "D", "/bar is a directory"); 
     103
    109104 
     105{ 
     106    my $dir = $mogc->list_directory('/bar'); 
     107    ok($dir, "Got directory listing for /bar"); 
     108    my $file1 = $dir->{'file1.txt'}; 
     109    ok($file1, "/file1.txt is in the listing"); 
     110    is($dir->{'file1.txt'}, "F:" . length($data), "/file1.txt is a file and has the correct length"); 
     111} 
     112 
     113ok($mogc->filepaths_disable, "Filepaths disabled successfully");