#! /usr/bin/env perl
#testreq: personal
##**************************************************************
##
## Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
## 
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License.  You may
## obtain a copy of the License at
## 
##    http://www.apache.org/licenses/LICENSE-2.0
## 
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##**************************************************************

use CondorTest;
use CondorUtils;
use Check::SimpleJob;

$testname = "job_filexfer_output_van";

# truly const variables in perl
sub IDLE{1};
sub HELD{5};
sub RUNNING{2};

my $job = $$;
my $baseoutfile = "submit_filetrans_output" . "$job";
my $oute = "$baseoutfile"."e.txt";
my $outf = "$baseoutfile"."f.txt";
my $outg = "$baseoutfile"."g.txt";
my $outh = "$baseoutfile"."h.txt";
my $outi = "$baseoutfile"."i.txt";
my $outj = "$baseoutfile"."j.txt";

my $alreadydone=0;

$execute = sub {
	my %args = @_;
	my $cluster = $args{"cluster"};

	CondorTest::debug("Running $cluster\n",1);

};

$success = sub
{
	CondorTest::debug("Base file transfer job!\n",1);
	if(!-f "$oute"){ print "$oute failed to arrive\n"; exit(1)};
	if(!-f "$outf"){ print "$outf failed to arrive\n"; exit(1)};
	if(!-f "$outg"){ print "$outg failed to arrive\n"; exit(1)};
	if(!-f "$outh"){ print "$outh failed to arrive\n"; exit(1)};
	if(!-f "$outi"){ print "$outi failed to arrive\n"; exit(1)};
	if(!-f "$outj"){ print "$outj failed to arrive\n"; exit(1)};
};

$abort = sub {
	CondorTest::debug("Job is gone now, cool.\n",1);
};

$timed = sub
{
	die "Job should have ended by now. file transfer broken!\n";
};

# make some needed files. All 0 sized and xxxxxx.txt for
# easy cleanup

my $job = $$;
CondorTest::debug("Process Id for this script is  $job\n",1);
my $basefile = "submit_filetrans_input" . "$job";
my $in = "$basefile".".txt";
my $ina = "$basefile"."a.txt";
my $inb = "$basefile"."b.txt";
my $inc = "$basefile"."c.txt";

my $inputdir = "job_"."$job"."_dir";

CreateDir("-p $inputdir");
CreateEmptyFile("$inputdir/$in");
CreateEmptyFile("$inputdir/$ina");
CreateEmptyFile("$inputdir/$inb");
CreateEmptyFile("$inputdir/$inc");

my $line = "";
my $args = "--job=$job --long ";


SimpleJob::RunCheck(
    runthis=>"x_job_filexfer_testjob.pl",
    duration=>"$args",
    should_transfer_files=>"YES",
    when_to_transfer_output=>"ON_EXIT",
    on_success=>$success,
    on_execute=>$execute,
    on_abort=>$abort,
);

CondorTest::EndTest();
print scalar localtime() . "\n";

if( $result != 0 )
{
    exit(1);
}

CondorTest::debug("$testname SUCCESS\n",1);
exit(0);
