7 use Time::HiRes qw(sleep);
16 find_mogclient_or_skip();
18 # create temp mysql db,
19 # use mogadm to init it,
20 # mogstored on temp dir,
21 # register mogstored temp dir,
26 plan skip_all => "Filepaths plugin has been separated from the server, a bit of work is needed to make the tests run again.";
29 my $sto = eval { temp_store(); };
33 plan skip_all => "Can't create temporary test database: $@";
41 my $mogroot = File::Temp::tempdir( CLEANUP => 1 );
42 mkdir("$mogroot/dev1") or die "Failed to create dev1 dir: #!";
44 my $ms = create_mogstored("127.0.1.1", $mogroot);
46 while (! -e "$mogroot/dev1/usage") {
47 print "Waiting on usage...\n";
51 local $ENV{PERL5OPT} = "-MMogileFS::Plugin::FilePaths";
52 my $tmptrack = create_temp_tracker($sto, ["--plugins=FilePaths"]);
55 my $mogc = MogileFS::Client->new(
57 hosts => [ "127.0.0.1:7001" ],
59 my $be = $mogc->{backend}; # gross, reaching inside of MogileFS::Client
61 # test some basic commands to backend
62 ok($tmptrack->mogadm("domain", "add", "testdom"), "created test domain");
63 ok($tmptrack->mogadm("class", "add", "testdom", "test", "--mindevcount=1"), "created test class in testdom");
64 ok($tmptrack->mogadm("host", "add", "host", "--ip=127.0.1.1", "--status=alive"), "created host");
65 ok($tmptrack->mogadm("device", "add", "host", 1), "created dev1 on host");
67 ok($mogc->filepaths_enable, "Filepaths enabled successfully");
71 my $was = $be->{timeout}; # can't use local on phash :(
73 ok($be->do_request("do_monitor_round", {}), "waited for monitor")
74 or die "Failed to wait for monitor";
75 $be->{timeout} = $was;
78 my $data = "My test file.\n" x 1024;
80 # create one sample file
82 my $fh = $mogc->new_file("/bar/file1.txt", "test");
83 ok($fh, "got filehandle");
85 die "Error: " . $mogc->errstr;
89 ok(close($fh), "closed file");
93 my $fh = $mogc->new_file("foo.txt", "test");
94 is($fh, undef, "File without absolute path should fail to be created");
98 my $dir = $mogc->filepaths_list_directory('/');
99 ok($dir, "Got a directory listing for /");
102 my $filecount = $dir->{files};
104 for (my $i = 0; $i < $filecount; $i++) {
105 my $prefix = "file$i";
107 $nodeinfo{type} = $dir->{"$prefix.type"};
108 my $filename = $dir->{$prefix};
109 $files{$filename} = \%nodeinfo;
111 ok(!$files{'foo.txt'}, "foo.txt didn't end up in the listing");
112 my $bar = $files{'bar'};
113 ok($bar, "/bar is in the listing");
114 is($bar->{type}, "D", "/bar is a directory");
118 my $dir = $mogc->filepaths_list_directory('/bar');
119 ok($dir, "Got directory listing for /bar");
122 my $filecount = $dir->{files};
124 for (my $i = 0; $i < $filecount; $i++) {
125 my $prefix = "file$i";
127 $nodeinfo{type} = $dir->{"$prefix.type"};
128 $nodeinfo{size} = $dir->{"$prefix.size"};
129 my $filename = $dir->{$prefix};
130 $files{$filename} = \%nodeinfo;
133 my $file1 = $files{'file1.txt'};
134 ok($file1, "/file1.txt is in the listing");
135 is($file1->{type}, "F", "Type of file1.txt is correct");
136 is($file1->{size}, length($data), "Size of file1.txt is correct");
139 ok($mogc->filepaths_disable, "Filepaths disabled successfully");