| 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"); |
|---|
| 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"); |
|---|
| 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 | } |
|---|
| | 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 | |
|---|
| | 113 | ok($mogc->filepaths_disable, "Filepaths disabled successfully"); |
|---|