5 use Test::More tests => 60;
6 use Data::Dump qw(dump);
10 use_ok 'CloudStore::Gearman';
12 my $hostname = `hostname -s`;
14 $hostname =~ s/-dev// && warn "# fix hostname for development";
17 my ( $function, $args ) = @_;
18 ok( my $o = CloudStore::Gearman->gearman_do( @_ ), join(' ',@_) );
19 diag "result = ",dump $o if $ENV{DEBUG};
25 CloudStore::Gearman->gearman_do( file_size => $file );
28 sub test_refresh_file_list {
30 ok ! file_exists( "~$login/.meta/files" ), "refresh_file_list removed .meta/files";
31 gearman list_files => "~$login";
34 my $quota = 5 * 1024 * 1024;
36 my $u1 = gearman 'create_user' => 'test@example.com secret ' . $quota;
37 like $u1, qr/u\d+/, "login $u1";
38 my $u2 = gearman 'create_user' => 'test2@example.com secret ' . ($quota + 1);
39 like $u2, qr/u\d+/, "login $u2";
40 my $u3 = gearman 'create_user' => 'slice2@example.com secret ' . ($quota + 2);
41 like $u3, qr/u\d+/, "login $u2 (on other slice)";
43 foreach my $login ( $u1, $u2, $u3 ) {
44 my $o = gearman $hostname . '_s1_quota_get' => $login;
46 cmp_ok $o, '=~', qr/^(\d+)\s+(\d+)$/, 'format: used quota';
49 gearman( 'user_usage' => $u1 );
51 gearman( $hostname . '_s1_torrent_list' );
53 diag "create .meta/files if it doesn't exist";
54 foreach my $login ( $u1, $u2 ) {
55 gearman list_files => "~$login";
56 ok file_exists "~$login/.meta/files", "file_exists ~$login/.meta/files";
59 if ( ! file_exists("~$u1/foo.txt") ) {
60 diag "create ~$u1/foo.txt";
61 $ENV{RSYNC_PASSWORD} ||= 'secret';
62 system('rsync', '-vv', $0, "rsync://$u1\@127.0.0.1:6501/$u1/" );
63 gearman rename_file => "~$u1/Gearman.t#foo.txt";
65 file_exists("~$u1/foo.txt") || BAIL_OUT("~$u1/foo.txt is required for rest of tests");
68 my $md5 = gearman( 'md5_get' => "~$u1/foo.txt" );
69 diag "md5_get = $md5";
71 gearman send_file => "~$u1/foo.txt#~$u2/dir with space/file with space";
72 test_refresh_file_list "$u2";
74 cmp_ok gearman( 'md5_get' => "~$u2/dir with space/file with space" ), 'eq', $md5, "md5_get on send_file to $u2";
76 my $files = gearman list_files => "~$u2";
77 like $files, qr|dir with space/file with space|, 'found sent file in list_files';
79 gearman send_file => "~$u2/dir with space/file with space#~$u3/another dir with spaces/and file with spaces";
80 test_refresh_file_list "$u3";
82 cmp_ok gearman( 'md5_get' => "~$u3/another dir with spaces/and file with spaces" ), 'eq', $md5, "md5_get on send_file to $u3";
84 gearman delete => "~$u2/dir with space/file with space";
85 test_refresh_file_list "$u2";
87 gearman delete => "~$u3/another dir with spaces/and file with spaces";
88 test_refresh_file_list "$u3";
90 gearman send_file => "~$u1/foo.txt#~$u2/foo.txt";
91 test_refresh_file_list "$u2";
93 gearman rename_file => "~$u2/foo.txt#bar.txt";
94 test_refresh_file_list "$u2";
95 gearman rename_file => "~$u2/bar.txt#baz.txt";
96 test_refresh_file_list "$u2";
99 gearman( file_size => "~$u1/foo.txt" ), '==',
100 gearman( file_size => "~$u2/baz.txt" ), 'size_same';
102 diag "test symlink to other shard";
103 gearman send_file => "~$u1/foo.txt#~$u3/foo.txt";
105 gearman( file_size => "~$u1/foo.txt" ), '==',
106 gearman( file_size => "~$u3/foo.txt" ), 'cross-slice symlink size same';
107 test_refresh_file_list "$u3";
109 gearman delete => "~$u2/baz.txt";
110 test_refresh_file_list "$u2";
112 ok ! file_exists "~$u2/baz.txt", 'deleted file size';